his_api_controller.go 402KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. }
  85. func (c *HisApiController) GetBatchSettleAccounts() {
  86. order_ids := c.GetString("order_ids")
  87. admin_user_id, _ := c.GetInt64("admin_user_id")
  88. adminUser := c.GetAdminUserInfo()
  89. orders := strings.Split(order_ids, ",")
  90. var newOrders []models.Orders
  91. for _, item := range orders {
  92. order, _ := service.GetHisOrderByIDTenOne(item)
  93. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  94. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  95. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  96. orderInfos = append(orderInfos, orderInfos_two...)
  97. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  98. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  99. var diagnosis_ids []string
  100. if his.ID > 0 {
  101. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  102. } else {
  103. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  104. }
  105. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  106. var dia_config []*models.HisXtDiagnoseConfig
  107. var name string
  108. for _, item := range diagnosis_ids {
  109. id, _ := strconv.ParseInt(item, 10, 64)
  110. diagnosisConfig, _ := service.FindDiagnoseById(id)
  111. dia_config = append(dia_config, diagnosisConfig)
  112. if len(name) == 0 {
  113. name = diagnosisConfig.ClassName
  114. } else {
  115. name = name + "," + diagnosisConfig.ClassName
  116. }
  117. }
  118. var bedCostTotal float64 = 0 //床位总费
  119. var bedCostSelfTotal float64 = 0 //床位自费
  120. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  121. var bedSelfTotal float64 = 0 //床位部分项目自费
  122. var bedInscpTotal float64 = 0 //床位部分项目自费
  123. var operationCostTotal float64 = 0 //手术费
  124. var operationCostSelfTotal float64 = 0 //手术费
  125. var operationCostPartSelfTotal float64 = 0 //手术费
  126. var operationSelfTotal float64 = 0 //床位部分项目自费
  127. var operationInscpTotal float64 = 0 //床位部分项目自费
  128. var otherCostTotal float64 = 0 //其他费用
  129. var otherCostSelfTotal float64 = 0 //其他费用
  130. var otherCostPartSelfTotal float64 = 0 //其他费用
  131. var otherSelfTotal float64 = 0 //床位部分项目自费
  132. var otherInscpTotal float64 = 0 //床位部分项目自费
  133. var materialCostTotal float64 = 0 //材料费
  134. var materialCostSelfTotal float64 = 0 //材料费
  135. var materialCostPartSelfTotal float64 = 0 //材料费
  136. var materialSelfTotal float64 = 0 //床位部分项目自费
  137. var materialInscpTotal float64 = 0 //床位部分项目自费
  138. var westernMedicineCostTotal float64 = 0 //西药费
  139. var westernMedicineCostSelfTotal float64 = 0 //西药费
  140. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  141. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  142. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  143. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  144. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  145. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  146. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  147. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  148. var checkCostTotal float64 = 0 //检查费
  149. var checkCostSelfTotal float64 = 0 //检查费
  150. var checkCostPartSelfTotal float64 = 0 //检查费
  151. var checkSelfTotal float64 = 0 //床位部分项目自费
  152. var checkInscpTotal float64 = 0 //床位部分项目自费
  153. var laboratoryCostTotal float64 = 0 //化验费
  154. var laboratoryCostSelfTotal float64 = 0 //化验费
  155. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  156. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  157. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  158. var treatCostTotal float64 = 0 //治疗费用
  159. var treatCostSelfTotal float64 = 0 //治疗费用
  160. var treatCostPartSelfTotal float64 = 0 //治疗费用
  161. var treatSelfTotal float64 = 0 //床位部分项目自费
  162. var treatInscpTotal float64 = 0 //床位部分项目自费
  163. decimal.DivisionPrecision = 2
  164. for _, item := range orderInfos {
  165. if item.MedChrgitmType == "01" { //床位费
  166. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  167. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  168. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  169. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  170. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  171. }
  172. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  173. if item.MedChrgitmType == "03" { //检查费
  174. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  175. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  176. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  177. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  178. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  179. }
  180. } else {
  181. if item.MedChrgitmType == "03" { //检查费
  182. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  183. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  184. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  185. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  186. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  187. }
  188. }
  189. if item.MedChrgitmType == "04" { //化验费
  190. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  191. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  192. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  193. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  194. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  195. }
  196. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  197. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  198. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  199. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  200. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  201. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  202. }
  203. if item.MedChrgitmType == "06" { //手术费
  204. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  205. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  206. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  207. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  208. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  209. }
  210. if item.MedChrgitmType == "08" { //材料费
  211. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  212. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  213. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  214. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  215. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  216. }
  217. if item.MedChrgitmType == "09" { //西药费
  218. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  219. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  220. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  221. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  222. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  223. }
  224. if item.MedChrgitmType == "11" { //中成费
  225. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  226. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  227. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  228. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  229. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  230. }
  231. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  232. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  233. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  234. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  235. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  236. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  237. }
  238. }
  239. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  240. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  241. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  242. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  243. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  244. var doctor_name string
  245. if roles.ID == 0 {
  246. doctor_name = "管理员"
  247. } else {
  248. doctor_name = roles.UserName
  249. }
  250. yiliao_leibie := ""
  251. switch order.MedType {
  252. case "11":
  253. yiliao_leibie = "普通门诊"
  254. break
  255. case "12":
  256. yiliao_leibie = "门诊挂号"
  257. break
  258. case "13":
  259. yiliao_leibie = "急诊"
  260. break
  261. case "14":
  262. yiliao_leibie = "门诊特殊病"
  263. break
  264. case "15":
  265. yiliao_leibie = "门诊统筹"
  266. break
  267. case "16":
  268. yiliao_leibie = "门诊慢性病"
  269. break
  270. case "21":
  271. yiliao_leibie = "普通住院"
  272. break
  273. }
  274. var newOrder models.Orders
  275. newOrder.Diagnosis = name
  276. newOrder.OrderInfos = orderInfos
  277. newOrder.Number = order.MdtrtId
  278. newOrder.Date = order.SettleAccountsDate
  279. newOrder.ChargeAdmin = charge_admin
  280. newOrder.PrintorAdmin = printor_admin
  281. newOrder.Order = order
  282. newOrder.BedCostTotal = bedCostTotal
  283. newOrder.BedCostSelfTotal = bedCostSelfTotal
  284. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  285. newOrder.BedSelfTotal = bedSelfTotal
  286. newOrder.BedInscpTotal = bedInscpTotal
  287. newOrder.OperationCostTotal = operationCostTotal
  288. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  289. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  290. newOrder.OperationSelfTotal = operationSelfTotal
  291. newOrder.OperationInscpTotal = operationInscpTotal
  292. newOrder.OtherCostTotal = otherCostTotal
  293. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  294. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  295. newOrder.OtherSelfTotal = otherSelfTotal
  296. newOrder.OtherInscpTotal = otherInscpTotal
  297. newOrder.MaterialCostTotal = materialCostTotal
  298. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  299. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  300. newOrder.MaterialSelfTotal = materialSelfTotal
  301. newOrder.MaterialInscpTotal = materialInscpTotal
  302. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  303. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  304. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  305. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  306. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  307. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  308. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  309. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  310. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  311. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  312. newOrder.CheckCostTotal = checkCostTotal
  313. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  314. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  315. newOrder.CheckSelfTotal = checkSelfTotal
  316. newOrder.CheckInscpTotal = checkInscpTotal
  317. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  318. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  319. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  320. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  321. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  322. newOrder.TreatCostTotal = treatCostTotal
  323. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  324. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  325. newOrder.TreatSelfTotal = treatSelfTotal
  326. newOrder.TreatInscpTotal = treatInscpTotal
  327. newOrder.DoctorInfo = doctor_info
  328. newOrder.DoctorName = doctor_name
  329. newOrder.HealthCardNo = order.PsnNo
  330. newOrder.YiliaoLeibie = yiliao_leibie
  331. newOrder.Patient = patient
  332. newOrder.OrgName = miConfig.OrgName
  333. newOrder.OrgCode = miConfig.Code
  334. newOrder.OrderNumber = order.Number
  335. newOrder.HisPatient = his
  336. newOrder.DiaConfig = dia_config
  337. newOrders = append(newOrders, newOrder)
  338. }
  339. c.ServeSuccessJSON(map[string]interface{}{
  340. "orders": newOrders,
  341. })
  342. }
  343. func (c *HisApiController) GetTestOrder() {
  344. order_id, _ := c.GetInt64("order_id")
  345. admin_user_id, _ := c.GetInt64("admin_user_id")
  346. adminUser := c.GetAdminUserInfo()
  347. order, _ := service.GetHisOrderByID(order_id)
  348. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  349. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  350. orderInfos = append(orderInfos, orderInfos_two...)
  351. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  352. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  353. var dia_config []*models.HisXtDiagnoseConfig
  354. var name string
  355. var bedCostTotal float64 = 0 //床位总费
  356. var bedCostSelfTotal float64 = 0 //床位自费
  357. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  358. var bedSelfTotal float64 = 0 //床位部分项目自费
  359. var bedInscpTotal float64 = 0 //床位部分项目自费
  360. var operationCostTotal float64 = 0 //手术费
  361. var operationCostSelfTotal float64 = 0 //手术费
  362. var operationCostPartSelfTotal float64 = 0 //手术费
  363. var operationSelfTotal float64 = 0 //床位部分项目自费
  364. var operationInscpTotal float64 = 0 //床位部分项目自费
  365. var otherCostTotal float64 = 0 //其他费用
  366. var otherCostSelfTotal float64 = 0 //其他费用
  367. var otherCostPartSelfTotal float64 = 0 //其他费用
  368. var otherSelfTotal float64 = 0 //床位部分项目自费
  369. var otherInscpTotal float64 = 0 //床位部分项目自费
  370. var materialCostTotal float64 = 0 //材料费
  371. var materialCostSelfTotal float64 = 0 //材料费
  372. var materialCostPartSelfTotal float64 = 0 //材料费
  373. var materialSelfTotal float64 = 0 //床位部分项目自费
  374. var materialInscpTotal float64 = 0 //床位部分项目自费
  375. var westernMedicineCostTotal float64 = 0 //西药费
  376. var westernMedicineCostSelfTotal float64 = 0 //西药费
  377. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  378. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  379. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  380. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  381. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  382. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  383. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  384. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  385. var checkCostTotal float64 = 0 //检查费
  386. var checkCostSelfTotal float64 = 0 //检查费
  387. var checkCostPartSelfTotal float64 = 0 //检查费
  388. var checkSelfTotal float64 = 0 //床位部分项目自费
  389. var checkInscpTotal float64 = 0 //床位部分项目自费
  390. var laboratoryCostTotal float64 = 0 //化验费
  391. var laboratoryCostSelfTotal float64 = 0 //化验费
  392. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  393. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  394. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  395. var treatCostTotal float64 = 0 //治疗费用
  396. var treatCostSelfTotal float64 = 0 //治疗费用
  397. var treatCostPartSelfTotal float64 = 0 //治疗费用
  398. var treatSelfTotal float64 = 0 //床位部分项目自费
  399. var treatInscpTotal float64 = 0 //床位部分项目自费
  400. decimal.DivisionPrecision = 2
  401. for _, item := range orderInfos {
  402. if item.MedChrgitmType == "01" { //床位费
  403. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  404. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  405. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  406. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  407. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  408. }
  409. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  410. if item.MedChrgitmType == "03" { //检查费
  411. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  412. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  413. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  414. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  415. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  416. }
  417. } else {
  418. if item.MedChrgitmType == "03" { //检查费
  419. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  420. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  421. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  422. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  423. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  424. }
  425. }
  426. if item.MedChrgitmType == "04" { //化验费
  427. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  428. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  429. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  430. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  431. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  432. }
  433. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  434. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  435. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  436. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  437. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  438. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  439. }
  440. if item.MedChrgitmType == "06" { //手术费
  441. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  442. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  443. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  444. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  445. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  446. }
  447. if item.MedChrgitmType == "08" { //材料费
  448. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  449. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  450. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  451. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  452. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  453. }
  454. if item.MedChrgitmType == "09" { //西药费
  455. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  456. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  457. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  458. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  459. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  460. }
  461. if item.MedChrgitmType == "11" { //中成费
  462. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  463. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  464. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  465. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  466. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  467. }
  468. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  469. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  470. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  471. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  472. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  473. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  474. }
  475. }
  476. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  477. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  478. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  479. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  480. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  481. var doctor_name string
  482. if roles.ID == 0 {
  483. doctor_name = "管理员"
  484. } else {
  485. doctor_name = roles.UserName
  486. }
  487. yiliao_leibie := ""
  488. switch order.MedType {
  489. case "11":
  490. yiliao_leibie = "普通门诊"
  491. break
  492. case "12":
  493. yiliao_leibie = "门诊挂号"
  494. break
  495. case "13":
  496. yiliao_leibie = "急诊"
  497. break
  498. case "14":
  499. yiliao_leibie = "门诊特殊病"
  500. break
  501. case "15":
  502. yiliao_leibie = "门诊统筹"
  503. break
  504. case "16":
  505. yiliao_leibie = "门诊慢性病"
  506. break
  507. case "21":
  508. yiliao_leibie = "普通住院"
  509. break
  510. }
  511. c.ServeSuccessJSON(map[string]interface{}{
  512. "diagnosis": name,
  513. "order_infos": orderInfos,
  514. "number": order.MdtrtId,
  515. "date": order.SettleAccountsDate,
  516. "charge_admin": charge_admin,
  517. "printor_admin": printor_admin,
  518. "info": order,
  519. "order": order,
  520. "bedCostTotal": bedCostTotal,
  521. "bedCostSelfTotal": bedCostSelfTotal,
  522. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  523. "bedSelfTotal": bedSelfTotal,
  524. "bedInscpTotal": bedInscpTotal,
  525. "operationCostTotal": operationCostTotal,
  526. "operationCostSelfTotal": operationCostSelfTotal,
  527. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  528. "operationSelfTotal": operationSelfTotal,
  529. "operationInscpTotal": operationInscpTotal,
  530. "otherCostTotal": otherCostTotal,
  531. "otherCostSelfTotal": otherCostSelfTotal,
  532. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  533. "otherSelfTotal": otherSelfTotal,
  534. "otherInscpTotal": otherInscpTotal,
  535. "materialCostTotal": materialCostTotal,
  536. "materialCostSelfTotal": materialCostSelfTotal,
  537. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  538. "materialSelfTotal": materialSelfTotal,
  539. "materialInscpTotal": materialInscpTotal,
  540. "westernMedicineCostTotal": westernMedicineCostTotal,
  541. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  542. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  543. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  544. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  545. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  546. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  547. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  548. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  549. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  550. "checkCostTotal": checkCostTotal,
  551. "checkCostSelfTotal": checkCostSelfTotal,
  552. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  553. "checkSelfTotal": checkSelfTotal,
  554. "checkInscpTotal": checkInscpTotal,
  555. "laboratoryCostTotal": laboratoryCostTotal,
  556. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  557. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  558. "laboratorySelfTotal": laboratorySelfTotal,
  559. "laboratoryInscpTotal": laboratoryInscpTotal,
  560. "treatCostTotal": treatCostTotal,
  561. "treatCostSelfTotal": treatCostSelfTotal,
  562. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  563. "treatSelfTotal": treatSelfTotal,
  564. "treatInscpTotal": treatInscpTotal,
  565. "doctor_info": doctor_info,
  566. "doctor_name": doctor_name,
  567. "health_card_no": order.PsnNo,
  568. "yiliao_leibie": yiliao_leibie,
  569. "patient": patient,
  570. "org_name": miConfig.OrgName,
  571. "org_code": miConfig.Code,
  572. "order_number": order.Number,
  573. "his_hospital": his_hospital,
  574. "dia_config": dia_config,
  575. })
  576. }
  577. func (c *PublicApiController) GetBaiLinExportData() {
  578. data := service.GetBaiLinOrderData()
  579. fmt.Println(len(data))
  580. var new_data []*models.NewCustomHisOrder
  581. for _, item := range data {
  582. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  583. new_data = append(new_data, item)
  584. }
  585. }
  586. fmt.Println(len(new_data))
  587. c.ServeSuccessJSON(map[string]interface{}{
  588. "list": new_data,
  589. })
  590. }
  591. func (c *HisApiController) GetHisUnChargePatientList() {
  592. record_date := c.GetString("record_date")
  593. timeLayout := "2006-01-02"
  594. loc, _ := time.LoadLocation("Local")
  595. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  596. if err != nil {
  597. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  598. return
  599. }
  600. recordDateTime := theTime.Unix()
  601. adminInfo := c.GetAdminUserInfo()
  602. var tempPatients []*service.NewTempPatients
  603. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  604. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  605. var patients []*service.NewTempPatients
  606. var patients_two []*service.NewTempPatients
  607. for _, item := range tempPatients {
  608. //过滤掉没挂号的和没开处方的
  609. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  610. patients = append(patients, item)
  611. }
  612. //过滤掉没挂号的
  613. if len(item.HisPatient) > 0 {
  614. patients_two = append(patients_two, item)
  615. }
  616. }
  617. c.ServeSuccessJSON(map[string]interface{}{
  618. "list": patients,
  619. "list_two": patients_two,
  620. })
  621. }
  622. func (c *HisApiController) GetPrivateExpensesOrder() {
  623. //id, _ := c.GetInt64("id")
  624. //record_time := c.GetString("record_time")
  625. order_id, _ := c.GetInt64("order_id")
  626. admin_user_id, _ := c.GetInt64("admin_user_id")
  627. //timeLayout := "2006-01-02"
  628. //loc, _ := time.LoadLocation("Local")
  629. //
  630. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  631. //if err != nil {
  632. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  633. // return
  634. //}
  635. //recordDateTime := theTime.Unix()
  636. adminUser := c.GetAdminUserInfo()
  637. order, _ := service.GetHisOrderByID(order_id)
  638. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  639. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  640. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  641. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  642. //var config []*models.HisXtDiagnoseConfig
  643. var name string
  644. if order.PType == 1 {
  645. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  646. for _, item := range diagnosis_ids {
  647. id, _ := strconv.ParseInt(item, 10, 64)
  648. diagnosisConfig, _ := service.FindDiagnoseById(id)
  649. if len(name) == 0 {
  650. name = diagnosisConfig.ClassName
  651. } else {
  652. name = name + "," + diagnosisConfig.ClassName
  653. }
  654. }
  655. } else {
  656. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  657. for _, item := range diagnosis_ids {
  658. id, _ := strconv.ParseInt(item, 10, 64)
  659. diagnosisConfig, _ := service.FindDiagnoseById(id)
  660. if len(name) == 0 {
  661. name = diagnosisConfig.ClassName
  662. } else {
  663. name = name + "," + diagnosisConfig.ClassName
  664. }
  665. }
  666. }
  667. var bedCostTotal float64 = 0 //床位总费
  668. //var bedCostSelfTotal float64 = 0 //床位自费
  669. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  670. var operationCostTotal float64 = 0 //手术费
  671. //var operationCostSelfTotal float64 = 0 //手术费
  672. var operationCostPartSelfTotal float64 = 0 //手术费
  673. var otherCostTotal float64 = 0 //其他费用
  674. //var otherCostSelfTotal float64 = 0 //其他费用
  675. var otherCostPartSelfTotal float64 = 0 //其他费用
  676. var materialCostTotal float64 = 0 //材料费
  677. //var materialCostSelfTotal float64 = 0 //材料费
  678. var materialCostPartSelfTotal float64 = 0 //材料费
  679. var westernMedicineCostTotal float64 = 0 //西药费
  680. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  681. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  682. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  683. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  684. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  685. var checkCostTotal float64 = 0 //检查费
  686. //var checkCostSelfTotal float64 = 0 //检查费
  687. var checkCostPartSelfTotal float64 = 0 //检查费
  688. var laboratoryCostTotal float64 = 0 //化验费
  689. //var laboratoryCostSelfTotal float64 = 0 //化验费
  690. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  691. var treatCostTotal float64 = 0 //治疗费用
  692. //var treatCostSelfTotal float64 = 0 //治疗费用
  693. var treatCostPartSelfTotal float64 = 0 //治疗费用
  694. var zhenChaCostTotal float64 = 0 //其他费用
  695. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  696. decimal.DivisionPrecision = 2
  697. for _, item := range orderInfos {
  698. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  699. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  700. item.MedChrgitmType = "09"
  701. }
  702. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  703. if item.HisPrescriptionProject.Type == 2 {
  704. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  705. fmt.Println("CostClassify")
  706. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  707. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  708. case 0:
  709. item.MedChrgitmType = "0"
  710. break
  711. case 1:
  712. item.MedChrgitmType = "14"
  713. break
  714. case 2:
  715. item.MedChrgitmType = "05"
  716. break
  717. case 3:
  718. item.MedChrgitmType = "03"
  719. break
  720. case 4:
  721. item.MedChrgitmType = "03"
  722. break
  723. case 5:
  724. item.MedChrgitmType = "08"
  725. break
  726. case 6:
  727. item.MedChrgitmType = "14"
  728. break
  729. case 7:
  730. item.MedChrgitmType = "14"
  731. break
  732. case 8:
  733. item.MedChrgitmType = "03"
  734. break
  735. case 9:
  736. item.MedChrgitmType = "14"
  737. break
  738. case 10:
  739. item.MedChrgitmType = "14"
  740. break
  741. case 11:
  742. item.MedChrgitmType = "06"
  743. break
  744. case 12:
  745. item.MedChrgitmType = "12"
  746. break
  747. case 13:
  748. item.MedChrgitmType = "01"
  749. break
  750. case 14:
  751. item.MedChrgitmType = "04"
  752. break
  753. case 15:
  754. item.MedChrgitmType = "14"
  755. break
  756. }
  757. } else {
  758. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  759. case 1:
  760. item.MedChrgitmType = "14"
  761. break
  762. case 2:
  763. item.MedChrgitmType = "05"
  764. break
  765. case 3:
  766. item.MedChrgitmType = "04"
  767. break
  768. case 4:
  769. item.MedChrgitmType = "14"
  770. break
  771. case 5:
  772. item.MedChrgitmType = "08"
  773. break
  774. case 6:
  775. item.MedChrgitmType = "14"
  776. break
  777. case 7:
  778. item.MedChrgitmType = "14"
  779. break
  780. case 8:
  781. item.MedChrgitmType = "03"
  782. break
  783. case 9:
  784. item.MedChrgitmType = "14"
  785. break
  786. }
  787. }
  788. } else if item.HisPrescriptionProject.Type == 3 {
  789. item.MedChrgitmType = "08"
  790. }
  791. }
  792. }
  793. order.PsnCashPay = order.MedfeeSumamt
  794. for _, item := range orderInfos {
  795. if item.MedChrgitmType == "01" { //床位费
  796. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  797. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  798. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  799. }
  800. if item.MedChrgitmType == "02" { //诊察费
  801. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  802. //zhenChaCostSelfTotal = zhenChaCostTotal
  803. }
  804. if item.MedChrgitmType == "03" { //检查费
  805. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  806. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  807. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  808. }
  809. if item.MedChrgitmType == "02" { //检查费
  810. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  811. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  812. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  813. }
  814. if item.MedChrgitmType == "04" { //化验费
  815. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  816. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  817. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  818. }
  819. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  820. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  821. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  822. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  823. }
  824. if item.MedChrgitmType == "06" { //手术费
  825. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  826. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  827. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  828. }
  829. if item.MedChrgitmType == "08" { //材料费
  830. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  831. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  832. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  833. }
  834. if item.MedChrgitmType == "09" { //西药费
  835. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  836. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  837. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  838. }
  839. if item.MedChrgitmType == "11" { //中成费
  840. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  841. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  842. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  843. }
  844. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  845. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  846. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  847. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  848. }
  849. }
  850. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  851. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  852. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  853. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  854. c.ServeSuccessJSON(map[string]interface{}{
  855. "patient": patient,
  856. "order_infos": orderInfos,
  857. "diagnosis": name,
  858. "bedCostTotal": bedCostTotal,
  859. "bedCostSelfTotal": bedCostTotal,
  860. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  861. "operationCostTotal": operationCostTotal,
  862. "operationCostSelfTotal": operationCostTotal,
  863. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  864. "otherCostTotal": otherCostTotal,
  865. "otherCostSelfTotal": otherCostTotal,
  866. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  867. "materialCostTotal": materialCostTotal,
  868. "materialCostSelfTotal": materialCostTotal,
  869. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  870. "westernMedicineCostTotal": westernMedicineCostTotal,
  871. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  872. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  873. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  874. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  875. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  876. "checkCostTotal": checkCostTotal,
  877. "checkCostSelfTotal": checkCostTotal,
  878. "zhenChaCostTotal": zhenChaCostTotal,
  879. "zhenChaCostSelfTotal": zhenChaCostTotal,
  880. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  881. "laboratoryCostTotal": laboratoryCostTotal,
  882. "laboratoryCostSelfTotal": laboratoryCostTotal,
  883. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  884. "treatCostTotal": treatCostTotal,
  885. "treatCostSelfTotal": treatCostTotal,
  886. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  887. "charge_admin": charge_admin,
  888. "printor_admin": printor_admin,
  889. "org_name": org.OrgName,
  890. "org_code": miConfig.Code,
  891. "name": patient.Name,
  892. "number": order.MdtrtId,
  893. "date": order.SettleAccountsDate,
  894. "info": order,
  895. "his_hospital": his_hospital,
  896. "his": his,
  897. })
  898. }
  899. func (c *HisApiController) RefudDetail() {
  900. order_id, _ := c.GetInt64("order_id")
  901. order, _ := service.GetHisOrderByID(order_id)
  902. adminUser := c.GetAdminUserInfo()
  903. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  904. c.ServeSuccessJSON(map[string]interface{}{
  905. "msg": "撤销成功",
  906. })
  907. }
  908. func (c *HisApiController) Sscard() {
  909. //r := CardInit()
  910. //if r == 0 {
  911. // GetBaseInfo()
  912. //}
  913. //c.ServeSuccessJSON(map[string]interface{}{
  914. // "list": "11",
  915. //})
  916. }
  917. func GetBaseInfo() error {
  918. //handle := syscall.MustLoadDLL("SSCard.dll")
  919. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  920. //
  921. //str := make([]byte, 256)
  922. //str1 := make([]byte, 256)
  923. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  924. //if ferr != nil {
  925. // fmt.Println("ReadCardBas 报错", ferr.Error())
  926. // return ferr
  927. //}
  928. //
  929. //fmt.Println(string(str))
  930. //
  931. //fmt.Println(r)
  932. return nil
  933. }
  934. func CardInit() int {
  935. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  936. //add := DllTestDef.MustFindProc("Init")
  937. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  938. //if err != nil {
  939. // fmt.Println("SSCard的运算结果为:", ret)
  940. //}
  941. //result := int(ret)
  942. return 0
  943. }
  944. func IntPtr(n int) uintptr {
  945. return uintptr(n)
  946. }
  947. func StrPtr(s string) uintptr {
  948. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  949. }
  950. func (c *HisApiController) GetHisPatientList() {
  951. //types, _ := c.GetInt64("type", 0)
  952. record_date := c.GetString("record_date")
  953. sch_type, _ := c.GetInt64("sch_type")
  954. timeLayout := "2006-01-02"
  955. loc, _ := time.LoadLocation("Local")
  956. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  957. if err != nil {
  958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  959. return
  960. }
  961. recordDateTime := theTime.Unix()
  962. adminInfo := c.GetAdminUserInfo()
  963. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  964. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  965. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  966. //获取当前用户的信息
  967. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  968. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  969. //获取所有科室信息
  970. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  971. c.ServeSuccessJSON(map[string]interface{}{
  972. "list": patients,
  973. "list_two": patients_two,
  974. "info": adminUserInfo,
  975. "doctors": doctors,
  976. "department": department,
  977. })
  978. }
  979. type CustomTemplate struct {
  980. ID int64 `gorm:"column:id" json:"id" form:"id"`
  981. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  982. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  983. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  984. Status int64 `gorm:"column:status" json:"status" form:"status"`
  985. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  986. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  987. Type int64 `gorm:"column:type" json:"type" form:"type"`
  988. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  989. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  990. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  991. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  992. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  993. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  994. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  995. }
  996. func (c *HisApiController) GetHisPatientInfo() {
  997. patient_id, _ := c.GetInt64("patient_id")
  998. his_patient_id, _ := c.GetInt64("his_patient_id")
  999. record_date := c.GetString("record_date")
  1000. number := c.GetString("number")
  1001. //start_time := c.GetString("start_time")
  1002. //end_time := c.GetString("end_time")
  1003. p_type, _ := c.GetInt64("p_type")
  1004. timeLayout := "2006-01-02"
  1005. loc, _ := time.LoadLocation("Local")
  1006. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1007. if err != nil {
  1008. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1009. return
  1010. }
  1011. recordDateTime := theTime.Unix()
  1012. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1013. //if err != nil {
  1014. //
  1015. //}
  1016. //startRecordDateTime := startTime.Unix()
  1017. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1018. //if err != nil {
  1019. //
  1020. //}
  1021. //endRecordDateTime := endTime.Unix()
  1022. admin := c.GetAdminUserInfo()
  1023. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1024. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1025. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1026. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1027. var prescriptions []*models.HisPrescription
  1028. var last_prescriptions []*models.HisPrescription
  1029. var sch_prescriptions []CustomTemplate
  1030. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1031. if p_type == 1 { //住院
  1032. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1033. for _, item := range prescriptions {
  1034. for _, subItem := range item.HisDoctorAdviceInfo {
  1035. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1036. if info.RetailPrice > 0 {
  1037. subItem.Drug.MinPrice = info.RetailPrice
  1038. }
  1039. }
  1040. }
  1041. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1042. } else { //门诊
  1043. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1044. for _, item := range prescriptions {
  1045. for _, subItem := range item.HisDoctorAdviceInfo {
  1046. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1047. if info.RetailPrice > 0 {
  1048. subItem.Drug.MinPrice = info.RetailPrice
  1049. }
  1050. }
  1051. }
  1052. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1053. }
  1054. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1055. if sch.ID > 0 {
  1056. var week string
  1057. t := time.Now()
  1058. switch t.Weekday().String() {
  1059. case "Monday":
  1060. week = "周一"
  1061. break
  1062. case "Tuesday":
  1063. week = "周二"
  1064. break
  1065. case "Wednesday":
  1066. week = "周三"
  1067. break
  1068. case "Thursday":
  1069. week = "周四"
  1070. break
  1071. case "Friday":
  1072. week = "周五"
  1073. break
  1074. case "Saturday":
  1075. week = "周六"
  1076. break
  1077. case "Sunday":
  1078. week = "周日"
  1079. break
  1080. }
  1081. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1082. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1083. //根据推送频率组装新的数组
  1084. for _, item := range temp_sch_prescriptions {
  1085. var cus CustomTemplate
  1086. cus.ID = item.ID
  1087. cus.UserOrgId = item.UserOrgId
  1088. cus.PatientId = item.PatientId
  1089. cus.MedType = item.MedType
  1090. cus.RecordDate = item.RecordDate
  1091. cus.Type = item.Type
  1092. cus.PType = item.PType
  1093. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1094. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1095. if subItem.FrequencyType == 1 { //每次必推
  1096. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1097. }
  1098. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1099. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1100. }
  1101. if subItem.FrequencyType == 2 { //按照天数频率
  1102. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1103. now := p.Unix()
  1104. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1105. dayStr2 := "-" + dayStr
  1106. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1107. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1108. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1109. if len(advices) == 0 {
  1110. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1111. }
  1112. }
  1113. }
  1114. }
  1115. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1116. if subItem.Type == 2 {
  1117. if subItem.XtHisProject.MedicalStatus != 1 {
  1118. if subItem.FrequencyType == 1 {
  1119. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1120. }
  1121. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1122. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1123. }
  1124. if subItem.FrequencyType == 2 {
  1125. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1126. now := p.Unix()
  1127. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1128. dayStr2 := "-" + dayStr
  1129. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1130. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1131. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1132. if len(projects) == 0 {
  1133. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1134. }
  1135. }
  1136. }
  1137. } else if subItem.Type == 3 {
  1138. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1139. if subItem.FrequencyType == 1 {
  1140. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1141. }
  1142. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1143. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1144. }
  1145. if subItem.FrequencyType == 2 {
  1146. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1147. now := p.Unix()
  1148. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1149. dayStr2 := "-" + dayStr
  1150. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1151. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1152. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1153. if len(projects) == 0 {
  1154. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1155. }
  1156. }
  1157. }
  1158. }
  1159. }
  1160. sch_prescriptions = append(sch_prescriptions, cus)
  1161. }
  1162. for _, item := range sch_prescriptions {
  1163. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1164. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1165. }
  1166. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1167. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1168. }
  1169. }
  1170. }
  1171. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1172. if config.ID > 0 && config.IsOpen == 1 {
  1173. for _, item := range sch_prescriptions {
  1174. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1175. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1176. if info.RetailPrice > 0 {
  1177. subItem.Drug.MinPrice = info.RetailPrice
  1178. }
  1179. }
  1180. }
  1181. }
  1182. if config.ID > 0 && config.IsOpen == 1 {
  1183. for _, item := range sch_prescriptions {
  1184. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1185. if subItem.Type == 3 {
  1186. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1187. if info.Price > 0 {
  1188. subItem.GoodInfo.PackingPrice = info.Price
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }
  1194. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1195. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1196. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1197. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1198. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1199. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1200. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1201. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1202. //获取所有科室信息
  1203. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1204. c.ServeSuccessJSON(map[string]interface{}{
  1205. "his_info": his_patient_info,
  1206. "xt_info": xt_patient_info,
  1207. "prescription": prescriptions,
  1208. "case_history": case_history,
  1209. "info": patientPrescriptionInfo,
  1210. //"month_prescriptions": monthPrescriptions,
  1211. "order": order,
  1212. "doctors": doctors,
  1213. "department": department,
  1214. "sch_prescriptions": sch_prescriptions,
  1215. "last_prescriptions": last_prescriptions,
  1216. "schedule": sch,
  1217. "count": count,
  1218. "drugStockConfig": drugStockConfig,
  1219. "last_info": lastPatientPrescriptionInfo,
  1220. })
  1221. return
  1222. }
  1223. func (c *HisApiController) GetHisPrescriptionConfig() {
  1224. adminInfo := c.GetAdminUserInfo()
  1225. //获取医嘱模版
  1226. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1227. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1228. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1229. //获取所有基础药
  1230. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1231. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1232. if config.ID > 0 && config.IsOpen == 1 {
  1233. for _, item := range drugs {
  1234. var index = 0
  1235. for _, subItem := range item.OtherDrugWarehouseInfo {
  1236. if index == 0 {
  1237. index = index + 1
  1238. if subItem.RetailPrice > 0 {
  1239. item.MinPrice = subItem.RetailPrice
  1240. }
  1241. }
  1242. }
  1243. }
  1244. }
  1245. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1246. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1247. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1248. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1249. //获取所有科室信息
  1250. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1251. //获取诊断信息
  1252. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1253. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1254. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1255. //获取是否开启保存耗材出库的开关
  1256. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1257. c.ServeSuccessJSON(map[string]interface{}{
  1258. "drugs": drugs,
  1259. "advices_template": advices,
  1260. "drugways": drugways,
  1261. "efs": efs,
  1262. "doctors": doctors,
  1263. "department": department,
  1264. "sick": sick,
  1265. "additions": additions,
  1266. "diagnose": diagnose,
  1267. "manufacturers": manufacturers,
  1268. "goodOutOpen": goodOutOpen,
  1269. })
  1270. }
  1271. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1272. //获取所有基础药
  1273. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1274. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1275. if config.ID > 0 && config.IsOpen == 1 {
  1276. for _, item := range drugs {
  1277. var index = 0
  1278. for _, subItem := range item.OtherDrugWarehouseInfo {
  1279. if index == 0 {
  1280. index = index + 1
  1281. if subItem.RetailPrice > 0 {
  1282. item.MinPrice = subItem.RetailPrice
  1283. }
  1284. }
  1285. }
  1286. }
  1287. }
  1288. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1289. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1290. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1291. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1292. //获取所有科室信息
  1293. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1294. //获取诊断信息
  1295. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1296. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1297. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1298. //获取是否开启保存耗材出库的开关
  1299. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1300. c.ServeSuccessJSON(map[string]interface{}{
  1301. "drugs": drugs,
  1302. "advices_template": advices,
  1303. "drugways": drugways,
  1304. "efs": efs,
  1305. "doctors": doctors,
  1306. "department": department,
  1307. "sick": sick,
  1308. "additions": additions,
  1309. "diagnose": diagnose,
  1310. "manufacturers": manufacturers,
  1311. "goodOutOpen": goodOutOpen,
  1312. })
  1313. }
  1314. }
  1315. func (c *HisApiController) CreateHisPrescription() {
  1316. record_date := c.GetString("record_date")
  1317. patient_id, _ := c.GetInt64("patient_id")
  1318. reg_type, _ := c.GetInt64("reg_type")
  1319. diagnose := c.GetString("diagnose")
  1320. sick_type, _ := c.GetInt64("sick_type")
  1321. sick_history := c.GetString("sick_history")
  1322. doctor_id, _ := c.GetInt64("doctor", 0)
  1323. department, _ := c.GetInt64("department", 0)
  1324. his_patient_id, _ := c.GetInt64("his_patient_id")
  1325. p_type, _ := c.GetInt64("p_type")
  1326. dataBody := make(map[string]interface{}, 0)
  1327. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1328. if err != nil {
  1329. utils.ErrorLog(err.Error())
  1330. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1331. return
  1332. }
  1333. timeLayout := "2006-01-02"
  1334. loc, _ := time.LoadLocation("Local")
  1335. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1336. if err != nil {
  1337. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1338. return
  1339. }
  1340. adminInfo := c.GetAdminUserInfo()
  1341. recordDateTime := theTime.Unix()
  1342. //查询默认出库仓库库存
  1343. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1344. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1345. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1346. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1347. if len(lists) == 1 {
  1348. his_patient_id = lists[0].ID
  1349. }
  1350. }
  1351. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1352. //保存处方出库
  1353. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1354. //自动出库
  1355. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1356. //耗材保存处方出库
  1357. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1358. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1359. //已发药和已收费限制逻辑
  1360. isMidicine := false
  1361. isCharge := false
  1362. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1363. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1364. if len(prescriptions) > 0 {
  1365. for _, item := range prescriptions {
  1366. items := item.(map[string]interface{})
  1367. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1368. utils.ErrorLog("id")
  1369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1370. return
  1371. }
  1372. id := int64(items["id"].(float64))
  1373. if id > 0 {
  1374. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1375. if err != nil {
  1376. if new_prescription.OrderStatus == 4 {
  1377. isCharge = true
  1378. }
  1379. }
  1380. }
  1381. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1382. advices := items["advices"].([]interface{})
  1383. if len(advices) > 0 {
  1384. for _, advice := range advices {
  1385. var adviceId int64
  1386. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1387. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1388. }
  1389. if adviceId > 0 {
  1390. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1391. if err == nil {
  1392. if his_advice_info.IsMedicine == 1 {
  1393. isMidicine = true
  1394. }
  1395. }
  1396. }
  1397. }
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. if isMidicine == true {
  1404. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1405. return
  1406. }
  1407. if isCharge == true {
  1408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1409. return
  1410. }
  1411. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1412. //药品发药出库
  1413. if pharmacyConfig.IsOpen == 1 {
  1414. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1415. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1416. if len(prescriptions) > 0 {
  1417. for _, item := range prescriptions {
  1418. items := item.(map[string]interface{})
  1419. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1420. advices := items["advices"].([]interface{})
  1421. if len(advices) > 0 {
  1422. for _, advice := range advices {
  1423. var drug_id int64
  1424. var prescribing_number float64
  1425. var prescribingNumberUnit string
  1426. var adviceId int64
  1427. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1428. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1429. }
  1430. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1431. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1432. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1433. }
  1434. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1435. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1436. }
  1437. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1438. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1439. }
  1440. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1441. if drug.ID == 0 {
  1442. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1443. return
  1444. }
  1445. //查询药品的所有库存
  1446. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1447. var total_count int64
  1448. for _, it := range list {
  1449. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1450. }
  1451. totals := strconv.FormatInt(total_count, 10)
  1452. //查询该药品是否存在开药记录
  1453. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1454. //新增处方
  1455. if advicelist.ID == 0 {
  1456. all_count, _ := strconv.ParseFloat(totals, 64)
  1457. if prescribingNumberUnit == drug.MinUnit {
  1458. if drug.IsUse != 1 {
  1459. if prescribing_number > all_count {
  1460. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1461. return
  1462. }
  1463. }
  1464. }
  1465. if prescribingNumberUnit == drug.MaxUnit {
  1466. num := prescribing_number * float64(drug.MinNumber)
  1467. if drug.IsUse != 1 {
  1468. if num > all_count {
  1469. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1470. return
  1471. }
  1472. }
  1473. }
  1474. }
  1475. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1476. if drugOutConfig.IsOpen != 1 {
  1477. //修改处方
  1478. for _, advice := range advices {
  1479. var drug_id int64
  1480. var prescribing_number float64
  1481. var prescribingNumberUnit string
  1482. var prescribingNumber string
  1483. var adviceId int64
  1484. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1485. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1486. }
  1487. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1488. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1489. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1490. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1491. }
  1492. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1493. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1494. }
  1495. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1496. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1497. }
  1498. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1499. if drug.ID == 0 {
  1500. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1501. return
  1502. }
  1503. //查询药品的所有库存
  1504. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1505. var total_count int64
  1506. for _, it := range list {
  1507. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1508. }
  1509. totals := strconv.FormatInt(total_count, 10)
  1510. //查询该药品是否存在开药记录
  1511. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1512. //新增处方
  1513. if advicelist.ID == 0 {
  1514. all_count, _ := strconv.ParseFloat(totals, 64)
  1515. if prescribingNumberUnit == drug.MinUnit {
  1516. if drug.IsUse != 1 {
  1517. if prescribing_number > all_count {
  1518. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1519. return
  1520. }
  1521. }
  1522. } else {
  1523. if prescribingNumberUnit == drug.MaxUnit {
  1524. num := prescribing_number * float64(drug.MinNumber)
  1525. if drug.IsUse != 1 {
  1526. if num > all_count {
  1527. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1528. return
  1529. }
  1530. }
  1531. }
  1532. }
  1533. }
  1534. //修改处方
  1535. if advicelist.ID > 0 {
  1536. var device_number int64
  1537. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1538. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1539. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1540. device_number = prescribingNumberInt * drug.MinNumber
  1541. }
  1542. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1543. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1544. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1545. device_number = prescribingNumberInt
  1546. }
  1547. var number_count int64
  1548. if prescribingNumberUnit == drug.MaxUnit {
  1549. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1550. number_count = prescribingNumberInt * drug.MinNumber
  1551. }
  1552. if prescribingNumberUnit == drug.MinUnit {
  1553. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1554. number_count = prescribingNumberInt
  1555. }
  1556. //如果修改的数量大于之前修改的数量
  1557. if (number_count - device_number) > 0 {
  1558. //如果修改的差数量 大于库存数量
  1559. if drug.IsUse != 1 {
  1560. if (number_count - device_number) > total_count {
  1561. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1562. return
  1563. }
  1564. }
  1565. }
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. }
  1576. //已发药和已收费限制逻辑
  1577. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1578. //校验库存总量
  1579. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1580. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1581. if len(prescriptions) > 0 {
  1582. for _, item := range prescriptions {
  1583. items := item.(map[string]interface{})
  1584. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1585. advices := items["advices"].([]interface{})
  1586. if len(advices) > 0 {
  1587. for _, advice := range advices {
  1588. var drug_id int64
  1589. var prescribing_number float64
  1590. var prescribingNumberUnit string
  1591. var adviceId int64
  1592. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1593. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1594. }
  1595. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1596. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1597. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1598. }
  1599. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1600. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1601. }
  1602. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1603. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1604. }
  1605. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1606. if drug.ID == 0 {
  1607. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1608. return
  1609. }
  1610. //查询药品的所有库存
  1611. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1612. var total_count int64
  1613. for _, it := range list {
  1614. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1615. }
  1616. totals := strconv.FormatInt(total_count, 10)
  1617. //查询该药品是否存在开药记录
  1618. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1619. //查询最新批次库存
  1620. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1621. var batch_number_count int64
  1622. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1623. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1624. //新增处方
  1625. if advicelist.ID == 0 {
  1626. all_count, _ := strconv.ParseFloat(totals, 64)
  1627. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1628. if prescribingNumberUnit == drug.MinUnit {
  1629. if drug.IsUse != 1 {
  1630. if prescribing_number > all_count {
  1631. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1632. return
  1633. }
  1634. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1635. if prescribing_number > batch_number_all_count {
  1636. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1637. return
  1638. }
  1639. }
  1640. }
  1641. }
  1642. if prescribingNumberUnit == drug.MaxUnit {
  1643. num := prescribing_number * float64(drug.MinNumber)
  1644. if drug.IsUse != 1 {
  1645. if num > all_count {
  1646. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1647. return
  1648. }
  1649. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1650. if num > batch_number_all_count {
  1651. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1652. return
  1653. }
  1654. }
  1655. }
  1656. }
  1657. }
  1658. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1659. if drugOutConfig.IsOpen != 1 {
  1660. //修改处方
  1661. for _, advice := range advices {
  1662. var drug_id int64
  1663. var prescribing_number float64
  1664. var prescribingNumberUnit string
  1665. var prescribingNumber string
  1666. var adviceId int64
  1667. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1668. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1669. }
  1670. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1671. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1672. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1673. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1674. }
  1675. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1676. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1677. }
  1678. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1679. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1680. }
  1681. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1682. if drug.ID == 0 {
  1683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1684. return
  1685. }
  1686. //查询药品的所有库存
  1687. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1688. var total_count int64
  1689. for _, it := range list {
  1690. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1691. }
  1692. totals := strconv.FormatInt(total_count, 10)
  1693. //查询该药品是否存在开药记录
  1694. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1695. //新增处方
  1696. if advicelist.ID == 0 {
  1697. //查询最新批次库存
  1698. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1699. var batch_number_count int64
  1700. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1701. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1702. all_count, _ := strconv.ParseFloat(totals, 64)
  1703. if prescribingNumberUnit == drug.MinUnit {
  1704. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1705. if drug.IsUse != 1 {
  1706. if prescribing_number > all_count {
  1707. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1708. return
  1709. }
  1710. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1711. if prescribing_number > batch_number_all_count {
  1712. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1713. return
  1714. }
  1715. }
  1716. }
  1717. } else {
  1718. if prescribingNumberUnit == drug.MaxUnit {
  1719. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1720. num := prescribing_number * float64(drug.MinNumber)
  1721. if drug.IsUse != 1 {
  1722. if num > all_count {
  1723. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1724. return
  1725. }
  1726. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1727. if prescribing_number > batch_number_all_count {
  1728. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1729. return
  1730. }
  1731. }
  1732. }
  1733. }
  1734. }
  1735. }
  1736. //修改处方
  1737. if advicelist.ID > 0 {
  1738. //查询最新批次库存
  1739. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1740. var batch_number_count int64
  1741. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1742. var device_number int64
  1743. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1744. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1745. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1746. device_number = prescribingNumberInt * drug.MinNumber
  1747. }
  1748. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1749. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1750. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1751. device_number = prescribingNumberInt
  1752. }
  1753. var number_count int64
  1754. if prescribingNumberUnit == drug.MaxUnit {
  1755. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1756. number_count = prescribingNumberInt * drug.MinNumber
  1757. }
  1758. if prescribingNumberUnit == drug.MinUnit {
  1759. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1760. number_count = prescribingNumberInt
  1761. }
  1762. //如果修改的数量大于之前修改的数量
  1763. if (number_count - device_number) > 0 {
  1764. //如果修改的差数量 大于库存数量
  1765. if drug.IsUse != 1 {
  1766. if (number_count - device_number) > total_count {
  1767. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1768. return
  1769. }
  1770. if (number_count - device_number) > batch_number_count {
  1771. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1772. return
  1773. }
  1774. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1775. // 查询该药品最后一次出库记录
  1776. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1777. var out_count int64
  1778. var in_count int64
  1779. var stock_max_number int64
  1780. var stock_min_number int64
  1781. for _, it := range outInfo {
  1782. if it.CountUnit == drug.MaxUnit {
  1783. it.Count = it.Count * drug.MinNumber
  1784. }
  1785. out_count += it.Count
  1786. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1787. stock_max_number = warehouseInfoList.StockMaxNumber
  1788. stock_min_number = warehouseInfoList.StockMinNumber
  1789. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1790. }
  1791. if out_count > 0 {
  1792. if (number_count - device_number) > in_count {
  1793. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1794. return
  1795. }
  1796. }
  1797. // 未出库
  1798. if out_count == 0 {
  1799. var sum_in_count int64
  1800. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1801. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1802. fmt.Println("sum_in_count", sum_in_count)
  1803. //如果修改的数量大于有库存的第一个批次
  1804. if number_count > sum_in_count {
  1805. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1806. return
  1807. }
  1808. }
  1809. }
  1810. }
  1811. }
  1812. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1813. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1814. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1815. if pharmacyConfig.IsOpen != 1 {
  1816. if device_number != number_count {
  1817. // 查询该药品最后一次出库记录
  1818. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1819. //回退库存
  1820. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1821. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1822. }
  1823. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1824. var stock_max_number int64
  1825. var stock_min_number int64
  1826. if number_count >= drug.MinNumber {
  1827. stock_max_number = device_number / drug.MinNumber
  1828. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1829. stock_min_number = device_number % drug.MinNumber
  1830. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1831. } else {
  1832. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1833. }
  1834. }
  1835. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1836. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1837. }
  1838. //删除记录
  1839. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1840. //查询默认仓库剩余多少库存
  1841. var sum_count int64
  1842. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1843. for _, its := range stockInfo {
  1844. if its.MaxUnit == drug.MaxUnit {
  1845. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1846. }
  1847. sum_count += its.StockMaxNumber + its.StockMinNumber
  1848. }
  1849. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. //保存处方开药
  1856. if drugOutConfig.IsOpen == 1 {
  1857. //修改处方
  1858. for _, advice := range advices {
  1859. var drug_id int64
  1860. var prescribing_number float64
  1861. var prescribingNumberUnit string
  1862. var prescribingNumber string
  1863. var adviceId int64
  1864. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1865. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1866. }
  1867. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1868. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1869. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1870. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1871. }
  1872. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1873. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1874. }
  1875. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1876. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1877. }
  1878. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1879. if drug.ID == 0 {
  1880. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1881. return
  1882. }
  1883. //查询药品的所有库存
  1884. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1885. var total_count int64
  1886. for _, it := range list {
  1887. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1888. }
  1889. totals := strconv.FormatInt(total_count, 10)
  1890. //查询该药品是否存在开药记录
  1891. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1892. //新增处方
  1893. if advicelist.ID == 0 {
  1894. //查询最新批次库存
  1895. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1896. var batch_number_count int64
  1897. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1898. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1899. all_count, _ := strconv.ParseFloat(totals, 64)
  1900. if prescribingNumberUnit == drug.MinUnit {
  1901. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1902. if drug.IsUse != 1 {
  1903. if prescribing_number > all_count {
  1904. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1905. return
  1906. }
  1907. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1908. if prescribing_number > batch_number_all_count {
  1909. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1910. return
  1911. }
  1912. }
  1913. }
  1914. } else {
  1915. if prescribingNumberUnit == drug.MaxUnit {
  1916. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1917. num := prescribing_number * float64(drug.MinNumber)
  1918. if drug.IsUse != 1 {
  1919. if num > all_count {
  1920. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1921. return
  1922. }
  1923. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1924. if prescribing_number > batch_number_all_count {
  1925. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1926. return
  1927. }
  1928. }
  1929. }
  1930. }
  1931. }
  1932. }
  1933. //修改处方
  1934. if advicelist.ID > 0 {
  1935. //查询最新批次库存
  1936. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1937. var batch_number_count int64
  1938. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1939. var device_number int64
  1940. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1941. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1942. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1943. device_number = prescribingNumberInt * drug.MinNumber
  1944. }
  1945. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1946. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1947. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1948. device_number = prescribingNumberInt
  1949. }
  1950. var number_count int64
  1951. if prescribingNumberUnit == drug.MaxUnit {
  1952. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1953. number_count = prescribingNumberInt * drug.MinNumber
  1954. }
  1955. if prescribingNumberUnit == drug.MinUnit {
  1956. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1957. number_count = prescribingNumberInt
  1958. }
  1959. //如果修改的数量大于之前修改的数量
  1960. if (number_count - device_number) > 0 {
  1961. //如果修改的差数量 大于库存数量
  1962. if drug.IsUse != 1 {
  1963. if (number_count - device_number) > total_count {
  1964. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1965. return
  1966. }
  1967. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1968. if (number_count - device_number) > batch_number_count {
  1969. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1970. return
  1971. }
  1972. }
  1973. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1974. //查询历史出库数据总批次
  1975. // 查询该药品最后一次出库记录
  1976. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1977. var out_count int64
  1978. var in_count int64
  1979. var stock_max_number int64
  1980. var stock_min_number int64
  1981. for _, it := range outInfo {
  1982. if it.CountUnit == drug.MaxUnit {
  1983. it.Count = it.Count * drug.MinNumber
  1984. }
  1985. out_count += it.Count
  1986. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1987. stock_max_number = warehouseInfoList.StockMaxNumber
  1988. stock_min_number = warehouseInfoList.StockMinNumber
  1989. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1990. }
  1991. if out_count > 0 {
  1992. if (number_count - device_number) > in_count {
  1993. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1994. return
  1995. }
  1996. }
  1997. // 未出库
  1998. if out_count == 0 {
  1999. var sum_in_count int64
  2000. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2001. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2002. //如果修改的数量大于有库存的第一个批次
  2003. if number_count > sum_in_count {
  2004. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2005. return
  2006. }
  2007. }
  2008. }
  2009. }
  2010. }
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. }
  2017. }
  2018. }
  2019. }
  2020. }
  2021. //校验耗材库存
  2022. if goodOutConfig.IsOpen == 1 {
  2023. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2024. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2025. if len(prescriptions) > 0 {
  2026. for _, item := range prescriptions {
  2027. items := item.(map[string]interface{})
  2028. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2029. projects := items["project"].([]interface{})
  2030. if len(projects) > 0 {
  2031. for _, project := range projects {
  2032. var project_id int64
  2033. var project_type int64
  2034. var totals float64
  2035. var project_name string
  2036. var parsetotal int64
  2037. var id int64
  2038. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2039. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2040. }
  2041. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2042. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2043. }
  2044. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2045. total, _ := project.(map[string]interface{})["total"].(string)
  2046. totals, _ = strconv.ParseFloat(total, 64)
  2047. }
  2048. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2049. project_name = project.(map[string]interface{})["project_name"].(string)
  2050. }
  2051. if project_type == 3 {
  2052. //查找该耗材的出库记录
  2053. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2054. if len(goodWarehouseInfo) == 0 {
  2055. //查询耗材库存
  2056. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2057. var stock_count int64
  2058. for _, it := range list {
  2059. stock_count += it.StockCount
  2060. }
  2061. stock_counts := strconv.FormatInt(stock_count, 10)
  2062. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2063. if totals > stock_total_count {
  2064. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2065. return
  2066. }
  2067. }
  2068. if len(goodWarehouseInfo) > 0 {
  2069. //查询该患者耗材的历史数据
  2070. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2071. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2072. //数量发生改变
  2073. if parsetotal != count {
  2074. //如果现在的数量大于历史数量,就要看库存是否足够
  2075. if parsetotal > count {
  2076. //查询耗材所有库存
  2077. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2078. var stock_count int64
  2079. for _, it := range list {
  2080. stock_count += it.StockCount
  2081. }
  2082. //库存不足
  2083. if (parsetotal - count) > stock_count {
  2084. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2085. return
  2086. }
  2087. }
  2088. }
  2089. }
  2090. }
  2091. }
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. //不使用耗材保存处方出库
  2099. if goodOutConfig.IsOpen != 1 {
  2100. if stockConfig.IsOpen == 1 {
  2101. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2102. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2103. if len(prescriptions) > 0 {
  2104. for _, item := range prescriptions {
  2105. items := item.(map[string]interface{})
  2106. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2107. projects := items["project"].([]interface{})
  2108. if len(projects) > 0 {
  2109. for _, project := range projects {
  2110. var project_id int64
  2111. var project_type int64
  2112. var totals float64
  2113. var project_name string
  2114. var parsetotal int64
  2115. var id int64
  2116. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2117. id = int64(project.(map[string]interface{})["id"].(float64))
  2118. }
  2119. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2120. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2121. }
  2122. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2123. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2124. }
  2125. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2126. total, _ := project.(map[string]interface{})["total"].(string)
  2127. totals, _ = strconv.ParseFloat(total, 64)
  2128. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2129. }
  2130. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2131. project_name = project.(map[string]interface{})["project_name"].(string)
  2132. }
  2133. if project_type == 3 {
  2134. //查找该耗材的出库记录
  2135. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2136. //没有出库记录
  2137. if len(goodWarehouseInfo) == 0 {
  2138. //查询耗材库存
  2139. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2140. var stock_count int64
  2141. for _, it := range list {
  2142. stock_count += it.StockCount
  2143. }
  2144. stock_counts := strconv.FormatInt(stock_count, 10)
  2145. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2146. if totals > stock_total_count {
  2147. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2148. return
  2149. }
  2150. //查找今日该患者已经出库的所有耗材
  2151. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2152. for _, item := range goodList {
  2153. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2154. var flush_count int64
  2155. for _, it := range goodListSix {
  2156. flush_count += it.StockCount
  2157. }
  2158. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2159. creater := adminInfo.AdminUser.Id
  2160. if errs != nil {
  2161. goodErrcode := models.XtGoodErrcode{
  2162. UserOrgId: item.OrgId,
  2163. Errcode: "手动出库更新剩余出库失败",
  2164. GoodId: item.GoodId,
  2165. Status: 1,
  2166. Ctime: time.Now().Unix(),
  2167. Mtime: 0,
  2168. Count: 0,
  2169. StockCount: 0,
  2170. Creater: creater,
  2171. BatchNumberId: 0,
  2172. WarehouseOutId: 0,
  2173. }
  2174. service.CreateGoodErrcode(goodErrcode)
  2175. }
  2176. }
  2177. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2178. }
  2179. //有出库记录
  2180. if len(goodWarehouseInfo) > 0 {
  2181. //查询该患者耗材的历史数据
  2182. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2183. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2184. //数量发生改变
  2185. if parsetotal != count {
  2186. //查找今日该患者已经出库的所有耗材
  2187. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2188. for _, item := range goodList {
  2189. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2190. var flush_count int64
  2191. for _, it := range goodListSix {
  2192. flush_count += it.StockCount
  2193. }
  2194. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2195. //减少出库数量
  2196. creater := adminInfo.AdminUser.Id
  2197. if errs != nil {
  2198. goodErrcode := models.XtGoodErrcode{
  2199. UserOrgId: item.OrgId,
  2200. Errcode: "手动出库更新剩余出库失败",
  2201. GoodId: item.GoodId,
  2202. Status: 1,
  2203. Ctime: time.Now().Unix(),
  2204. Mtime: 0,
  2205. Count: 0,
  2206. StockCount: 0,
  2207. Creater: creater,
  2208. BatchNumberId: 0,
  2209. WarehouseOutId: 0,
  2210. }
  2211. service.CreateGoodErrcode(goodErrcode)
  2212. }
  2213. //查询默认仓库
  2214. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2215. var total_count int64
  2216. for _, it := range stockList {
  2217. total_count += it.StockCount
  2218. }
  2219. //基础库插入数据
  2220. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2221. }
  2222. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. }
  2230. }
  2231. }
  2232. }
  2233. }
  2234. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2235. var hpInfo models.HisPrescriptionInfo
  2236. if info.ID == 0 {
  2237. var randNum int
  2238. randNum = rand.Intn(10000) + 1000
  2239. timestamp := time.Now().Unix()
  2240. tempTime := time.Unix(timestamp, 0)
  2241. timeFormat := tempTime.Format("20060102150405")
  2242. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2243. hpInfo = models.HisPrescriptionInfo{
  2244. HisPatientId: his_patient_id,
  2245. UserOrgId: adminInfo.CurrentOrgId,
  2246. RecordDate: theTime.Unix(),
  2247. PatientId: patient_id,
  2248. Status: 1,
  2249. Ctime: time.Now().Unix(),
  2250. Mtime: time.Now().Unix(),
  2251. Creator: adminInfo.AdminUser.Id,
  2252. Modifier: adminInfo.AdminUser.Id,
  2253. Diagnosis: diagnose,
  2254. SickHistory: sick_history,
  2255. Departments: department,
  2256. RegisterType: reg_type,
  2257. PrescriptionNumber: p_number,
  2258. PrescriptionStatus: 1,
  2259. Doctor: role.UserName,
  2260. DoctorId: doctor_id,
  2261. SickType: sick_type,
  2262. PType: p_type,
  2263. }
  2264. service.SavePatientPrescriptionInfo(hpInfo)
  2265. redis := service.RedisClient()
  2266. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2267. redis.Set(key, "", time.Second)
  2268. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2269. redis.Set(keyOne, "", time.Second)
  2270. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2271. redis.Set(keySeven, "", time.Second)
  2272. defer redis.Close()
  2273. } else {
  2274. hpInfo = models.HisPrescriptionInfo{
  2275. ID: info.ID,
  2276. UserOrgId: adminInfo.CurrentOrgId,
  2277. RecordDate: info.RecordDate,
  2278. PatientId: info.PatientId,
  2279. Status: 1,
  2280. Ctime: info.Ctime,
  2281. Mtime: time.Now().Unix(),
  2282. Creator: info.Creator,
  2283. Modifier: adminInfo.AdminUser.Id,
  2284. Diagnosis: diagnose,
  2285. SickHistory: sick_history,
  2286. Departments: department,
  2287. RegisterType: reg_type,
  2288. PrescriptionNumber: info.PrescriptionNumber,
  2289. Doctor: role.UserName,
  2290. PrescriptionStatus: info.PrescriptionStatus,
  2291. DoctorId: doctor_id,
  2292. SickType: sick_type,
  2293. PType: info.PType,
  2294. HisPatientId: info.HisPatientId,
  2295. }
  2296. service.SavePatientPrescriptionInfo(hpInfo)
  2297. redis := service.RedisClient()
  2298. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2299. redis.Set(key, "", time.Second)
  2300. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2301. redis.Set(keyOne, "", time.Second)
  2302. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2303. redis.Set(keySeven, "", time.Second)
  2304. defer redis.Close()
  2305. }
  2306. //定义切片
  2307. var adviceList []models.HisDoctorAdviceInfo
  2308. var projectList []models.HisPrescriptionProject
  2309. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2310. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2311. var tempPrescription *models.HisPrescription
  2312. if len(prescriptions) > 0 {
  2313. for _, item := range prescriptions {
  2314. items := item.(map[string]interface{})
  2315. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2316. utils.ErrorLog("id")
  2317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2318. return
  2319. }
  2320. id := int64(items["id"].(float64))
  2321. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2322. tempPrescription = &new_prescription
  2323. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2324. utils.ErrorLog("type")
  2325. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2326. return
  2327. }
  2328. types := int64(items["type"].(float64))
  2329. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2330. utils.ErrorLog("med_type")
  2331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2332. return
  2333. }
  2334. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2335. if med_type == "0" {
  2336. med_type = "14"
  2337. }
  2338. //if order_status == 0 {
  2339. // order_status = 1
  2340. //}
  2341. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2342. utils.ErrorLog("pre_time")
  2343. }
  2344. preTime, _ := items["pre_time"].(string)
  2345. timeLayout := "2006-01-02"
  2346. loc, _ := time.LoadLocation("Local")
  2347. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2348. if err != nil {
  2349. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2350. return
  2351. }
  2352. pTime := theTime2.Unix()
  2353. ctime := time.Now().Unix()
  2354. if tempPrescription.ID == 0 {
  2355. prescription := &models.HisPrescription{
  2356. ID: 0,
  2357. PatientId: patient_id,
  2358. UserOrgId: adminInfo.CurrentOrgId,
  2359. RecordDate: recordDateTime,
  2360. Ctime: ctime,
  2361. Mtime: ctime,
  2362. Type: types,
  2363. Modifier: adminInfo.AdminUser.Id,
  2364. Creator: adminInfo.AdminUser.Id,
  2365. Status: 1,
  2366. Doctor: role.UserName,
  2367. HisPatientId: his_patient_id,
  2368. OrderStatus: 1,
  2369. BatchNumber: "",
  2370. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2371. PreTime: pTime,
  2372. PType: p_type,
  2373. MedType: med_type,
  2374. }
  2375. tempPrescription = prescription
  2376. service.SaveHisPrescription(tempPrescription)
  2377. redis := service.RedisClient()
  2378. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2379. redis.Set(key, "", time.Second)
  2380. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2381. redis.Set(keyOne, "", time.Second)
  2382. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2383. redis.Set(keySeven, "", time.Second)
  2384. defer redis.Close()
  2385. } else {
  2386. tempPrescription.ID = id
  2387. tempPrescription.Type = types
  2388. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2389. tempPrescription.Mtime = time.Now().Unix()
  2390. tempPrescription.Doctor = role.UserName
  2391. //tempPrescription.OrderStatus = order_status
  2392. tempPrescription.PreTime = pTime
  2393. tempPrescription.MedType = med_type
  2394. service.SaveHisPrescription(tempPrescription)
  2395. redis := service.RedisClient()
  2396. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2397. redis.Set(key, "", time.Second)
  2398. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2399. redis.Set(keyOne, "", time.Second)
  2400. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2401. redis.Set(keySeven, "", time.Second)
  2402. defer redis.Close()
  2403. }
  2404. //service.SaveHisPrescription(prescription)
  2405. //更改患者挂号状态
  2406. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2407. fmt.Println("更改失败", err2)
  2408. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2409. advices := items["advices"].([]interface{})
  2410. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2411. groupNo := int64(0)
  2412. ctime := time.Now().Unix()
  2413. mtime := ctime
  2414. if len(advices) > 0 {
  2415. for _, advice := range advices {
  2416. var s models.HisDoctorAdviceInfo
  2417. s.PrescriptionId = tempPrescription.ID
  2418. s.AdviceType = 2
  2419. s.AdviceDoctor = doctor_id
  2420. s.StopState = 2
  2421. s.ExecutionState = 2
  2422. s.AdviceDate = recordDateTime
  2423. s.Status = 1
  2424. s.UserOrgId = adminInfo.CurrentOrgId
  2425. s.RecordDate = recordDateTime
  2426. s.StartTime = tempPrescription.PreTime
  2427. s.Groupno = groupNo
  2428. s.CreatedTime = ctime
  2429. s.UpdatedTime = mtime
  2430. s.PatientId = patient_id
  2431. s.HisPatientId = his_patient_id
  2432. s.StartTime = pTime
  2433. s.IsSettle = 2
  2434. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2435. if errcode > 0 {
  2436. c.ServeFailJSONWithSGJErrorCode(errcode)
  2437. return
  2438. }
  2439. s.StartTime = pTime
  2440. var total_count int64 //处方总库存
  2441. //查询改药品信息
  2442. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2443. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2444. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2445. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2446. total_count += prescribingNumberSeven * medical.MinNumber
  2447. }
  2448. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2449. total_count += prescribingNumberSeven
  2450. }
  2451. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2452. total_count += prescribingNumberSeven
  2453. }
  2454. service.CreateHisDoctorAdvice(&s)
  2455. //存储切片中
  2456. adviceList = append(adviceList, s)
  2457. redis := service.RedisClient()
  2458. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2459. redis.Set(key, "", time.Second)
  2460. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2461. redis.Set(keyOne, "", time.Second)
  2462. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2463. redis.Set(keySeven, "", time.Second)
  2464. var randNum int
  2465. randNum = rand.Intn(10000) + 1000
  2466. timestamp := time.Now().Unix()
  2467. tempTime := time.Unix(timestamp, 0)
  2468. timeFormat := tempTime.Format("20060102150405")
  2469. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2470. service.CreateHisDoctorAdvice(&s)
  2471. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2472. redis.Set(keySix, "", time.Second)
  2473. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2474. redis.Set(keyFive, "", time.Second)
  2475. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2476. redis.Set(keyEight, "", time.Second)
  2477. defer redis.Close()
  2478. }
  2479. }
  2480. }
  2481. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2482. projects := items["project"].([]interface{})
  2483. if len(projects) > 0 {
  2484. for _, project := range projects {
  2485. var p models.HisPrescriptionProject
  2486. p.PrescriptionId = tempPrescription.ID
  2487. p.Ctime = time.Now().Unix()
  2488. p.Mtime = time.Now().Unix()
  2489. p.PatientId = patient_id
  2490. p.RecordDate = recordDateTime
  2491. p.Doctor = doctor_id
  2492. p.UserOrgId = adminInfo.CurrentOrgId
  2493. p.HisPatientId = his_patient_id
  2494. p.Status = 1
  2495. p.StartTime = pTime
  2496. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2497. if errcode > 0 {
  2498. c.ServeFailJSONWithSGJErrorCode(errcode)
  2499. return
  2500. }
  2501. if p.ID == 0 {
  2502. p.IsOut = 2
  2503. }
  2504. if p.ID > 0 {
  2505. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2506. p.IsOut = projectDetail.IsOut
  2507. }
  2508. service.CreateHisProjectTwo(&p)
  2509. projectList = append(projectList, p)
  2510. var randNum int
  2511. randNum = rand.Intn(10000) + 1000
  2512. timestamp := time.Now().Unix()
  2513. tempTime := time.Unix(timestamp, 0)
  2514. timeFormat := tempTime.Format("20060102150405")
  2515. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2516. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2517. //新增或者编辑项目,修改对应的标签数据
  2518. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2519. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2520. var label models.HisLabelPrintInfo
  2521. project, _ := service.GetProjectDetail(p.ProjectId)
  2522. if project.CostClassify == 3 { //类别为检验检查
  2523. if p.TeamId > 0 { //检验检查组套
  2524. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2525. if tempLabel.ID == 0 {
  2526. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2527. label.Number = tempPrescription.PrescriptionNumber
  2528. label.ProjectId = project.ID
  2529. label.Status = 1
  2530. label.IsPrint = 2
  2531. label.DoctorId = info.DoctorId
  2532. label.UserOrgId = p.UserOrgId
  2533. label.PatientId = patient_id
  2534. label.RecordDate = recordDateTime
  2535. label.Ctime = time.Now().Unix()
  2536. label.Mtime = time.Now().Unix()
  2537. label.ItemId = p.TeamId
  2538. label.FeedetlSn = p.FeedetlSn
  2539. label.PProjectId = p.ID
  2540. label.ProjectName = team.ProjectTeam
  2541. label.PatientName = patient.Name
  2542. service.CreateHisLabelRecord(&label)
  2543. }
  2544. } else { //单条检验检查项目
  2545. label.Number = tempPrescription.PrescriptionNumber
  2546. label.ProjectId = project.ID
  2547. label.Status = 1
  2548. label.DoctorId = info.DoctorId
  2549. label.UserOrgId = p.UserOrgId
  2550. label.PatientId = patient_id
  2551. label.RecordDate = recordDateTime
  2552. label.IsPrint = 2
  2553. label.Ctime = time.Now().Unix()
  2554. label.Mtime = time.Now().Unix()
  2555. label.FeedetlSn = p.FeedetlSn
  2556. label.PProjectId = p.ID
  2557. label.ItemId = p.TeamId
  2558. label.ProjectName = project.ProjectName
  2559. label.PatientName = patient.Name
  2560. service.CreateHisLabelRecord(&label)
  2561. }
  2562. }
  2563. }
  2564. }
  2565. service.SaveHisProjectTwo(&p)
  2566. }
  2567. }
  2568. }
  2569. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2570. // addition := items["addition"].([]interface{})
  2571. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2572. // ctime := time.Now().Unix()
  2573. // mtime := ctime
  2574. // if len(addition) > 0 {
  2575. // for _, item := range addition {
  2576. // var s models.HisAdditionalCharge
  2577. // s.PrescriptionId = tempPrescription.ID
  2578. // s.Status = 1
  2579. // s.UserOrgId = adminInfo.CurrentOrgId
  2580. // s.RecordDate = recordDateTime
  2581. // s.CreatedTime = ctime
  2582. // s.UpdatedTime = mtime
  2583. // s.PatientId = patient_id
  2584. // s.HisPatientId = his_patient_id
  2585. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2586. // if errcode > 0 {
  2587. // c.ServeFailJSONWithSGJErrorCode(errcode)
  2588. // return
  2589. // }
  2590. // service.CreateAdditionalCharge(&s)
  2591. // var randNum int
  2592. // randNum = rand.Intn(10000) + 1000
  2593. // timestamp := time.Now().Unix()
  2594. // tempTime := time.Unix(timestamp, 0)
  2595. // timeFormat := tempTime.Format("20060102150405")
  2596. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  2597. // service.CreateAdditionalCharge(&s)
  2598. //
  2599. // }
  2600. // }
  2601. //}
  2602. }
  2603. }
  2604. //查询今日该患者开的药品处方
  2605. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2606. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2607. //药品出库
  2608. if drugOutConfig.IsOpen == 1 {
  2609. for _, item := range hisdoctorlist {
  2610. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  2611. // 查询该药品最后一次出库记录
  2612. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  2613. if len(druginfo) > 0 {
  2614. //回退库存
  2615. for _, it := range druginfo {
  2616. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2617. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2618. }
  2619. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2620. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2621. }
  2622. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2623. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2624. }
  2625. }
  2626. }
  2627. //删除记录
  2628. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  2629. //查询最后一次数据
  2630. if drugOutConfig.IsOpen == 1 {
  2631. //出库
  2632. if drug.IsUse == 2 {
  2633. creater := adminInfo.AdminUser.Id
  2634. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  2635. }
  2636. //更新字典里面的库存
  2637. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  2638. var sum_count int64
  2639. for _, its := range stockInfo {
  2640. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  2641. if its.MaxUnit == baseDrug.MaxUnit {
  2642. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  2643. }
  2644. sum_count += its.StockMaxNumber + its.StockMinNumber
  2645. }
  2646. //更新基础库存
  2647. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  2648. //剩余库存
  2649. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  2650. }
  2651. }
  2652. }
  2653. //耗材保存处方出库
  2654. if goodOutConfig.IsOpen == 1 {
  2655. //查询今日耗材出库数量
  2656. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2657. for _, item := range hisgoodlist {
  2658. //查询历史出库数据
  2659. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2660. var out_count_five int64
  2661. for _, item := range flowGood {
  2662. out_count_five += item.Count
  2663. }
  2664. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2665. if out_count_five != parseIntCount {
  2666. //查询耗材最后一次出库记录
  2667. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2668. //查询默认出库仓库库存
  2669. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2670. if len(wareOut) > 0 {
  2671. for _, it := range wareOut {
  2672. //回退库存
  2673. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2674. //删除出库记录
  2675. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2676. }
  2677. }
  2678. timeStr := time.Now().Format("2006-01-02")
  2679. timeArr := strings.Split(timeStr, "-")
  2680. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2681. total = total + 1
  2682. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2683. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2684. number = number + total
  2685. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2686. operation_time := time.Now().Unix()
  2687. creater := c.GetAdminUserInfo().AdminUser.Id
  2688. recordDateStr := time.Now().Format("2006-01-02")
  2689. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2690. nowtime := recordDate.Unix()
  2691. warehouseOut := models.WarehouseOut{
  2692. WarehouseOutOrderNumber: warehousing_out_order,
  2693. OperationTime: operation_time,
  2694. OrgId: adminInfo.CurrentOrgId,
  2695. Creater: creater,
  2696. Ctime: time.Now().Unix(),
  2697. Status: 1,
  2698. WarehouseOutTime: nowtime,
  2699. Type: 1,
  2700. StorehouseId: storeConfig.StorehouseOutInfo,
  2701. IsCheck: 1,
  2702. IsSys: 1,
  2703. }
  2704. //查询是否生成出库单
  2705. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2706. if out.ID == 0 {
  2707. service.AddSigleWarehouseOut(&warehouseOut)
  2708. }
  2709. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2710. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2711. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2712. dialyPrepareOne := models.DialysisBeforePrepare{
  2713. GoodTypeId: goodObj.GoodTypeId,
  2714. GoodId: item.ProjectId,
  2715. PatientId: item.PatientId,
  2716. RecordDate: item.RecordDate,
  2717. UserOrgId: adminInfo.CurrentOrgId,
  2718. Count: parseIntCount,
  2719. Ctime: time.Now().Unix(),
  2720. Creater: creater,
  2721. Status: 1,
  2722. StorehouseId: houseConfig.StorehouseOutInfo,
  2723. ProjectId: item.ID,
  2724. }
  2725. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2726. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2727. //查询历史出库数据
  2728. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2729. var out_count int64
  2730. for _, item := range flowGood {
  2731. out_count += item.Count
  2732. }
  2733. //如果历史数和当前数据不想等才进行退库出库
  2734. if out_count != parseIntCount {
  2735. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2736. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2737. detail := models.AutomaticReduceDetail{
  2738. WarehouseOutId: 0,
  2739. WarehouseOutOrderNumber: "",
  2740. PatientId: item.PatientId,
  2741. Ctime: time.Now().Unix(),
  2742. Mtime: 0,
  2743. Status: 1,
  2744. RecordTime: item.RecordDate,
  2745. OrgId: item.UserOrgId,
  2746. GoodId: item.ProjectId,
  2747. GoodTypeId: 0,
  2748. Count: parseIntCount,
  2749. Type: 0,
  2750. ProjectId: item.ID,
  2751. StorehouseId: 0,
  2752. }
  2753. service.CreateAutoDetail(detail)
  2754. //查询剩余库存
  2755. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2756. var sum_count int64
  2757. for _, item := range goodList {
  2758. sum_count += item.StockCount
  2759. }
  2760. //更新剩余库存
  2761. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2762. //耗材
  2763. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2764. }
  2765. }
  2766. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2767. //查询历史出库数据
  2768. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2769. var out_count int64
  2770. for _, item := range flowGood {
  2771. out_count += item.Count
  2772. }
  2773. //如果历史数和当前数据不想等才进行退库出库
  2774. if out_count != parseIntCount {
  2775. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2776. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2777. detail := models.AutomaticReduceDetail{
  2778. WarehouseOutId: 0,
  2779. WarehouseOutOrderNumber: "",
  2780. PatientId: item.PatientId,
  2781. Ctime: time.Now().Unix(),
  2782. Mtime: 0,
  2783. Status: 1,
  2784. RecordTime: item.RecordDate,
  2785. OrgId: item.UserOrgId,
  2786. GoodId: item.ProjectId,
  2787. GoodTypeId: 0,
  2788. Count: parseIntCount,
  2789. Type: 0,
  2790. ProjectId: item.ID,
  2791. StorehouseId: 0,
  2792. }
  2793. service.CreateAutoDetail(detail)
  2794. //查询剩余库存
  2795. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2796. var sum_count int64
  2797. for _, item := range goodList {
  2798. sum_count += item.StockCount
  2799. }
  2800. //更新剩余库存
  2801. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2802. //耗材
  2803. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2804. }
  2805. }
  2806. }
  2807. }
  2808. }
  2809. }
  2810. //redisClient := service.RedisClient()
  2811. //defer redisClient.Close()
  2812. //
  2813. //list := models.HisList{
  2814. // Patient_id: patient_id,
  2815. // Advice_id:0,
  2816. // Record_date: 0,
  2817. // Advice: adviceList,
  2818. // Project: nil,
  2819. //}
  2820. //hisLis = append(hisLis, list)
  2821. //
  2822. //advice_json, _ := json.Marshal(&hisLis)
  2823. //redisClient.RPush("111", advice_json).Result()
  2824. //result, _ := redisClient.RPop("111").Result()
  2825. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2826. //
  2827. //var dat []map[string]interface{}
  2828. //json.Unmarshal([]byte(result), &dat)
  2829. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2830. //
  2831. //for k,v:=range dat{
  2832. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2833. //}
  2834. //project_json, _ := json.Marshal(&projectList)
  2835. //redisClient.LPush("222", project_json).Result()
  2836. if err == nil {
  2837. c.ServeSuccessJSON(map[string]interface{}{
  2838. "msg": "保存成功",
  2839. })
  2840. return
  2841. } else {
  2842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2843. return
  2844. }
  2845. }
  2846. func (c *HisApiController) EditHisPrescription() {
  2847. record_date := c.GetString("record_date")
  2848. patient_id, _ := c.GetInt64("patient_id")
  2849. reg_type, _ := c.GetInt64("reg_type")
  2850. //diagnose, _ := c.GetInt64("diagnose", 0)
  2851. diagnose := c.GetString("diagnose")
  2852. sick_type, _ := c.GetInt64("sick_type")
  2853. sick_history := c.GetString("sick_history")
  2854. doctor_id, _ := c.GetInt64("doctor", 0)
  2855. department, _ := c.GetInt64("department", 0)
  2856. his_patient_id, _ := c.GetInt64("his_patient_id")
  2857. p_type, _ := c.GetInt64("p_type")
  2858. dataBody := make(map[string]interface{}, 0)
  2859. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2860. if err != nil {
  2861. utils.ErrorLog(err.Error())
  2862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2863. return
  2864. }
  2865. timeLayout := "2006-01-02"
  2866. loc, _ := time.LoadLocation("Local")
  2867. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2868. if err != nil {
  2869. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2870. return
  2871. }
  2872. adminInfo := c.GetAdminUserInfo()
  2873. recordDateTime := theTime.Unix()
  2874. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2875. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2876. var hpInfo models.HisPrescriptionInfo
  2877. if info.ID == 0 {
  2878. var randNum int
  2879. randNum = rand.Intn(10000) + 1000
  2880. timestamp := time.Now().Unix()
  2881. tempTime := time.Unix(timestamp, 0)
  2882. timeFormat := tempTime.Format("20060102150405")
  2883. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2884. hpInfo = models.HisPrescriptionInfo{
  2885. UserOrgId: adminInfo.CurrentOrgId,
  2886. RecordDate: theTime.Unix(),
  2887. PatientId: patient_id,
  2888. Status: 1,
  2889. Ctime: time.Now().Unix(),
  2890. Mtime: time.Now().Unix(),
  2891. Creator: adminInfo.AdminUser.Id,
  2892. Modifier: adminInfo.AdminUser.Id,
  2893. Diagnosis: diagnose,
  2894. SickHistory: sick_history,
  2895. Departments: department,
  2896. RegisterType: reg_type,
  2897. PrescriptionNumber: p_number,
  2898. PrescriptionStatus: 1,
  2899. Doctor: role.UserName,
  2900. DoctorId: doctor_id,
  2901. SickType: sick_type,
  2902. PType: p_type,
  2903. }
  2904. service.SavePatientPrescriptionInfo(hpInfo)
  2905. } else {
  2906. hpInfo = models.HisPrescriptionInfo{
  2907. ID: info.ID,
  2908. UserOrgId: adminInfo.CurrentOrgId,
  2909. RecordDate: info.RecordDate,
  2910. PatientId: info.PatientId,
  2911. Status: 1,
  2912. Ctime: info.Ctime,
  2913. Mtime: time.Now().Unix(),
  2914. Creator: info.Creator,
  2915. Modifier: adminInfo.AdminUser.Id,
  2916. Diagnosis: diagnose,
  2917. SickHistory: sick_history,
  2918. Departments: department,
  2919. RegisterType: reg_type,
  2920. PrescriptionNumber: info.PrescriptionNumber,
  2921. Doctor: role.UserName,
  2922. PrescriptionStatus: info.PrescriptionStatus,
  2923. DoctorId: doctor_id,
  2924. SickType: sick_type,
  2925. PType: info.PType,
  2926. }
  2927. service.SavePatientPrescriptionInfo(hpInfo)
  2928. }
  2929. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2930. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2931. if len(prescriptions) > 0 {
  2932. for _, item := range prescriptions {
  2933. items := item.(map[string]interface{})
  2934. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2935. utils.ErrorLog("id")
  2936. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2937. return
  2938. }
  2939. id := int64(items["id"].(float64))
  2940. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2941. utils.ErrorLog("type")
  2942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2943. return
  2944. }
  2945. types := int64(items["type"].(float64))
  2946. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2947. utils.ErrorLog("med_type")
  2948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2949. return
  2950. }
  2951. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2952. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2953. ctime := time.Now().Unix()
  2954. prescription := &models.HisPrescription{
  2955. ID: id,
  2956. PatientId: patient_id,
  2957. UserOrgId: adminInfo.CurrentOrgId,
  2958. RecordDate: recordDateTime,
  2959. Ctime: ctime,
  2960. Mtime: ctime,
  2961. Type: types,
  2962. Modifier: adminInfo.AdminUser.Id,
  2963. Creator: adminInfo.AdminUser.Id,
  2964. Status: 1,
  2965. Doctor: role.UserName,
  2966. HisPatientId: his_patient_id,
  2967. OrderStatus: 1,
  2968. BatchNumber: "",
  2969. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2970. PType: hpInfo.PType,
  2971. MedType: med_type,
  2972. }
  2973. if historyPrescription.ID > 0 {
  2974. prescription.PreTime = historyPrescription.PreTime
  2975. }
  2976. service.SaveHisPrescription(prescription)
  2977. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2978. advices := items["advices"].([]interface{})
  2979. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2980. groupNo := int64(0)
  2981. ctime := time.Now().Unix()
  2982. mtime := ctime
  2983. if len(advices) > 0 {
  2984. for _, advice := range advices {
  2985. var s models.HisDoctorAdviceInfo
  2986. s.PrescriptionId = prescription.ID
  2987. s.AdviceType = 2
  2988. s.AdviceDoctor = adminInfo.AdminUser.Id
  2989. s.StopState = 2
  2990. s.ExecutionState = 2
  2991. s.AdviceDate = recordDateTime
  2992. s.Status = 1
  2993. s.UserOrgId = adminInfo.CurrentOrgId
  2994. s.RecordDate = recordDateTime
  2995. s.StartTime = prescription.PreTime
  2996. s.Groupno = groupNo
  2997. s.CreatedTime = ctime
  2998. s.UpdatedTime = mtime
  2999. s.PatientId = patient_id
  3000. s.HisPatientId = his_patient_id
  3001. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3002. if errcode > 0 {
  3003. c.ServeFailJSONWithSGJErrorCode(errcode)
  3004. return
  3005. }
  3006. service.CreateHisDoctorAdvice(&s)
  3007. redis := service.RedisClient()
  3008. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3009. redis.Set(key, "", time.Second)
  3010. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3011. fmt.Println("keyOne", keyOne)
  3012. redis.Set(keyOne, "", time.Second)
  3013. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3014. redis.Set(keySeven, "", time.Second)
  3015. redis.Close()
  3016. }
  3017. }
  3018. }
  3019. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3020. projects := items["project"].([]interface{})
  3021. if len(projects) > 0 {
  3022. for _, project := range projects {
  3023. var p models.HisPrescriptionProject
  3024. p.PrescriptionId = prescription.ID
  3025. p.Ctime = time.Now().Unix()
  3026. p.Mtime = time.Now().Unix()
  3027. p.PatientId = patient_id
  3028. p.RecordDate = recordDateTime
  3029. p.UserOrgId = adminInfo.CurrentOrgId
  3030. p.HisPatientId = his_patient_id
  3031. p.Status = 1
  3032. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3033. if errcode > 0 {
  3034. c.ServeFailJSONWithSGJErrorCode(errcode)
  3035. return
  3036. }
  3037. service.CreateHisProjectTwo(&p)
  3038. }
  3039. }
  3040. }
  3041. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3042. addition := items["addition"].([]interface{})
  3043. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3044. ctime := time.Now().Unix()
  3045. mtime := ctime
  3046. if len(addition) > 0 {
  3047. for _, item := range addition {
  3048. var s models.HisAdditionalCharge
  3049. s.PrescriptionId = prescription.ID
  3050. s.Status = 1
  3051. s.UserOrgId = adminInfo.CurrentOrgId
  3052. s.RecordDate = recordDateTime
  3053. s.CreatedTime = ctime
  3054. s.UpdatedTime = mtime
  3055. s.PatientId = patient_id
  3056. s.HisPatientId = his_patient_id
  3057. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3058. if errcode > 0 {
  3059. c.ServeFailJSONWithSGJErrorCode(errcode)
  3060. return
  3061. }
  3062. service.CreateAdditionalCharge(&s)
  3063. }
  3064. }
  3065. }
  3066. }
  3067. }
  3068. }
  3069. if err == nil {
  3070. c.ServeSuccessJSON(map[string]interface{}{
  3071. "msg": "保存成功",
  3072. })
  3073. return
  3074. } else {
  3075. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3076. return
  3077. }
  3078. }
  3079. func (c *HisApiController) DeletePrescription() {
  3080. prescription_id, _ := c.GetInt64("id")
  3081. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3082. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3083. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3084. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3085. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3086. //耗材保存处方出库
  3087. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3088. //已收费和已发药限制逻辑
  3089. isCharge := false
  3090. isMedicine := false
  3091. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3092. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3093. for _, item := range new_prescriptions {
  3094. if item.IsMedicine == 1 {
  3095. isMedicine = true
  3096. }
  3097. }
  3098. for _, item := range new_prescriptions {
  3099. if item.OrderStatus == 4 {
  3100. isCharge = true
  3101. }
  3102. }
  3103. if p_err != nil {
  3104. if new_prescription.ID > 0 {
  3105. if new_prescription.OrderStatus == 2 {
  3106. isCharge = true
  3107. }
  3108. }
  3109. }
  3110. for _, item := range advices {
  3111. if item.IsMedicine == 1 {
  3112. isMedicine = true
  3113. }
  3114. }
  3115. if isCharge {
  3116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3117. return
  3118. }
  3119. if isMedicine {
  3120. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3121. return
  3122. }
  3123. //已收费和已发药限制逻辑
  3124. if len(projects) > 0 {
  3125. for _, item := range projects {
  3126. service.DeletePrintInfo(item.ID) //删除打印信息
  3127. if goodOutConfig.IsOpen != 1 {
  3128. if stockConfig.IsOpen == 1 {
  3129. if item.Type == 3 && item.IsOut == 1 {
  3130. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3131. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3132. good.Total = good.Total + f_count
  3133. service.UpdateGoodInfo(&good)
  3134. operation_time := time.Now().Unix()
  3135. creater := c.GetAdminUserInfo().AdminUser.Id
  3136. //创建退库单
  3137. timeStr := time.Now().Format("2006-01-02")
  3138. timeArr := strings.Split(timeStr, "-")
  3139. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3140. total = total + 1
  3141. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3142. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3143. cancelStock := models.CancelStock{
  3144. OrderNumber: orderNumber,
  3145. OperaTime: operation_time,
  3146. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3147. Creater: creater,
  3148. Ctime: time.Now().Unix(),
  3149. Status: 1,
  3150. ReturnTime: item.RecordDate,
  3151. Type: 1,
  3152. StorehouseId: houseConfig.StorehouseOutInfo,
  3153. IsCheck: 1,
  3154. }
  3155. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3156. if msgerrkonde == gorm.ErrRecordNotFound {
  3157. service.AddSigleCancelStock(&cancelStock)
  3158. }
  3159. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3160. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3161. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3162. //查询该耗材是否出库
  3163. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3164. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3165. deaerler, _ := service.GetDealerById(info.Dealer)
  3166. var total_count int64
  3167. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3168. total_count += count
  3169. if info.ID > 0 {
  3170. if info.Count >= total_count {
  3171. //回退库存
  3172. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3173. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3174. var flush_count int64
  3175. for _, it := range goodList {
  3176. flush_count += it.StockCount
  3177. }
  3178. cancelStockInfo := models.CancelStockInfo{
  3179. GoodId: item.ProjectId,
  3180. CancelStockId: cancel.ID,
  3181. GoodTypeId: good.GoodTypeId,
  3182. Count: prescribingNumber,
  3183. Price: info.Price,
  3184. Total: 0,
  3185. ProductDate: info.ProductDate,
  3186. ExpiryDate: info.ExpiryDate,
  3187. Ctime: time.Now().Unix(),
  3188. Status: 1,
  3189. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3190. OrderNumber: cancel.OrderNumber,
  3191. Type: 0,
  3192. Dealer: deaerler.DealerName,
  3193. Manufacturer: manufacturer.ManufacturerName,
  3194. Number: info.Number,
  3195. RegisterAccount: "",
  3196. Remark: "",
  3197. WarehouseInfoId: info.WarehouseInfotId,
  3198. PatientId: info.PatientId,
  3199. RecordDate: info.SysRecordTime,
  3200. StorehouseId: houseConfig.StorehouseOutInfo,
  3201. IsCheck: 1,
  3202. }
  3203. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3204. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3205. flow := models.VmStockFlow{
  3206. WarehousingId: info.WarehouseInfotId,
  3207. GoodId: item.ProjectId,
  3208. Number: info.Number,
  3209. LicenseNumber: info.LicenseNumber,
  3210. Count: prescribingNumber,
  3211. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3212. PatientId: item.PatientId,
  3213. SystemTime: info.SysRecordTime,
  3214. ConsumableType: 7,
  3215. IsSys: 0,
  3216. WarehousingOrder: "",
  3217. WarehouseOutId: info.WarehouseOutId,
  3218. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3219. IsEdit: 0,
  3220. CancelStockId: cancel.ID,
  3221. CancelOrderNumber: cancel.OrderNumber,
  3222. Manufacturer: manufacturer.ID,
  3223. Dealer: 0,
  3224. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3225. UpdateCreator: 0,
  3226. Status: 1,
  3227. Ctime: time.Now().Unix(),
  3228. Mtime: 0,
  3229. Price: info.Price,
  3230. WarehousingDetailId: info.WarehouseInfotId,
  3231. WarehouseOutDetailId: info.ID,
  3232. CancelOutDetailId: cancelInfo.ID,
  3233. ProductDate: info.ProductDate,
  3234. ExpireDate: info.ExpiryDate,
  3235. StorehouseId: houseConfig.StorehouseOutInfo,
  3236. OverCount: flush_count,
  3237. }
  3238. service.CreateStockFlowOne(flow)
  3239. //退库数量增加
  3240. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3241. //出库数量减少
  3242. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3243. }
  3244. if info.Count < total_count {
  3245. //回退库存
  3246. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3247. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3248. var flush_count int64
  3249. for _, it := range goodList {
  3250. flush_count += it.StockCount
  3251. }
  3252. cancelStockInfo := models.CancelStockInfo{
  3253. GoodId: item.ProjectId,
  3254. CancelStockId: cancel.ID,
  3255. GoodTypeId: good.GoodTypeId,
  3256. Count: info.Count,
  3257. Price: info.Price,
  3258. Total: 0,
  3259. ProductDate: info.ProductDate,
  3260. ExpiryDate: info.ExpiryDate,
  3261. Ctime: time.Now().Unix(),
  3262. Status: 1,
  3263. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3264. OrderNumber: cancel.OrderNumber,
  3265. Type: 0,
  3266. Dealer: deaerler.DealerName,
  3267. Manufacturer: manufacturer.ManufacturerName,
  3268. Number: info.Number,
  3269. RegisterAccount: "",
  3270. Remark: "",
  3271. WarehouseInfoId: info.WarehouseInfotId,
  3272. PatientId: info.PatientId,
  3273. RecordDate: info.SysRecordTime,
  3274. StorehouseId: houseConfig.StorehouseOutInfo,
  3275. IsCheck: 1,
  3276. }
  3277. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3278. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3279. flow := models.VmStockFlow{
  3280. WarehousingId: info.WarehouseInfotId,
  3281. GoodId: item.ProjectId,
  3282. Number: info.Number,
  3283. LicenseNumber: info.LicenseNumber,
  3284. Count: info.Count,
  3285. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3286. PatientId: item.PatientId,
  3287. SystemTime: info.SysRecordTime,
  3288. ConsumableType: 7,
  3289. IsSys: 0,
  3290. WarehousingOrder: "",
  3291. WarehouseOutId: info.WarehouseOutId,
  3292. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3293. IsEdit: 0,
  3294. CancelStockId: cancel.ID,
  3295. CancelOrderNumber: cancel.OrderNumber,
  3296. Manufacturer: manufacturer.ID,
  3297. Dealer: 0,
  3298. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3299. UpdateCreator: 0,
  3300. Status: 1,
  3301. Ctime: time.Now().Unix(),
  3302. Mtime: 0,
  3303. Price: info.Price,
  3304. WarehousingDetailId: info.WarehouseInfotId,
  3305. WarehouseOutDetailId: info.ID,
  3306. CancelOutDetailId: cancelInfo.ID,
  3307. ProductDate: info.ProductDate,
  3308. ExpireDate: info.ExpiryDate,
  3309. StorehouseId: houseConfig.StorehouseOutInfo,
  3310. OverCount: flush_count,
  3311. }
  3312. service.CreateStockFlowOne(flow)
  3313. //退库数量增加
  3314. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3315. //出库数量减少
  3316. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3317. }
  3318. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3319. var flush_count int64
  3320. for _, it := range goodList {
  3321. flush_count += it.StockCount
  3322. }
  3323. //查询已出库数量
  3324. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3325. if prescribingNumber < dialysisInfo.Count {
  3326. //改变数量
  3327. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3328. }
  3329. if prescribingNumber >= dialysisInfo.Count {
  3330. //删除出库表
  3331. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3332. }
  3333. //更新库存
  3334. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3335. //更新基础库库存
  3336. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3337. }
  3338. }
  3339. }
  3340. }
  3341. //保存耗材出库
  3342. if goodOutConfig.IsOpen == 1 {
  3343. if item.Type == 3 {
  3344. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3345. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3346. good.Total = good.Total + f_count
  3347. service.UpdateGoodInfo(&good)
  3348. operation_time := time.Now().Unix()
  3349. creater := c.GetAdminUserInfo().AdminUser.Id
  3350. //创建退库单
  3351. timeStr := time.Now().Format("2006-01-02")
  3352. timeArr := strings.Split(timeStr, "-")
  3353. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3354. total = total + 1
  3355. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3356. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3357. cancelStock := models.CancelStock{
  3358. OrderNumber: orderNumber,
  3359. OperaTime: operation_time,
  3360. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3361. Creater: creater,
  3362. Ctime: time.Now().Unix(),
  3363. Status: 1,
  3364. ReturnTime: item.RecordDate,
  3365. Type: 1,
  3366. StorehouseId: houseConfig.StorehouseOutInfo,
  3367. IsCheck: 1,
  3368. }
  3369. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3370. if msgerrkonde == gorm.ErrRecordNotFound {
  3371. service.AddSigleCancelStock(&cancelStock)
  3372. }
  3373. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3374. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3375. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3376. //查询该耗材是否出库
  3377. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3378. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3379. deaerler, _ := service.GetDealerById(info.Dealer)
  3380. var total_count int64
  3381. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3382. total_count += count
  3383. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3384. var flush_count int64
  3385. for _, it := range goodList {
  3386. flush_count += it.StockCount
  3387. }
  3388. fmt.Println("历史出库数据", info.Count)
  3389. fmt.Println("出库数量", total_count)
  3390. if info.ID > 0 {
  3391. cancelStockInfo := models.CancelStockInfo{
  3392. GoodId: item.ProjectId,
  3393. CancelStockId: cancel.ID,
  3394. GoodTypeId: good.GoodTypeId,
  3395. Count: prescribingNumber,
  3396. Price: info.Price,
  3397. Total: 0,
  3398. ProductDate: info.ProductDate,
  3399. ExpiryDate: info.ExpiryDate,
  3400. Ctime: time.Now().Unix(),
  3401. Status: 1,
  3402. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3403. OrderNumber: cancel.OrderNumber,
  3404. Type: 0,
  3405. Dealer: deaerler.DealerName,
  3406. Manufacturer: manufacturer.ManufacturerName,
  3407. Number: info.Number,
  3408. RegisterAccount: "",
  3409. Remark: "",
  3410. WarehouseInfoId: info.WarehouseInfotId,
  3411. PatientId: info.PatientId,
  3412. RecordDate: info.SysRecordTime,
  3413. StorehouseId: houseConfig.StorehouseOutInfo,
  3414. IsCheck: 1,
  3415. }
  3416. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3417. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3418. //查询出库数量
  3419. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3420. //出库数据 大于 退库数量
  3421. if len(list) > 0 {
  3422. for _, it := range list {
  3423. //回退库存
  3424. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3425. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3426. var flush_count_one int64
  3427. for _, it := range goodList {
  3428. flush_count_one += it.StockCount
  3429. }
  3430. //查询该批次是否有退库数据
  3431. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3432. creater := c.GetAdminUserInfo().AdminUser.Id
  3433. flow := models.VmStockFlow{
  3434. WarehousingId: it.WarehouseInfotId,
  3435. GoodId: it.GoodId,
  3436. Number: it.Number,
  3437. LicenseNumber: it.LicenseNumber,
  3438. Count: it.Count,
  3439. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3440. PatientId: it.PatientId,
  3441. SystemTime: it.SysRecordTime,
  3442. ConsumableType: 7,
  3443. IsSys: 0,
  3444. WarehousingOrder: "",
  3445. WarehouseOutId: it.WarehouseOutId,
  3446. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3447. IsEdit: 0,
  3448. CancelStockId: cancel.ID,
  3449. CancelOrderNumber: cancel.OrderNumber,
  3450. Manufacturer: manufacturer.ID,
  3451. Dealer: 0,
  3452. Creator: creater,
  3453. UpdateCreator: 0,
  3454. Status: 1,
  3455. Ctime: time.Now().Unix(),
  3456. Mtime: 0,
  3457. Price: it.Price,
  3458. WarehousingDetailId: it.WarehouseInfotId,
  3459. WarehouseOutDetailId: it.ID,
  3460. CancelOutDetailId: cancelInfo.ID,
  3461. ProductDate: it.ProductDate,
  3462. ExpireDate: it.ExpiryDate,
  3463. StorehouseId: houseConfig.StorehouseOutInfo,
  3464. OverCount: flush_count_one,
  3465. }
  3466. service.CreateStockFlowOne(flow)
  3467. //if flow.ID > 0 {
  3468. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3469. //}
  3470. }
  3471. }
  3472. //flow := models.VmStockFlow{
  3473. // WarehousingId: info.WarehouseInfotId,
  3474. // GoodId: item.ProjectId,
  3475. // Number: info.Number,
  3476. // LicenseNumber: info.LicenseNumber,
  3477. // Count: prescribingNumber,
  3478. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3479. // PatientId: item.PatientId,
  3480. // SystemTime: info.SysRecordTime,
  3481. // ConsumableType: 7,
  3482. // IsSys: 0,
  3483. // WarehousingOrder: "",
  3484. // WarehouseOutId: info.WarehouseOutId,
  3485. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3486. // IsEdit: 0,
  3487. // CancelStockId: cancel.ID,
  3488. // CancelOrderNumber: cancel.OrderNumber,
  3489. // Manufacturer: manufacturer.ID,
  3490. // Dealer: 0,
  3491. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3492. // UpdateCreator: 0,
  3493. // Status: 1,
  3494. // Ctime: time.Now().Unix(),
  3495. // Mtime: 0,
  3496. // Price: info.Price,
  3497. // WarehousingDetailId: info.WarehouseInfotId,
  3498. // WarehouseOutDetailId: info.ID,
  3499. // CancelOutDetailId: cancelInfo.ID,
  3500. // ProductDate: info.ProductDate,
  3501. // ExpireDate: info.ExpiryDate,
  3502. // StorehouseId: houseConfig.StorehouseOutInfo,
  3503. // OverCount: flush_count,
  3504. //}
  3505. //service.CreateStockFlowOne(flow)
  3506. //退库数量增加
  3507. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3508. //出库数量减少
  3509. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3510. //查询已出库数量
  3511. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3512. if prescribingNumber < dialysisInfo.Count {
  3513. //改变数量
  3514. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3515. }
  3516. if prescribingNumber >= dialysisInfo.Count {
  3517. //删除出库表
  3518. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3519. }
  3520. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3521. var flush_count_one int64
  3522. for _, it := range goodList {
  3523. flush_count_one += it.StockCount
  3524. }
  3525. //更新库存
  3526. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3527. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3528. //更新基础库库存
  3529. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3530. }
  3531. }
  3532. }
  3533. }
  3534. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3535. fmt.Println(err)
  3536. }
  3537. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3538. fmt.Println(err)
  3539. if len(advices) > 0 {
  3540. for _, item := range advices {
  3541. redis := service.RedisClient()
  3542. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  3543. redis.Set(keyFive, "", time.Second)
  3544. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  3545. redis.Set(keyOne, "", time.Second)
  3546. redis.Close()
  3547. }
  3548. }
  3549. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3550. if len(advices) > 0 {
  3551. for _, item := range advices {
  3552. creater := c.GetAdminUserInfo().AdminUser.Id
  3553. service.DrugAutoAddCancelInfo(item, creater)
  3554. }
  3555. }
  3556. } else {
  3557. if drugOutConfig.IsOpen == 1 {
  3558. if len(advices) > 0 {
  3559. for _, item := range advices {
  3560. creater := c.GetAdminUserInfo().AdminUser.Id
  3561. service.DrugAutoAddCancelInfo(item, creater)
  3562. }
  3563. }
  3564. } else {
  3565. if len(advices) > 0 {
  3566. for _, item := range advices {
  3567. creater := c.GetAdminUserInfo().AdminUser.Id
  3568. service.DrugAutoAddCancelInfo(item, creater)
  3569. }
  3570. }
  3571. }
  3572. }
  3573. c.ServeSuccessJSON(map[string]interface{}{
  3574. "msg": "删除成功",
  3575. })
  3576. return
  3577. }
  3578. func (c *HisApiController) DeleteDoctorAdvice() {
  3579. id, _ := c.GetInt64("id")
  3580. advice, _ := service.GetHisDoctorAdvicesById(id)
  3581. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3582. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3583. //已收费和已发药的限制逻辑
  3584. isCharge := false
  3585. isMedicine := false
  3586. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3587. //获取今天该患者所有处方,判断是否发药或者收费
  3588. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3589. for _, item := range new_prescriptions {
  3590. if item.IsMedicine == 1 {
  3591. isMedicine = true
  3592. }
  3593. }
  3594. for _, item := range new_prescriptions {
  3595. if item.OrderStatus == 4 {
  3596. isCharge = true
  3597. }
  3598. }
  3599. if isMedicine {
  3600. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3601. return
  3602. }
  3603. if isCharge {
  3604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3605. return
  3606. }
  3607. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  3608. for _, item := range advices {
  3609. if item.IsMedicine == 1 {
  3610. isMedicine = true
  3611. }
  3612. }
  3613. if isMedicine {
  3614. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  3615. return
  3616. }
  3617. if new_prescription.ID > 0 {
  3618. if new_prescription.OrderStatus == 2 {
  3619. isCharge = true
  3620. }
  3621. }
  3622. if isCharge {
  3623. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3624. return
  3625. }
  3626. //已收费和已发药的限制逻辑
  3627. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  3628. redis := service.RedisClient()
  3629. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  3630. redis.Set(keyFive, "", time.Second)
  3631. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  3632. redis.Set(keyOne, "", time.Second)
  3633. defer redis.Close()
  3634. if err == nil {
  3635. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  3636. //查询是否在处方中出库
  3637. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3638. if openConfig.IsOpen != 1 {
  3639. //判断该医嘱是否执行了
  3640. if advice.ExecutionState == 1 {
  3641. creater := c.GetAdminUserInfo().AdminUser.Id
  3642. service.DrugAutoAddCancelInfo(&advice, creater)
  3643. }
  3644. }
  3645. //开启保存处方扣减功能
  3646. if openConfig.IsOpen == 1 {
  3647. creater := c.GetAdminUserInfo().AdminUser.Id
  3648. service.DrugAutoAddCancelInfo(&advice, creater)
  3649. }
  3650. } else {
  3651. if drugOutConfig.IsOpen == 1 {
  3652. //查询是否在处方中出库
  3653. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  3654. if openConfig.IsOpen != 1 {
  3655. //判断该医嘱是否执行了
  3656. if advice.ExecutionState == 1 {
  3657. creater := c.GetAdminUserInfo().AdminUser.Id
  3658. service.DrugAutoAddCancelInfo(&advice, creater)
  3659. }
  3660. }
  3661. //开启保存处方扣减功能
  3662. if openConfig.IsOpen == 1 {
  3663. creater := c.GetAdminUserInfo().AdminUser.Id
  3664. service.DrugAutoAddCancelInfo(&advice, creater)
  3665. }
  3666. } else {
  3667. //判断该医嘱是否执行了
  3668. if advice.ExecutionState == 1 {
  3669. creater := c.GetAdminUserInfo().AdminUser.Id
  3670. service.DrugAutoAddCancelInfo(&advice, creater)
  3671. }
  3672. }
  3673. }
  3674. c.ServeSuccessJSON(map[string]interface{}{
  3675. "msg": "删除成功",
  3676. })
  3677. return
  3678. } else {
  3679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3680. return
  3681. }
  3682. }
  3683. func (c *HisApiController) DeleteProject() {
  3684. id, _ := c.GetInt64("id")
  3685. adminInfo := c.GetAdminUserInfo()
  3686. project, _ := service.GetHisProjectByID(id)
  3687. // var consumable models.DialysisBeforePrepare
  3688. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3689. //耗材保存处方出库
  3690. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3691. isCharge := false
  3692. isMedicine := false
  3693. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3694. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3695. for _, item := range new_prescriptions {
  3696. if item.IsMedicine == 1 {
  3697. isMedicine = true
  3698. }
  3699. }
  3700. for _, item := range new_prescriptions {
  3701. if item.OrderStatus == 4 {
  3702. isCharge = true
  3703. }
  3704. }
  3705. if isMedicine {
  3706. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3707. return
  3708. }
  3709. if isCharge {
  3710. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3711. return
  3712. }
  3713. if new_prescription.ID > 0 {
  3714. if new_prescription.OrderStatus == 2 {
  3715. isCharge = true
  3716. }
  3717. }
  3718. if isCharge {
  3719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3720. return
  3721. }
  3722. service.DeletePrintInfo(id)
  3723. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3724. label.Status = 0
  3725. service.CreateHisLabelRecord(&label)
  3726. fmt.Println(goodOutConfig.IsOpen)
  3727. if goodOutConfig.IsOpen != 1 {
  3728. if stockConfig.IsOpen == 1 {
  3729. if project.Type == 2 {
  3730. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3731. fmt.Println(err)
  3732. }
  3733. if project.Type == 3 && project.IsOut == 1 {
  3734. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3735. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3736. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3737. operation_time := time.Now().Unix()
  3738. creater := adminInfo.AdminUser.Id
  3739. //创建退库单
  3740. timeStr := time.Now().Format("2006-01-02")
  3741. timeArr := strings.Split(timeStr, "-")
  3742. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3743. total = total + 1
  3744. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3745. cancelStock := models.CancelStock{
  3746. OrderNumber: orderNumber,
  3747. OperaTime: operation_time,
  3748. OrgId: adminInfo.CurrentOrgId,
  3749. Creater: creater,
  3750. Ctime: time.Now().Unix(),
  3751. Status: 1,
  3752. ReturnTime: project.RecordDate,
  3753. Type: 1,
  3754. StorehouseId: houseConfig.StorehouseOutInfo,
  3755. IsCheck: 1,
  3756. }
  3757. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3758. if msgerrkonde == gorm.ErrRecordNotFound {
  3759. service.AddSigleCancelStock(&cancelStock)
  3760. }
  3761. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3762. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3763. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3764. //查询是否有出库
  3765. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3766. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3767. deaerler, _ := service.GetDealerById(info.Dealer)
  3768. if info.ID > 0 {
  3769. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3770. if info.Count >= prescribingNumber {
  3771. cancelStockInfo := models.CancelStockInfo{
  3772. GoodId: project.ProjectId,
  3773. CancelStockId: cancel.ID,
  3774. GoodTypeId: good.GoodTypeId,
  3775. Count: prescribingNumber,
  3776. Price: info.Price,
  3777. Total: 0,
  3778. ProductDate: info.ProductDate,
  3779. ExpiryDate: info.ExpiryDate,
  3780. Ctime: time.Now().Unix(),
  3781. Status: 1,
  3782. OrgId: adminInfo.CurrentOrgId,
  3783. OrderNumber: cancel.OrderNumber,
  3784. Type: 0,
  3785. Dealer: deaerler.DealerName,
  3786. Manufacturer: manufacturer.ManufacturerName,
  3787. Number: info.Number,
  3788. RegisterAccount: "",
  3789. Remark: "",
  3790. WarehouseInfoId: info.WarehouseInfotId,
  3791. PatientId: info.PatientId,
  3792. RecordDate: info.SysRecordTime,
  3793. StorehouseId: houseConfig.StorehouseOutInfo,
  3794. IsCheck: 1,
  3795. }
  3796. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3797. //回退库存
  3798. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3799. //退库数量增加
  3800. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3801. //出库数量减少
  3802. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3803. }
  3804. if info.Count < prescribingNumber {
  3805. cancelStockInfo := models.CancelStockInfo{
  3806. GoodId: project.ProjectId,
  3807. CancelStockId: cancel.ID,
  3808. GoodTypeId: good.GoodTypeId,
  3809. Count: info.Count,
  3810. Price: info.Price,
  3811. Total: 0,
  3812. ProductDate: info.ProductDate,
  3813. ExpiryDate: info.ExpiryDate,
  3814. Ctime: time.Now().Unix(),
  3815. Status: 1,
  3816. OrgId: adminInfo.CurrentOrgId,
  3817. OrderNumber: cancel.OrderNumber,
  3818. Type: 0,
  3819. Dealer: deaerler.DealerName,
  3820. Manufacturer: manufacturer.ManufacturerName,
  3821. Number: info.Number,
  3822. RegisterAccount: "",
  3823. Remark: "",
  3824. WarehouseInfoId: info.WarehouseInfotId,
  3825. PatientId: info.PatientId,
  3826. RecordDate: info.SysRecordTime,
  3827. StorehouseId: houseConfig.StorehouseOutInfo,
  3828. IsCheck: 1,
  3829. }
  3830. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3831. //回退库存
  3832. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3833. //退库数量增加
  3834. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3835. //出库数量减少
  3836. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3837. }
  3838. //查询剩余库存
  3839. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3840. var over_count int64
  3841. for _, it := range goodList {
  3842. over_count += it.StockCount
  3843. }
  3844. //出库数据 大于 退库数量
  3845. if info.Count >= prescribingNumber {
  3846. flow := models.VmStockFlow{
  3847. WarehousingId: info.WarehouseInfotId,
  3848. GoodId: project.ProjectId,
  3849. Number: info.Number,
  3850. LicenseNumber: info.LicenseNumber,
  3851. Count: prescribingNumber,
  3852. UserOrgId: adminInfo.CurrentOrgId,
  3853. PatientId: project.PatientId,
  3854. SystemTime: info.SysRecordTime,
  3855. ConsumableType: 7,
  3856. IsSys: 0,
  3857. WarehousingOrder: "",
  3858. WarehouseOutId: info.WarehouseOutId,
  3859. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3860. IsEdit: 0,
  3861. CancelStockId: cancel.ID,
  3862. CancelOrderNumber: cancel.OrderNumber,
  3863. Manufacturer: manufacturer.ID,
  3864. Dealer: 0,
  3865. Creator: adminInfo.AdminUser.Id,
  3866. UpdateCreator: 0,
  3867. Status: 1,
  3868. Ctime: time.Now().Unix(),
  3869. Mtime: 0,
  3870. Price: info.Price,
  3871. WarehousingDetailId: info.WarehouseInfotId,
  3872. WarehouseOutDetailId: info.ID,
  3873. CancelOutDetailId: cancelInfo.ID,
  3874. ProductDate: info.ProductDate,
  3875. ExpireDate: info.ExpiryDate,
  3876. StorehouseId: houseConfig.StorehouseOutInfo,
  3877. OverCount: over_count,
  3878. }
  3879. service.CreateStockFlowOne(flow)
  3880. }
  3881. //出库数据小于退库数据
  3882. if info.Count < prescribingNumber {
  3883. flow := models.VmStockFlow{
  3884. WarehousingId: info.WarehouseInfotId,
  3885. GoodId: project.ProjectId,
  3886. Number: info.Number,
  3887. LicenseNumber: info.LicenseNumber,
  3888. Count: info.Count,
  3889. UserOrgId: adminInfo.CurrentOrgId,
  3890. PatientId: project.PatientId,
  3891. SystemTime: info.SysRecordTime,
  3892. ConsumableType: 7,
  3893. IsSys: 0,
  3894. WarehousingOrder: "",
  3895. WarehouseOutId: info.WarehouseOutId,
  3896. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3897. IsEdit: 0,
  3898. CancelStockId: cancel.ID,
  3899. CancelOrderNumber: cancel.OrderNumber,
  3900. Manufacturer: manufacturer.ID,
  3901. Dealer: 0,
  3902. Creator: adminInfo.AdminUser.Id,
  3903. UpdateCreator: 0,
  3904. Status: 1,
  3905. Ctime: time.Now().Unix(),
  3906. Mtime: 0,
  3907. Price: info.Price,
  3908. WarehousingDetailId: info.WarehouseInfotId,
  3909. WarehouseOutDetailId: info.ID,
  3910. CancelOutDetailId: cancelInfo.ID,
  3911. ProductDate: info.ProductDate,
  3912. ExpireDate: info.ExpiryDate,
  3913. StorehouseId: houseConfig.StorehouseOutInfo,
  3914. OverCount: over_count,
  3915. }
  3916. service.CreateStockFlowOne(flow)
  3917. }
  3918. //查询已出库数量
  3919. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3920. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3921. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3922. if prescribingNumber < dialysisInfo.Count {
  3923. //改变数量
  3924. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3925. }
  3926. if prescribingNumber >= dialysisInfo.Count {
  3927. //删除出库表
  3928. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3929. }
  3930. //更新剩余库存
  3931. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3932. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3933. var total_count_one int64
  3934. for _, it := range stockList {
  3935. total_count_one += it.StockCount
  3936. }
  3937. //基础库插入数据
  3938. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3939. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3940. var flush_count int64
  3941. for _, it := range goodListOne {
  3942. flush_count += it.StockCount
  3943. }
  3944. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3945. if errs != nil {
  3946. goodErrcode := models.XtGoodErrcode{
  3947. UserOrgId: project.UserOrgId,
  3948. Errcode: "手动出库更新剩余出库失败",
  3949. GoodId: project.ProjectId,
  3950. Status: 1,
  3951. Ctime: time.Now().Unix(),
  3952. Mtime: 0,
  3953. Count: 0,
  3954. StockCount: 0,
  3955. Creater: creater,
  3956. BatchNumberId: 0,
  3957. WarehouseOutId: 0,
  3958. }
  3959. service.CreateGoodErrcode(goodErrcode)
  3960. }
  3961. }
  3962. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3963. fmt.Println(err)
  3964. } else {
  3965. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3966. fmt.Println(err)
  3967. }
  3968. } else {
  3969. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3970. fmt.Println(err)
  3971. }
  3972. }
  3973. //保存处方出库
  3974. if goodOutConfig.IsOpen == 1 {
  3975. if project.Type == 3 {
  3976. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3977. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3978. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3979. operation_time := time.Now().Unix()
  3980. creater := adminInfo.AdminUser.Id
  3981. //创建退库单
  3982. timeStr := time.Now().Format("2006-01-02")
  3983. timeArr := strings.Split(timeStr, "-")
  3984. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3985. total = total + 1
  3986. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3987. cancelStock := models.CancelStock{
  3988. OrderNumber: orderNumber,
  3989. OperaTime: operation_time,
  3990. OrgId: adminInfo.CurrentOrgId,
  3991. Creater: creater,
  3992. Ctime: time.Now().Unix(),
  3993. Status: 1,
  3994. ReturnTime: project.RecordDate,
  3995. Type: 1,
  3996. StorehouseId: houseConfig.StorehouseOutInfo,
  3997. IsCheck: 1,
  3998. }
  3999. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4000. if msgerrkonde == gorm.ErrRecordNotFound {
  4001. service.AddSigleCancelStock(&cancelStock)
  4002. }
  4003. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4004. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4005. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4006. //获取出库数据
  4007. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4008. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4009. deaerler, _ := service.GetDealerById(info.Dealer)
  4010. if info.ID > 0 {
  4011. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4012. if info.Count >= prescribingNumber {
  4013. cancelStockInfo := models.CancelStockInfo{
  4014. GoodId: project.ProjectId,
  4015. CancelStockId: cancel.ID,
  4016. GoodTypeId: good.GoodTypeId,
  4017. Count: prescribingNumber,
  4018. Price: info.Price,
  4019. Total: 0,
  4020. ProductDate: info.ProductDate,
  4021. ExpiryDate: info.ExpiryDate,
  4022. Ctime: time.Now().Unix(),
  4023. Status: 1,
  4024. OrgId: adminInfo.CurrentOrgId,
  4025. OrderNumber: cancel.OrderNumber,
  4026. Type: 0,
  4027. Dealer: deaerler.DealerName,
  4028. Manufacturer: manufacturer.ManufacturerName,
  4029. Number: info.Number,
  4030. RegisterAccount: "",
  4031. Remark: "",
  4032. WarehouseInfoId: info.WarehouseInfotId,
  4033. PatientId: info.PatientId,
  4034. RecordDate: info.SysRecordTime,
  4035. StorehouseId: houseConfig.StorehouseOutInfo,
  4036. IsCheck: 1,
  4037. }
  4038. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4039. //退库数量增加
  4040. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4041. //出库数量减少
  4042. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4043. }
  4044. if info.Count < prescribingNumber {
  4045. cancelStockInfo := models.CancelStockInfo{
  4046. GoodId: project.ProjectId,
  4047. CancelStockId: cancel.ID,
  4048. GoodTypeId: good.GoodTypeId,
  4049. Count: prescribingNumber,
  4050. Price: info.Price,
  4051. Total: 0,
  4052. ProductDate: info.ProductDate,
  4053. ExpiryDate: info.ExpiryDate,
  4054. Ctime: time.Now().Unix(),
  4055. Status: 1,
  4056. OrgId: adminInfo.CurrentOrgId,
  4057. OrderNumber: cancel.OrderNumber,
  4058. Type: 0,
  4059. Dealer: deaerler.DealerName,
  4060. Manufacturer: manufacturer.ManufacturerName,
  4061. Number: info.Number,
  4062. RegisterAccount: "",
  4063. Remark: "",
  4064. WarehouseInfoId: info.WarehouseInfotId,
  4065. PatientId: info.PatientId,
  4066. RecordDate: info.SysRecordTime,
  4067. StorehouseId: houseConfig.StorehouseOutInfo,
  4068. IsCheck: 1,
  4069. }
  4070. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4071. //回退库存
  4072. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4073. }
  4074. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4075. var over_count int64
  4076. for _, it := range goodList {
  4077. over_count += it.StockCount
  4078. }
  4079. //查询出库数量
  4080. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4081. //出库数据 大于 退库数量
  4082. if len(list) > 0 {
  4083. for _, it := range list {
  4084. //回退库存
  4085. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4086. //退库数量增加
  4087. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4088. //出库数量减少
  4089. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4090. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4091. var over_count_one int64
  4092. for _, it := range goodList {
  4093. over_count_one += it.StockCount
  4094. }
  4095. //查询该批次是否有退库数据
  4096. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4097. flow := models.VmStockFlow{
  4098. WarehousingId: it.WarehouseInfotId,
  4099. GoodId: it.GoodId,
  4100. Number: it.Number,
  4101. LicenseNumber: it.LicenseNumber,
  4102. Count: it.Count,
  4103. UserOrgId: adminInfo.CurrentOrgId,
  4104. PatientId: it.PatientId,
  4105. SystemTime: it.SysRecordTime,
  4106. ConsumableType: 7,
  4107. IsSys: 0,
  4108. WarehousingOrder: "",
  4109. WarehouseOutId: it.WarehouseOutId,
  4110. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4111. IsEdit: 0,
  4112. CancelStockId: cancel.ID,
  4113. CancelOrderNumber: cancel.OrderNumber,
  4114. Manufacturer: manufacturer.ID,
  4115. Dealer: 0,
  4116. Creator: adminInfo.AdminUser.Id,
  4117. UpdateCreator: 0,
  4118. Status: 1,
  4119. Ctime: time.Now().Unix(),
  4120. Mtime: 0,
  4121. Price: it.Price,
  4122. WarehousingDetailId: it.WarehouseInfotId,
  4123. WarehouseOutDetailId: it.ID,
  4124. CancelOutDetailId: cancelInfo.ID,
  4125. ProductDate: it.ProductDate,
  4126. ExpireDate: it.ExpiryDate,
  4127. StorehouseId: houseConfig.StorehouseOutInfo,
  4128. OverCount: over_count_one,
  4129. }
  4130. service.CreateStockFlowOne(flow)
  4131. }
  4132. }
  4133. //查询已出库数量
  4134. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4135. if prescribingNumber < dialysisInfo.Count {
  4136. //改变数量
  4137. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4138. }
  4139. if prescribingNumber >= dialysisInfo.Count {
  4140. //删除出库表
  4141. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4142. }
  4143. //更新剩余库存
  4144. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4145. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4146. var total_count_one int64
  4147. for _, it := range stockList {
  4148. total_count_one += it.StockCount
  4149. }
  4150. //基础库插入数据
  4151. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4152. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4153. var flush_count int64
  4154. for _, it := range goodListOne {
  4155. flush_count += it.StockCount
  4156. }
  4157. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4158. if errs != nil {
  4159. goodErrcode := models.XtGoodErrcode{
  4160. UserOrgId: project.UserOrgId,
  4161. Errcode: "手动出库更新剩余出库失败",
  4162. GoodId: project.ProjectId,
  4163. Status: 1,
  4164. Ctime: time.Now().Unix(),
  4165. Mtime: 0,
  4166. Count: 0,
  4167. StockCount: 0,
  4168. Creater: creater,
  4169. BatchNumberId: 0,
  4170. WarehouseOutId: 0,
  4171. }
  4172. service.CreateGoodErrcode(goodErrcode)
  4173. }
  4174. }
  4175. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4176. fmt.Println(err)
  4177. } else {
  4178. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4179. fmt.Println(err)
  4180. }
  4181. }
  4182. c.ServeSuccessJSON(map[string]interface{}{
  4183. "msg": "删除成功",
  4184. })
  4185. return
  4186. }
  4187. func (c *HisApiController) CreateHisAdditionalCharge() {
  4188. his_patient_id, _ := c.GetInt64("his_patient_id")
  4189. patient_id, _ := c.GetInt64("patient_id")
  4190. record_date := c.GetString("record_date")
  4191. timeLayout := "2006-01-02"
  4192. loc, _ := time.LoadLocation("Local")
  4193. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4194. if err != nil {
  4195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4196. return
  4197. }
  4198. adminInfo := c.GetAdminUserInfo()
  4199. recordDateTime := theTime.Unix()
  4200. dataBody := make(map[string]interface{}, 0)
  4201. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4202. if err != nil {
  4203. utils.ErrorLog(err.Error())
  4204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4205. return
  4206. }
  4207. var additions []*models.HisAdditionalCharge
  4208. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4209. additions, _ := dataBody["addition"].([]interface{})
  4210. if len(additions) > 0 {
  4211. for _, item := range additions {
  4212. items := item.(map[string]interface{})
  4213. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4214. utils.ErrorLog("item_id")
  4215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4216. return
  4217. }
  4218. item_id := int64(items["item_id"].(float64))
  4219. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4220. utils.ErrorLog("item_name")
  4221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4222. return
  4223. }
  4224. item_name := items["item_name"].(string)
  4225. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4226. utils.ErrorLog("price")
  4227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4228. return
  4229. }
  4230. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4231. ctime := time.Now().Unix()
  4232. additional := &models.HisAdditionalCharge{
  4233. PatientId: patient_id,
  4234. HisPatientId: his_patient_id,
  4235. UserOrgId: adminInfo.CurrentOrgId,
  4236. RecordDate: recordDateTime,
  4237. CreatedTime: ctime,
  4238. UpdatedTime: ctime,
  4239. Modifier: adminInfo.AdminUser.Id,
  4240. Creator: adminInfo.AdminUser.Id,
  4241. Price: price,
  4242. ItemName: item_name,
  4243. ItemId: item_id,
  4244. Status: 1,
  4245. }
  4246. additions = append(additions, additional)
  4247. }
  4248. }
  4249. }
  4250. for _, item := range additions {
  4251. service.CreateAddtionalCharge(item)
  4252. }
  4253. c.ServeSuccessJSON(map[string]interface{}{
  4254. "msg": "创建成功",
  4255. })
  4256. }
  4257. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4258. blood_fat := c.GetString("blood_fat")
  4259. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4260. blood_sugar := c.GetString("blood_sugar")
  4261. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4262. chief_conplaint := c.GetString("chief_conplaint")
  4263. dbp := c.GetString("dbp")
  4264. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4265. delivery_way, _ := c.GetInt64("delivery_way")
  4266. diagnostic := c.GetString("diagnostic")
  4267. family_history := c.GetString("family_history")
  4268. height := c.GetString("height")
  4269. history_of_present_illness := c.GetString("history_of_present_illness")
  4270. is_infect, _ := c.GetInt64("is_infect")
  4271. past_history := c.GetString("past_history")
  4272. patient_id, _ := c.GetInt64("patient_id")
  4273. his_patient_id, _ := c.GetInt64("his_patient_id")
  4274. personal_history := c.GetString("personal_history")
  4275. pulse := c.GetString("pulse")
  4276. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4277. sbp := c.GetString("sbp")
  4278. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4279. heightfloat, _ := strconv.ParseFloat(height, 64)
  4280. sicktype := c.GetString("sick_type")
  4281. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4282. symptom := c.GetString("symptom")
  4283. sick_date := c.GetString("sick_date")
  4284. temperatures := c.GetString("temperature")
  4285. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4286. record_date := c.GetString("record_date")
  4287. breathing := c.GetString("breathing")
  4288. doctor_advice := c.GetString("doctor_advice")
  4289. remark := c.GetString("remark")
  4290. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4291. sick, _ := c.GetInt64("sick")
  4292. diagnose, _ := c.GetInt64("diagnose")
  4293. //id, _ := c.GetInt64("id")
  4294. timeLayout := "2006-01-02"
  4295. loc, _ := time.LoadLocation("Local")
  4296. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4297. allergic_history := c.GetString("allergic_history")
  4298. if err != nil {
  4299. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4300. return
  4301. }
  4302. recordDateTime := theTime.Unix()
  4303. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4304. if err != nil {
  4305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4306. return
  4307. }
  4308. sickTimes := sickTime.Unix()
  4309. ctime := time.Now().Unix()
  4310. primary_disease := c.GetString("primary_disease")
  4311. confirm_failure_date := c.GetString("confirm_failure_date")
  4312. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4313. drug_allergy_history := c.GetString("drug_allergy_history")
  4314. physical_examination := c.GetString("physical_examination")
  4315. special_inspection := c.GetString("special_inspection")
  4316. lab_apparatus := c.GetString("lab_apparatus")
  4317. caseHistory := models.HisPatientCaseHistory{
  4318. HisPatientId: his_patient_id,
  4319. PatientId: patient_id,
  4320. Temperature: temperature,
  4321. BloodSugar: bloodsugarfloat,
  4322. Pulse: pulsefloat,
  4323. Sbp: sbpfloat,
  4324. Dbp: dbpfloat,
  4325. Height: heightfloat,
  4326. BloodFat: bloodfatfloat,
  4327. SickType: sick_type,
  4328. Symptom: symptom,
  4329. SickDate: sickTimes,
  4330. IsInfect: is_infect,
  4331. HistoryOfPresentIllness: history_of_present_illness,
  4332. PastHistory: past_history,
  4333. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4334. ChiefConplaint: chief_conplaint,
  4335. PersonalHistory: personal_history,
  4336. FamilyHistory: family_history,
  4337. Diagnostic: diagnostic,
  4338. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4339. Status: 1,
  4340. Ctime: ctime,
  4341. Mtime: ctime,
  4342. RecordDate: recordDateTime,
  4343. DeliveryWay: delivery_way,
  4344. Breathing: breathingfloat,
  4345. DoctorAdvice: doctor_advice,
  4346. Remark: remark,
  4347. Sick: sick,
  4348. Diagnose: diagnose,
  4349. AllergicHistory: allergic_history,
  4350. PrimaryDisease: primary_disease,
  4351. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4352. DrugAllergyHistory: drug_allergy_history,
  4353. PhysicalExamination: physical_examination,
  4354. SpecialInspection: special_inspection,
  4355. LabApparatus: lab_apparatus,
  4356. }
  4357. //查询该患者是否有病历
  4358. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4359. if errcodes == gorm.ErrRecordNotFound {
  4360. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4361. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4362. if err != nil {
  4363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4364. return
  4365. }
  4366. c.ServeSuccessJSON(map[string]interface{}{
  4367. "caseHistory": caseHistory,
  4368. "historyInfo": historyInfo,
  4369. })
  4370. return
  4371. } else if errcodes == nil {
  4372. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4373. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4374. if err != nil {
  4375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4376. return
  4377. }
  4378. c.ServeSuccessJSON(map[string]interface{}{
  4379. "caseHistory": caseHistory,
  4380. "historyInfo": historyInfo,
  4381. })
  4382. }
  4383. //查询该患者是否有病历
  4384. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4385. //if errcode == gorm.ErrRecordNotFound {
  4386. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4387. // if err != nil {
  4388. // c.ServeSuccessJSON(map[string]interface{}{
  4389. // "msg": "保存成功",
  4390. // })
  4391. // }
  4392. //} else if errcode == nil {
  4393. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4394. // return
  4395. //}
  4396. }
  4397. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4398. patient_id, _ := c.GetInt64("patient_id", 0)
  4399. adminUser := c.GetAdminUserInfo()
  4400. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4401. c.ServeSuccessJSON(map[string]interface{}{
  4402. "list": caseHistorys,
  4403. })
  4404. }
  4405. func (c *HisApiController) GetHisPatientCaseHistory() {
  4406. record_date, _ := c.GetInt64("record_date", 0)
  4407. patient_id, _ := c.GetInt64("patient_id", 0)
  4408. admin := c.GetAdminUserInfo()
  4409. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4410. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4411. c.ServeSuccessJSON(map[string]interface{}{
  4412. "info": info,
  4413. "case_history": case_history,
  4414. })
  4415. }
  4416. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4417. template_name := c.GetString("template_name")
  4418. template_remark := c.GetString("template_remark")
  4419. doctor := c.GetAdminUserInfo().AdminUser.Id
  4420. diagnostic := c.GetString("diagnostic")
  4421. chief_conplaint := c.GetString("chief_conplain")
  4422. history_of_present_illness := c.GetString("history_of_present_illness")
  4423. past_history := c.GetString("past_history")
  4424. personal_history := c.GetString("personal_history")
  4425. family_history := c.GetString("family_history")
  4426. user_name := c.GetString("user_name")
  4427. doctor_advice := c.GetString("doctor_advice")
  4428. remark := c.GetString("remark")
  4429. //record_date := c.GetString("record_date")
  4430. //fmt.Println("record_date--------",record_date)
  4431. //timeLayout := "2006-01-02"
  4432. //loc, _ := time.LoadLocation("Local")
  4433. //
  4434. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4435. //if err != nil {
  4436. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4437. // return
  4438. //}
  4439. //recordDateTime := theTime.Unix()
  4440. ctime := time.Now().Unix()
  4441. template := models.HisCaseHistoryTemplate{
  4442. HistoryOfPresentIllness: history_of_present_illness,
  4443. PastHistory: past_history,
  4444. ChiefConplaint: chief_conplaint,
  4445. PersonalHistory: personal_history,
  4446. FamilyHistory: family_history,
  4447. Diagnostic: diagnostic,
  4448. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4449. Status: 1,
  4450. Ctime: ctime,
  4451. Mtime: ctime,
  4452. RecordDate: time.Now().Unix(),
  4453. TemplateName: template_name,
  4454. TemplateRemark: template_remark,
  4455. Creator: doctor,
  4456. Modifier: doctor,
  4457. UserName: user_name,
  4458. DoctorAdvice: doctor_advice,
  4459. Remark: remark,
  4460. }
  4461. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4462. if err == nil {
  4463. c.ServeSuccessJSON(map[string]interface{}{
  4464. "msg": "保存成功",
  4465. })
  4466. } else {
  4467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4468. return
  4469. }
  4470. }
  4471. func (c *HisApiController) GetCaseHistoryTemplate() {
  4472. timeLayout := "2006-01-02"
  4473. loc, _ := time.LoadLocation("Local")
  4474. keyword := c.GetString("keyword")
  4475. start_time := c.GetString("start_time")
  4476. end_time := c.GetString("end_time")
  4477. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4478. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4479. admin := c.GetAdminUserInfo()
  4480. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4481. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4482. c.ServeSuccessJSON(map[string]interface{}{
  4483. "template": template,
  4484. //"history": history,
  4485. })
  4486. }
  4487. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4488. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4489. utils.ErrorLog("drug_name")
  4490. return enums.ErrorCodeParamWrong
  4491. }
  4492. adviceName, _ := json["drug_name"].(string)
  4493. if len(adviceName) == 0 {
  4494. utils.ErrorLog("len(advice_name) == 0")
  4495. return enums.ErrorCodeParamWrong
  4496. }
  4497. advice.AdviceName = adviceName
  4498. adviceDesc, _ := json["advice_desc"].(string)
  4499. advice.AdviceDesc = adviceDesc
  4500. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4501. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4502. advice.DrugSpec = drugSpec
  4503. }
  4504. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4505. remark, _ := json["remark"].(string)
  4506. advice.Remark = remark
  4507. }
  4508. if json["id"] == nil {
  4509. advice.DrugId = 0
  4510. } else {
  4511. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4512. drug_id := int64(json["id"].(float64))
  4513. advice.DrugId = drug_id
  4514. }
  4515. }
  4516. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4517. advice_id := int64(json["advice_id"].(float64))
  4518. advice.ID = advice_id
  4519. if advice.ID > 0 {
  4520. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4521. if err == nil {
  4522. if hisAdvice.ID > 0 {
  4523. advice.ExecutionTime = hisAdvice.ExecutionTime
  4524. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4525. advice.ExecutionState = hisAdvice.ExecutionState
  4526. advice.CheckTime = hisAdvice.CheckTime
  4527. advice.Checker = hisAdvice.Checker
  4528. advice.CheckState = hisAdvice.CheckState
  4529. advice.StartTime = hisAdvice.StartTime
  4530. advice.FeedetlSn = hisAdvice.FeedetlSn
  4531. }
  4532. }
  4533. }
  4534. }
  4535. //
  4536. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4537. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4538. // advice.ExecutionTime = execution_time
  4539. //}
  4540. //
  4541. //
  4542. //
  4543. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4544. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4545. // advice.ExecutionStaff = execution_staff
  4546. //}
  4547. //
  4548. //
  4549. //
  4550. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4551. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4552. // advice.ExecutionState = execution_state
  4553. //}
  4554. //
  4555. //
  4556. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4557. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4558. // advice.CheckTime = check_time
  4559. //}
  4560. //
  4561. //
  4562. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4563. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4564. // advice.CheckState = check_state
  4565. //}
  4566. //
  4567. //
  4568. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4569. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4570. // advice.Checker = checker
  4571. //}
  4572. //
  4573. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4574. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4575. // advice.StartTime = start_time
  4576. //}
  4577. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4578. drugSpecUnit, _ := json["min_unit"].(string)
  4579. advice.DrugSpecUnit = drugSpecUnit
  4580. }
  4581. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4582. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4583. advice.SingleDose = singleDose
  4584. }
  4585. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4586. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4587. advice.SingleDoseUnit = singleDoseUnit
  4588. }
  4589. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4590. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4591. advice.PrescribingNumber = prescribingNumber
  4592. }
  4593. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4594. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4595. advice.PrescribingNumberUnit = prescribingNumberUnit
  4596. }
  4597. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4598. deliveryWay, _ := json["delivery_way"].(string)
  4599. advice.DeliveryWay = deliveryWay
  4600. }
  4601. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4602. executionFrequency, _ := json["execution_frequency"].(string)
  4603. advice.ExecutionFrequency = executionFrequency
  4604. }
  4605. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4606. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4607. advice.Price = price
  4608. }
  4609. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4610. med_list_codg, _ := json["medical_insurance_number"].(string)
  4611. advice.MedListCodg = med_list_codg
  4612. }
  4613. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4614. day := int64(json["day"].(float64))
  4615. advice.Day = day
  4616. }
  4617. return 0
  4618. }
  4619. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4620. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4621. id := int64(json["id"].(float64))
  4622. project.ID = id
  4623. historyProject, _ := service.GetHisProjectByID(id)
  4624. project.FeedetlSn = historyProject.FeedetlSn
  4625. }
  4626. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4627. project_id := int64(json["project_id"].(float64))
  4628. project.ProjectId = project_id
  4629. }
  4630. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4631. // price := int64(json["price"].(float64))
  4632. // formatInt_price := strconv.FormatInt(price, 10)
  4633. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4634. // project.Price = float_price
  4635. // }
  4636. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4637. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4638. project.Price = price
  4639. }
  4640. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4641. total, _ := json["total"].(string)
  4642. project.Count = total
  4643. }
  4644. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4645. medical_code, _ := json["medical_code"].(string)
  4646. project.MedListCodg = medical_code
  4647. }
  4648. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4649. single_dose, _ := json["single_dose"].(string)
  4650. project.SingleDose = single_dose
  4651. }
  4652. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4653. delivery_way, _ := json["delivery_way"].(string)
  4654. project.DeliveryWay = delivery_way
  4655. }
  4656. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4657. execution_frequency, _ := json["execution_frequency"].(string)
  4658. project.ExecutionFrequency = execution_frequency
  4659. }
  4660. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4661. remark, _ := json["remark"].(string)
  4662. project.Remark = remark
  4663. }
  4664. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4665. day, _ := json["number_days"].(string)
  4666. project.Day = day
  4667. }
  4668. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4669. unit, _ := json["unit"].(string)
  4670. project.Unit = unit
  4671. }
  4672. return 0
  4673. }
  4674. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4675. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4676. id := int64(json["id"].(float64))
  4677. historyAddtions, _ := service.GetHisAdditionByID(id)
  4678. additionalCharge.ID = id
  4679. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4680. }
  4681. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4682. item_id := int64(json["item_id"].(float64))
  4683. additionalCharge.ItemId = item_id
  4684. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4685. if config.ID > 0 {
  4686. if len(config.Code) > 0 {
  4687. additionalCharge.MedListCodg = config.Code
  4688. }
  4689. }
  4690. }
  4691. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4692. // price := int64(json["price"].(float64))
  4693. // formatInt_price := strconv.FormatInt(price, 10)
  4694. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4695. // additionalCharge.Price = float_price
  4696. // }
  4697. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4698. // price := int64(json["price"].(float64))
  4699. // formatInt_price := strconv.FormatInt(price, 10)
  4700. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4701. // additionalCharge.Price = float_price
  4702. //}
  4703. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4704. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4705. additionalCharge.Price = price
  4706. }
  4707. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4708. count, _ := json["count"].(string)
  4709. counts, _ := strconv.ParseInt(count, 10, 64)
  4710. additionalCharge.Count = counts
  4711. }
  4712. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4713. item_name, _ := json["item_name"].(string)
  4714. additionalCharge.ItemName = item_name
  4715. }
  4716. return 0
  4717. }
  4718. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4719. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4720. utils.ErrorLog("drug_name")
  4721. return enums.ErrorCodeParamWrong
  4722. }
  4723. adviceName, _ := json["drug_name"].(string)
  4724. if len(adviceName) == 0 {
  4725. utils.ErrorLog("len(advice_name) == 0")
  4726. return enums.ErrorCodeParamWrong
  4727. }
  4728. advice.AdviceName = adviceName
  4729. adviceDesc, _ := json["advice_desc"].(string)
  4730. advice.AdviceDesc = adviceDesc
  4731. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4732. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4733. advice.DrugSpec = drugSpec
  4734. }
  4735. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4736. remark, _ := json["remark"].(string)
  4737. advice.Remark = remark
  4738. }
  4739. if json["id"] == nil {
  4740. advice.DrugId = 0
  4741. } else {
  4742. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4743. drug_id := int64(json["id"].(float64))
  4744. advice.DrugId = drug_id
  4745. }
  4746. }
  4747. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4748. groupno := int64(json["groupno"].(float64))
  4749. advice.Groupno = groupno
  4750. }
  4751. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4752. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4753. advice.HospApprFlag = hosp_appr_flag
  4754. }
  4755. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4756. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4757. advice.PrescribingNumber = prescribingNumber
  4758. }
  4759. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4760. // frequency_type := int64(json["frequency_type"].(float64))
  4761. // advice.FrequencyType = frequency_type
  4762. //}
  4763. //
  4764. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4765. // day_count := int64(json["day_count"].(float64))
  4766. // advice.DayCount = day_count
  4767. //}
  4768. //
  4769. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4770. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4771. // week_day, _ := json["week_day"].(string)
  4772. // advice.WeekDay = week_day
  4773. //}
  4774. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4775. drugSpecUnit, _ := json["min_unit"].(string)
  4776. advice.DrugSpecUnit = drugSpecUnit
  4777. }
  4778. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4779. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4780. advice.SingleDose = singleDose
  4781. }
  4782. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4783. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4784. advice.SingleDoseUnit = singleDoseUnit
  4785. }
  4786. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4787. deliveryWay, _ := json["delivery_way"].(string)
  4788. advice.DeliveryWay = deliveryWay
  4789. }
  4790. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4791. executionFrequency, _ := json["execution_frequency"].(string)
  4792. advice.ExecutionFrequency = executionFrequency
  4793. }
  4794. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4795. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4796. advice.Price = price
  4797. }
  4798. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4799. med_list_codg, _ := json["medical_insurance_number"].(string)
  4800. advice.MedListCodg = med_list_codg
  4801. }
  4802. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4803. day := int64(json["day"].(float64))
  4804. advice.Day = day
  4805. }
  4806. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4807. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4808. advice.PrescribingNumberUnit = prescribingNumberUnit
  4809. }
  4810. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4811. advice_id := int64(json["advice_id"].(float64))
  4812. advice.ID = advice_id
  4813. if advice.ID > 0 {
  4814. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4815. if err == nil {
  4816. if hisAdvice.ID > 0 {
  4817. advice.ExecutionTime = hisAdvice.ExecutionTime
  4818. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4819. advice.ExecutionState = hisAdvice.ExecutionState
  4820. advice.CheckTime = hisAdvice.CheckTime
  4821. advice.Checker = hisAdvice.Checker
  4822. advice.CheckState = hisAdvice.CheckState
  4823. advice.StartTime = hisAdvice.StartTime
  4824. advice.HospApprFlag = hisAdvice.HospApprFlag
  4825. advice.IsMedicine = hisAdvice.IsMedicine
  4826. if hisAdvice.UserOrgId == 10028 {
  4827. 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 {
  4828. advice.ExecutionTime = 0
  4829. advice.ExecutionStaff = 0
  4830. advice.ExecutionState = 2
  4831. advice.CheckTime = 0
  4832. advice.Checker = 0
  4833. advice.CheckState = 2
  4834. }
  4835. } else {
  4836. 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 {
  4837. advice.ExecutionTime = 0
  4838. advice.ExecutionStaff = 0
  4839. advice.ExecutionState = 2
  4840. advice.CheckTime = 0
  4841. advice.Checker = 0
  4842. advice.CheckState = 2
  4843. }
  4844. }
  4845. //advice.Groupno = hisAdvice.Groupno
  4846. }
  4847. }
  4848. }
  4849. }
  4850. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4851. //
  4852. //if drugStockConfig.IsOpen == 1 {
  4853. //
  4854. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4855. // if advice.ID == 0 { //医嘱不存在
  4856. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4857. // drug.Total = drug.Total - advice.PrescribingNumber
  4858. // service.UpdateBaseDrugLib(&drug)
  4859. //
  4860. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4861. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4862. // drug.Total = drug.Total - num
  4863. // service.UpdateBaseDrugLib(&drug)
  4864. // }
  4865. //
  4866. // } else if advice.ID > 0 { //医嘱存在
  4867. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4868. // var num float64
  4869. //
  4870. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4871. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4872. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4873. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4874. // drug.Total = drug.Total + num
  4875. // service.UpdateBaseDrugLib(&drug)
  4876. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4877. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4878. // drug.Total = drug.Total - num
  4879. // service.UpdateBaseDrugLib(&drug)
  4880. // }
  4881. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4882. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4883. // if num2 > advice.PrescribingNumber {
  4884. // num = num2 - advice.PrescribingNumber
  4885. // drug.Total = drug.Total + num
  4886. // service.UpdateBaseDrugLib(&drug)
  4887. // } else if num2 < advice.PrescribingNumber {
  4888. // num = advice.PrescribingNumber - num2
  4889. // drug.Total = drug.Total - num
  4890. // service.UpdateBaseDrugLib(&drug)
  4891. // }
  4892. //
  4893. // }
  4894. //
  4895. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4896. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4897. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4898. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4899. // if num1 > num2 {
  4900. // num = num1 - num2
  4901. // drug.Total = drug.Total + num
  4902. // service.UpdateBaseDrugLib(&drug)
  4903. // } else if num1 < num2 {
  4904. // num = num2 - num1
  4905. // drug.Total = drug.Total - num
  4906. // service.UpdateBaseDrugLib(&drug)
  4907. // }
  4908. //
  4909. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4910. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4911. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4912. // if hisAdvice.PrescribingNumber > num2 {
  4913. // num = hisAdvice.PrescribingNumber - num2
  4914. // drug.Total = drug.Total + num
  4915. // service.UpdateBaseDrugLib(&drug)
  4916. // } else if num2 < advice.PrescribingNumber {
  4917. // num = num2 - hisAdvice.PrescribingNumber
  4918. // drug.Total = drug.Total - num
  4919. // service.UpdateBaseDrugLib(&drug)
  4920. // }
  4921. //
  4922. // }
  4923. // }
  4924. // }
  4925. //}
  4926. //
  4927. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4928. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4929. // advice.ExecutionTime = execution_time
  4930. //}
  4931. //
  4932. //
  4933. //
  4934. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4935. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4936. // advice.ExecutionStaff = execution_staff
  4937. //}
  4938. //
  4939. //
  4940. //
  4941. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4942. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4943. // advice.ExecutionState = execution_state
  4944. //}
  4945. //
  4946. //
  4947. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4948. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4949. // advice.CheckTime = check_time
  4950. //}
  4951. //
  4952. //
  4953. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4954. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4955. // advice.CheckState = check_state
  4956. //}
  4957. //
  4958. //
  4959. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4960. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4961. // advice.Checker = checker
  4962. //}
  4963. //
  4964. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4965. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4966. // advice.StartTime = start_time
  4967. //}
  4968. return 0
  4969. }
  4970. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4971. project.ExecutionStaff = 0
  4972. project.ExecutionState = 2
  4973. project.ExecutionTime = 0
  4974. project.Checker = 0
  4975. project.CheckState = 2
  4976. project.CheckTime = 0
  4977. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4978. id := int64(json["id"].(float64))
  4979. project.ID = id
  4980. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4981. project.ExecutionStaff = temp_project.ExecutionStaff
  4982. project.ExecutionState = temp_project.ExecutionState
  4983. project.ExecutionTime = temp_project.ExecutionTime
  4984. project.Checker = temp_project.Checker
  4985. project.CheckState = temp_project.CheckState
  4986. project.CheckTime = temp_project.CheckTime
  4987. project.TeamId = temp_project.TeamId
  4988. }
  4989. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4990. types := int64(json["type"].(float64))
  4991. project.Type = types
  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["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4998. team_id := int64(json["team_id"].(float64))
  4999. project.TeamId = team_id
  5000. }
  5001. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5002. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5003. project.Price = price
  5004. }
  5005. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5006. total, _ := json["total"].(string)
  5007. //totals, _ := strconv.ParseInt(total, 10, 64)
  5008. project.Count = total
  5009. }
  5010. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5011. medical_code, _ := json["medical_code"].(string)
  5012. project.MedListCodg = medical_code
  5013. }
  5014. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5015. single_dose, _ := json["single_dose"].(string)
  5016. project.SingleDose = single_dose
  5017. }
  5018. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5019. delivery_way, _ := json["delivery_way"].(string)
  5020. project.DeliveryWay = delivery_way
  5021. }
  5022. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5023. execution_frequency, _ := json["execution_frequency"].(string)
  5024. project.ExecutionFrequency = execution_frequency
  5025. }
  5026. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5027. remark, _ := json["remark"].(string)
  5028. project.Remark = remark
  5029. }
  5030. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5031. day, _ := json["number_days"].(string)
  5032. project.Day = day
  5033. }
  5034. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5035. unit, _ := json["unit"].(string)
  5036. project.Unit = unit
  5037. }
  5038. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5039. // frequency_type := int64(json["frequency_type"].(float64))
  5040. // project.FrequencyType = frequency_type
  5041. //}
  5042. //
  5043. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5044. // day_count := int64(json["day_count"].(float64))
  5045. // project.DayCount = day_count
  5046. //}
  5047. //
  5048. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5049. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5050. // week_day, _ := json["week_day"].(string)
  5051. // project.WeekDay = week_day
  5052. //}
  5053. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5054. //
  5055. //if project.ID == 0 {
  5056. // if stockConfig.IsOpen == 1 {
  5057. // if project.Type == 3 {
  5058. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5059. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5060. // good.Total = good.Total - f_count
  5061. // service.UpdateGoodInfo(&good)
  5062. // }
  5063. // }
  5064. //
  5065. //} else {
  5066. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5067. //
  5068. // if stockConfig.IsOpen == 1 {
  5069. // if project.Type == 3 {
  5070. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5071. // if project.Count < temp_project.Count {
  5072. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5073. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5074. //
  5075. // other_count := f_count_two - f_count_one
  5076. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5077. // good.Total = good.Total + other_count_two
  5078. // service.UpdateGoodInfo(&good)
  5079. // } else if project.Count > temp_project.Count {
  5080. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5081. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5082. //
  5083. // other_count := f_count_one - f_count_two
  5084. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5085. // good.Total = good.Total - other_count_two
  5086. // service.UpdateGoodInfo(&good)
  5087. // }
  5088. //
  5089. // }
  5090. // }
  5091. //
  5092. //}
  5093. return 0
  5094. }
  5095. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5096. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5097. id := int64(json["id"].(float64))
  5098. additionalCharge.ID = id
  5099. }
  5100. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5101. item_id := int64(json["item_id"].(float64))
  5102. additionalCharge.ItemId = item_id
  5103. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5104. if config.ID > 0 {
  5105. if len(config.Code) > 0 {
  5106. additionalCharge.MedListCodg = config.Code
  5107. }
  5108. }
  5109. }
  5110. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5111. // price := int64(json["price"].(float64))
  5112. // formatInt_price := strconv.FormatInt(price, 10)
  5113. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5114. // additionalCharge.Price = float_price
  5115. // }
  5116. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5117. // price := int64(json["price"].(float64))
  5118. // formatInt_price := strconv.FormatInt(price, 10)
  5119. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5120. // additionalCharge.Price = float_price
  5121. //}
  5122. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5123. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5124. additionalCharge.Price = price
  5125. }
  5126. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5127. count, _ := json["count"].(string)
  5128. counts, _ := strconv.ParseInt(count, 10, 64)
  5129. additionalCharge.Count = counts
  5130. }
  5131. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5132. item_name, _ := json["item_name"].(string)
  5133. additionalCharge.ItemName = item_name
  5134. }
  5135. return 0
  5136. }
  5137. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5138. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5139. utils.ErrorLog("drug_name")
  5140. return enums.ErrorCodeParamWrong
  5141. }
  5142. adviceName, _ := json["drug_name"].(string)
  5143. if len(adviceName) == 0 {
  5144. utils.ErrorLog("len(advice_name) == 0")
  5145. return enums.ErrorCodeParamWrong
  5146. }
  5147. advice.AdviceName = adviceName
  5148. adviceDesc, _ := json["advice_desc"].(string)
  5149. advice.AdviceDesc = adviceDesc
  5150. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5151. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5152. advice.DrugSpec = drugSpec
  5153. }
  5154. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5155. remark, _ := json["remark"].(string)
  5156. advice.Remark = remark
  5157. }
  5158. if json["id"] == nil {
  5159. advice.DrugId = 0
  5160. } else {
  5161. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5162. drug_id := int64(json["id"].(float64))
  5163. advice.DrugId = drug_id
  5164. }
  5165. }
  5166. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5167. drugSpecUnit, _ := json["min_unit"].(string)
  5168. advice.DrugSpecUnit = drugSpecUnit
  5169. }
  5170. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5171. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5172. advice.SingleDose = singleDose
  5173. }
  5174. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5175. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5176. advice.SingleDoseUnit = singleDoseUnit
  5177. }
  5178. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5179. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5180. advice.PrescribingNumber = prescribingNumber
  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["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5187. deliveryWay, _ := json["delivery_way"].(string)
  5188. advice.DeliveryWay = deliveryWay
  5189. }
  5190. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5191. executionFrequency, _ := json["execution_frequency"].(string)
  5192. advice.ExecutionFrequency = executionFrequency
  5193. }
  5194. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5195. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5196. advice.Price = price
  5197. }
  5198. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5199. med_list_codg, _ := json["medical_insurance_number"].(string)
  5200. advice.MedListCodg = med_list_codg
  5201. }
  5202. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5203. day := int64(json["day"].(float64))
  5204. advice.Day = day
  5205. }
  5206. advice.FrequencyType = 1
  5207. return 0
  5208. }
  5209. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5210. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5211. types := int64(json["type"].(float64))
  5212. project.Type = types
  5213. }
  5214. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5215. project_id := int64(json["project_id"].(float64))
  5216. project.ProjectId = project_id
  5217. }
  5218. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5219. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5220. project.Price = price
  5221. }
  5222. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5223. total, _ := json["total"].(string)
  5224. //totals, _ := strconv.ParseInt(total, 10, 64)
  5225. project.Count = total
  5226. }
  5227. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5228. medical_code, _ := json["medical_code"].(string)
  5229. project.MedListCodg = medical_code
  5230. }
  5231. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5232. single_dose, _ := json["single_dose"].(string)
  5233. project.SingleDose = single_dose
  5234. }
  5235. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5236. delivery_way, _ := json["delivery_way"].(string)
  5237. project.DeliveryWay = delivery_way
  5238. }
  5239. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5240. execution_frequency, _ := json["execution_frequency"].(string)
  5241. project.ExecutionFrequency = execution_frequency
  5242. }
  5243. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5244. remark, _ := json["remark"].(string)
  5245. project.Remark = remark
  5246. }
  5247. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5248. day, _ := json["number_days"].(string)
  5249. project.Day = day
  5250. }
  5251. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5252. unit, _ := json["unit"].(string)
  5253. project.Unit = unit
  5254. }
  5255. project.FrequencyType = 1
  5256. return 0
  5257. }
  5258. func (c *HisApiController) GetHisOrderList() {
  5259. page, _ := c.GetInt64("page", -1)
  5260. limit, _ := c.GetInt64("limit", -1)
  5261. start_time := c.GetString("start_time")
  5262. end_time := c.GetString("end_time")
  5263. types, _ := c.GetInt64("type", 0)
  5264. keywords := c.GetString("keywords")
  5265. p_type, _ := c.GetInt64("p_type", 0)
  5266. sort_type, _ := c.GetInt64("sort_type", 0)
  5267. charge_type, _ := c.GetInt64("charge_type", 0)
  5268. sch_type, _ := c.GetInt64("sch_type", 0)
  5269. zone_type, _ := c.GetInt64("zone_type", 0)
  5270. timeLayout := "2006-01-02"
  5271. loc, _ := time.LoadLocation("Local")
  5272. var startTime int64
  5273. if len(start_time) > 0 {
  5274. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5275. if err != nil {
  5276. //fmt.Println(err)
  5277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5278. return
  5279. }
  5280. startTime = theTime.Unix()
  5281. }
  5282. var endTime int64
  5283. if len(end_time) > 0 {
  5284. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5285. if err != nil {
  5286. utils.ErrorLog(err.Error())
  5287. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5288. return
  5289. }
  5290. endTime = theTime.Unix()
  5291. }
  5292. adminUser := c.GetAdminUserInfo()
  5293. org_id := adminUser.CurrentOrgId
  5294. 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)
  5295. for _, item := range order {
  5296. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5297. item.DoctorName = info.Doctor
  5298. item.DepartmentName = info.XtHisDepartment.Name
  5299. }
  5300. if err == nil {
  5301. c.ServeSuccessJSON(map[string]interface{}{
  5302. "order": order,
  5303. "total": total,
  5304. })
  5305. } else {
  5306. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5307. return
  5308. }
  5309. }
  5310. func (c *HisApiController) GetHisOrder() {
  5311. patient_id, _ := c.GetInt64("patient_id", 0)
  5312. number := c.GetString("number")
  5313. adminInfo := c.GetAdminUserInfo()
  5314. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5315. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5316. if err == nil {
  5317. c.ServeSuccessJSON(map[string]interface{}{
  5318. "order": order,
  5319. "prescription": prescriptions,
  5320. })
  5321. } else {
  5322. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5323. return
  5324. }
  5325. }
  5326. func (c *HisApiController) GetHisPrescriptionList() {
  5327. record_date := c.GetString("record_date")
  5328. keywords := c.GetString("keywords")
  5329. page, _ := c.GetInt64("page")
  5330. limit, _ := c.GetInt64("limit")
  5331. sch_type, _ := c.GetInt64("sch_type")
  5332. timeLayout := "2006-01-02"
  5333. loc, _ := time.LoadLocation("Local")
  5334. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5335. if err != nil {
  5336. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5337. return
  5338. }
  5339. recordDateTime := theTime.Unix()
  5340. adminInfo := c.GetAdminUserInfo()
  5341. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5342. //adminInfo := c.GetAdminUserInfo()
  5343. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5344. //fmt.Println(prescriptionOrder)
  5345. if err == nil {
  5346. c.ServeSuccessJSON(map[string]interface{}{
  5347. "order": prescriptionOrder,
  5348. "total": total,
  5349. })
  5350. } else {
  5351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5352. return
  5353. }
  5354. }
  5355. func (c *HisApiController) GetHisPrescriptionInfo() {
  5356. id, _ := c.GetInt64("id")
  5357. adminInfo := c.GetAdminUserInfo()
  5358. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5359. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5360. if err == nil {
  5361. c.ServeSuccessJSON(map[string]interface{}{
  5362. "order": prescriptionOrder,
  5363. "prescription": prescription,
  5364. })
  5365. } else {
  5366. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5367. return
  5368. }
  5369. }
  5370. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5371. adminUser := c.GetAdminUserInfo()
  5372. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5373. c.ServeSuccessJSON(map[string]interface{}{
  5374. "config": config,
  5375. })
  5376. }
  5377. type ResultTwo struct {
  5378. ErrMsg interface{} `json:"err_msg"`
  5379. InfRefmsgid string `json:"inf_refmsgid"`
  5380. Infcode int64 `json:"infcode"`
  5381. Output struct {
  5382. Baseinfo struct {
  5383. Age float64 `json:"age"`
  5384. Brdy string `json:"brdy"`
  5385. Certno string `json:"certno"`
  5386. Gend string `json:"gend"`
  5387. Naty string `json:"naty"`
  5388. PsnCertType string `json:"psn_cert_type"`
  5389. PsnName string `json:"psn_name"`
  5390. PsnNo string `json:"psn_no"`
  5391. } `json:"baseinfo"`
  5392. Idetinfo []interface{} `json:"idetinfo"`
  5393. Iinfo []struct {
  5394. Balc float64 `json:"balc"`
  5395. CvlservFlag string `json:"cvlserv_flag"`
  5396. EmpName string `json:"emp_name"`
  5397. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5398. Insutype string `json:"insutype"`
  5399. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5400. PausInsuDate interface{} `json:"paus_insu_date"`
  5401. PsnInsuDate string `json:"psn_insu_date"`
  5402. PsnInsuStas string `json:"psn_insu_stas"`
  5403. PsnType string `json:"psn_type"`
  5404. } `json:"insuinfo"`
  5405. } `json:"output"`
  5406. RefmsgTime string `json:"refmsg_time"`
  5407. RespondTime string `json:"respond_time"`
  5408. Signtype interface{} `json:"signtype"`
  5409. WarnInfo interface{} `json:"warn_info"`
  5410. }
  5411. type ResultThree struct {
  5412. Cainfo interface{} `json:"cainfo"`
  5413. ErrMsg interface{} `json:"err_msg"`
  5414. InfRefmsgid string `json:"inf_refmsgid"`
  5415. Infcode int64 `json:"infcode"`
  5416. Output struct {
  5417. Data struct {
  5418. IptOtpNo string `json:"ipt_otp_no"`
  5419. MdtrtID string `json:"mdtrt_id"`
  5420. PsnNo string `json:"psn_no"`
  5421. } `json:"data"`
  5422. } `json:"output"`
  5423. RefmsgTime string `json:"refmsg_time"`
  5424. RespondTime string `json:"respond_time"`
  5425. Signtype interface{} `json:"signtype"`
  5426. WarnMsg interface{} `json:"warn_msg"`
  5427. }
  5428. type ResultFour struct {
  5429. Cainfo string `json:"cainfo"`
  5430. ErrMsg string `json:"err_msg"`
  5431. InfRefmsgid string `json:"inf_refmsgid"`
  5432. Infcode int64 `json:"infcode"`
  5433. Output struct {
  5434. Result []struct {
  5435. BasMednFlag string `json:"bas_medn_flag"`
  5436. ChldMedcFlag string `json:"chld_medc_flag"`
  5437. ChrgitmLv string `json:"chrgitm_lv"`
  5438. Cnt float64 `json:"cnt"`
  5439. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5440. DrtReimFlag string `json:"drt_reim_flag"`
  5441. FeedetlSn string `json:"feedetl_sn"`
  5442. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5443. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5444. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5445. ListSpItemFlag string `json:"list_sp_item_flag"`
  5446. LmtUsedFlag string `json:"lmt_used_flag"`
  5447. MedChrgitmType string `json:"med_chrgitm_type"`
  5448. Memo string `json:"memo"`
  5449. OverlmtAmt float64 `json:"overlmt_amt"`
  5450. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5451. Pric float64 `json:"pric"`
  5452. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5453. SelfpayProp float64 `json:"selfpay_prop"`
  5454. } `json:"result"`
  5455. } `json:"output"`
  5456. RefmsgTime string `json:"refmsg_time"`
  5457. RespondTime string `json:"respond_time"`
  5458. Signtype string `json:"signtype"`
  5459. WarnMsg string `json:"warn_msg"`
  5460. }
  5461. type ResultFive struct {
  5462. Insutype string `json:"insutype"`
  5463. }
  5464. type ResultSix struct {
  5465. Cainfo interface{} `json:"cainfo"`
  5466. ErrMsg interface{} `json:"err_msg"`
  5467. InfRefmsgid string `json:"inf_refmsgid"`
  5468. Infcode int64 `json:"infcode"`
  5469. Output struct {
  5470. } `json:"output"`
  5471. RefmsgTime string `json:"refmsg_time"`
  5472. RespondTime string `json:"respond_time"`
  5473. Signtype interface{} `json:"signtype"`
  5474. WarnMsg interface{} `json:"warn_msg"`
  5475. }
  5476. type ResultSeven struct {
  5477. Cainfo string `json:"cainfo"`
  5478. ErrMsg string `json:"err_msg"`
  5479. InfRefmsgid string `json:"inf_refmsgid"`
  5480. Infcode int64 `json:"infcode"`
  5481. Output struct {
  5482. Setldetail []interface{} `json:"setldetail"`
  5483. Setlinfo struct {
  5484. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5485. AcctPay float64 `json:"acct_pay"`
  5486. ActPayDedc float64 `json:"act_pay_dedc"`
  5487. Age float64 `json:"age"`
  5488. Balc float64 `json:"balc"`
  5489. Brdy string `json:"brdy"`
  5490. Certno string `json:"certno"`
  5491. ClrOptins string `json:"clr_optins"`
  5492. ClrType string `json:"clr_type"`
  5493. ClrWay string `json:"clr_way"`
  5494. CvlservFlag string `json:"cvlserv_flag"`
  5495. CvlservPay float64 `json:"cvlserv_pay"`
  5496. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5497. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5498. Gend string `json:"gend"`
  5499. HifesPay float64 `json:"hifes_pay"`
  5500. HifmiPay float64 `json:"hifmi_pay"`
  5501. HifobPay float64 `json:"hifob_pay"`
  5502. HifpPay float64 `json:"hifp_pay"`
  5503. HospPartAmt float64 `json:"hosp_part_amt"`
  5504. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5505. Insutype string `json:"insutype"`
  5506. MafPay float64 `json:"maf_pay"`
  5507. MdtrtCertType string `json:"mdtrt_cert_type"`
  5508. MdtrtID string `json:"mdtrt_id"`
  5509. MedType string `json:"med_type"`
  5510. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5511. MedinsSetlID string `json:"medins_setl_id"`
  5512. Naty string `json:"naty"`
  5513. OthPay float64 `json:"oth_pay"`
  5514. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5515. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5516. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5517. PsnCashPay float64 `json:"psn_cash_pay"`
  5518. PsnCertType string `json:"psn_cert_type"`
  5519. PsnName string `json:"psn_name"`
  5520. PsnNo string `json:"psn_no"`
  5521. PsnPartAmt float64 `json:"psn_part_amt"`
  5522. PsnType string `json:"psn_type"`
  5523. SetlID string `json:"setl_id"`
  5524. SetlTime string `json:"setl_time"`
  5525. } `json:"setlinfo"`
  5526. } `json:"output"`
  5527. RefmsgTime string `json:"refmsg_time"`
  5528. RespondTime string `json:"respond_time"`
  5529. Signtype interface{} `json:"signtype"`
  5530. WarnMsg interface{} `json:"warn_msg"`
  5531. }
  5532. type ResultEight struct {
  5533. Cainfo string `json:"cainfo"`
  5534. ErrMsg string `json:"err_msg"`
  5535. InfRefmsgid string `json:"inf_refmsgid"`
  5536. Infcode int64 `json:"infcode"`
  5537. Output struct {
  5538. Stmtinfo struct {
  5539. SetlOptins string `json:"setl_optins"`
  5540. StmtRslt string `json:"stmt_rslt"`
  5541. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  5542. } `json:"stmtinfo"`
  5543. } `json:"output"`
  5544. RefmsgTime string `json:"refmsg_time"`
  5545. RespondTime string `json:"respond_time"`
  5546. Signtype interface{} `json:"signtype"`
  5547. WarnMsg interface{} `json:"warn_msg"`
  5548. }
  5549. type ResultNine struct {
  5550. Cainfo string `json:"cainfo"`
  5551. ErrMsg string `json:"err_msg"`
  5552. InfRefmsgid string `json:"inf_refmsgid"`
  5553. Infcode int64 `json:"infcode"`
  5554. Output struct {
  5555. FileQuryNo string `json:"file_qury_no"`
  5556. } `json:"output"`
  5557. RefmsgTime string `json:"refmsg_time"`
  5558. RespondTime string `json:"respond_time"`
  5559. Signtype interface{} `json:"signtype"`
  5560. WarnMsg interface{} `json:"warn_msg"`
  5561. }
  5562. type ResultTen struct {
  5563. Cainfo string `json:"cainfo"`
  5564. ErrMsg string `json:"err_msg"`
  5565. InfRefmsgid string `json:"inf_refmsgid"`
  5566. Infcode int64 `json:"infcode"`
  5567. Output struct {
  5568. DldEndtime string `json:"dld_endtime"`
  5569. FileQuryNo string `json:"file_qury_no"`
  5570. Filename string `json:"filename"`
  5571. } `json:"output"`
  5572. RefmsgTime string `json:"refmsg_time"`
  5573. RespondTime string `json:"respond_time"`
  5574. Signtype interface{} `json:"signtype"`
  5575. WarnMsg interface{} `json:"warn_msg"`
  5576. }
  5577. type ResultEleven struct {
  5578. Cainfo string `json:"cainfo"`
  5579. ErrMsg string `json:"err_msg"`
  5580. InfRefmsgid string `json:"inf_refmsgid"`
  5581. Infcode int64 `json:"infcode"`
  5582. Output struct {
  5583. Setlinfo struct {
  5584. FixmedinsName string `json:"fixmedins_name"`
  5585. FixmedinsCode string `json:"fixmedins_code"`
  5586. PsnNo string `json:"psn_no"`
  5587. PsnName string `json:"psn_name"`
  5588. HifobPay float64 `json:"hifob_pay"`
  5589. Gend string `json:"gend"`
  5590. Brdy string `json:"brdy"`
  5591. PsnCertType string `json:"psn_cert_type"`
  5592. PsnType string `json:"psn_type"`
  5593. EmpName string `json:"emp_name"`
  5594. Certno string `json:"certno"`
  5595. Insutype string `json:"insutype"`
  5596. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5597. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5598. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5599. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5600. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5601. ActPayDedc float64 `json:"act_pay_dedc"`
  5602. HifpPay float64 `json:"hifp_pay"`
  5603. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5604. CvlservPay float64 `json:"cvlserv_pay"`
  5605. HifesPay float64 `json:"hifes_pay"`
  5606. HifmiPay float64 `json:"hifmi_pay"`
  5607. MafPay float64 `json:"maf_pay"`
  5608. OthPay float64 `json:"oth_pay"`
  5609. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5610. PsnPay float64 `json:"psn_pay"`
  5611. AcctPay float64 `json:"acct_pay"`
  5612. CashPayamt float64 `json:"cash_payamt"`
  5613. Balc float64 `json:"balc"`
  5614. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5615. MedinsSetlId string `json:"medins_setl_id"`
  5616. RefdSetlFlag string `json:"refd_setl_flag"`
  5617. SetlTime string `json:"setl_time"`
  5618. MedType string `json:"med_type"`
  5619. } `json:"setlinfo"`
  5620. } `json:"output"`
  5621. RefmsgTime string `json:"refmsg_time"`
  5622. RespondTime string `json:"respond_time"`
  5623. Signtype interface{} `json:"signtype"`
  5624. WarnMsg interface{} `json:"warn_msg"`
  5625. }
  5626. type Custom struct {
  5627. DetItemFeeSumamt string
  5628. Cut string
  5629. FeedetlSn string
  5630. Price string
  5631. MedListCodg string
  5632. Type int64
  5633. AdviceId int64
  5634. ProjectId int64
  5635. ItemId int64
  5636. }
  5637. // 获取个人信息----挂号-----上传就诊信息
  5638. func (c *HisApiController) GetRegisterInfo() {
  5639. id, _ := c.GetInt64("id")
  5640. record_time := c.GetString("record_time")
  5641. settlementValue, _ := c.GetInt64("settlement_value")
  5642. medical_insurance_card := c.GetString("medical_insurance_card")
  5643. name := c.GetString("name")
  5644. id_card_type, _ := c.GetInt64("id_card_type")
  5645. certificates, _ := c.GetInt64("certificates")
  5646. medical_care, _ := c.GetInt64("medical_care")
  5647. birthday := c.GetString("birthday")
  5648. age, _ := c.GetInt64("age")
  5649. id_card := c.GetString("id_card")
  5650. register_type, _ := c.GetInt64("register")
  5651. doctor, _ := c.GetInt64("doctor")
  5652. department, _ := c.GetInt64("department")
  5653. gender, _ := c.GetInt64("sex")
  5654. phone := c.GetString("phone")
  5655. registration_fee, _ := c.GetFloat("registration_fee")
  5656. medical_expenses, _ := c.GetFloat("medical_expenses")
  5657. social_type, _ := c.GetInt64("social_type")
  5658. //diagnosis_id, _ := c.GetInt64("diagnosis")
  5659. diagnosis_ids := c.GetString("diagnosis")
  5660. sick_type, _ := c.GetInt64("sick_type")
  5661. reg_type := c.GetString("p_type")
  5662. timeLayout := "2006-01-02"
  5663. loc, _ := time.LoadLocation("Local")
  5664. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  5665. birthUnix := birthdays.Unix()
  5666. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5667. if err != nil {
  5668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5669. return
  5670. }
  5671. recordDateTime := theTime.Unix()
  5672. adminInfo := c.GetAdminUserInfo()
  5673. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5674. if tempPatient.ID == 0 {
  5675. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5676. return
  5677. }
  5678. var patient service.Patients
  5679. if id == 0 {
  5680. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5681. } else {
  5682. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5683. }
  5684. if patient.ID == 0 {
  5685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5686. return
  5687. }
  5688. if len(patient.IdCardNo) == 0 {
  5689. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5690. return
  5691. }
  5692. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5693. if len(his) >= 1 {
  5694. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5695. if len(his) >= 1 && order.ID == 0 {
  5696. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5697. return
  5698. }
  5699. }
  5700. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5701. fmt.Println(timeStr)
  5702. timeArr := strings.Split(timeStr, " ")
  5703. fmt.Println(timeArr)
  5704. timeArrTwo := strings.Split(timeArr[0], "-")
  5705. timeArrThree := strings.Split(timeArr[1], ":")
  5706. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5707. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5708. if len(lists) == 0 {
  5709. var hisPatient models.XtHisPatient
  5710. hisPatient = models.XtHisPatient{
  5711. Name: name,
  5712. Age: age,
  5713. Gender: gender,
  5714. Birthday: birthUnix,
  5715. Phone: phone,
  5716. MedicalTreatmentType: medical_care,
  5717. IdType: certificates,
  5718. IdCardNo: id_card,
  5719. BalanceAccountsType: settlementValue,
  5720. SocialType: social_type,
  5721. MedicalInsuranceNumber: medical_insurance_card,
  5722. RegisterType: register_type,
  5723. RegisterCost: registration_fee,
  5724. TreatmentCost: medical_expenses,
  5725. AdminUserId: adminInfo.AdminUser.Id,
  5726. UserOrgId: adminInfo.CurrentOrgId,
  5727. Status: 1,
  5728. RecordDate: recordDateTime,
  5729. IsReturn: 1,
  5730. PatientId: patient.ID,
  5731. Ctime: time.Now().Unix(),
  5732. Mtime: time.Now().Unix(),
  5733. Number: str,
  5734. IdCardType: id_card_type,
  5735. Departments: department,
  5736. Doctor: doctor,
  5737. PType: reg_type,
  5738. Diagnosis: diagnosis_ids,
  5739. SickType: sick_type,
  5740. }
  5741. service.CreateHisPatient(&hisPatient)
  5742. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5743. c.ServeSuccessJSON(map[string]interface{}{
  5744. "his_info": hisPatient,
  5745. })
  5746. } else {
  5747. //chrgBchno := rand.Intn(1000000) + 10000
  5748. var hisPatient models.XtHisPatient
  5749. hisPatient = models.XtHisPatient{
  5750. Name: name,
  5751. Age: age,
  5752. Gender: gender,
  5753. Birthday: birthUnix,
  5754. Phone: phone,
  5755. MedicalTreatmentType: medical_care,
  5756. IdType: certificates,
  5757. IdCardNo: id_card,
  5758. BalanceAccountsType: settlementValue,
  5759. SocialType: social_type,
  5760. MedicalInsuranceNumber: medical_insurance_card,
  5761. RegisterType: register_type,
  5762. RegisterCost: registration_fee,
  5763. TreatmentCost: medical_expenses,
  5764. AdminUserId: adminInfo.AdminUser.Id,
  5765. UserOrgId: adminInfo.CurrentOrgId,
  5766. Status: 1,
  5767. RecordDate: recordDateTime,
  5768. IsReturn: 1,
  5769. PatientId: patient.ID,
  5770. Ctime: time.Now().Unix(),
  5771. Mtime: time.Now().Unix(),
  5772. Number: str,
  5773. IdCardType: id_card_type,
  5774. Departments: department,
  5775. Doctor: doctor,
  5776. PType: reg_type,
  5777. Diagnosis: diagnosis_ids,
  5778. SickType: sick_type,
  5779. }
  5780. service.CreateHisPatient(&hisPatient)
  5781. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5782. c.ServeSuccessJSON(map[string]interface{}{
  5783. "his_info": hisPatient,
  5784. })
  5785. }
  5786. }
  5787. // 上传明细----结算
  5788. func (c *HisApiController) GetUploadInfo() {
  5789. id, _ := c.GetInt64("id")
  5790. record_time := c.GetString("record_time")
  5791. his_patient_id, _ := c.GetInt64("his_patient_id")
  5792. oth_desc := c.GetString("oth_desc")
  5793. pay_way, _ := c.GetInt64("pay_way")
  5794. pay_ways := c.GetString("pay_ways")
  5795. pay_price, _ := c.GetFloat("pay_price")
  5796. pay_card_no := c.GetString("pay_card_no")
  5797. discount_price, _ := c.GetFloat("discount_price")
  5798. preferential_price, _ := c.GetFloat("preferential_price")
  5799. reality_price, _ := c.GetFloat("reality_price")
  5800. found_price, _ := c.GetFloat("found_price")
  5801. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5802. private_price, _ := c.GetFloat("private_price")
  5803. timeLayout := "2006-01-02"
  5804. loc, _ := time.LoadLocation("Local")
  5805. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5806. fapiao_code := c.GetString("fapiao_code")
  5807. fapiao_number := c.GetString("fapiao_number")
  5808. diagnosis_id := c.GetString("diagnosis")
  5809. sick_type, _ := c.GetInt64("sick_type")
  5810. reg_type, _ := c.GetInt64("p_type")
  5811. order_id, _ := c.GetInt64("order_id")
  5812. cash_pay := c.GetString("cash_pay")
  5813. wechat_pay := c.GetString("wechat_pay")
  5814. ali_pay := c.GetString("ali_pay")
  5815. jifen_pay := c.GetString("jifen_pay")
  5816. band_card_pay := c.GetString("band_card_pay")
  5817. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5818. tmp_decimal := c.GetString("tmp_decimal")
  5819. var decimal float64 //本次使用的押金
  5820. var errmsg error
  5821. tx := service.XTWriteDB().Begin() //开了事务
  5822. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5823. defer func() {
  5824. if errmsg != nil {
  5825. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5826. tx.Rollback()
  5827. } else {
  5828. tx.Commit()
  5829. }
  5830. }()
  5831. fmt.Println("dec_way", dec_way)
  5832. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5833. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5834. return
  5835. }
  5836. if len(tmp_decimal) > 0 {
  5837. if tmp_decimal[0] == 45 {
  5838. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5839. return
  5840. }
  5841. }
  5842. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5843. fmt.Println(errs)
  5844. decimal = tt
  5845. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5846. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5847. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5848. if err != nil {
  5849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5850. return
  5851. }
  5852. recordDateTime := theTime.Unix()
  5853. adminUser := c.GetAdminUserInfo()
  5854. var prescriptions []*models.HisPrescription
  5855. var prescriptionsOne []*models.HisPrescription
  5856. var start_time int64
  5857. var end_time int64
  5858. ids_str := c.GetString("ids")
  5859. ids_arr := strings.Split(ids_str, ",")
  5860. if tempOrder.ID == 0 {
  5861. if settle_accounts_type == 1 { //日结
  5862. fmt.Println(reg_type)
  5863. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5864. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5865. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5866. } else {
  5867. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5868. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5869. }
  5870. } else { //月结
  5871. start_time_str := c.GetString("start_time")
  5872. end_time_str := c.GetString("end_time")
  5873. timeLayout := "2006-01-02"
  5874. loc, _ := time.LoadLocation("Local")
  5875. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5876. if err != nil {
  5877. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5878. return
  5879. }
  5880. recordStartTime := theStartTime.Unix()
  5881. start_time = recordStartTime
  5882. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5883. if err != nil {
  5884. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5885. return
  5886. }
  5887. recordEndTime := theEndTime.Unix()
  5888. end_time = recordEndTime
  5889. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5890. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5891. }
  5892. var goods []*models.DialysisBeforePrepareGoods
  5893. var newGoods []*models.NewDialysisBeforePrepareGoods
  5894. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5895. var infos []*models.HisDoctorAdviceInfo
  5896. var infoList []*models.HisDoctorAdviceInfo
  5897. var hisAdvice []*models.HisDoctorAdviceInfo
  5898. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5899. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5900. //判断库存不足
  5901. //结算出库开关
  5902. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5903. if settConfig.IsOpen == 1 {
  5904. //判断库存的地方
  5905. for _, info := range prescriptions {
  5906. if info.Type == 1 {
  5907. infos = append(infos, info.HisDoctorAdviceInfo...)
  5908. }
  5909. if info.Type == 2 {
  5910. for _, sumItem := range info.HisPrescriptionProject {
  5911. if sumItem.Type == 3 {
  5912. var good models.DialysisBeforePrepareGoods
  5913. var newGood models.NewDialysisBeforePrepareGoods
  5914. good.GoodId = sumItem.GoodInfo.ID
  5915. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5916. count, _ := strconv.Atoi(sumItem.Count)
  5917. good.Count = int64(count)
  5918. good.StorehouseId = houseConfig.StorehouseOutInfo
  5919. good.ProjectId = sumItem.ID
  5920. goods = append(goods, &good)
  5921. newGood.GoodId = sumItem.GoodInfo.ID
  5922. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5923. count2, _ := strconv.Atoi(sumItem.Count)
  5924. newGood.Count = int64(count2)
  5925. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5926. newGood.ProjectId = sumItem.ID
  5927. newGoods = append(newGoods, &newGood)
  5928. }
  5929. }
  5930. }
  5931. }
  5932. for _, info := range prescriptionsOne {
  5933. if info.Type == 1 {
  5934. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5935. }
  5936. if info.Type == 2 {
  5937. for _, sumItem := range info.HisPrescriptionProject {
  5938. if sumItem.Type == 3 {
  5939. var newGood models.NewDialysisBeforePrepareGoods
  5940. newGood.GoodId = sumItem.GoodInfo.ID
  5941. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5942. count2, _ := strconv.Atoi(sumItem.Count)
  5943. newGood.Count = int64(count2)
  5944. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5945. newGood.ProjectId = sumItem.ID
  5946. newGoodOne = append(newGoodOne, &newGood)
  5947. }
  5948. }
  5949. }
  5950. }
  5951. //判断
  5952. for _, itemOne := range infos {
  5953. for _, itemTwo := range hisAdvice {
  5954. if itemOne.DrugId == itemTwo.DrugId {
  5955. itemTwo.Child = append(itemTwo.Child, itemOne)
  5956. }
  5957. }
  5958. }
  5959. for _, itemTwo := range hisAdvice {
  5960. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5961. var sum_out_count int64
  5962. for _, itemThree := range itemTwo.Child {
  5963. var prescribing_number int64
  5964. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5965. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5966. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5967. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5968. }
  5969. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5970. prescribing_number = parseIntPrescribingNumber
  5971. }
  5972. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5973. prescribing_number = parseIntPrescribingNumber
  5974. }
  5975. sum_out_count += prescribing_number
  5976. }
  5977. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5978. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5979. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5980. if sum_out_count > drugStockOut.FlushCount {
  5981. c.ServeSuccessJSON(map[string]interface{}{
  5982. "msg": "2",
  5983. "drug": medical,
  5984. })
  5985. return
  5986. }
  5987. }
  5988. fmt.Println("newGoods99999988882os", newGoods)
  5989. for _, itemOne := range newGoods {
  5990. for _, item := range newGoodOne {
  5991. if itemOne.GoodId == item.GoodId {
  5992. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5993. }
  5994. }
  5995. }
  5996. for _, item := range newGoodOne {
  5997. var sum_out_count_one int64
  5998. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5999. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6000. sum_out_count_one += itemOne.Count
  6001. }
  6002. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6003. fmt.Println("sum_out_count_one", sum_out_count_one)
  6004. fmt.Println("list.FlushCount", list.FlushCount)
  6005. if sum_out_count_one > list.FlushCount {
  6006. c.ServeSuccessJSON(map[string]interface{}{
  6007. "msg": "3",
  6008. "good": good,
  6009. })
  6010. return
  6011. }
  6012. }
  6013. }
  6014. timestamp := time.Now().Unix()
  6015. tempTime := time.Unix(timestamp, 0)
  6016. timeFormat := tempTime.Format("20060102150405")
  6017. chrgBchno := rand.Intn(100000) + 10000
  6018. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6019. strconv.FormatInt(his.PatientId, 10)
  6020. var ids []int64
  6021. for _, item := range prescriptions {
  6022. ids = append(ids, item.ID)
  6023. }
  6024. var total float64
  6025. for _, item := range prescriptions {
  6026. fmt.Println(item)
  6027. if item.Type == 1 { //药品
  6028. for _, subItem := range item.HisDoctorAdviceInfo {
  6029. total = total + (subItem.Price * subItem.PrescribingNumber)
  6030. }
  6031. }
  6032. if item.Type == 2 { //项目
  6033. for _, subItem := range item.HisPrescriptionProject {
  6034. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6035. total = total + (subItem.Price * cnt)
  6036. }
  6037. }
  6038. for _, subItem := range item.HisAdditionalCharge {
  6039. total = total + (subItem.Price * float64(subItem.Count))
  6040. }
  6041. }
  6042. if reg_type == 1111 || reg_type == 1112 {
  6043. reg_type = 11
  6044. }
  6045. tm := time.Unix(time.Now().Unix(), 0)
  6046. allTotal := fmt.Sprintf("%.4f", total)
  6047. totals, _ := strconv.ParseFloat(allTotal, 64)
  6048. order := &models.HisOrder{
  6049. UserOrgId: adminUser.CurrentOrgId,
  6050. HisPatientId: his.ID,
  6051. PatientId: id,
  6052. SettleAccountsDate: recordDateTime,
  6053. Ctime: time.Now().Unix(),
  6054. Mtime: time.Now().Unix(),
  6055. Status: 1,
  6056. OrderStatus: 2,
  6057. MdtrtId: his.Number,
  6058. Number: chrg_bchno,
  6059. MedfeeSumamt: totals,
  6060. PayWay: pay_way,
  6061. PayWays: pay_ways,
  6062. PayPrice: pay_price,
  6063. MedType: strconv.Itoa(int(reg_type)),
  6064. PayCardNo: pay_card_no,
  6065. DiscountPrice: discount_price,
  6066. PreferentialPrice: preferential_price,
  6067. RealityPrice: reality_price,
  6068. FoundPrice: found_price,
  6069. MedicalInsurancePrice: medical_insurance_price,
  6070. PrivatePrice: private_price,
  6071. SettleEndTime: end_time,
  6072. SettleStartTime: start_time,
  6073. PsnPartAmt: totals,
  6074. PsnCashPay: totals,
  6075. SettleType: settle_accounts_type,
  6076. FaPiaoCode: fapiao_code,
  6077. FaPiaoNumber: fapiao_number,
  6078. Diagnosis: diagnosis_id,
  6079. PType: 2,
  6080. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6081. Decimal: decimal,
  6082. OthDesc: oth_desc,
  6083. CashPay: cash_pay,
  6084. WechatPay: wechat_pay,
  6085. AliPay: ali_pay,
  6086. JifenPay: jifen_pay,
  6087. BandCardPay: band_card_pay,
  6088. }
  6089. err = service.CreateOrderTX(order, tx)
  6090. if err != nil {
  6091. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6092. return
  6093. }
  6094. var customs []*Custom
  6095. for _, item := range prescriptions {
  6096. if item.Type == 1 { //药品a
  6097. for _, subItem := range item.HisDoctorAdviceInfo {
  6098. cus := &Custom{
  6099. AdviceId: subItem.ID,
  6100. ProjectId: 0,
  6101. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6102. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6103. FeedetlSn: subItem.FeedetlSn,
  6104. Price: fmt.Sprintf("%.4f", subItem.Price),
  6105. MedListCodg: subItem.MedListCodg,
  6106. Type: 1,
  6107. }
  6108. customs = append(customs, cus)
  6109. }
  6110. }
  6111. if item.Type == 2 { //项目
  6112. for _, subItem := range item.HisPrescriptionProject {
  6113. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6114. cus := &Custom{
  6115. AdviceId: 0,
  6116. ProjectId: subItem.ID,
  6117. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6118. Cut: fmt.Sprintf("%.4f", cnt),
  6119. FeedetlSn: subItem.FeedetlSn,
  6120. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6121. MedListCodg: subItem.MedListCodg,
  6122. Type: 2,
  6123. }
  6124. customs = append(customs, cus)
  6125. }
  6126. }
  6127. for _, item := range item.HisAdditionalCharge {
  6128. cus := &Custom{
  6129. ItemId: item.ID,
  6130. AdviceId: 0,
  6131. ProjectId: 0,
  6132. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6133. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6134. FeedetlSn: item.FeedetlSn,
  6135. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6136. MedListCodg: item.XtHisAddtionConfig.Code,
  6137. Type: 3,
  6138. }
  6139. customs = append(customs, cus)
  6140. }
  6141. }
  6142. for _, item := range customs {
  6143. var advice_id int64 = 0
  6144. var project_id int64 = 0
  6145. var item_id int64 = 0
  6146. var types int64 = 0
  6147. if item.Type == 1 {
  6148. advice_id = item.AdviceId
  6149. project_id = 0
  6150. item_id = 0
  6151. } else if item.Type == 2 {
  6152. advice_id = 0
  6153. item_id = 0
  6154. project_id = item.ProjectId
  6155. } else if item.Type == 3 {
  6156. advice_id = 0
  6157. item_id = item.ItemId
  6158. project_id = 0
  6159. }
  6160. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6161. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6162. pric, _ := strconv.ParseFloat(item.Price, 32)
  6163. info := &models.HisOrderInfo{
  6164. OrderNumber: order.Number,
  6165. UploadDate: time.Now().Unix(),
  6166. AdviceId: advice_id,
  6167. DetItemFeeSumamt: detItemFeeSumamt,
  6168. Cnt: cut,
  6169. Pric: pric,
  6170. PatientId: id,
  6171. Status: 1,
  6172. Mtime: time.Now().Unix(),
  6173. Ctime: time.Now().Unix(),
  6174. UserOrgId: adminUser.CurrentOrgId,
  6175. HisPatientId: his.ID,
  6176. OrderId: order.ID,
  6177. ProjectId: project_id,
  6178. Type: types,
  6179. ItemId: item_id,
  6180. }
  6181. service.CreateOrderInfoTX(info, tx)
  6182. }
  6183. his.Diagnosis = diagnosis_id
  6184. his.SickType = sick_type
  6185. his.RegisterType = reg_type
  6186. his.MedicalTreatmentType = reg_type
  6187. service.UpdataHisPateintTX(&his, tx)
  6188. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6189. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6190. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6191. //判断是否使用了押金
  6192. if dec_way == "true" {
  6193. tmpstring := strconv.FormatInt(order.ID, 10)
  6194. //扣押金
  6195. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6196. order.Decimal = decimal
  6197. service.UpDateOrderTwo(order)
  6198. if errmsg != nil {
  6199. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6200. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6201. return
  6202. }
  6203. }
  6204. if err == nil {
  6205. for _, info := range prescriptions {
  6206. if info.Type == 1 {
  6207. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6208. }
  6209. if info.Type == 2 {
  6210. for _, sumItem := range info.HisPrescriptionProject {
  6211. if sumItem.Type == 3 {
  6212. var good models.DialysisBeforePrepareGoods
  6213. var newGood models.NewDialysisBeforePrepareGoods
  6214. var oldGood models.OldDialysisBeforePrepareGoods
  6215. good.GoodId = sumItem.GoodInfo.ID
  6216. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6217. count, _ := strconv.Atoi(sumItem.Count)
  6218. good.Count = int64(count)
  6219. good.StorehouseId = houseConfig.StorehouseOutInfo
  6220. good.ProjectId = sumItem.ID
  6221. good.PatientId = sumItem.PatientId
  6222. goods = append(goods, &good)
  6223. newGood.GoodId = sumItem.GoodInfo.ID
  6224. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6225. count2, _ := strconv.Atoi(sumItem.Count)
  6226. newGood.Count = int64(count2)
  6227. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6228. newGood.ProjectId = sumItem.ID
  6229. newGood.PatientId = sumItem.HisPatientId
  6230. newGoods = append(newGoods, &newGood)
  6231. oldGood.GoodId = sumItem.GoodInfo.ID
  6232. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6233. count3, _ := strconv.Atoi(sumItem.Count)
  6234. oldGood.Count = int64(count3)
  6235. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6236. oldGood.ProjectId = sumItem.ID
  6237. oldGood.RecordDate = sumItem.RecordDate
  6238. oldGood.PatientId = sumItem.HisPatientId
  6239. oldGoods = append(oldGoods, &oldGood)
  6240. }
  6241. }
  6242. }
  6243. }
  6244. if settConfig.IsOpen == 1 {
  6245. for _, item := range infoList {
  6246. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6247. if medical.IsUse == 2 {
  6248. //药品出库
  6249. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6250. //查询默认仓库
  6251. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6252. //查询默认仓库剩余多少库存
  6253. var sum_count int64
  6254. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6255. for _, its := range stockInfo {
  6256. if its.MaxUnit == medical.MaxUnit {
  6257. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6258. }
  6259. sum_count += its.StockMaxNumber + its.StockMinNumber
  6260. }
  6261. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6262. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6263. }
  6264. }
  6265. orgId := c.GetAdminUserInfo().CurrentOrgId
  6266. if len(oldGoods) > 0 {
  6267. timeStr := time.Now().Format("2006-01-02")
  6268. timeArr := strings.Split(timeStr, "-")
  6269. total, _ := service.FindAllWarehouseOut(orgId)
  6270. total = total + 1
  6271. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6272. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6273. number = number + total
  6274. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6275. operation_time := time.Now().Unix()
  6276. creater := c.GetAdminUserInfo().AdminUser.Id
  6277. //查询默认出库仓库库存
  6278. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6279. recordDateStr := time.Now().Format("2006-01-02")
  6280. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6281. nowtime := recordDate.Unix()
  6282. warehouseOut := models.WarehouseOut{
  6283. WarehouseOutOrderNumber: warehousing_out_order,
  6284. OperationTime: operation_time,
  6285. OrgId: orgId,
  6286. Creater: creater,
  6287. Ctime: time.Now().Unix(),
  6288. Status: 1,
  6289. WarehouseOutTime: nowtime,
  6290. Type: 1,
  6291. StorehouseId: storeConfig.StorehouseOutInfo,
  6292. IsCheck: 1,
  6293. OrderId: order.ID,
  6294. IsSys: 5,
  6295. }
  6296. //查询是否生成出库单
  6297. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6298. if out.ID == 0 {
  6299. service.AddSigleWarehouseOut(&warehouseOut)
  6300. }
  6301. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6302. for _, item := range oldGoods {
  6303. dialyPrepareOne := models.DialysisBeforePrepare{
  6304. GoodTypeId: item.GoodTypeId,
  6305. GoodId: item.GoodId,
  6306. PatientId: his.PatientId,
  6307. RecordDate: item.RecordDate,
  6308. UserOrgId: adminUser.CurrentOrgId,
  6309. Count: item.Count,
  6310. Ctime: time.Now().Unix(),
  6311. Creater: adminUser.AdminUser.Id,
  6312. CommdityCode: item.CommdityCode,
  6313. Status: 1,
  6314. StorehouseId: houseConfig.StorehouseOutInfo,
  6315. }
  6316. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6317. //非零用
  6318. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6319. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6320. //查询剩余库存
  6321. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6322. var sum_count int64
  6323. for _, item := range goodList {
  6324. sum_count += item.StockCount
  6325. }
  6326. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6327. //耗材
  6328. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6329. }
  6330. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6331. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6332. //查询剩余库存
  6333. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6334. var sum_count int64
  6335. for _, item := range goodList {
  6336. sum_count += item.StockCount
  6337. }
  6338. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6339. //耗材
  6340. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6341. }
  6342. }
  6343. }
  6344. }
  6345. c.ServeSuccessJSON(map[string]interface{}{
  6346. "msg": "结算成功",
  6347. })
  6348. }
  6349. }
  6350. }
  6351. // 退款
  6352. func (c *HisApiController) Refund() {
  6353. order_id, _ := c.GetInt64("order_id")
  6354. order, _ := service.GetHisOrderByID(order_id)
  6355. adminUser := c.GetAdminUserInfo()
  6356. orgid := c.GetAdminUserInfo().CurrentOrgId
  6357. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6358. if err != nil {
  6359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6360. return
  6361. }
  6362. tmp := strconv.FormatInt(order.ID, 10)
  6363. //当押金不为零时产生退费记录
  6364. if order.Decimal != 0 {
  6365. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6366. if err != nil {
  6367. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6368. return
  6369. }
  6370. }
  6371. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6372. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6373. var goods []*models.DialysisBeforePrepareGoods
  6374. var newGoods []*models.NewDialysisBeforePrepareGoods
  6375. var infos []*models.HisDoctorAdviceInfo
  6376. for _, info := range orders {
  6377. if info.AdviceId > 0 && info.ProjectId == 0 {
  6378. infos = append(infos, &info.HisDoctorAdviceInfo)
  6379. }
  6380. if info.ProjectId > 0 && info.AdviceId == 0 {
  6381. if info.HisPrescriptionProject.Type == 3 {
  6382. var good models.DialysisBeforePrepareGoods
  6383. var newGood models.NewDialysisBeforePrepareGoods
  6384. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6385. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6386. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6387. good.Count = int64(count)
  6388. good.StorehouseId = houseConfig.StorehouseOutInfo
  6389. good.ProjectId = info.HisPrescriptionProject.ID
  6390. good.PatientId = info.PatientId
  6391. good.OrderId = order_id
  6392. goods = append(goods, &good)
  6393. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6394. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6395. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6396. newGood.Count = int64(count2)
  6397. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6398. newGood.ProjectId = info.HisPrescriptionProject.ID
  6399. newGood.RecordDate = order.SettleAccountsDate
  6400. newGood.UserOrgId = order.UserOrgId
  6401. newGood.PatientId = info.PatientId
  6402. newGood.OrderId = order_id
  6403. newGoods = append(newGoods, &newGood)
  6404. }
  6405. }
  6406. }
  6407. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6408. if settConfig.IsOpen == 1 {
  6409. for _, item := range infos {
  6410. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6411. }
  6412. for _, item := range newGoods {
  6413. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6414. }
  6415. }
  6416. c.ServeSuccessJSON(map[string]interface{}{
  6417. "msg": "退费成功",
  6418. })
  6419. }
  6420. func (c *HisApiController) RefundNumber() {
  6421. his_patient_id, _ := c.GetInt64("id")
  6422. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6423. info.Status = 0
  6424. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6425. if count > 0 {
  6426. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6427. return
  6428. }
  6429. err := service.SaveHisPatient(info)
  6430. if err == nil {
  6431. c.ServeSuccessJSON(map[string]interface{}{
  6432. "msg": "退号成功",
  6433. })
  6434. } else {
  6435. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6436. return
  6437. }
  6438. }
  6439. func (this *HisApiController) AdditionalCharge() {
  6440. dataBody := make(map[string]interface{}, 0)
  6441. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6442. fmt.Println(err)
  6443. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6444. patient_id := int64(dataBody["patient_id"].(float64))
  6445. medicineData, _ := dataBody["medicineData"].([]interface{})
  6446. adminUserInfo := this.GetAdminUserInfo()
  6447. orgId := adminUserInfo.CurrentOrgId
  6448. admin_user_id := adminUserInfo.AdminUser.Id
  6449. timeStr := time.Now().Format("2006-01-02")
  6450. timeLayout := "2006-01-02 15:04:05"
  6451. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6452. timenow := timeStringToTime.Unix()
  6453. var additionalCharges []*models.HisAdditionalCharge
  6454. for _, item := range medicineData {
  6455. var randNum int
  6456. randNum = rand.Intn(10000) + 1000
  6457. timestamp := time.Now().Unix()
  6458. tempTime := time.Unix(timestamp, 0)
  6459. timeFormat := tempTime.Format("20060102150405")
  6460. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6461. items := item.(map[string]interface{})
  6462. money := items["price"].(string)
  6463. item_id_str := items["item_id"].(string)
  6464. name := items["name"].(string)
  6465. id_str := items["id"].(string)
  6466. moneys, _ := strconv.ParseInt(money, 10, 64)
  6467. monStr := strconv.FormatInt(moneys, 10)
  6468. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6469. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6470. id, _ := strconv.ParseInt(id_str, 10, 64)
  6471. additionalCharge := &models.HisAdditionalCharge{
  6472. ID: id,
  6473. HisPatientId: his_patient_id,
  6474. UserOrgId: orgId,
  6475. PatientId: patient_id,
  6476. RecordDate: timenow,
  6477. Price: monneyStr,
  6478. Status: 1,
  6479. ItemName: name,
  6480. ItemId: item_id,
  6481. AdminUserId: admin_user_id,
  6482. CreatedTime: time.Now().Unix(),
  6483. OrderStatus: 0,
  6484. PrescriptionNumber: "",
  6485. BatchNumber: "",
  6486. FeedetlSn: p_number,
  6487. }
  6488. service.CreateAdditionalCharge(additionalCharge)
  6489. additionalCharges = append(additionalCharges, additionalCharge)
  6490. }
  6491. this.ServeSuccessJSON(map[string]interface{}{
  6492. "msg": "添加成功",
  6493. "additional_charges": additionalCharges,
  6494. })
  6495. }
  6496. func (this *HisApiController) DeleteAddition() {
  6497. id, _ := this.GetInt64("id")
  6498. //TODO 需要判断是否已经结算
  6499. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6500. if err == nil {
  6501. this.ServeSuccessJSON(map[string]interface{}{
  6502. "msg": "删除成功",
  6503. })
  6504. return
  6505. } else {
  6506. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6507. return
  6508. }
  6509. }
  6510. func (this *HisApiController) GetAdminUsers() {
  6511. adminUser := this.GetAdminUserInfo()
  6512. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6513. this.ServeSuccessJSON(map[string]interface{}{
  6514. "doctors": doctors,
  6515. })
  6516. }
  6517. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6518. change_type, _ := this.GetInt64("type", 0)
  6519. record_date := this.GetString("record_time")
  6520. patient_id, _ := this.GetInt64("patient_id", 0)
  6521. p_type, _ := this.GetInt64("p_type", 0)
  6522. timeLayout := "2006-01-02"
  6523. loc, _ := time.LoadLocation("Local")
  6524. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6525. record_time := theAdviceRecordTime.Unix()
  6526. adminUserInfo := this.GetAdminUserInfo()
  6527. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6528. if err == nil {
  6529. if len(prescriptions) == 0 {
  6530. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6531. return
  6532. } else {
  6533. this.ServeSuccessJSON(map[string]interface{}{
  6534. "prescriptions": prescriptions,
  6535. })
  6536. return
  6537. }
  6538. } else {
  6539. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6540. return
  6541. }
  6542. }
  6543. func (this *HisApiController) GetCallHisPrescription() {
  6544. patient_id, _ := this.GetInt64("patient_id", 0)
  6545. timeLayout := "2006-01-02"
  6546. loc, _ := time.LoadLocation("Local")
  6547. start_time := this.GetString("start_time")
  6548. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6549. end_time := this.GetString("end_time")
  6550. p_type, _ := this.GetInt64("p_type")
  6551. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6552. adminUserInfo := this.GetAdminUserInfo()
  6553. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6554. if err == nil {
  6555. this.ServeSuccessJSON(map[string]interface{}{
  6556. "prescriptions": prescriptions,
  6557. })
  6558. return
  6559. } else {
  6560. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6561. return
  6562. }
  6563. }
  6564. func (this *HisApiController) GetHisDayPrescription() {
  6565. timeLayout := "2006-01-02"
  6566. loc, _ := time.LoadLocation("Local")
  6567. start_time := this.GetString("start_time")
  6568. patient_id, _ := this.GetInt64("patient_id", 0)
  6569. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6570. end_time := this.GetString("end_time")
  6571. p_type, _ := this.GetInt64("p_type")
  6572. order_status, _ := this.GetInt64("type")
  6573. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6574. adminUserInfo := this.GetAdminUserInfo()
  6575. var dayHisPrescription []*models.HisPrescription
  6576. var err error
  6577. if order_status == 1 || order_status == 0 {
  6578. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6579. } else if order_status == 2 {
  6580. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6581. }
  6582. var settle_total float64
  6583. for _, item := range dayHisPrescription {
  6584. if len(item.HisPrescriptionProject) > 0 {
  6585. for _, subItem := range item.HisPrescriptionProject {
  6586. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6587. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6588. settle_total = settle_total + total
  6589. }
  6590. }
  6591. if len(item.HisDoctorAdviceInfo) > 0 {
  6592. for _, subItem := range item.HisDoctorAdviceInfo {
  6593. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6594. settle_total = settle_total + total
  6595. }
  6596. }
  6597. }
  6598. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6599. if err == nil {
  6600. this.ServeSuccessJSON(map[string]interface{}{
  6601. "day_prescription": dayHisPrescription,
  6602. "settle_total": settle_total,
  6603. })
  6604. return
  6605. } else {
  6606. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6607. return
  6608. }
  6609. }
  6610. func (c *HisApiController) GetHisChargePatientList() {
  6611. record_date := c.GetString("record_date")
  6612. order_status, _ := c.GetInt64("type")
  6613. timeLayout := "2006-01-02"
  6614. loc, _ := time.LoadLocation("Local")
  6615. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6616. if err != nil {
  6617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6618. return
  6619. }
  6620. recordDateTime := theTime.Unix()
  6621. adminInfo := c.GetAdminUserInfo()
  6622. var tempPatients []*service.NewTempPatients
  6623. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6624. if order_status != 2 {
  6625. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6626. } else {
  6627. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6628. }
  6629. var patients []*service.NewTempPatients
  6630. var patients_two []*service.NewTempPatients
  6631. for _, item := range tempPatients {
  6632. //过滤掉没挂号的和没开处方的
  6633. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6634. patients = append(patients, item)
  6635. }
  6636. //过滤掉没挂号的
  6637. if len(item.HisPatient) > 0 {
  6638. patients_two = append(patients_two, item)
  6639. }
  6640. }
  6641. c.ServeSuccessJSON(map[string]interface{}{
  6642. "list": patients,
  6643. "list_two": patients_two,
  6644. })
  6645. }
  6646. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6647. record_date := c.GetString("record_date")
  6648. timeLayout := "2006-01-02"
  6649. loc, _ := time.LoadLocation("Local")
  6650. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6651. if err != nil {
  6652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6653. return
  6654. }
  6655. recordDateTime := theTime.Unix()
  6656. adminUser := c.GetAdminUserInfo()
  6657. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6658. var patients []*service.Patients
  6659. for _, item := range tempPatients {
  6660. if item.HisPatient.ID == 0 {
  6661. patients = append(patients, item)
  6662. }
  6663. }
  6664. c.ServeSuccessJSON(map[string]interface{}{
  6665. "list": patients,
  6666. //"list_two": patients_two,
  6667. })
  6668. }
  6669. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6670. newArr = make([]*service.Patients, 0)
  6671. for i := 0; i < len(patient); i++ {
  6672. repeat := false
  6673. for j := i + 1; j < len(patient); j++ {
  6674. if patient[i].ID == patient[j].ID {
  6675. repeat = true
  6676. break
  6677. }
  6678. }
  6679. if !repeat {
  6680. newArr = append(newArr, patient[i])
  6681. }
  6682. }
  6683. return
  6684. }
  6685. func (c *HisApiController) GetHisChargePatientInfo() {
  6686. patient_id, _ := c.GetInt64("patient_id")
  6687. his_patient_id, _ := c.GetInt64("his_patient_id")
  6688. record_date := c.GetString("record_date")
  6689. //start_time := c.GetString("start_time")
  6690. //end_time := c.GetString("end_time")
  6691. order_status, _ := c.GetInt64("type", 0)
  6692. p_type, _ := c.GetInt64("p_type", 0)
  6693. order_id, _ := c.GetInt64("order_id", 0)
  6694. timeLayout := "2006-01-02"
  6695. loc, _ := time.LoadLocation("Local")
  6696. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6697. if err != nil {
  6698. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6699. return
  6700. }
  6701. recordDateTime := theTime.Unix()
  6702. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6703. //if err != nil {
  6704. //
  6705. //}
  6706. //startRecordDateTime := startTime.Unix()
  6707. //
  6708. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6709. //if err != nil {
  6710. //
  6711. //}
  6712. //endRecordDateTime := endTime.Unix()
  6713. admin := c.GetAdminUserInfo()
  6714. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6715. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6716. var prescriptions []*models.HisPrescription
  6717. //var unChargeMonthPrescriptions []*models.HisPrescription
  6718. order, _ := service.GetHisOrderByID(order_id)
  6719. if order_status == 1 || order_status == 0 {
  6720. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6721. } else if order_status == 2 {
  6722. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6723. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6724. }
  6725. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6726. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6727. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6728. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6729. //获取所有科室信息
  6730. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6731. c.ServeSuccessJSON(map[string]interface{}{
  6732. "his_info": his_patient_info,
  6733. "xt_info": xt_patient_info,
  6734. "prescription": prescriptions,
  6735. "case_history": case_history,
  6736. "info": patientPrescriptionInfo,
  6737. "last_info": lastPatientPrescriptionInfo,
  6738. "order": order,
  6739. "doctors": doctors,
  6740. "department": department,
  6741. })
  6742. return
  6743. }
  6744. func (c *HisApiController) GetAllOrderDetail() {
  6745. order_id, _ := c.GetInt64("id", 0)
  6746. order, _ := service.GetHisOrderByID(order_id)
  6747. if order.ID == 0 {
  6748. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6749. return
  6750. }
  6751. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6752. org_id := c.GetAdminUserInfo().CurrentOrgId
  6753. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6754. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6755. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6756. c.ServeSuccessJSON(map[string]interface{}{
  6757. "order": order,
  6758. "order_info": order_info,
  6759. "patient": patient,
  6760. "admin_info": adminInfo,
  6761. "hospital_record": record,
  6762. })
  6763. return
  6764. }
  6765. func (c *HisApiController) GetAllOrderDetailCollect() {
  6766. order_id, _ := c.GetInt64("id", 0)
  6767. order, _ := service.GetHisOrderByID(order_id)
  6768. if order.ID == 0 {
  6769. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6770. return
  6771. }
  6772. org_id := c.GetAdminUserInfo().CurrentOrgId
  6773. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6774. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6775. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6776. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6777. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6778. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6779. var bedCostTotal float64 = 0 //床位总费
  6780. //var bedCostSelfTotal float64 = 0 //床位自费
  6781. var operationCostTotal float64 = 0 //手术费
  6782. //var operationCostSelfTotal float64 = 0 //手术费
  6783. var otherCostTotal float64 = 0 //其他费用
  6784. //var otherCostSelfTotal float64 = 0 //其他费用
  6785. var materialCostTotal float64 = 0 //材料费
  6786. //var materialCostSelfTotal float64 = 0 //材料费
  6787. var westernMedicineCostTotal float64 = 0 //西药费
  6788. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6789. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6790. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6791. var checkCostTotal float64 = 0 //检查费
  6792. //var checkCostSelfTotal float64 = 0 //检查费
  6793. var laboratoryCostTotal float64 = 0 //化验费
  6794. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6795. var treatCostTotal float64 = 0 //治疗费用
  6796. //var treatCostSelfTotal float64 = 0 //治疗费用
  6797. var zhenChaCostTotal float64 = 0 //其他费用
  6798. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6799. decimal.DivisionPrecision = 2
  6800. var BalanceAccountsType int64
  6801. if his.ID > 0 {
  6802. BalanceAccountsType = his.BalanceAccountsType
  6803. } else {
  6804. BalanceAccountsType = record.BalanceAccountsType
  6805. }
  6806. if BalanceAccountsType != 2 {
  6807. for _, item := range order_info {
  6808. if org_id == 10215 {
  6809. if item.MedChrgitmType == "01" { //床位费
  6810. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6811. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6812. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6813. }
  6814. if item.MedChrgitmType == "02" { //诊察费
  6815. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6816. //zhenChaCostSelfTotal = zhenChaCostTotal
  6817. }
  6818. if item.MedChrgitmType == "03" { //检查费
  6819. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6820. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6821. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6822. }
  6823. //if item.MedChrgitmType == "02" { //检查费
  6824. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6825. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6826. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6827. //}
  6828. if item.MedChrgitmType == "04" { //化验费
  6829. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6830. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6831. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6832. }
  6833. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6834. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6835. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6836. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6837. }
  6838. if item.MedChrgitmType == "06" { //手术费
  6839. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6840. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6841. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6842. }
  6843. if item.MedChrgitmType == "08" { //材料费
  6844. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6845. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6846. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6847. }
  6848. if item.MedChrgitmType == "09" { //西药费
  6849. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6850. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6851. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6852. }
  6853. if item.MedChrgitmType == "11" { //中成费
  6854. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6855. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6856. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6857. }
  6858. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6859. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6860. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6861. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6862. }
  6863. } else if org_id == 10188 || org_id == 10217 {
  6864. if item.MedChrgitmType == "01" { //床位费
  6865. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6866. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6867. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6868. }
  6869. if item.MedChrgitmType == "02" { //诊察费
  6870. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6871. //zhenChaCostSelfTotal = zhenChaCostTotal
  6872. }
  6873. if item.MedChrgitmType == "03" { //检查费
  6874. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6875. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6876. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6877. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6878. }
  6879. //if item.MedChrgitmType == "02" { //检查费
  6880. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6881. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6882. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6883. //}
  6884. if item.MedChrgitmType == "04" { //化验费
  6885. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6886. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6887. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6888. }
  6889. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6890. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6891. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6892. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6893. }
  6894. if item.MedChrgitmType == "06" { //手术费
  6895. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6896. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6897. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6898. }
  6899. if item.MedChrgitmType == "08" { //材料费
  6900. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6901. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6902. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6903. }
  6904. if item.MedChrgitmType == "09" { //西药费
  6905. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6906. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6907. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6908. }
  6909. if item.MedChrgitmType == "11" { //中成费
  6910. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6911. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6912. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6913. }
  6914. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6915. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6916. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6917. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6918. }
  6919. } else {
  6920. if item.MedChrgitmType == "01" { //床位费
  6921. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6922. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6923. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6924. }
  6925. //if item.MedChrgitmType == "02" { //诊察费
  6926. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6927. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6928. //}
  6929. if item.MedChrgitmType == "03" { //检查费
  6930. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6931. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6932. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6933. }
  6934. //if item.MedChrgitmType == "02" { //检查费
  6935. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6936. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6937. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6938. //}
  6939. if item.MedChrgitmType == "04" { //化验费
  6940. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6941. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6942. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6943. }
  6944. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6945. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6946. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6947. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6948. }
  6949. if item.MedChrgitmType == "06" { //手术费
  6950. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6951. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6952. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6953. }
  6954. if item.MedChrgitmType == "08" { //材料费
  6955. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6956. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6957. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6958. }
  6959. if item.MedChrgitmType == "09" { //西药费
  6960. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6961. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6962. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6963. }
  6964. if item.MedChrgitmType == "11" { //中成费
  6965. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6966. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6967. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6968. }
  6969. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6970. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6971. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6972. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6973. }
  6974. }
  6975. }
  6976. c.ServeSuccessJSON(map[string]interface{}{
  6977. "order": order,
  6978. "order_info": order_info,
  6979. "patient": patient,
  6980. "admin_info": adminInfo,
  6981. "his_hospital": record,
  6982. "bedCostTotal": bedCostTotal,
  6983. "operationCostTotal": operationCostTotal,
  6984. "otherCostTotal": otherCostTotal,
  6985. "materialCostTotal": materialCostTotal,
  6986. "westernMedicineCostTotal": westernMedicineCostTotal,
  6987. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6988. "checkCostTotal": checkCostTotal,
  6989. "zhenChaCostTotal": zhenChaCostTotal,
  6990. "laboratoryCostTotal": laboratoryCostTotal,
  6991. "treatCostTotal": treatCostTotal,
  6992. })
  6993. } else {
  6994. for _, item := range order_info {
  6995. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6996. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6997. item.MedChrgitmType = "09"
  6998. }
  6999. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7000. if item.HisPrescriptionProject.Type == 2 {
  7001. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7002. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7003. case 0:
  7004. item.MedChrgitmType = "0"
  7005. break
  7006. case 1:
  7007. item.MedChrgitmType = "14"
  7008. break
  7009. case 2:
  7010. item.MedChrgitmType = "05"
  7011. break
  7012. case 3:
  7013. item.MedChrgitmType = "03"
  7014. break
  7015. case 4:
  7016. item.MedChrgitmType = "03"
  7017. break
  7018. case 5:
  7019. item.MedChrgitmType = "08"
  7020. break
  7021. case 6:
  7022. item.MedChrgitmType = "14"
  7023. break
  7024. case 7:
  7025. item.MedChrgitmType = "14"
  7026. break
  7027. case 8:
  7028. item.MedChrgitmType = "03"
  7029. break
  7030. case 9:
  7031. item.MedChrgitmType = "14"
  7032. break
  7033. case 10:
  7034. item.MedChrgitmType = "14"
  7035. break
  7036. case 11:
  7037. item.MedChrgitmType = "06"
  7038. break
  7039. case 12:
  7040. item.MedChrgitmType = "12"
  7041. break
  7042. case 13:
  7043. item.MedChrgitmType = "01"
  7044. break
  7045. case 14:
  7046. item.MedChrgitmType = "04"
  7047. break
  7048. case 15:
  7049. item.MedChrgitmType = "14"
  7050. break
  7051. }
  7052. } else {
  7053. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7054. case 1:
  7055. item.MedChrgitmType = "14"
  7056. break
  7057. case 2:
  7058. item.MedChrgitmType = "05"
  7059. break
  7060. case 3:
  7061. item.MedChrgitmType = "04"
  7062. break
  7063. case 4:
  7064. item.MedChrgitmType = "14"
  7065. break
  7066. case 5:
  7067. item.MedChrgitmType = "08"
  7068. break
  7069. case 6:
  7070. item.MedChrgitmType = "14"
  7071. break
  7072. case 7:
  7073. item.MedChrgitmType = "14"
  7074. break
  7075. case 8:
  7076. item.MedChrgitmType = "03"
  7077. break
  7078. case 9:
  7079. item.MedChrgitmType = "14"
  7080. break
  7081. }
  7082. }
  7083. } else if item.HisPrescriptionProject.Type == 3 {
  7084. item.MedChrgitmType = "08"
  7085. }
  7086. }
  7087. }
  7088. for _, item := range order_info {
  7089. if org_id == 10215 {
  7090. if item.MedChrgitmType == "01" { //床位费
  7091. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7092. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7093. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7094. }
  7095. if item.MedChrgitmType == "02" { //诊察费
  7096. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7097. //zhenChaCostSelfTotal = zhenChaCostTotal
  7098. }
  7099. if item.MedChrgitmType == "03" { //检查费
  7100. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7101. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7102. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7103. }
  7104. //if item.MedChrgitmType == "02" { //检查费
  7105. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7106. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7107. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7108. //}
  7109. if item.MedChrgitmType == "04" { //化验费
  7110. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7111. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7112. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7113. }
  7114. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7115. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7116. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7117. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7118. }
  7119. if item.MedChrgitmType == "06" { //手术费
  7120. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7121. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7122. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7123. }
  7124. if item.MedChrgitmType == "08" { //材料费
  7125. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7126. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7127. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7128. }
  7129. if item.MedChrgitmType == "09" { //西药费
  7130. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7131. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7132. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7133. }
  7134. if item.MedChrgitmType == "11" { //中成费
  7135. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7136. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7137. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7138. }
  7139. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7140. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7141. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7142. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7143. }
  7144. } else {
  7145. if item.MedChrgitmType == "01" { //床位费
  7146. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7147. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7148. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7149. }
  7150. //if item.MedChrgitmType == "02" { //诊察费
  7151. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7152. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7153. //}
  7154. if item.MedChrgitmType == "03" { //检查费
  7155. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7156. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7157. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7158. }
  7159. //if item.MedChrgitmType == "02" { //检查费
  7160. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7161. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7162. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7163. //}
  7164. if item.MedChrgitmType == "04" { //化验费
  7165. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7166. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7167. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7168. }
  7169. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7170. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7171. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7172. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7173. }
  7174. if item.MedChrgitmType == "06" { //手术费
  7175. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7176. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7177. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7178. }
  7179. if item.MedChrgitmType == "08" { //材料费
  7180. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7181. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7182. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7183. }
  7184. if item.MedChrgitmType == "09" { //西药费
  7185. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7186. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7187. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7188. }
  7189. if item.MedChrgitmType == "11" { //中成费
  7190. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7191. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7192. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7193. }
  7194. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7195. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7196. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7197. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7198. }
  7199. }
  7200. }
  7201. c.ServeSuccessJSON(map[string]interface{}{
  7202. "order": order,
  7203. "order_info": order_info,
  7204. "patient": patient,
  7205. "admin_info": adminInfo,
  7206. "his_hospital": record,
  7207. "bedCostTotal": bedCostTotal,
  7208. "operationCostTotal": operationCostTotal,
  7209. "otherCostTotal": otherCostTotal,
  7210. "materialCostTotal": materialCostTotal,
  7211. "westernMedicineCostTotal": westernMedicineCostTotal,
  7212. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7213. "checkCostTotal": checkCostTotal,
  7214. "zhenChaCostTotal": zhenChaCostTotal,
  7215. "laboratoryCostTotal": laboratoryCostTotal,
  7216. "treatCostTotal": treatCostTotal,
  7217. })
  7218. }
  7219. }
  7220. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7221. page, _ := c.GetInt64("page")
  7222. limit, _ := c.GetInt64("limit")
  7223. keywords := c.GetString("keywords")
  7224. start_time := c.GetString("start_time")
  7225. end_time := c.GetString("end_time")
  7226. //clr_type := c.GetString("clr_type")
  7227. insutype := c.GetString("insutype")
  7228. timeLayout := "2006-01-02"
  7229. loc, _ := time.LoadLocation("Local")
  7230. var theStartTIme int64
  7231. if len(start_time) > 0 {
  7232. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7233. theStartTIme = theTime.Unix()
  7234. }
  7235. var theEndtTIme int64
  7236. if len(end_time) > 0 {
  7237. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7238. theEndtTIme = theTime.Unix()
  7239. }
  7240. if page <= 0 {
  7241. page = 1
  7242. }
  7243. if limit <= 0 {
  7244. limit = 10
  7245. }
  7246. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7247. c.ServeSuccessJSON(map[string]interface{}{
  7248. "total": total,
  7249. "list": list,
  7250. })
  7251. return
  7252. }
  7253. func (c *HisApiController) GetPutOnRecordList() {
  7254. page, _ := c.GetInt64("page")
  7255. limit, _ := c.GetInt64("limit")
  7256. keywords := c.GetString("keywords")
  7257. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7258. if page <= 0 {
  7259. page = 1
  7260. }
  7261. if limit <= 0 {
  7262. limit = 10
  7263. }
  7264. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7265. c.ServeSuccessJSON(map[string]interface{}{
  7266. "total": total,
  7267. "list": list,
  7268. })
  7269. return
  7270. }
  7271. func (c *HisApiController) GetCompareData() {
  7272. start_time := c.GetString("start_time")
  7273. end_time := c.GetString("end_time")
  7274. insutype := c.GetString("insutype")
  7275. clr_type := c.GetString("clr_type")
  7276. timeLayout := "2006-01-02"
  7277. loc, _ := time.LoadLocation("Local")
  7278. var theStartTIme int64
  7279. if len(start_time) > 0 {
  7280. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7281. if err != nil {
  7282. theStartTIme = 0
  7283. }
  7284. theStartTIme = theTime.Unix()
  7285. }
  7286. var theEndtTIme int64
  7287. if len(end_time) > 0 {
  7288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7289. if err != nil {
  7290. theEndtTIme = 0
  7291. }
  7292. theEndtTIme = theTime.Unix()
  7293. }
  7294. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7295. fmt.Println(err)
  7296. if err == nil {
  7297. c.ServeSuccessJSON(map[string]interface{}{
  7298. "list": formData,
  7299. })
  7300. } else {
  7301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7302. return
  7303. }
  7304. }
  7305. func (c *HisApiController) GetFaPiaoData() {
  7306. order_id, _ := c.GetInt64("order_id")
  7307. patient_id, _ := c.GetInt64("patient_id")
  7308. number := c.GetString("number")
  7309. adminUser := c.GetAdminUserInfo()
  7310. order, _ := service.GetHisOrderByID(order_id)
  7311. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7312. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7313. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7314. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  7315. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7316. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  7317. var bedCostTotal float64 = 0 //床位总费
  7318. var bedCostSelfTotal float64 = 0 //床位自费
  7319. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7320. var operationCostTotal float64 = 0 //手术费
  7321. var operationCostSelfTotal float64 = 0 //手术费
  7322. var operationCostPartSelfTotal float64 = 0 //手术费
  7323. var otherCostTotal float64 = 0 //其他费用
  7324. var otherCostSelfTotal float64 = 0 //其他费用
  7325. var otherCostPartSelfTotal float64 = 0 //其他费用
  7326. var materialCostTotal float64 = 0 //材料费
  7327. var materialCostSelfTotal float64 = 0 //材料费
  7328. var materialCostPartSelfTotal float64 = 0 //材料费
  7329. var westernMedicineCostTotal float64 = 0 //西药费
  7330. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7331. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7332. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7333. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7334. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7335. var checkCostTotal float64 = 0 //检查费
  7336. var checkCostSelfTotal float64 = 0 //检查费
  7337. var checkCostPartSelfTotal float64 = 0 //检查费
  7338. var laboratoryCostTotal float64 = 0 //化验费
  7339. var laboratoryCostSelfTotal float64 = 0 //化验费
  7340. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7341. var treatCostTotal float64 = 0 //治疗费用
  7342. var treatCostSelfTotal float64 = 0 //治疗费用
  7343. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7344. var zhenChaCostTotal float64 = 0 //其他费用
  7345. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7346. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7347. decimal.DivisionPrecision = 2
  7348. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7349. var balanceAccountsType int64
  7350. if his.ID > 0 {
  7351. balanceAccountsType = his.BalanceAccountsType
  7352. } else {
  7353. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7354. }
  7355. if balanceAccountsType == 2 {
  7356. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7357. for _, item := range orderInfos_two {
  7358. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7359. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7360. item.MedChrgitmType = "09"
  7361. }
  7362. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7363. if item.HisPrescriptionProject.Type == 2 {
  7364. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7365. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7366. case 0:
  7367. item.MedChrgitmType = "0"
  7368. break
  7369. case 1:
  7370. item.MedChrgitmType = "14"
  7371. break
  7372. case 2:
  7373. item.MedChrgitmType = "05"
  7374. break
  7375. case 3:
  7376. item.MedChrgitmType = "03"
  7377. break
  7378. case 4:
  7379. item.MedChrgitmType = "03"
  7380. break
  7381. case 5:
  7382. item.MedChrgitmType = "08"
  7383. break
  7384. case 6:
  7385. item.MedChrgitmType = "14"
  7386. break
  7387. case 7:
  7388. item.MedChrgitmType = "14"
  7389. break
  7390. case 8:
  7391. item.MedChrgitmType = "03"
  7392. break
  7393. case 9:
  7394. item.MedChrgitmType = "14"
  7395. break
  7396. case 10:
  7397. item.MedChrgitmType = "14"
  7398. break
  7399. case 11:
  7400. item.MedChrgitmType = "06"
  7401. break
  7402. case 12:
  7403. item.MedChrgitmType = "12"
  7404. break
  7405. case 13:
  7406. item.MedChrgitmType = "01"
  7407. break
  7408. case 14:
  7409. item.MedChrgitmType = "04"
  7410. break
  7411. case 15:
  7412. item.MedChrgitmType = "02"
  7413. break
  7414. }
  7415. } else {
  7416. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7417. case 1:
  7418. item.MedChrgitmType = "14"
  7419. break
  7420. case 2:
  7421. item.MedChrgitmType = "05"
  7422. break
  7423. case 3:
  7424. item.MedChrgitmType = "03"
  7425. break
  7426. case 4:
  7427. item.MedChrgitmType = "03"
  7428. break
  7429. case 5:
  7430. item.MedChrgitmType = "08"
  7431. break
  7432. case 6:
  7433. item.MedChrgitmType = "14"
  7434. break
  7435. case 7:
  7436. item.MedChrgitmType = "14"
  7437. break
  7438. case 8:
  7439. item.MedChrgitmType = "03"
  7440. break
  7441. case 9:
  7442. item.MedChrgitmType = "14"
  7443. break
  7444. }
  7445. }
  7446. } else if item.HisPrescriptionProject.Type == 3 {
  7447. item.MedChrgitmType = "08"
  7448. }
  7449. }
  7450. }
  7451. for _, item := range orderInfos_two {
  7452. fmt.Println(item.MedChrgitmType)
  7453. if item.MedChrgitmType == "01" { //床位费
  7454. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7455. bedCostSelfTotal = bedCostTotal
  7456. }
  7457. if item.MedChrgitmType == "02" { //诊察费
  7458. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7459. zhenChaCostSelfTotal = zhenChaCostTotal
  7460. }
  7461. if item.MedChrgitmType == "03" { //检查费
  7462. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7463. checkCostSelfTotal = checkCostTotal
  7464. }
  7465. if item.MedChrgitmType == "04" { //化验费
  7466. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7467. laboratoryCostSelfTotal = laboratoryCostTotal
  7468. }
  7469. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7470. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7471. treatCostSelfTotal = treatCostTotal
  7472. }
  7473. if item.MedChrgitmType == "06" { //手术费
  7474. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7475. operationCostSelfTotal = treatCostTotal
  7476. }
  7477. if item.MedChrgitmType == "08" { //材料费
  7478. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7479. materialCostSelfTotal = materialCostTotal
  7480. }
  7481. if item.MedChrgitmType == "09" { //西药费
  7482. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7483. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7484. }
  7485. if item.MedChrgitmType == "11" { //中成费
  7486. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7487. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7488. }
  7489. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7490. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7491. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7492. otherCostSelfTotal = otherCostTotal
  7493. }
  7494. } else {
  7495. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7496. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7497. otherCostSelfTotal = otherCostTotal
  7498. }
  7499. }
  7500. }
  7501. } else {
  7502. for _, item := range orderInfos {
  7503. if item.MedChrgitmType == "01" { //床位费
  7504. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7505. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7506. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7507. }
  7508. if item.MedChrgitmType == "02" { //诊察费
  7509. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7510. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7511. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7512. }
  7513. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7514. if item.MedChrgitmType == "03" { //检查费
  7515. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7516. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7517. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7518. }
  7519. } else {
  7520. if item.MedChrgitmType == "03" { //检查费
  7521. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7522. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7523. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7524. }
  7525. }
  7526. if item.MedChrgitmType == "04" { //化验费
  7527. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7528. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7529. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7530. }
  7531. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7532. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7533. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7534. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7535. }
  7536. if item.MedChrgitmType == "06" { //手术费
  7537. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7538. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7539. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7540. }
  7541. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7542. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7543. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7544. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7545. }
  7546. if item.MedChrgitmType == "09" { //西药费
  7547. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7548. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7549. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7550. }
  7551. if item.MedChrgitmType == "11" { //中成费
  7552. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7553. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7554. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7555. }
  7556. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7557. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7558. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7559. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7560. }
  7561. }
  7562. }
  7563. timeLayout := "2006-01-02"
  7564. loc, _ := time.LoadLocation("Local")
  7565. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7566. if err != nil {
  7567. }
  7568. startRecordDateTime := startTime.Unix()
  7569. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7570. if err != nil {
  7571. }
  7572. endRecordDateTime := endTime.Unix()
  7573. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7574. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7575. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7576. c.ServeSuccessJSON(map[string]interface{}{
  7577. "order_number": order.Number, //业务流水号
  7578. "id_card_no": his.IdCardNo, //社会保障号
  7579. "department_name": department.Name, //科室
  7580. "number": his.Number, //门诊号
  7581. "date": order.SettleAccountsDate, //结算日期
  7582. "name": order.PsnName, //姓名
  7583. "gender": patient.Gender, //性别
  7584. "psn_cash_money": order.PsnCashPay, //个人支付
  7585. "pay_way": "门诊", //结算方式
  7586. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7587. "admin_user_name": admin.UserName, //收款员
  7588. "order": order,
  7589. "order_info": orderInfos_two,
  7590. "his": his,
  7591. "bedCostTotal": bedCostTotal,
  7592. "bedCostSelfTotal": bedCostSelfTotal,
  7593. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7594. "operationCostTotal": operationCostTotal,
  7595. "operationCostSelfTotal": operationCostSelfTotal,
  7596. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7597. "otherCostTotal": otherCostTotal,
  7598. "otherCostSelfTotal": otherCostSelfTotal,
  7599. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7600. "materialCostTotal": materialCostTotal,
  7601. "materialCostSelfTotal": materialCostSelfTotal,
  7602. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7603. "westernMedicineCostTotal": westernMedicineCostTotal,
  7604. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7605. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7606. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7607. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7608. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7609. "checkCostTotal": checkCostTotal,
  7610. "checkCostSelfTotal": checkCostSelfTotal,
  7611. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7612. "laboratoryCostTotal": laboratoryCostTotal,
  7613. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7614. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7615. "treatCostTotal": treatCostTotal,
  7616. "treatCostSelfTotal": treatCostSelfTotal,
  7617. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7618. "zhenChaCostTotal": zhenChaCostTotal,
  7619. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7620. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7621. "his_hospital_record": his_hospital_record,
  7622. "pre_pay_money": pre_pay_money,
  7623. "refund_sum": sum,
  7624. })
  7625. }
  7626. func (this *HisApiController) GetIncomeStatisticsData() {
  7627. start_time := this.GetString("start_time")
  7628. end_time := this.GetString("end_time")
  7629. key_words := this.GetString("key_words")
  7630. limit, _ := this.GetInt64("limit")
  7631. page, _ := this.GetInt64("page")
  7632. if page <= 0 {
  7633. page = 1
  7634. }
  7635. if limit <= 0 {
  7636. limit = 10
  7637. }
  7638. statistics_type, _ := this.GetInt64("statistics_type")
  7639. admin := this.GetAdminUserInfo()
  7640. timeLayout := "2006-01-02"
  7641. loc, _ := time.LoadLocation("Local")
  7642. var theStartTIme int64
  7643. if len(start_time) > 0 {
  7644. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7645. if err != nil {
  7646. theStartTIme = 0
  7647. }
  7648. theStartTIme = theTime.Unix()
  7649. }
  7650. var theEndtTIme int64
  7651. if len(end_time) > 0 {
  7652. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7653. if err != nil {
  7654. theEndtTIme = 0
  7655. }
  7656. theEndtTIme = theTime.Unix()
  7657. }
  7658. if statistics_type == 1 {
  7659. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7660. this.ServeSuccessJSON(map[string]interface{}{
  7661. "list": list,
  7662. "total": total,
  7663. })
  7664. } else {
  7665. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7666. this.ServeSuccessJSON(map[string]interface{}{
  7667. "list": list,
  7668. "total": total,
  7669. })
  7670. }
  7671. }
  7672. func (c *HisApiController) PostProjectInformation() {
  7673. adminUser := c.GetAdminUserInfo()
  7674. orgId := adminUser.CurrentOrgId
  7675. dataBody := make(map[string]interface{}, 0)
  7676. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7677. if err != nil {
  7678. utils.ErrorLog(err.Error())
  7679. return
  7680. }
  7681. utils.ErrorLog("%v", dataBody)
  7682. var projectList []*models.HisProject
  7683. var total_goods []interface{}
  7684. tempProjects := dataBody["projects"].([]interface{})
  7685. total_goods = tempProjects
  7686. for index, projectMap := range tempProjects {
  7687. projectM := projectMap.(map[string]interface{})
  7688. var project models.HisProject
  7689. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7690. utils.ErrorLog("project_name")
  7691. return
  7692. }
  7693. project_name, _ := projectM["project_name"].(string)
  7694. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7695. err_log := models.ExportErrLog{
  7696. LogType: 6,
  7697. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7698. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7699. Status: 1,
  7700. CreateTime: time.Now().Unix(),
  7701. UpdateTime: time.Now().Unix(),
  7702. ExportTime: time.Now().Unix(),
  7703. }
  7704. service.CreateExportErrLog(&err_log)
  7705. continue
  7706. }
  7707. project.ProjectName = project_name
  7708. prices := projectM["price"].(string)
  7709. price, _ := strconv.ParseFloat(prices, 64)
  7710. if price <= 0 { //名字为空则生成一条导入错误日志
  7711. err_log := models.ExportErrLog{
  7712. LogType: 6,
  7713. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7714. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7715. Status: 1,
  7716. CreateTime: time.Now().Unix(),
  7717. UpdateTime: time.Now().Unix(),
  7718. ExportTime: time.Now().Unix(),
  7719. }
  7720. service.CreateExportErrLog(&err_log)
  7721. continue
  7722. }
  7723. project.Price = price
  7724. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7725. utils.ErrorLog("unit_id")
  7726. return
  7727. }
  7728. unit := projectM["unit"].(string)
  7729. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7730. err_log := models.ExportErrLog{
  7731. LogType: 6,
  7732. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7733. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7734. Status: 1,
  7735. CreateTime: time.Now().Unix(),
  7736. UpdateTime: time.Now().Unix(),
  7737. ExportTime: time.Now().Unix(),
  7738. }
  7739. service.CreateExportErrLog(&err_log)
  7740. continue
  7741. }
  7742. project.Unit = unit
  7743. cost_classify := projectM["cost_classify"].(string)
  7744. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7745. err_log := models.ExportErrLog{
  7746. LogType: 6,
  7747. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7748. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7749. Status: 1,
  7750. CreateTime: time.Now().Unix(),
  7751. UpdateTime: time.Now().Unix(),
  7752. ExportTime: time.Now().Unix(),
  7753. }
  7754. service.CreateExportErrLog(&err_log)
  7755. continue
  7756. }
  7757. var costClassify = "费用类别"
  7758. var cost_classify_id int64
  7759. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7760. if len(cost_classify) != 0 {
  7761. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7762. if errcode == gorm.ErrRecordNotFound {
  7763. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7764. dataconfig := models.DictDataconfig{
  7765. ParentId: costClassifyConfig.ID,
  7766. Module: "system",
  7767. OrgId: orgId,
  7768. Name: cost_classify,
  7769. FieldName: "",
  7770. Value: costConfig.Value + 1,
  7771. CreatedTime: "",
  7772. UpdatedTime: "",
  7773. CreateUserId: adminUser.AdminUser.Id,
  7774. Status: 1,
  7775. Remark: "",
  7776. DeleteIdSystem: 0,
  7777. Title: "",
  7778. Content: "",
  7779. Order: 0,
  7780. Code: "",
  7781. }
  7782. service.CreatedDicConfig(&dataconfig)
  7783. }
  7784. }
  7785. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7786. for _, it := range costClassList {
  7787. if cost_classify == it.Name {
  7788. cost_classify_id = int64(it.Value)
  7789. }
  7790. }
  7791. project.CostClassify = cost_classify_id
  7792. executive_section := projectM["executive_section"].(string)
  7793. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7794. err_log := models.ExportErrLog{
  7795. LogType: 6,
  7796. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7797. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7798. Status: 1,
  7799. CreateTime: time.Now().Unix(),
  7800. UpdateTime: time.Now().Unix(),
  7801. ExportTime: time.Now().Unix(),
  7802. }
  7803. service.CreateExportErrLog(&err_log)
  7804. continue
  7805. }
  7806. if len(executive_section) != 0 {
  7807. //查找科室是否有内容
  7808. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7809. if errcodedepart == gorm.ErrRecordNotFound {
  7810. department := models.XtHisDepartment{
  7811. Name: executive_section,
  7812. Status: 1,
  7813. UserOrgId: adminUser.CurrentOrgId,
  7814. CreatedTime: time.Now().Unix(),
  7815. }
  7816. service.CreateDePartment(&department)
  7817. }
  7818. }
  7819. var executive_section_id int64
  7820. departMentList, _ := service.GetAllDepartMent(orgId)
  7821. for _, it := range departMentList {
  7822. if executive_section == it.Name {
  7823. executive_section_id = it.ID
  7824. }
  7825. }
  7826. project.ExecutiveSection = executive_section_id
  7827. medical_coverage := projectM["medical_coverage"].(string)
  7828. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7829. err_log := models.ExportErrLog{
  7830. LogType: 6,
  7831. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7832. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7833. Status: 1,
  7834. CreateTime: time.Now().Unix(),
  7835. UpdateTime: time.Now().Unix(),
  7836. ExportTime: time.Now().Unix(),
  7837. }
  7838. service.CreateExportErrLog(&err_log)
  7839. continue
  7840. }
  7841. var medicalCoverage = "医保等级"
  7842. var medical_coverage_id int64
  7843. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7844. if len(medical_coverage) != 0 {
  7845. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7846. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7847. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7848. dataconfig := models.DictDataconfig{
  7849. ParentId: medicalCoverageConfig.ID,
  7850. Module: "system",
  7851. OrgId: orgId,
  7852. Name: medical_coverage,
  7853. FieldName: "",
  7854. Value: medicalCoverageConfig.Value + 1,
  7855. CreatedTime: "",
  7856. UpdatedTime: "",
  7857. CreateUserId: adminUser.AdminUser.Id,
  7858. Status: 1,
  7859. Remark: "",
  7860. DeleteIdSystem: 0,
  7861. Title: "",
  7862. Content: "",
  7863. Order: 0,
  7864. Code: "",
  7865. }
  7866. service.CreatedDicConfig(&dataconfig)
  7867. }
  7868. }
  7869. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7870. for _, it := range medicalCoverageList {
  7871. if medical_coverage == it.Name {
  7872. medical_coverage_id = int64(it.Value)
  7873. }
  7874. }
  7875. project.MedicalCoverage = medical_coverage_id
  7876. pinyin := projectM["pinyin"].(string)
  7877. project.Pinyin = pinyin
  7878. wubi := projectM["wubi"].(string)
  7879. project.Wubi = wubi
  7880. statistical_classification := projectM["statistical_classification"].(string)
  7881. var statisticalClassification = "统计分类"
  7882. var statistical_classification_id int64
  7883. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7884. if len(statistical_classification) != 0 {
  7885. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7886. if classificationerrcodes == gorm.ErrRecordNotFound {
  7887. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7888. dataconfig := models.DictDataconfig{
  7889. ParentId: classiFication.ID,
  7890. Module: "system",
  7891. OrgId: orgId,
  7892. Name: statistical_classification,
  7893. FieldName: "",
  7894. Value: classiFicationConfig.Value + 1,
  7895. CreatedTime: "",
  7896. UpdatedTime: "",
  7897. CreateUserId: adminUser.AdminUser.Id,
  7898. Status: 1,
  7899. Remark: "",
  7900. DeleteIdSystem: 0,
  7901. Title: "",
  7902. Content: "",
  7903. Order: 0,
  7904. Code: "",
  7905. }
  7906. service.CreatedDicConfig(&dataconfig)
  7907. }
  7908. }
  7909. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7910. for _, it := range classiFicationList {
  7911. if statistical_classification == it.Name {
  7912. statistical_classification_id = int64(it.Value)
  7913. }
  7914. }
  7915. project.StatisticalClassification = statistical_classification_id
  7916. disease_directory := int64(projectM["disease_directory"].(float64))
  7917. project.DiseaseDirectory = disease_directory
  7918. is_record := int64(projectM["is_record"].(float64))
  7919. project.IsRecord = is_record
  7920. medical_code := projectM["medical_code"].(string)
  7921. project.MedicalCode = medical_code
  7922. tube_color := projectM["tube_color"].(string)
  7923. var tubeColor = "试管颜色"
  7924. var tube_color_id int64
  7925. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7926. if len(tube_color) != 0 {
  7927. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7928. if errcodetube == gorm.ErrRecordNotFound {
  7929. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7930. dataconfig := models.DictDataconfig{
  7931. ParentId: tubeColorConfig.ID,
  7932. Module: "system",
  7933. OrgId: orgId,
  7934. Name: tube_color,
  7935. FieldName: "",
  7936. Value: tubeConfig.Value + 1,
  7937. CreatedTime: "",
  7938. UpdatedTime: "",
  7939. CreateUserId: adminUser.AdminUser.Id,
  7940. Status: 1,
  7941. Remark: "",
  7942. DeleteIdSystem: 0,
  7943. Title: "",
  7944. Content: "",
  7945. Order: 0,
  7946. Code: "",
  7947. }
  7948. service.CreatedDicConfig(&dataconfig)
  7949. }
  7950. }
  7951. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7952. for _, it := range tubeColorList {
  7953. if tube_color == it.Name {
  7954. tube_color_id = int64(it.Value)
  7955. }
  7956. }
  7957. project.TubeColor = tube_color_id
  7958. single_dose := projectM["single_dose"].(string)
  7959. project.SingleDose = single_dose
  7960. execution_frequency := projectM["execution_frequency"].(string)
  7961. project.ExecutionFrequency = execution_frequency
  7962. delivery_way := projectM["delivery_way"].(string)
  7963. project.DeliveryWay = delivery_way
  7964. number_days := projectM["number_days"].(string)
  7965. project.NumberDays = number_days
  7966. total := projectM["total"].(string)
  7967. project.Total = total
  7968. medical_status := int64(projectM["medical_status"].(float64))
  7969. project.MedicalStatus = medical_status
  7970. category := int64(projectM["category"].(float64))
  7971. project.Category = category
  7972. specail_project := int64(projectM["specail_project"].(float64))
  7973. project.SpecailProject = specail_project
  7974. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7975. project.SocialSecurityDirectoryCode = social_security_directory_code
  7976. remark := projectM["remark"].(string)
  7977. project.Remark = remark
  7978. record_date := projectM["record_date"].(string)
  7979. timeLayout := "2006-01-02"
  7980. loc, _ := time.LoadLocation("Local")
  7981. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7982. project.RecordDate = theTime.Unix()
  7983. projectList = append(projectList, &project)
  7984. }
  7985. export_time := time.Now().Unix()
  7986. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7987. if len(projectList) > 0 {
  7988. for _, item := range projectList {
  7989. project := models.HisProject{
  7990. ProjectName: item.ProjectName,
  7991. Price: item.Price,
  7992. Unit: item.Unit,
  7993. CostClassify: item.CostClassify,
  7994. ExecutiveSection: item.ExecutiveSection,
  7995. MedicalCoverage: item.MedicalCoverage,
  7996. UserOrgId: orgId,
  7997. Status: 1,
  7998. CreatedTime: time.Now().Unix(),
  7999. Pinyin: item.Pinyin,
  8000. Wubi: item.Wubi,
  8001. StatisticalClassification: item.StatisticalClassification,
  8002. DiseaseDirectory: item.DiseaseDirectory,
  8003. IsRecord: item.IsRecord,
  8004. MedicalCode: item.MedicalCode,
  8005. TubeColor: item.TubeColor,
  8006. SingleDose: item.SingleDose,
  8007. DeliveryWay: item.DeliveryWay,
  8008. NumberDays: item.NumberDays,
  8009. Total: item.Total,
  8010. Category: item.Category,
  8011. MedicalStatus: item.MedicalStatus,
  8012. SpecailProject: item.SpecailProject,
  8013. RecordDate: item.RecordDate,
  8014. Remark: item.Remark,
  8015. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8016. ExecutionFrequency: item.ExecutionFrequency,
  8017. }
  8018. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8019. if errcodeproject == gorm.ErrRecordNotFound {
  8020. service.CreateProjectInfomation(&project)
  8021. } else if errcodeproject == nil {
  8022. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8023. }
  8024. log := models.ExportLog{
  8025. LogType: 6,
  8026. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8027. TotalNum: int64(len(total_goods)),
  8028. FailNum: int64(len(errLogs)),
  8029. SuccessNum: int64(len(projectList)),
  8030. CreateTime: time.Now().Unix(),
  8031. UpdateTime: time.Now().Unix(),
  8032. ExportTime: export_time,
  8033. Status: 1,
  8034. }
  8035. service.CreateExportLog(&log)
  8036. c.ServeSuccessJSON(map[string]interface{}{
  8037. "msg": "导入成功",
  8038. "total_num": len(total_goods),
  8039. "success_num": len(projectList),
  8040. "fail_num": int64(len(errLogs)),
  8041. })
  8042. }
  8043. } else {
  8044. log := models.ExportLog{
  8045. LogType: 6,
  8046. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8047. TotalNum: int64(len(total_goods)),
  8048. FailNum: int64(len(errLogs)),
  8049. SuccessNum: int64(len(projectList)),
  8050. CreateTime: time.Now().Unix(),
  8051. UpdateTime: time.Now().Unix(),
  8052. ExportTime: export_time,
  8053. Status: 1,
  8054. }
  8055. service.CreateExportLog(&log)
  8056. c.ServeSuccessJSON(map[string]interface{}{
  8057. "msg": "导入成功",
  8058. "total_num": len(total_goods),
  8059. "success_num": len(projectList),
  8060. "fail_num": int64(len(errLogs)),
  8061. })
  8062. }
  8063. }
  8064. //func (this *HisApiController) EditProjectInformation(){
  8065. //
  8066. // id, _ := this.GetInt64("id")
  8067. // project_team := this.GetString("project_team")
  8068. // price := this.GetString("price")
  8069. // price_float, _ := strconv.ParseFloat(price, 64)
  8070. // pinyin := this.GetString("pinyin")
  8071. // wubi := this.GetString("wubi")
  8072. // tube_color, _ := this.GetInt64("tube_color")
  8073. // team_type, _ := this.GetInt64("team_type")
  8074. // remark := this.GetString("remark")
  8075. // ids := this.GetString("ids")
  8076. // item_id := this.GetString("item_id")
  8077. // projectTeam := models.XtHisProjectTeam{
  8078. // ProjectTeam: project_team,
  8079. // Price: price_float,
  8080. // Pinyin: pinyin,
  8081. // Wubi: wubi,
  8082. // TubeColor: tube_color,
  8083. // TeamType: team_type,
  8084. // Remark: remark,
  8085. // ProjectId: ids,
  8086. // ItemId: item_id,
  8087. // }
  8088. //
  8089. //
  8090. // dataBody := make(map[string]interface{}, 0)
  8091. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8092. // if err != nil {
  8093. // utils.ErrorLog(err.Error())
  8094. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8095. // return
  8096. // }
  8097. //
  8098. // err = service.UpdatedProjectTeam(id, &projectTeam)
  8099. //
  8100. //
  8101. // if err != nil {
  8102. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  8103. // return
  8104. // }
  8105. //
  8106. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  8107. // infos, _ := dataBody["info"].([]interface{})
  8108. // if len(infos) > 0 {
  8109. // var ids []string
  8110. //
  8111. // for _, item := range infos {
  8112. // items := item.(map[string]interface{})
  8113. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  8114. // utils.ErrorLog("id")
  8115. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8116. // return
  8117. // }
  8118. // id := int64(items["id"].(float64))
  8119. //
  8120. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8121. // utils.ErrorLog("type")
  8122. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8123. // return
  8124. // }
  8125. // types := int64(items["type"].(float64))
  8126. //
  8127. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  8128. // utils.ErrorLog("number")
  8129. // }
  8130. //
  8131. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  8132. //
  8133. // projectList := models.XtHisProjectList{
  8134. // Number: number,
  8135. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  8136. // ProjectId: id,
  8137. // Status: 1,
  8138. // CreatedTime: time.Now().Unix(),
  8139. // UpdatedTime: time.Now().Unix(),
  8140. // TeamId: projectTeam.ID,
  8141. // Type: types,
  8142. // }
  8143. // list := projectList
  8144. //
  8145. // service.CreateProjectList(&list)
  8146. //
  8147. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  8148. //
  8149. // }
  8150. // ids_str := strings.Join(ids, ",")
  8151. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  8152. // service.SaveProjectTeam(&projectTeam)
  8153. // this.ServeSuccessJSON(map[string]interface{}{
  8154. // "projectTeam": projectTeam,
  8155. // })
  8156. // }
  8157. // }
  8158. //}
  8159. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  8160. name := c.GetString("name")
  8161. mode_id, _ := c.GetInt64("mode", 0)
  8162. types, _ := c.GetInt64("type", 0)
  8163. patient_id, _ := c.GetInt64("patient_id", 0)
  8164. types = 1
  8165. adminInfo := c.GetAdminUserInfo()
  8166. template := &models.HisPrescriptionTemplate{
  8167. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8168. PatientId: patient_id,
  8169. Type: types,
  8170. Status: 1,
  8171. Ctime: time.Now().Unix(),
  8172. Mtime: time.Now().Unix(),
  8173. Name: name,
  8174. Mode: mode_id,
  8175. }
  8176. dataBody := make(map[string]interface{}, 0)
  8177. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8178. if err != nil {
  8179. utils.ErrorLog(err.Error())
  8180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8181. return
  8182. }
  8183. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  8184. //如果已经存在记录则删除处方
  8185. if template_one.ID > 0 {
  8186. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  8187. for _, item := range ps {
  8188. service.DelelteHisPrescriptionInfoTemplate(item.ID, item.UserOrgId)
  8189. }
  8190. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8191. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8192. if len(prescriptions) > 0 {
  8193. for _, item := range prescriptions {
  8194. items := item.(map[string]interface{})
  8195. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8196. utils.ErrorLog("type")
  8197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8198. return
  8199. }
  8200. types := int64(items["type"].(float64))
  8201. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8202. utils.ErrorLog("med_type")
  8203. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8204. return
  8205. }
  8206. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8207. ctime := time.Now().Unix()
  8208. prescription := &models.HisPrescriptionInfoTemplate{
  8209. PatientId: patient_id,
  8210. UserOrgId: adminInfo.CurrentOrgId,
  8211. Ctime: ctime,
  8212. Mtime: ctime,
  8213. Type: types,
  8214. Modifier: adminInfo.AdminUser.Id,
  8215. Creator: adminInfo.AdminUser.Id,
  8216. Status: 1,
  8217. PTemplateId: template_one.ID,
  8218. MedType: med_type,
  8219. }
  8220. service.CreateHisPrescriptionInfoTemplate(prescription)
  8221. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8222. advices := items["advices"].([]interface{})
  8223. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8224. ctime := time.Now().Unix()
  8225. mtime := ctime
  8226. if len(advices) > 0 {
  8227. for _, advice := range advices {
  8228. var s models.HisPrescriptionAdviceTemplate
  8229. s.PrescriptionId = prescription.ID
  8230. s.AdviceType = 2
  8231. s.StopState = 2
  8232. s.ExecutionState = 2
  8233. s.Status = 1
  8234. s.UserOrgId = adminInfo.CurrentOrgId
  8235. s.CreatedTime = ctime
  8236. s.UpdatedTime = mtime
  8237. s.PatientId = patient_id
  8238. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8239. if errcode > 0 {
  8240. c.ServeFailJSONWithSGJErrorCode(errcode)
  8241. return
  8242. }
  8243. service.CreateHisPrescriptionAdviceTemplate(&s)
  8244. }
  8245. }
  8246. }
  8247. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8248. projects := items["project"].([]interface{})
  8249. if len(projects) > 0 {
  8250. for _, project := range projects {
  8251. var p models.HisPrescriptionProjectTemplate
  8252. p.PrescriptionId = prescription.ID
  8253. p.Ctime = time.Now().Unix()
  8254. p.Mtime = time.Now().Unix()
  8255. p.PatientId = patient_id
  8256. p.UserOrgId = adminInfo.CurrentOrgId
  8257. p.Status = 1
  8258. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8259. if errcode > 0 {
  8260. c.ServeFailJSONWithSGJErrorCode(errcode)
  8261. return
  8262. }
  8263. service.CreateHisPrescriptionProjectTemplate(&p)
  8264. }
  8265. }
  8266. }
  8267. }
  8268. c.ServeSuccessJSON(map[string]interface{}{
  8269. "msg": "创建成功",
  8270. })
  8271. }
  8272. }
  8273. } else {
  8274. err = service.CreateHisPrescriptionTemplate(template)
  8275. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  8276. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  8277. if len(prescriptions) > 0 {
  8278. for _, item := range prescriptions {
  8279. items := item.(map[string]interface{})
  8280. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  8281. utils.ErrorLog("type")
  8282. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8283. return
  8284. }
  8285. types := int64(items["type"].(float64))
  8286. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  8287. utils.ErrorLog("med_type")
  8288. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8289. return
  8290. }
  8291. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  8292. ctime := time.Now().Unix()
  8293. prescription := &models.HisPrescriptionInfoTemplate{
  8294. PatientId: patient_id,
  8295. UserOrgId: adminInfo.CurrentOrgId,
  8296. Ctime: ctime,
  8297. Mtime: ctime,
  8298. Type: types,
  8299. Modifier: adminInfo.AdminUser.Id,
  8300. Creator: adminInfo.AdminUser.Id,
  8301. Status: 1,
  8302. PTemplateId: template.ID,
  8303. MedType: med_type,
  8304. }
  8305. service.CreateHisPrescriptionInfoTemplate(prescription)
  8306. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  8307. advices := items["advices"].([]interface{})
  8308. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  8309. ctime := time.Now().Unix()
  8310. mtime := ctime
  8311. if len(advices) > 0 {
  8312. for _, advice := range advices {
  8313. var s models.HisPrescriptionAdviceTemplate
  8314. s.PrescriptionId = prescription.ID
  8315. s.AdviceType = 2
  8316. s.StopState = 2
  8317. s.ExecutionState = 2
  8318. s.Status = 1
  8319. s.UserOrgId = adminInfo.CurrentOrgId
  8320. s.CreatedTime = ctime
  8321. s.UpdatedTime = mtime
  8322. s.PatientId = patient_id
  8323. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  8324. if errcode > 0 {
  8325. c.ServeFailJSONWithSGJErrorCode(errcode)
  8326. return
  8327. }
  8328. service.CreateHisPrescriptionAdviceTemplate(&s)
  8329. }
  8330. }
  8331. }
  8332. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  8333. projects := items["project"].([]interface{})
  8334. if len(projects) > 0 {
  8335. for _, project := range projects {
  8336. var p models.HisPrescriptionProjectTemplate
  8337. p.PrescriptionId = prescription.ID
  8338. p.Ctime = time.Now().Unix()
  8339. p.Mtime = time.Now().Unix()
  8340. p.PatientId = patient_id
  8341. p.UserOrgId = adminInfo.CurrentOrgId
  8342. p.Status = 1
  8343. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  8344. if errcode > 0 {
  8345. c.ServeFailJSONWithSGJErrorCode(errcode)
  8346. return
  8347. }
  8348. service.CreateHisPrescriptionProjectTemplate(&p)
  8349. }
  8350. }
  8351. }
  8352. }
  8353. c.ServeSuccessJSON(map[string]interface{}{
  8354. "msg": "创建成功",
  8355. })
  8356. }
  8357. }
  8358. }
  8359. }
  8360. func (c *HisApiController) PreSettle() {
  8361. id, _ := c.GetInt64("id")
  8362. record_time := c.GetString("record_time")
  8363. his_patient_id, _ := c.GetInt64("his_patient_id")
  8364. timeLayout := "2006-01-02"
  8365. loc, _ := time.LoadLocation("Local")
  8366. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  8367. diagnosis_id := c.GetString("diagnosis")
  8368. sick_type, _ := c.GetInt64("sick_type")
  8369. reg_type, _ := c.GetInt64("p_type")
  8370. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8371. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  8372. if err != nil {
  8373. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8374. return
  8375. }
  8376. recordDateTime := theTime.Unix()
  8377. adminUser := c.GetAdminUserInfo()
  8378. var prescriptions []*models.HisPrescription
  8379. var start_time int64
  8380. var end_time int64
  8381. ids_str := c.GetString("ids")
  8382. ids_arr := strings.Split(ids_str, ",")
  8383. fmt.Println(reg_type)
  8384. if settle_accounts_type == 1 { //日结
  8385. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  8386. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  8387. } else {
  8388. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  8389. }
  8390. fmt.Println(prescriptions)
  8391. } else { //月结
  8392. start_time_str := c.GetString("start_time")
  8393. end_time_str := c.GetString("end_time")
  8394. timeLayout := "2006-01-02"
  8395. loc, _ := time.LoadLocation("Local")
  8396. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  8397. if err != nil {
  8398. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8399. return
  8400. }
  8401. recordStartTime := theStartTime.Unix()
  8402. start_time = recordStartTime
  8403. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  8404. if err != nil {
  8405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8406. return
  8407. }
  8408. recordEndTime := theEndTime.Unix()
  8409. end_time = recordEndTime
  8410. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  8411. }
  8412. if reg_type == 1111 || reg_type == 1112 {
  8413. reg_type = 11
  8414. }
  8415. timestamp := time.Now().Unix()
  8416. tempTime := time.Unix(timestamp, 0)
  8417. timeFormat := tempTime.Format("20060102150405")
  8418. chrgBchno := rand.Intn(100000) + 10000
  8419. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  8420. strconv.FormatInt(his.PatientId, 10)
  8421. var ids []int64
  8422. for _, item := range prescriptions {
  8423. ids = append(ids, item.ID)
  8424. }
  8425. fmt.Println(ids)
  8426. var total float64
  8427. for _, item := range prescriptions {
  8428. fmt.Println(item)
  8429. if item.Type == 1 { //药品
  8430. for _, subItem := range item.HisDoctorAdviceInfo {
  8431. total = total + (subItem.Price * subItem.PrescribingNumber)
  8432. }
  8433. }
  8434. if item.Type == 2 { //项目
  8435. for _, subItem := range item.HisPrescriptionProject {
  8436. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8437. total = total + (subItem.Price * cnt)
  8438. }
  8439. }
  8440. for _, subItem := range item.HisAdditionalCharge {
  8441. total = total + (subItem.Price * float64(subItem.Count))
  8442. }
  8443. }
  8444. allTotal := fmt.Sprintf("%.2f", total)
  8445. totals, _ := strconv.ParseFloat(allTotal, 64)
  8446. order := &models.HisOrder{
  8447. UserOrgId: adminUser.CurrentOrgId,
  8448. HisPatientId: his.ID,
  8449. PatientId: id,
  8450. SettleAccountsDate: recordDateTime,
  8451. Ctime: time.Now().Unix(),
  8452. Mtime: time.Now().Unix(),
  8453. Status: 1,
  8454. OrderStatus: 1,
  8455. MdtrtId: his.Number,
  8456. Number: chrg_bchno,
  8457. MedfeeSumamt: totals,
  8458. SettleEndTime: end_time,
  8459. SettleStartTime: start_time,
  8460. SettleType: settle_accounts_type,
  8461. PsnPartAmt: totals,
  8462. PsnCashPay: totals,
  8463. PType: 2,
  8464. IsPre: 1,
  8465. MedType: strconv.Itoa(int(reg_type)),
  8466. Diagnosis: diagnosis_id,
  8467. }
  8468. err = service.CreateOrder(order)
  8469. if err != nil {
  8470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  8471. return
  8472. }
  8473. var customs []*Custom
  8474. for _, item := range prescriptions {
  8475. fmt.Println(item.Type)
  8476. if item.Type == 1 { //药品
  8477. for _, subItem := range item.HisDoctorAdviceInfo {
  8478. cus := &Custom{
  8479. AdviceId: subItem.ID,
  8480. ProjectId: 0,
  8481. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  8482. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  8483. FeedetlSn: subItem.FeedetlSn,
  8484. Price: fmt.Sprintf("%.2f", subItem.Price),
  8485. MedListCodg: subItem.MedListCodg,
  8486. Type: 1,
  8487. }
  8488. customs = append(customs, cus)
  8489. }
  8490. }
  8491. if item.Type == 2 { //项目
  8492. for _, subItem := range item.HisPrescriptionProject {
  8493. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  8494. cus := &Custom{
  8495. AdviceId: 0,
  8496. ProjectId: subItem.ID,
  8497. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  8498. Cut: fmt.Sprintf("%.2f", cnt),
  8499. FeedetlSn: subItem.FeedetlSn,
  8500. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  8501. MedListCodg: subItem.MedListCodg,
  8502. Type: 2,
  8503. }
  8504. customs = append(customs, cus)
  8505. }
  8506. }
  8507. for _, item := range item.HisAdditionalCharge {
  8508. cus := &Custom{
  8509. ItemId: item.ID,
  8510. AdviceId: 0,
  8511. ProjectId: 0,
  8512. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  8513. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  8514. FeedetlSn: item.FeedetlSn,
  8515. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  8516. MedListCodg: item.XtHisAddtionConfig.Code,
  8517. Type: 3,
  8518. }
  8519. customs = append(customs, cus)
  8520. }
  8521. }
  8522. fmt.Println(customs)
  8523. for _, item := range customs {
  8524. var advice_id int64 = 0
  8525. var project_id int64 = 0
  8526. var item_id int64 = 0
  8527. var types int64 = 0
  8528. if item.Type == 1 {
  8529. advice_id = item.AdviceId
  8530. project_id = 0
  8531. item_id = 0
  8532. } else if item.Type == 2 {
  8533. advice_id = 0
  8534. item_id = 0
  8535. project_id = item.ProjectId
  8536. } else if item.Type == 3 {
  8537. advice_id = 0
  8538. item_id = item.ItemId
  8539. project_id = 0
  8540. }
  8541. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  8542. cut, _ := strconv.ParseFloat(item.Cut, 32)
  8543. pric, _ := strconv.ParseFloat(item.Price, 32)
  8544. info := &models.HisOrderInfo{
  8545. OrderNumber: order.Number,
  8546. UploadDate: time.Now().Unix(),
  8547. AdviceId: advice_id,
  8548. DetItemFeeSumamt: detItemFeeSumamt,
  8549. Cnt: cut,
  8550. Pric: pric,
  8551. PatientId: id,
  8552. Status: 1,
  8553. Mtime: time.Now().Unix(),
  8554. Ctime: time.Now().Unix(),
  8555. UserOrgId: adminUser.CurrentOrgId,
  8556. HisPatientId: his.ID,
  8557. OrderId: order.ID,
  8558. ProjectId: project_id,
  8559. Type: types,
  8560. ItemId: item_id,
  8561. }
  8562. service.CreateOrderInfo(info)
  8563. }
  8564. his.SickType = sick_type
  8565. service.UpdataHisPateint(&his)
  8566. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8567. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8568. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8569. if err == nil {
  8570. c.ServeSuccessJSON(map[string]interface{}{
  8571. "msg": "结算成功",
  8572. })
  8573. }
  8574. }
  8575. type CustomOrderInfo struct {
  8576. Name string
  8577. Spec string
  8578. Unit string
  8579. Count float64
  8580. Price float64
  8581. Total float64
  8582. }
  8583. func (c *HisApiController) GetPrivateExpensesInfo() {
  8584. order_id, _ := c.GetInt64("id", 0)
  8585. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8586. order, _ := service.GetHisOrderByID(order_id)
  8587. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8588. if order.ID == 0 {
  8589. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8590. return
  8591. }
  8592. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8593. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8594. org_id := c.GetAdminUserInfo().CurrentOrgId
  8595. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8596. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8597. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8598. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8599. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8600. var orderInfos_four []*models.HisOrderInfoTwo
  8601. for _, item := range orderInfos_three {
  8602. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8603. item.HisPrescriptionProject.IsCheckTeam = 1
  8604. orderInfos_four = append(orderInfos_four, item)
  8605. }
  8606. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8607. item.HisPrescriptionProject.IsCheckTeam = 2
  8608. orderInfos_two = append(orderInfos_two, item)
  8609. }
  8610. }
  8611. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8612. var cus_slice []CustomOrderInfo
  8613. for _, item := range new_order_info {
  8614. var cus CustomOrderInfo
  8615. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8616. cus.Unit = ""
  8617. cus.Spec = ""
  8618. var total float64
  8619. for _, subItem := range orderInfos_four {
  8620. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8621. total = total + subItem.DetItemFeeSumamt
  8622. fmt.Println(subItem.DetItemFeeSumamt)
  8623. }
  8624. }
  8625. cus.Count = 1
  8626. cus.Total = total
  8627. cus_slice = append(cus_slice, cus)
  8628. }
  8629. orderInfos = append(orderInfos, orderInfos_two...)
  8630. if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  8631. orderInfos = append(orderInfos, orderInfos_three...)
  8632. }
  8633. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8634. c.ServeSuccessJSON(map[string]interface{}{
  8635. "order": order,
  8636. "order_info": orderInfos,
  8637. "patient": patient,
  8638. "admin_info": adminInfo,
  8639. "his": his,
  8640. "current_admin": role,
  8641. "org_config": miConfig,
  8642. "new_order_info": cus_slice,
  8643. })
  8644. }
  8645. func (this *HisApiController) ChangeMedType() {
  8646. med_type := this.GetString("med_type")
  8647. old_med_type := this.GetString("old_med_type")
  8648. ids := this.GetString("ids")
  8649. settle_type, _ := this.GetInt64("settle_type")
  8650. start_time := this.GetString("start_time")
  8651. end_time := this.GetString("end_time")
  8652. ids_arr := strings.Split(ids, ",")
  8653. if settle_type == 1 { //日结
  8654. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8655. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8656. prescription.MedType = med_type
  8657. err := service.SaveHisPrescription(&prescription)
  8658. if err == nil {
  8659. this.ServeSuccessJSON(map[string]interface{}{
  8660. "msg": "修改成功",
  8661. })
  8662. } else {
  8663. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8664. return
  8665. }
  8666. } else if settle_type == 2 {
  8667. timeLayout := "2006-01-02"
  8668. loc, _ := time.LoadLocation("Local")
  8669. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8670. if err != nil {
  8671. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8672. return
  8673. }
  8674. recordStartTime := theStartTime.Unix()
  8675. start_time_timestamp := recordStartTime
  8676. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8677. if err != nil {
  8678. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8679. return
  8680. }
  8681. recordEndTime := theEndTime.Unix()
  8682. end_time_timestamp := recordEndTime
  8683. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8684. if updateErr == nil {
  8685. this.ServeSuccessJSON(map[string]interface{}{
  8686. "msg": "修改成功",
  8687. })
  8688. } else {
  8689. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8690. return
  8691. }
  8692. }
  8693. }
  8694. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8695. patient_id, _ := c.GetInt64("patient_id")
  8696. his_patient_id, _ := c.GetInt64("his_patient_id")
  8697. record_date := c.GetString("record_date")
  8698. start_time := c.GetString("start_time")
  8699. end_time := c.GetString("end_time")
  8700. order_status, _ := c.GetInt64("type", 0)
  8701. p_type, _ := c.GetInt64("p_type", 0)
  8702. order_id, _ := c.GetInt64("order_id", 0)
  8703. timeLayout := "2006-01-02"
  8704. loc, _ := time.LoadLocation("Local")
  8705. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8706. if err != nil {
  8707. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8708. return
  8709. }
  8710. recordDateTime := theTime.Unix()
  8711. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8712. if err != nil {
  8713. }
  8714. startRecordDateTime := startTime.Unix()
  8715. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8716. if err != nil {
  8717. }
  8718. endRecordDateTime := endTime.Unix()
  8719. admin := c.GetAdminUserInfo()
  8720. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8721. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8722. order, _ := service.GetHisOrderByID(order_id)
  8723. var monthPrescriptions []*models.HisPrescription
  8724. if order_status == 1 || order_status == 0 {
  8725. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8726. } else if order_status == 2 {
  8727. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8728. }
  8729. var settle_total float64
  8730. for _, item := range monthPrescriptions {
  8731. if len(item.HisPrescriptionProject) > 0 {
  8732. for _, subItem := range item.HisPrescriptionProject {
  8733. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8734. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8735. settle_total = settle_total + total
  8736. }
  8737. }
  8738. if len(item.HisDoctorAdviceInfo) > 0 {
  8739. for _, subItem := range item.HisDoctorAdviceInfo {
  8740. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8741. settle_total = settle_total + total
  8742. }
  8743. }
  8744. }
  8745. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8746. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8747. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8748. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8749. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8750. //获取所有科室信息
  8751. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8752. c.ServeSuccessJSON(map[string]interface{}{
  8753. "his_info": his_patient_info,
  8754. "xt_info": xt_patient_info,
  8755. "case_history": case_history,
  8756. "info": patientPrescriptionInfo,
  8757. "last_info": lastPatientPrescriptionInfo,
  8758. "month_prescriptions": monthPrescriptions,
  8759. "order": order,
  8760. "doctors": doctors,
  8761. "department": department,
  8762. "settle_total": settle_total,
  8763. })
  8764. return
  8765. }
  8766. func (c *HisApiController) GetHisMonthPatientInfo() {
  8767. patient_id, _ := c.GetInt64("patient_id")
  8768. his_patient_id, _ := c.GetInt64("his_patient_id")
  8769. record_date := c.GetString("record_date")
  8770. number := c.GetString("number")
  8771. start_time := c.GetString("start_time")
  8772. end_time := c.GetString("end_time")
  8773. p_type, _ := c.GetInt64("p_type")
  8774. timeLayout := "2006-01-02"
  8775. loc, _ := time.LoadLocation("Local")
  8776. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8777. if err != nil {
  8778. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8779. return
  8780. }
  8781. recordDateTime := theTime.Unix()
  8782. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8783. if err != nil {
  8784. }
  8785. startRecordDateTime := startTime.Unix()
  8786. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8787. if err != nil {
  8788. }
  8789. endRecordDateTime := endTime.Unix()
  8790. admin := c.GetAdminUserInfo()
  8791. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8792. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8793. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8794. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8795. var settle_total float64
  8796. for _, item := range monthPrescriptions {
  8797. if len(item.HisPrescriptionProject) > 0 {
  8798. for _, subItem := range item.HisPrescriptionProject {
  8799. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8800. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8801. settle_total = settle_total + total
  8802. }
  8803. }
  8804. if len(item.HisDoctorAdviceInfo) > 0 {
  8805. for _, subItem := range item.HisDoctorAdviceInfo {
  8806. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8807. settle_total = settle_total + total
  8808. }
  8809. }
  8810. }
  8811. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8812. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8813. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8814. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8815. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8816. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8817. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8818. //获取所有科室信息
  8819. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8820. c.ServeSuccessJSON(map[string]interface{}{
  8821. "his_info": his_patient_info,
  8822. "xt_info": xt_patient_info,
  8823. "case_history": case_history,
  8824. "info": patientPrescriptionInfo,
  8825. "month_prescriptions": monthPrescriptions,
  8826. "order": order,
  8827. "doctors": doctors,
  8828. "department": department,
  8829. "count": count,
  8830. "drugStockConfig": drugStockConfig,
  8831. "last_info": lastPatientPrescriptionInfo,
  8832. "settle_total": settle_total,
  8833. })
  8834. return
  8835. }
  8836. func (c *HisApiController) GetAllOrder() {
  8837. org_id := c.GetAdminUserInfo().CurrentOrgId
  8838. orders, _ := service.GetNewHisOrderList(org_id)
  8839. c.ServeSuccessJSON(map[string]interface{}{
  8840. "order": orders,
  8841. })
  8842. return
  8843. }
  8844. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8845. newArr = make([]*models.HisOrderInfoTwo, 0)
  8846. for i := 0; i < len(arr); i++ {
  8847. repeat := false
  8848. for j := i + 1; j < len(arr); j++ {
  8849. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8850. repeat = true
  8851. break
  8852. }
  8853. }
  8854. if !repeat {
  8855. newArr = append(newArr, arr[i])
  8856. }
  8857. }
  8858. return
  8859. }
  8860. // 修改处方退库操作 参数传修改之前的处方数据
  8861. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8862. if advice.ExecutionState == 1 {
  8863. //查询该病人该药品是否有库存记录
  8864. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8865. if errcode == gorm.ErrRecordNotFound {
  8866. } else {
  8867. //退库
  8868. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8869. if advice.PrescribingNumberUnit == drug.MinUnit {
  8870. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8871. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8872. //退库
  8873. warehouseInfo := models.DrugWarehouseInfo{
  8874. StockMinNumber: prescribingNumber,
  8875. }
  8876. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8877. operation_time := time.Now().Unix()
  8878. creater := advice.AdviceDoctor
  8879. ctime := time.Now().Unix()
  8880. timeStr := time.Now().Format("2006-01-02")
  8881. timeArr := strings.Split(timeStr, "-")
  8882. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8883. total = total + 1
  8884. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8885. cancelStock := models.DrugCancelStock{
  8886. OrderNumber: orderNumber,
  8887. OperaTime: operation_time,
  8888. OrgId: advice.UserOrgId,
  8889. Creater: creater,
  8890. Ctime: ctime,
  8891. Status: 1,
  8892. ReturnTime: advice.AdviceDate,
  8893. Dealer: info.Dealer,
  8894. Manufacturer: info.Manufacturer,
  8895. Type: 1,
  8896. }
  8897. service.AddSigleDrugCancelStock(&cancelStock)
  8898. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8899. dealer, _ := service.GetDealerById(info.Dealer)
  8900. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8901. cancelStockInfo := models.DrugCancelStockInfo{
  8902. OrderNumber: cancelInfo.OrderNumber,
  8903. CancelStockId: cancelInfo.ID,
  8904. DrugId: info.DrugId,
  8905. Count: info.Count,
  8906. Status: 1,
  8907. Ctime: ctime,
  8908. OrgId: advice.UserOrgId,
  8909. Type: 1,
  8910. Manufacturer: manufactureName.ManufacturerName,
  8911. Dealer: dealer.DealerName,
  8912. Total: 0,
  8913. RetailPrice: info.RetailPrice,
  8914. RetailTotalPrice: info.RetailTotalPrice,
  8915. Price: info.Price,
  8916. RegisterAccount: "",
  8917. Remark: info.Remark,
  8918. BatchNumber: info.BatchNumber,
  8919. MaxUnit: info.CountUnit,
  8920. ProductDate: info.ProductDate,
  8921. ExpiryDate: info.ExpiryDate,
  8922. BatchNumberId: info.WarehouseInfoId,
  8923. }
  8924. flow := models.DrugFlow{
  8925. WarehousingId: 0,
  8926. DrugId: info.DrugId,
  8927. Number: "",
  8928. BatchNumber: info.BatchNumber,
  8929. Count: info.Count,
  8930. UserOrgId: advice.UserOrgId,
  8931. PatientId: 0,
  8932. SystemTime: ctime,
  8933. ConsumableType: 4,
  8934. IsSys: 0,
  8935. WarehousingOrder: "",
  8936. WarehouseOutId: 0,
  8937. WarehouseOutOrderNumber: "",
  8938. IsEdit: 0,
  8939. CancelStockId: cancelStock.ID,
  8940. CancelOrderNumber: cancelStock.OrderNumber,
  8941. Manufacturer: info.Manufacturer,
  8942. Dealer: info.Dealer,
  8943. Creator: advice.UserOrgId,
  8944. UpdateCreator: 0,
  8945. Status: 1,
  8946. Ctime: time.Now().Unix(),
  8947. Mtime: 0,
  8948. Price: info.Price,
  8949. WarehousingDetailId: 0,
  8950. WarehouseOutDetailId: 0,
  8951. CancelOutDetailId: 0,
  8952. ExpireDate: info.ExpiryDate,
  8953. ProductDate: info.ProductDate,
  8954. MaxUnit: info.CountUnit,
  8955. MinUnit: "",
  8956. }
  8957. service.CreatedCancelStock(cancelStockInfo)
  8958. service.CreateDrugFlowOne(flow)
  8959. } else {
  8960. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8961. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8962. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8963. warehouseInfo := models.DrugWarehouseInfo{
  8964. StockMinNumber: prescribingNumber,
  8965. }
  8966. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8967. }
  8968. operation_time := time.Now().Unix()
  8969. creater := advice.AdviceDoctor
  8970. ctime := time.Now().Unix()
  8971. timeStr := time.Now().Format("2006-01-02")
  8972. timeArr := strings.Split(timeStr, "-")
  8973. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8974. total = total + 1
  8975. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8976. cancelStock := models.DrugCancelStock{
  8977. OrderNumber: orderNumber,
  8978. OperaTime: operation_time,
  8979. OrgId: advice.UserOrgId,
  8980. Creater: creater,
  8981. Ctime: ctime,
  8982. Status: 1,
  8983. ReturnTime: advice.AdviceDate,
  8984. Dealer: info.Dealer,
  8985. Manufacturer: info.Manufacturer,
  8986. Type: 1,
  8987. }
  8988. service.AddSigleDrugCancelStock(&cancelStock)
  8989. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8990. dealer, _ := service.GetDealerById(info.Dealer)
  8991. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8992. cancelStockInfo := models.DrugCancelStockInfo{
  8993. OrderNumber: cancelInfo.OrderNumber,
  8994. CancelStockId: cancelInfo.ID,
  8995. DrugId: info.DrugId,
  8996. Count: info.Count,
  8997. Status: 1,
  8998. Ctime: ctime,
  8999. OrgId: advice.UserOrgId,
  9000. Type: 1,
  9001. Manufacturer: manufactureName.ManufacturerName,
  9002. Dealer: dealer.DealerName,
  9003. Total: 0,
  9004. RetailPrice: info.RetailPrice,
  9005. RetailTotalPrice: info.RetailTotalPrice,
  9006. Price: info.Price,
  9007. RegisterAccount: "",
  9008. Remark: info.Remark,
  9009. BatchNumber: info.BatchNumber,
  9010. MaxUnit: info.CountUnit,
  9011. ProductDate: info.ProductDate,
  9012. ExpiryDate: info.ExpiryDate,
  9013. BatchNumberId: info.WarehouseInfoId,
  9014. }
  9015. flow := models.DrugFlow{
  9016. WarehousingId: 0,
  9017. DrugId: info.DrugId,
  9018. Number: "",
  9019. BatchNumber: info.BatchNumber,
  9020. Count: info.Count,
  9021. UserOrgId: advice.UserOrgId,
  9022. PatientId: 0,
  9023. SystemTime: ctime,
  9024. ConsumableType: 4,
  9025. IsSys: 0,
  9026. WarehousingOrder: "",
  9027. WarehouseOutId: 0,
  9028. WarehouseOutOrderNumber: "",
  9029. IsEdit: 0,
  9030. CancelStockId: cancelStock.ID,
  9031. CancelOrderNumber: cancelStock.OrderNumber,
  9032. Manufacturer: info.Manufacturer,
  9033. Dealer: info.Dealer,
  9034. Creator: advice.AdviceDoctor,
  9035. UpdateCreator: 0,
  9036. Status: 1,
  9037. Ctime: time.Now().Unix(),
  9038. Mtime: 0,
  9039. Price: info.Price,
  9040. WarehousingDetailId: 0,
  9041. WarehouseOutDetailId: 0,
  9042. CancelOutDetailId: 0,
  9043. ExpireDate: info.ExpiryDate,
  9044. ProductDate: info.ProductDate,
  9045. MaxUnit: info.CountUnit,
  9046. MinUnit: "",
  9047. }
  9048. service.CreatedCancelStock(cancelStockInfo)
  9049. service.CreateDrugFlowOne(flow)
  9050. }
  9051. }
  9052. }
  9053. return err
  9054. }
  9055. func (this *HisApiController) DeleteNCDS() {
  9056. id, _ := this.GetInt64("id", 0)
  9057. if id > 0 {
  9058. service.DeletePsnNCDSRecordById(id)
  9059. this.ServeSuccessJSON(map[string]interface{}{
  9060. "msg": "删除成功",
  9061. })
  9062. } else {
  9063. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  9064. return
  9065. }
  9066. }
  9067. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  9068. id, _ := c.GetInt64("id")
  9069. advice, _ := service.GetHisDoctorAdviceInfo(id)
  9070. c.ServeSuccessJSON(map[string]interface{}{
  9071. "advice": advice,
  9072. })
  9073. return
  9074. }
  9075. func (c *HisApiController) GetHisMonthChargePatientList() {
  9076. record_date := c.GetString("record_date")
  9077. start_time := c.GetString("start_time")
  9078. end_time := c.GetString("end_time")
  9079. timeLayout := "2006-01-02"
  9080. loc, _ := time.LoadLocation("Local")
  9081. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9082. if err != nil {
  9083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9084. return
  9085. }
  9086. if err != nil {
  9087. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9088. return
  9089. }
  9090. recordDateTime := theTime.Unix()
  9091. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9092. if err != nil {
  9093. }
  9094. startRecordDateTime := startTime.Unix()
  9095. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9096. if err != nil {
  9097. }
  9098. endRecordDateTime := endTime.Unix()
  9099. adminInfo := c.GetAdminUserInfo()
  9100. var tempMonthChargePatients []*service.MonthChargePatients
  9101. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  9102. for _, item := range tempPatients {
  9103. //过滤没有处方的
  9104. if len(item.HisPrescription) == 0 {
  9105. tempMonthChargePatients = append(tempMonthChargePatients, item)
  9106. }
  9107. }
  9108. c.ServeSuccessJSON(map[string]interface{}{
  9109. "list": tempMonthChargePatients,
  9110. })
  9111. }