his_api_controller.go 441KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363
  1. package controllers
  2. import (
  3. "XT_New/enums"
  4. "XT_New/models"
  5. "XT_New/service"
  6. "XT_New/utils"
  7. "encoding/json"
  8. "fmt"
  9. "github.com/astaxie/beego"
  10. "github.com/jinzhu/gorm"
  11. "github.com/shopspring/decimal"
  12. "math/rand"
  13. "reflect"
  14. "strconv"
  15. "strings"
  16. "syscall"
  17. "time"
  18. "unsafe"
  19. )
  20. type HisApiController struct {
  21. BaseAuthAPIController
  22. }
  23. func HisManagerApiRegistRouters() {
  24. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  25. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  26. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  27. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  28. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  29. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  30. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  31. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  32. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  33. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  34. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  35. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  36. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  37. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  40. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  41. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  42. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  43. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  44. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  45. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  46. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  47. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  48. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  49. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  50. //新增附加费用
  51. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  52. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  53. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  54. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  55. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  56. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  57. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  58. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  59. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  60. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  61. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  62. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  63. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  64. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  65. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  66. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  67. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  68. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  69. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  70. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  71. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  72. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  73. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  74. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  75. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  76. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  77. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  78. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  79. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  82. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  83. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  84. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  85. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  86. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  87. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  88. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  89. }
  90. func (c *HisApiController) CheckHisPatient() {
  91. record_date := c.GetString("record_date")
  92. patient_id, _ := c.GetInt64("patient_id")
  93. timeLayout := "2006-01-02"
  94. loc, _ := time.LoadLocation("Local")
  95. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  96. if err != nil {
  97. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  98. return
  99. }
  100. recordDateTime := theTime.Unix()
  101. adminInfo := c.GetAdminUserInfo()
  102. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  103. if len(patients) > 1 {
  104. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  105. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  106. c.ServeSuccessJSON(map[string]interface{}{
  107. "status": 1,
  108. "msg": "关联",
  109. "ps": ps,
  110. "his_patient_id": patients[len(patients)-1].ID,
  111. "patient_id": patients[len(patients)-1].PatientId,
  112. })
  113. } else {
  114. c.ServeSuccessJSON(map[string]interface{}{
  115. "status": 0,
  116. "msg": "无需关联",
  117. })
  118. }
  119. } else {
  120. c.ServeSuccessJSON(map[string]interface{}{
  121. "status": 0,
  122. "msg": "无需关联",
  123. })
  124. return
  125. }
  126. }
  127. func (c *HisApiController) AssociationHisPrescription() {
  128. record_date := c.GetString("record_date")
  129. his_patient_id, _ := c.GetInt64("his_patient_id")
  130. patient_id, _ := c.GetInt64("patient_id")
  131. p_ids := c.GetString("p_ids")
  132. p_ids_arr := strings.Split(p_ids, ",")
  133. timeLayout := "2006-01-02"
  134. loc, _ := time.LoadLocation("Local")
  135. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  136. if err != nil {
  137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. return
  139. }
  140. recordDateTime := theTime.Unix()
  141. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  142. if his_patient_id == 0 || his_patient.ID == 0 {
  143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  144. return
  145. }
  146. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  147. if err == nil {
  148. c.ServeSuccessJSON(map[string]interface{}{
  149. "msg": "关联处方成功",
  150. })
  151. return
  152. } else {
  153. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  154. return
  155. }
  156. }
  157. //func (c *HisApiController) AssociationHisPrescription() {
  158. // record_date, _ := c.GetInt64("record_date")
  159. // his_patient_id, _ := c.GetInt64("his_patient_id")
  160. // patient_id, _ := c.GetInt64("patient_id")
  161. // p_ids := c.GetString("p_ids")
  162. // p_ids_arr := strings.Split(p_ids, ",")
  163. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  164. // if his_patient_id == 0 || his_patient.ID == 0 {
  165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  166. // return
  167. // }
  168. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  169. // if err == nil {
  170. // c.ServeSuccessJSON(map[string]interface{}{
  171. // "msg": "关联处方成功",
  172. // })
  173. // return
  174. // } else {
  175. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  176. // return
  177. // }
  178. //}
  179. func (c *HisApiController) GetFaPiaoNumber() {
  180. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  181. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  182. fmt.Println(count)
  183. var zero string
  184. number := count + 1
  185. if number >= 1000 {
  186. zero = "0000" + strconv.FormatInt(number, 10)
  187. } else if number >= 10000 {
  188. zero = "000" + strconv.FormatInt(number, 10)
  189. } else if number >= 100000 {
  190. zero = "00" + strconv.FormatInt(number, 10)
  191. } else if number >= 1000000 {
  192. zero = "0" + strconv.FormatInt(number, 10)
  193. } else {
  194. zero = strconv.FormatInt(number, 10)
  195. }
  196. c.ServeSuccessJSON(map[string]interface{}{
  197. "fapiao_number": zero,
  198. })
  199. return
  200. }
  201. func (c *HisApiController) ChangeOrderDesc() {
  202. id, _ := c.GetInt64("id")
  203. desc := c.GetString("desc")
  204. change_type := c.GetString("change_type")
  205. order, _ := service.GetHisOrderByID(id)
  206. if order.ID == 0 {
  207. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  208. return
  209. }
  210. switch change_type {
  211. case "oth_desc":
  212. order.OthDesc = desc
  213. break
  214. case "cash_pay":
  215. order.CashPay = desc
  216. break
  217. case "jifen_pay":
  218. order.JifenPay = desc
  219. break
  220. case "band_card_pay":
  221. order.BandCardPay = desc
  222. break
  223. case "ali_pay":
  224. order.AliPay = desc
  225. break
  226. case "wechat_pay":
  227. order.WechatPay = desc
  228. break
  229. case "fa_piao_number":
  230. order.FaPiaoNumber = desc
  231. break
  232. case "fa_piao_code":
  233. order.FaPiaoCode = desc
  234. break
  235. }
  236. err := service.SaveHisOrder(&order)
  237. if err == nil {
  238. c.ServeSuccessJSON(map[string]interface{}{
  239. "msg": "修改成功",
  240. })
  241. return
  242. } else {
  243. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  244. return
  245. }
  246. }
  247. func (c *HisApiController) GetMonthHisPatient() {
  248. record_date := c.GetString("record_date")
  249. //order_status, _ := c.GetInt64("type")
  250. timeLayout := "2006-01-02"
  251. loc, _ := time.LoadLocation("Local")
  252. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  253. if err != nil {
  254. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  255. return
  256. }
  257. recordDateTime := theTime.Unix()
  258. adminInfo := c.GetAdminUserInfo()
  259. var tempPatients []service.NewTempPatients
  260. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  261. // 获取当前时间
  262. now := time.Now()
  263. // 获取本月的第一天
  264. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  265. // 获取下个月的第一天
  266. nextMonth := firstDay.AddDate(0, 1, 0)
  267. // 获取本月的最后一天
  268. lastDay := nextMonth.Add(-time.Nanosecond)
  269. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  270. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  271. var patients []service.NewTempPatients
  272. var patients_two []service.NewTempPatients
  273. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  274. for _, item := range tempPatients {
  275. //过滤掉没挂号的和没开处方的
  276. if len(item.HisPrescription) > 0 {
  277. patients = append(patients, item)
  278. patients_two = append(patients_two, item)
  279. }
  280. ////过滤掉没挂号的
  281. //if len(item.HisPatient) > 0 {
  282. //}
  283. }
  284. } else {
  285. for _, item := range tempPatients {
  286. //过滤掉没挂号的和没开处方的
  287. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  288. patients = append(patients, item)
  289. }
  290. ////过滤掉没挂号的
  291. //if len(item.HisPatient) > 0 {
  292. // patients_two = append(patients_two, item)
  293. //}
  294. }
  295. }
  296. c.ServeSuccessJSON(map[string]interface{}{
  297. "list": patients,
  298. "list_two": patients_two,
  299. "chargePatients": chargePatients,
  300. })
  301. }
  302. func (c *HisApiController) GetBatchSettleAccounts() {
  303. order_ids := c.GetString("order_ids")
  304. admin_user_id, _ := c.GetInt64("admin_user_id")
  305. adminUser := c.GetAdminUserInfo()
  306. orders := strings.Split(order_ids, ",")
  307. var newOrders []models.Orders
  308. for _, item := range orders {
  309. order, _ := service.GetHisOrderByIDTenOne(item)
  310. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  311. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  312. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  313. orderInfos = append(orderInfos, orderInfos_two...)
  314. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  315. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  316. var diagnosis_ids []string
  317. if his.ID > 0 {
  318. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  319. } else {
  320. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  321. }
  322. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  323. var dia_config []*models.HisXtDiagnoseConfig
  324. var name string
  325. for _, item := range diagnosis_ids {
  326. id, _ := strconv.ParseInt(item, 10, 64)
  327. diagnosisConfig, _ := service.FindDiagnoseById(id)
  328. dia_config = append(dia_config, diagnosisConfig)
  329. if len(name) == 0 {
  330. name = diagnosisConfig.ClassName
  331. } else {
  332. name = name + "," + diagnosisConfig.ClassName
  333. }
  334. }
  335. var bedCostTotal float64 = 0 //床位总费
  336. var bedCostSelfTotal float64 = 0 //床位自费
  337. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  338. var bedSelfTotal float64 = 0 //床位部分项目自费
  339. var bedInscpTotal float64 = 0 //床位部分项目自费
  340. var operationCostTotal float64 = 0 //手术费
  341. var operationCostSelfTotal float64 = 0 //手术费
  342. var operationCostPartSelfTotal float64 = 0 //手术费
  343. var operationSelfTotal float64 = 0 //床位部分项目自费
  344. var operationInscpTotal float64 = 0 //床位部分项目自费
  345. var otherCostTotal float64 = 0 //其他费用
  346. var otherCostSelfTotal float64 = 0 //其他费用
  347. var otherCostPartSelfTotal float64 = 0 //其他费用
  348. var otherSelfTotal float64 = 0 //床位部分项目自费
  349. var otherInscpTotal float64 = 0 //床位部分项目自费
  350. var materialCostTotal float64 = 0 //材料费
  351. var materialCostSelfTotal float64 = 0 //材料费
  352. var materialCostPartSelfTotal float64 = 0 //材料费
  353. var materialSelfTotal float64 = 0 //床位部分项目自费
  354. var materialInscpTotal float64 = 0 //床位部分项目自费
  355. var westernMedicineCostTotal float64 = 0 //西药费
  356. var westernMedicineCostSelfTotal float64 = 0 //西药费
  357. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  358. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  359. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  360. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  361. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  362. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  363. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  364. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  365. var checkCostTotal float64 = 0 //检查费
  366. var checkCostSelfTotal float64 = 0 //检查费
  367. var checkCostPartSelfTotal float64 = 0 //检查费
  368. var checkSelfTotal float64 = 0 //床位部分项目自费
  369. var checkInscpTotal float64 = 0 //床位部分项目自费
  370. var laboratoryCostTotal float64 = 0 //化验费
  371. var laboratoryCostSelfTotal float64 = 0 //化验费
  372. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  373. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  374. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  375. var treatCostTotal float64 = 0 //治疗费用
  376. var treatCostSelfTotal float64 = 0 //治疗费用
  377. var treatCostPartSelfTotal float64 = 0 //治疗费用
  378. var treatSelfTotal float64 = 0 //床位部分项目自费
  379. var treatInscpTotal float64 = 0 //床位部分项目自费
  380. decimal.DivisionPrecision = 2
  381. for _, item := range orderInfos {
  382. if item.MedChrgitmType == "01" { //床位费
  383. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  384. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  385. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  386. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  387. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  388. }
  389. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  390. if item.MedChrgitmType == "03" { //检查费
  391. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  392. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  393. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  394. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  395. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  396. }
  397. } else {
  398. if item.MedChrgitmType == "03" { //检查费
  399. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  400. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  401. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  402. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  403. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  404. }
  405. }
  406. if item.MedChrgitmType == "04" { //化验费
  407. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  408. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  409. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  410. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  411. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  412. }
  413. if item.MedChrgitmType == "05" { //治疗费
  414. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  415. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  416. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  417. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  418. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  419. }
  420. if item.MedChrgitmType == "06" { //手术费
  421. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  422. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  423. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  424. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  425. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  426. }
  427. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  428. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  429. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  430. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  431. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  432. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  433. }
  434. if item.MedChrgitmType == "09" { //西药费
  435. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  436. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  437. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  438. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  439. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  440. }
  441. if item.MedChrgitmType == "11" { //中成费
  442. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  443. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  444. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  445. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  446. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  447. }
  448. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  449. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  450. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  451. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  452. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  453. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  454. }
  455. }
  456. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  457. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  458. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  459. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  460. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  461. var doctor_name string
  462. if roles.ID == 0 {
  463. doctor_name = "管理员"
  464. } else {
  465. doctor_name = roles.UserName
  466. }
  467. yiliao_leibie := ""
  468. switch order.MedType {
  469. case "11":
  470. yiliao_leibie = "普通门诊"
  471. break
  472. case "12":
  473. yiliao_leibie = "门诊挂号"
  474. break
  475. case "13":
  476. yiliao_leibie = "急诊"
  477. break
  478. case "14":
  479. yiliao_leibie = "门诊特殊病"
  480. break
  481. case "15":
  482. yiliao_leibie = "门诊统筹"
  483. break
  484. case "16":
  485. yiliao_leibie = "门诊慢性病"
  486. break
  487. case "21":
  488. yiliao_leibie = "普通住院"
  489. break
  490. }
  491. var newOrder models.Orders
  492. newOrder.Diagnosis = name
  493. newOrder.OrderInfos = orderInfos
  494. newOrder.Number = order.MdtrtId
  495. newOrder.Date = order.SettleAccountsDate
  496. newOrder.ChargeAdmin = charge_admin
  497. newOrder.PrintorAdmin = printor_admin
  498. newOrder.Order = order
  499. newOrder.BedCostTotal = bedCostTotal
  500. newOrder.BedCostSelfTotal = bedCostSelfTotal
  501. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  502. newOrder.BedSelfTotal = bedSelfTotal
  503. newOrder.BedInscpTotal = bedInscpTotal
  504. newOrder.OperationCostTotal = operationCostTotal
  505. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  506. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  507. newOrder.OperationSelfTotal = operationSelfTotal
  508. newOrder.OperationInscpTotal = operationInscpTotal
  509. newOrder.OtherCostTotal = otherCostTotal
  510. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  511. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  512. newOrder.OtherSelfTotal = otherSelfTotal
  513. newOrder.OtherInscpTotal = otherInscpTotal
  514. newOrder.MaterialCostTotal = materialCostTotal
  515. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  516. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  517. newOrder.MaterialSelfTotal = materialSelfTotal
  518. newOrder.MaterialInscpTotal = materialInscpTotal
  519. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  520. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  521. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  522. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  523. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  524. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  525. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  526. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  527. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  528. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  529. newOrder.CheckCostTotal = checkCostTotal
  530. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  531. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  532. newOrder.CheckSelfTotal = checkSelfTotal
  533. newOrder.CheckInscpTotal = checkInscpTotal
  534. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  535. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  536. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  537. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  538. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  539. newOrder.TreatCostTotal = treatCostTotal
  540. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  541. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  542. newOrder.TreatSelfTotal = treatSelfTotal
  543. newOrder.TreatInscpTotal = treatInscpTotal
  544. newOrder.DoctorInfo = doctor_info
  545. newOrder.DoctorName = doctor_name
  546. newOrder.HealthCardNo = order.PsnNo
  547. newOrder.YiliaoLeibie = yiliao_leibie
  548. newOrder.Patient = patient
  549. newOrder.OrgName = miConfig.OrgName
  550. newOrder.OrgCode = miConfig.Code
  551. newOrder.OrderNumber = order.Number
  552. newOrder.HisPatient = his
  553. newOrder.DiaConfig = dia_config
  554. newOrders = append(newOrders, newOrder)
  555. }
  556. c.ServeSuccessJSON(map[string]interface{}{
  557. "orders": newOrders,
  558. })
  559. }
  560. func (c *HisApiController) GetTestOrder() {
  561. order_id, _ := c.GetInt64("order_id")
  562. admin_user_id, _ := c.GetInt64("admin_user_id")
  563. adminUser := c.GetAdminUserInfo()
  564. order, _ := service.GetHisOrderByID(order_id)
  565. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  566. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  567. orderInfos = append(orderInfos, orderInfos_two...)
  568. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  569. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  570. var dia_config []*models.HisXtDiagnoseConfig
  571. var name string
  572. var bedCostTotal float64 = 0 //床位总费
  573. var bedCostSelfTotal float64 = 0 //床位自费
  574. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  575. var bedSelfTotal float64 = 0 //床位部分项目自费
  576. var bedInscpTotal float64 = 0 //床位部分项目自费
  577. var operationCostTotal float64 = 0 //手术费
  578. var operationCostSelfTotal float64 = 0 //手术费
  579. var operationCostPartSelfTotal float64 = 0 //手术费
  580. var operationSelfTotal float64 = 0 //床位部分项目自费
  581. var operationInscpTotal float64 = 0 //床位部分项目自费
  582. var otherCostTotal float64 = 0 //其他费用
  583. var otherCostSelfTotal float64 = 0 //其他费用
  584. var otherCostPartSelfTotal float64 = 0 //其他费用
  585. var otherSelfTotal float64 = 0 //床位部分项目自费
  586. var otherInscpTotal float64 = 0 //床位部分项目自费
  587. var materialCostTotal float64 = 0 //材料费
  588. var materialCostSelfTotal float64 = 0 //材料费
  589. var materialCostPartSelfTotal float64 = 0 //材料费
  590. var materialSelfTotal float64 = 0 //床位部分项目自费
  591. var materialInscpTotal float64 = 0 //床位部分项目自费
  592. var westernMedicineCostTotal float64 = 0 //西药费
  593. var westernMedicineCostSelfTotal float64 = 0 //西药费
  594. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  595. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  596. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  597. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  598. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  599. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  600. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  601. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  602. var checkCostTotal float64 = 0 //检查费
  603. var checkCostSelfTotal float64 = 0 //检查费
  604. var checkCostPartSelfTotal float64 = 0 //检查费
  605. var checkSelfTotal float64 = 0 //床位部分项目自费
  606. var checkInscpTotal float64 = 0 //床位部分项目自费
  607. var laboratoryCostTotal float64 = 0 //化验费
  608. var laboratoryCostSelfTotal float64 = 0 //化验费
  609. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  610. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  611. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  612. var treatCostTotal float64 = 0 //治疗费用
  613. var treatCostSelfTotal float64 = 0 //治疗费用
  614. var treatCostPartSelfTotal float64 = 0 //治疗费用
  615. var treatSelfTotal float64 = 0 //床位部分项目自费
  616. var treatInscpTotal float64 = 0 //床位部分项目自费
  617. decimal.DivisionPrecision = 2
  618. for _, item := range orderInfos {
  619. if item.MedChrgitmType == "01" { //床位费
  620. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  621. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  622. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  623. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  624. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  625. }
  626. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  627. if item.MedChrgitmType == "03" { //检查费
  628. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  629. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  630. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  631. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  632. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  633. }
  634. } else {
  635. if item.MedChrgitmType == "03" { //检查费
  636. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  637. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  638. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  639. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  640. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  641. }
  642. }
  643. if item.MedChrgitmType == "04" { //化验费
  644. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  645. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  646. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  647. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  648. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  649. }
  650. if item.MedChrgitmType == "05" { //治疗费
  651. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  652. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  653. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  654. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  655. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  656. }
  657. if item.MedChrgitmType == "06" { //手术费
  658. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  659. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  660. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  661. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  662. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  663. }
  664. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  665. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  666. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  667. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  668. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  669. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  670. }
  671. if item.MedChrgitmType == "09" { //西药费
  672. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  673. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  674. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  675. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  676. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  677. }
  678. if item.MedChrgitmType == "11" { //中成费
  679. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  680. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  681. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  682. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  683. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  684. }
  685. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  686. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  687. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  688. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  689. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  690. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  691. }
  692. }
  693. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  694. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  695. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  696. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  697. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  698. var doctor_name string
  699. if roles.ID == 0 {
  700. doctor_name = "管理员"
  701. } else {
  702. doctor_name = roles.UserName
  703. }
  704. yiliao_leibie := ""
  705. switch order.MedType {
  706. case "11":
  707. yiliao_leibie = "普通门诊"
  708. break
  709. case "12":
  710. yiliao_leibie = "门诊挂号"
  711. break
  712. case "13":
  713. yiliao_leibie = "急诊"
  714. break
  715. case "14":
  716. yiliao_leibie = "门诊特殊病"
  717. break
  718. case "15":
  719. yiliao_leibie = "门诊统筹"
  720. break
  721. case "16":
  722. yiliao_leibie = "门诊慢性病"
  723. break
  724. case "21":
  725. yiliao_leibie = "普通住院"
  726. break
  727. }
  728. c.ServeSuccessJSON(map[string]interface{}{
  729. "diagnosis": name,
  730. "order_infos": orderInfos,
  731. "number": order.MdtrtId,
  732. "date": order.SettleAccountsDate,
  733. "charge_admin": charge_admin,
  734. "printor_admin": printor_admin,
  735. "info": order,
  736. "order": order,
  737. "bedCostTotal": bedCostTotal,
  738. "bedCostSelfTotal": bedCostSelfTotal,
  739. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  740. "bedSelfTotal": bedSelfTotal,
  741. "bedInscpTotal": bedInscpTotal,
  742. "operationCostTotal": operationCostTotal,
  743. "operationCostSelfTotal": operationCostSelfTotal,
  744. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  745. "operationSelfTotal": operationSelfTotal,
  746. "operationInscpTotal": operationInscpTotal,
  747. "otherCostTotal": otherCostTotal,
  748. "otherCostSelfTotal": otherCostSelfTotal,
  749. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  750. "otherSelfTotal": otherSelfTotal,
  751. "otherInscpTotal": otherInscpTotal,
  752. "materialCostTotal": materialCostTotal,
  753. "materialCostSelfTotal": materialCostSelfTotal,
  754. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  755. "materialSelfTotal": materialSelfTotal,
  756. "materialInscpTotal": materialInscpTotal,
  757. "westernMedicineCostTotal": westernMedicineCostTotal,
  758. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  759. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  760. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  761. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  762. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  763. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  764. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  765. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  766. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  767. "checkCostTotal": checkCostTotal,
  768. "checkCostSelfTotal": checkCostSelfTotal,
  769. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  770. "checkSelfTotal": checkSelfTotal,
  771. "checkInscpTotal": checkInscpTotal,
  772. "laboratoryCostTotal": laboratoryCostTotal,
  773. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  774. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  775. "laboratorySelfTotal": laboratorySelfTotal,
  776. "laboratoryInscpTotal": laboratoryInscpTotal,
  777. "treatCostTotal": treatCostTotal,
  778. "treatCostSelfTotal": treatCostSelfTotal,
  779. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  780. "treatSelfTotal": treatSelfTotal,
  781. "treatInscpTotal": treatInscpTotal,
  782. "doctor_info": doctor_info,
  783. "doctor_name": doctor_name,
  784. "health_card_no": order.PsnNo,
  785. "yiliao_leibie": yiliao_leibie,
  786. "patient": patient,
  787. "org_name": miConfig.OrgName,
  788. "org_code": miConfig.Code,
  789. "order_number": order.Number,
  790. "his_hospital": his_hospital,
  791. "dia_config": dia_config,
  792. })
  793. }
  794. func (c *PublicApiController) GetBaiLinExportData() {
  795. data := service.GetBaiLinOrderData()
  796. fmt.Println(len(data))
  797. var new_data []*models.NewCustomHisOrder
  798. for _, item := range data {
  799. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  800. new_data = append(new_data, item)
  801. }
  802. }
  803. fmt.Println(len(new_data))
  804. c.ServeSuccessJSON(map[string]interface{}{
  805. "list": new_data,
  806. })
  807. }
  808. func (c *HisApiController) GetHisUnChargePatientList() {
  809. record_date := c.GetString("record_date")
  810. sch_type, _ := c.GetInt64("sch_type")
  811. timeLayout := "2006-01-02"
  812. loc, _ := time.LoadLocation("Local")
  813. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  814. if err != nil {
  815. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  816. return
  817. }
  818. recordDateTime := theTime.Unix()
  819. adminInfo := c.GetAdminUserInfo()
  820. var tempPatients []*service.NewTempPatients
  821. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  822. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  823. var patients []*service.NewTempPatients
  824. var patients_two []*service.NewTempPatients
  825. for _, item := range tempPatients {
  826. //过滤掉没挂号的和没开处方的
  827. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  828. patients = append(patients, item)
  829. }
  830. //过滤掉没挂号的
  831. if len(item.HisPatient) > 0 {
  832. patients_two = append(patients_two, item)
  833. }
  834. }
  835. c.ServeSuccessJSON(map[string]interface{}{
  836. "list": patients,
  837. "list_two": patients_two,
  838. })
  839. }
  840. func (c *HisApiController) GetPrivateExpensesOrder() {
  841. //id, _ := c.GetInt64("id")
  842. //record_time := c.GetString("record_time")
  843. order_id, _ := c.GetInt64("order_id")
  844. admin_user_id, _ := c.GetInt64("admin_user_id")
  845. //timeLayout := "2006-01-02"
  846. //loc, _ := time.LoadLocation("Local")
  847. //
  848. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  849. //if err != nil {
  850. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  851. // return
  852. //}
  853. //recordDateTime := theTime.Unix()
  854. adminUser := c.GetAdminUserInfo()
  855. order, _ := service.GetHisOrderByID(order_id)
  856. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  857. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  858. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  859. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  860. //var config []*models.HisXtDiagnoseConfig
  861. var name string
  862. if order.PType == 1 {
  863. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  864. for _, item := range diagnosis_ids {
  865. id, _ := strconv.ParseInt(item, 10, 64)
  866. diagnosisConfig, _ := service.FindDiagnoseById(id)
  867. if len(name) == 0 {
  868. name = diagnosisConfig.ClassName
  869. } else {
  870. name = name + "," + diagnosisConfig.ClassName
  871. }
  872. }
  873. } else {
  874. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  875. for _, item := range diagnosis_ids {
  876. id, _ := strconv.ParseInt(item, 10, 64)
  877. diagnosisConfig, _ := service.FindDiagnoseById(id)
  878. if len(name) == 0 {
  879. name = diagnosisConfig.ClassName
  880. } else {
  881. name = name + "," + diagnosisConfig.ClassName
  882. }
  883. }
  884. }
  885. var bedCostTotal float64 = 0 //床位总费
  886. //var bedCostSelfTotal float64 = 0 //床位自费
  887. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  888. var operationCostTotal float64 = 0 //手术费
  889. //var operationCostSelfTotal float64 = 0 //手术费
  890. var operationCostPartSelfTotal float64 = 0 //手术费
  891. var otherCostTotal float64 = 0 //其他费用
  892. //var otherCostSelfTotal float64 = 0 //其他费用
  893. var otherCostPartSelfTotal float64 = 0 //其他费用
  894. var materialCostTotal float64 = 0 //材料费
  895. //var materialCostSelfTotal float64 = 0 //材料费
  896. var materialCostPartSelfTotal float64 = 0 //材料费
  897. var westernMedicineCostTotal float64 = 0 //西药费
  898. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  899. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  900. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  901. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  902. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  903. var checkCostTotal float64 = 0 //检查费
  904. //var checkCostSelfTotal float64 = 0 //检查费
  905. var checkCostPartSelfTotal float64 = 0 //检查费
  906. var laboratoryCostTotal float64 = 0 //化验费
  907. //var laboratoryCostSelfTotal float64 = 0 //化验费
  908. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  909. var treatCostTotal float64 = 0 //治疗费用
  910. //var treatCostSelfTotal float64 = 0 //治疗费用
  911. var treatCostPartSelfTotal float64 = 0 //治疗费用
  912. var zhenChaCostTotal float64 = 0 //其他费用
  913. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  914. decimal.DivisionPrecision = 2
  915. for _, item := range orderInfos {
  916. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  917. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  918. item.MedChrgitmType = "09"
  919. }
  920. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  921. if item.HisPrescriptionProject.Type == 2 {
  922. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  923. fmt.Println("CostClassify")
  924. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  925. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  926. case 0:
  927. item.MedChrgitmType = "0"
  928. break
  929. case 1:
  930. item.MedChrgitmType = "14"
  931. break
  932. case 2:
  933. item.MedChrgitmType = "05"
  934. break
  935. case 3:
  936. item.MedChrgitmType = "03"
  937. break
  938. case 4:
  939. item.MedChrgitmType = "03"
  940. break
  941. case 5:
  942. item.MedChrgitmType = "08"
  943. break
  944. case 6:
  945. item.MedChrgitmType = "14"
  946. break
  947. case 7:
  948. item.MedChrgitmType = "14"
  949. break
  950. case 8:
  951. item.MedChrgitmType = "03"
  952. break
  953. case 9:
  954. item.MedChrgitmType = "14"
  955. break
  956. case 10:
  957. item.MedChrgitmType = "14"
  958. break
  959. case 11:
  960. item.MedChrgitmType = "06"
  961. break
  962. case 12:
  963. item.MedChrgitmType = "12"
  964. break
  965. case 13:
  966. item.MedChrgitmType = "01"
  967. break
  968. case 14:
  969. item.MedChrgitmType = "04"
  970. break
  971. case 15:
  972. item.MedChrgitmType = "14"
  973. break
  974. }
  975. } else {
  976. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  977. case 1:
  978. item.MedChrgitmType = "14"
  979. break
  980. case 2:
  981. item.MedChrgitmType = "05"
  982. break
  983. case 3:
  984. item.MedChrgitmType = "04"
  985. break
  986. case 4:
  987. item.MedChrgitmType = "14"
  988. break
  989. case 5:
  990. item.MedChrgitmType = "08"
  991. break
  992. case 6:
  993. item.MedChrgitmType = "14"
  994. break
  995. case 7:
  996. item.MedChrgitmType = "14"
  997. break
  998. case 8:
  999. item.MedChrgitmType = "03"
  1000. break
  1001. case 9:
  1002. item.MedChrgitmType = "14"
  1003. break
  1004. default:
  1005. item.MedChrgitmType = "14"
  1006. break
  1007. }
  1008. }
  1009. } else if item.HisPrescriptionProject.Type == 3 {
  1010. item.MedChrgitmType = "08"
  1011. }
  1012. }
  1013. }
  1014. order.PsnCashPay = order.MedfeeSumamt
  1015. for _, item := range orderInfos {
  1016. if item.MedChrgitmType == "01" { //床位费
  1017. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1018. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1019. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1020. }
  1021. if item.MedChrgitmType == "02" { //诊察费
  1022. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1023. //zhenChaCostSelfTotal = zhenChaCostTotal
  1024. }
  1025. if item.MedChrgitmType == "03" { //检查费
  1026. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //检查费
  1031. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1033. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1034. }
  1035. if item.MedChrgitmType == "04" { //化验费
  1036. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1037. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1038. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1039. }
  1040. if item.MedChrgitmType == "05" { //治疗费
  1041. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "06" { //手术费
  1046. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1051. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "09" { //西药费
  1056. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "11" { //中成费
  1061. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1066. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. }
  1071. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1072. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1073. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1074. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1075. c.ServeSuccessJSON(map[string]interface{}{
  1076. "patient": patient,
  1077. "order_infos": orderInfos,
  1078. "diagnosis": name,
  1079. "bedCostTotal": bedCostTotal,
  1080. "bedCostSelfTotal": bedCostTotal,
  1081. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1082. "operationCostTotal": operationCostTotal,
  1083. "operationCostSelfTotal": operationCostTotal,
  1084. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1085. "otherCostTotal": otherCostTotal,
  1086. "otherCostSelfTotal": otherCostTotal,
  1087. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1088. "materialCostTotal": materialCostTotal,
  1089. "materialCostSelfTotal": materialCostTotal,
  1090. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1091. "westernMedicineCostTotal": westernMedicineCostTotal,
  1092. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1093. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1094. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1095. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1096. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1097. "checkCostTotal": checkCostTotal,
  1098. "checkCostSelfTotal": checkCostTotal,
  1099. "zhenChaCostTotal": zhenChaCostTotal,
  1100. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1101. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1102. "laboratoryCostTotal": laboratoryCostTotal,
  1103. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1104. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1105. "treatCostTotal": treatCostTotal,
  1106. "treatCostSelfTotal": treatCostTotal,
  1107. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1108. "charge_admin": charge_admin,
  1109. "printor_admin": printor_admin,
  1110. "org_name": org.OrgName,
  1111. "org_code": miConfig.Code,
  1112. "name": patient.Name,
  1113. "number": order.MdtrtId,
  1114. "date": order.SettleAccountsDate,
  1115. "info": order,
  1116. "his_hospital": his_hospital,
  1117. "his": his,
  1118. })
  1119. }
  1120. func (c *HisApiController) RefudDetail() {
  1121. order_id, _ := c.GetInt64("order_id")
  1122. order, _ := service.GetHisOrderByID(order_id)
  1123. adminUser := c.GetAdminUserInfo()
  1124. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1125. c.ServeSuccessJSON(map[string]interface{}{
  1126. "msg": "撤销成功",
  1127. })
  1128. }
  1129. func (c *HisApiController) Sscard() {
  1130. //r := CardInit()
  1131. //if r == 0 {
  1132. // GetBaseInfo()
  1133. //}
  1134. //c.ServeSuccessJSON(map[string]interface{}{
  1135. // "list": "11",
  1136. //})
  1137. }
  1138. func GetBaseInfo() error {
  1139. //handle := syscall.MustLoadDLL("SSCard.dll")
  1140. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1141. //
  1142. //str := make([]byte, 256)
  1143. //str1 := make([]byte, 256)
  1144. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1145. //if ferr != nil {
  1146. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1147. // return ferr
  1148. //}
  1149. //
  1150. //fmt.Println(string(str))
  1151. //
  1152. //fmt.Println(r)
  1153. return nil
  1154. }
  1155. func CardInit() int {
  1156. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1157. //add := DllTestDef.MustFindProc("Init")
  1158. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1159. //if err != nil {
  1160. // fmt.Println("SSCard的运算结果为:", ret)
  1161. //}
  1162. //result := int(ret)
  1163. return 0
  1164. }
  1165. func IntPtr(n int) uintptr {
  1166. return uintptr(n)
  1167. }
  1168. func StrPtr(s string) uintptr {
  1169. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1170. }
  1171. func (c *HisApiController) GetHisPatientList() {
  1172. //types, _ := c.GetInt64("type", 0)
  1173. record_date := c.GetString("record_date")
  1174. sch_type, _ := c.GetInt64("sch_type")
  1175. timeLayout := "2006-01-02"
  1176. loc, _ := time.LoadLocation("Local")
  1177. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1178. if err != nil {
  1179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1180. return
  1181. }
  1182. recordDateTime := theTime.Unix()
  1183. adminInfo := c.GetAdminUserInfo()
  1184. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1185. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1186. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1187. //获取当前用户的信息
  1188. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1189. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1190. //获取所有科室信息
  1191. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1192. c.ServeSuccessJSON(map[string]interface{}{
  1193. "list": patients,
  1194. "list_two": patients_two,
  1195. "info": adminUserInfo,
  1196. "doctors": doctors,
  1197. "department": department,
  1198. })
  1199. }
  1200. type CustomTemplate struct {
  1201. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1202. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1203. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1204. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1205. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1206. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1207. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1208. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1209. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1210. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1211. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1212. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1213. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1214. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1215. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1216. }
  1217. func (c *HisApiController) GetHisPatientInfo() {
  1218. patient_id, _ := c.GetInt64("patient_id")
  1219. his_patient_id, _ := c.GetInt64("his_patient_id")
  1220. record_date := c.GetString("record_date")
  1221. number := c.GetString("number")
  1222. //start_time := c.GetString("start_time")
  1223. //end_time := c.GetString("end_time")
  1224. p_type, _ := c.GetInt64("p_type")
  1225. timeLayout := "2006-01-02"
  1226. loc, _ := time.LoadLocation("Local")
  1227. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1228. if err != nil {
  1229. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1230. return
  1231. }
  1232. recordDateTime := theTime.Unix()
  1233. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1234. //if err != nil {
  1235. //
  1236. //}
  1237. //startRecordDateTime := startTime.Unix()
  1238. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1239. //if err != nil {
  1240. //
  1241. //}
  1242. //endRecordDateTime := endTime.Unix()
  1243. admin := c.GetAdminUserInfo()
  1244. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1245. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1246. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1247. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1248. var prescriptions []*models.HisPrescription
  1249. var last_prescriptions []*models.HisPrescription
  1250. var sch_prescriptions []CustomTemplate
  1251. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1252. if p_type == 1 { //住院
  1253. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1254. for _, item := range prescriptions {
  1255. for _, subItem := range item.HisDoctorAdviceInfo {
  1256. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1257. if info.RetailPrice > 0 {
  1258. subItem.Drug.MinPrice = info.RetailPrice
  1259. }
  1260. }
  1261. }
  1262. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1263. } else { //门诊
  1264. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1265. for _, item := range prescriptions {
  1266. for _, subItem := range item.HisDoctorAdviceInfo {
  1267. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1268. if info.RetailPrice > 0 {
  1269. subItem.Drug.MinPrice = info.RetailPrice
  1270. }
  1271. }
  1272. }
  1273. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1274. }
  1275. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1276. if sch.ID > 0 {
  1277. var week string
  1278. t := time.Now()
  1279. switch t.Weekday().String() {
  1280. case "Monday":
  1281. week = "周一"
  1282. break
  1283. case "Tuesday":
  1284. week = "周二"
  1285. break
  1286. case "Wednesday":
  1287. week = "周三"
  1288. break
  1289. case "Thursday":
  1290. week = "周四"
  1291. break
  1292. case "Friday":
  1293. week = "周五"
  1294. break
  1295. case "Saturday":
  1296. week = "周六"
  1297. break
  1298. case "Sunday":
  1299. week = "周日"
  1300. break
  1301. }
  1302. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1303. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1304. //根据推送频率组装新的数组
  1305. for _, item := range temp_sch_prescriptions {
  1306. var cus CustomTemplate
  1307. cus.ID = item.ID
  1308. cus.UserOrgId = item.UserOrgId
  1309. cus.PatientId = item.PatientId
  1310. cus.MedType = item.MedType
  1311. cus.RecordDate = item.RecordDate
  1312. cus.Type = item.Type
  1313. cus.PType = item.PType
  1314. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1315. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1316. if subItem.FrequencyType == 1 { //每次必推
  1317. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1318. }
  1319. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1320. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1321. }
  1322. if subItem.FrequencyType == 2 { //按照天数频率
  1323. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1324. now := p.Unix()
  1325. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1326. dayStr2 := "-" + dayStr
  1327. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1328. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1329. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1330. if len(advices) == 0 {
  1331. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1332. }
  1333. }
  1334. }
  1335. }
  1336. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1337. if subItem.Type == 2 {
  1338. if subItem.XtHisProject.MedicalStatus != 1 {
  1339. if subItem.FrequencyType == 1 {
  1340. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1341. }
  1342. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1343. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 2 {
  1346. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1347. now := p.Unix()
  1348. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1349. dayStr2 := "-" + dayStr
  1350. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1351. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1352. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1353. if len(projects) == 0 {
  1354. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1355. }
  1356. }
  1357. }
  1358. } else if subItem.Type == 3 {
  1359. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1360. if subItem.FrequencyType == 1 {
  1361. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1362. }
  1363. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1364. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1365. }
  1366. if subItem.FrequencyType == 2 {
  1367. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1368. now := p.Unix()
  1369. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1370. dayStr2 := "-" + dayStr
  1371. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1372. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1373. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1374. if len(projects) == 0 {
  1375. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1376. }
  1377. }
  1378. }
  1379. }
  1380. }
  1381. sch_prescriptions = append(sch_prescriptions, cus)
  1382. }
  1383. for _, item := range sch_prescriptions {
  1384. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1385. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1386. }
  1387. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1388. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1389. }
  1390. }
  1391. }
  1392. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1393. if config.ID > 0 && config.IsOpen == 1 {
  1394. for _, item := range sch_prescriptions {
  1395. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1396. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1397. if info.RetailPrice > 0 {
  1398. subItem.Drug.MinPrice = info.RetailPrice
  1399. }
  1400. }
  1401. }
  1402. }
  1403. if config.ID > 0 && config.IsOpen == 1 {
  1404. for _, item := range sch_prescriptions {
  1405. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1406. if subItem.Type == 3 {
  1407. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1408. if info.Price > 0 {
  1409. subItem.GoodInfo.PackingPrice = info.Price
  1410. }
  1411. }
  1412. }
  1413. }
  1414. }
  1415. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1416. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1417. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1418. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1419. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1420. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1421. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1422. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1423. //获取所有科室信息
  1424. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1425. c.ServeSuccessJSON(map[string]interface{}{
  1426. "his_info": his_patient_info,
  1427. "xt_info": xt_patient_info,
  1428. "prescription": prescriptions,
  1429. "case_history": case_history,
  1430. "info": patientPrescriptionInfo,
  1431. //"month_prescriptions": monthPrescriptions,
  1432. "order": order,
  1433. "doctors": doctors,
  1434. "department": department,
  1435. "sch_prescriptions": sch_prescriptions,
  1436. "last_prescriptions": last_prescriptions,
  1437. "schedule": sch,
  1438. "count": count,
  1439. "drugStockConfig": drugStockConfig,
  1440. "last_info": lastPatientPrescriptionInfo,
  1441. })
  1442. return
  1443. }
  1444. func (c *HisApiController) GetHisPrescriptionConfig() {
  1445. adminInfo := c.GetAdminUserInfo()
  1446. //获取医嘱模版
  1447. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1448. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1449. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1450. //获取所有基础药
  1451. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1452. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1453. if config.ID > 0 && config.IsOpen == 1 {
  1454. for _, item := range drugs {
  1455. var index = 0
  1456. for _, subItem := range item.OtherDrugWarehouseInfo {
  1457. if index == 0 {
  1458. index = index + 1
  1459. if subItem.RetailPrice > 0 {
  1460. item.MinPrice = subItem.RetailPrice
  1461. }
  1462. }
  1463. }
  1464. }
  1465. }
  1466. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1467. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1468. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1469. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1470. //获取所有科室信息
  1471. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1472. //获取诊断信息
  1473. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1474. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1475. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1476. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1477. //获取是否开启保存耗材出库的开关
  1478. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1479. c.ServeSuccessJSON(map[string]interface{}{
  1480. "drugs": drugs,
  1481. "advices_template": advices,
  1482. "drugways": drugways,
  1483. "efs": efs,
  1484. "doctors": doctors,
  1485. "department": department,
  1486. "sick": sick,
  1487. "additions": additions,
  1488. "diagnose": diagnose,
  1489. "manufacturers": manufacturers,
  1490. "goodOutOpen": goodOutOpen,
  1491. "patientDiagnose": patientDiagnose,
  1492. })
  1493. }
  1494. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1495. //获取所有基础药
  1496. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1497. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1498. if config.ID > 0 && config.IsOpen == 1 {
  1499. for _, item := range drugs {
  1500. var index = 0
  1501. for _, subItem := range item.OtherDrugWarehouseInfo {
  1502. if index == 0 {
  1503. index = index + 1
  1504. if subItem.RetailPrice > 0 {
  1505. item.MinPrice = subItem.RetailPrice
  1506. }
  1507. }
  1508. }
  1509. }
  1510. }
  1511. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1512. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1513. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1514. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1515. //获取所有科室信息
  1516. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1517. //获取诊断信息
  1518. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1519. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1520. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1521. //获取是否开启保存耗材出库的开关
  1522. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1523. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1524. c.ServeSuccessJSON(map[string]interface{}{
  1525. "drugs": drugs,
  1526. "advices_template": advices,
  1527. "drugways": drugways,
  1528. "efs": efs,
  1529. "doctors": doctors,
  1530. "department": department,
  1531. "sick": sick,
  1532. "additions": additions,
  1533. "diagnose": diagnose,
  1534. "manufacturers": manufacturers,
  1535. "goodOutOpen": goodOutOpen,
  1536. "patientDiagnose": patientDiagnose,
  1537. })
  1538. }
  1539. }
  1540. func (c *HisApiController) CreateHisPrescription() {
  1541. record_date := c.GetString("record_date")
  1542. patient_id, _ := c.GetInt64("patient_id")
  1543. reg_type, _ := c.GetInt64("reg_type")
  1544. diagnose := c.GetString("diagnose")
  1545. sick_type, _ := c.GetInt64("sick_type")
  1546. sick_history := c.GetString("sick_history")
  1547. doctor_id, _ := c.GetInt64("doctor", 0)
  1548. department, _ := c.GetInt64("department", 0)
  1549. his_patient_id, _ := c.GetInt64("his_patient_id")
  1550. p_type, _ := c.GetInt64("p_type")
  1551. patient_diagnose := c.GetString("patient_diagnose")
  1552. dataBody := make(map[string]interface{}, 0)
  1553. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1554. if err != nil {
  1555. utils.ErrorLog(err.Error())
  1556. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1557. return
  1558. }
  1559. timeLayout := "2006-01-02"
  1560. loc, _ := time.LoadLocation("Local")
  1561. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1562. if err != nil {
  1563. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1564. return
  1565. }
  1566. adminInfo := c.GetAdminUserInfo()
  1567. recordDateTime := theTime.Unix()
  1568. //查询默认出库仓库库存
  1569. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1570. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1571. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1572. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1573. if len(lists) == 1 {
  1574. his_patient_id = lists[0].ID
  1575. }
  1576. }
  1577. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1578. //保存处方出库
  1579. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1580. //自动出库
  1581. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1582. //耗材保存处方出库
  1583. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1584. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1585. //已发药和已收费限制逻辑
  1586. isMidicine := false
  1587. isCharge := false
  1588. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1589. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1590. if len(prescriptions) > 0 {
  1591. for _, item := range prescriptions {
  1592. items := item.(map[string]interface{})
  1593. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1594. utils.ErrorLog("id")
  1595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1596. return
  1597. }
  1598. id := int64(items["id"].(float64))
  1599. if id > 0 {
  1600. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1601. if err != nil {
  1602. if new_prescription.OrderStatus == 4 {
  1603. isCharge = true
  1604. }
  1605. }
  1606. }
  1607. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1608. advices := items["advices"].([]interface{})
  1609. if len(advices) > 0 {
  1610. for _, advice := range advices {
  1611. var adviceId int64
  1612. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1613. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1614. }
  1615. if adviceId > 0 {
  1616. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1617. if err == nil {
  1618. if his_advice_info.IsMedicine == 1 {
  1619. isMidicine = true
  1620. }
  1621. }
  1622. }
  1623. }
  1624. }
  1625. }
  1626. }
  1627. }
  1628. }
  1629. if isMidicine == true {
  1630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1631. return
  1632. }
  1633. if isCharge == true {
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1635. return
  1636. }
  1637. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1638. //药品发药出库
  1639. if pharmacyConfig.IsOpen == 1 {
  1640. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1641. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1642. if len(prescriptions) > 0 {
  1643. for _, item := range prescriptions {
  1644. items := item.(map[string]interface{})
  1645. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1646. advices := items["advices"].([]interface{})
  1647. if len(advices) > 0 {
  1648. for _, advice := range advices {
  1649. var drug_id int64
  1650. var prescribing_number float64
  1651. var prescribingNumberUnit string
  1652. var adviceId int64
  1653. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1654. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1655. }
  1656. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1657. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1658. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1659. }
  1660. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1661. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1662. }
  1663. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1664. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1665. }
  1666. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1667. if drug.ID == 0 {
  1668. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1669. return
  1670. }
  1671. //查询药品的所有库存
  1672. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1673. var total_count int64
  1674. for _, it := range list {
  1675. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1676. }
  1677. totals := strconv.FormatInt(total_count, 10)
  1678. //查询该药品是否存在开药记录
  1679. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1680. fmt.Println("wooooooooooooo", advicelist.ID)
  1681. fmt.Println("prescribingNumberUnit", prescribingNumberUnit)
  1682. fmt.Println("prescribingNumberUnit", drug.MinUnit)
  1683. fmt.Println("prescribingNumberUnit", drug.MaxUnit)
  1684. //新增处方
  1685. if advicelist.ID == 0 {
  1686. all_count, _ := strconv.ParseFloat(totals, 64)
  1687. if prescribingNumberUnit == drug.MinUnit {
  1688. fmt.Println("prescribing_number", prescribing_number)
  1689. fmt.Println("all_count", all_count)
  1690. if drug.IsUse != 1 {
  1691. if drug.IsProject == 0 || drug.IsProject == 2 {
  1692. if all_count == 0 {
  1693. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1694. return
  1695. }
  1696. if prescribing_number > all_count {
  1697. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1698. return
  1699. }
  1700. }
  1701. }
  1702. }
  1703. if prescribingNumberUnit == drug.MaxUnit {
  1704. num := prescribing_number * float64(drug.MinNumber)
  1705. if drug.IsUse != 1 {
  1706. if drug.IsProject == 0 || drug.IsProject == 2 {
  1707. if all_count == 0 {
  1708. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1709. return
  1710. }
  1711. if num > all_count {
  1712. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1713. return
  1714. }
  1715. }
  1716. }
  1717. }
  1718. }
  1719. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1720. if drugOutConfig.IsOpen != 1 {
  1721. //修改处方
  1722. for _, advice := range advices {
  1723. var drug_id int64
  1724. var prescribing_number float64
  1725. var prescribingNumberUnit string
  1726. var prescribingNumber string
  1727. var adviceId int64
  1728. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1729. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1730. }
  1731. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1732. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1733. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1734. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1735. }
  1736. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1737. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1738. }
  1739. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1740. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1741. }
  1742. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1743. if drug.ID == 0 {
  1744. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1745. return
  1746. }
  1747. //查询药品的所有库存
  1748. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1749. var total_count int64
  1750. for _, it := range list {
  1751. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1752. }
  1753. totals := strconv.FormatInt(total_count, 10)
  1754. //查询该药品是否存在开药记录
  1755. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1756. //新增处方
  1757. if advicelist.ID == 0 {
  1758. all_count, _ := strconv.ParseFloat(totals, 64)
  1759. if prescribingNumberUnit == drug.MinUnit {
  1760. if drug.IsUse != 1 {
  1761. if drug.IsProject == 0 || drug.IsProject == 2 {
  1762. if all_count == 0 {
  1763. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1764. return
  1765. }
  1766. if prescribing_number > all_count {
  1767. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1768. return
  1769. }
  1770. }
  1771. }
  1772. } else {
  1773. if prescribingNumberUnit == drug.MaxUnit {
  1774. num := prescribing_number * float64(drug.MinNumber)
  1775. if drug.IsUse != 1 {
  1776. if drug.IsProject == 0 || drug.IsProject == 2 {
  1777. if all_count == 0 {
  1778. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1779. return
  1780. }
  1781. if num > all_count {
  1782. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1783. return
  1784. }
  1785. }
  1786. }
  1787. }
  1788. }
  1789. }
  1790. //修改处方
  1791. if advicelist.ID > 0 {
  1792. var device_number int64
  1793. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1794. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1795. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1796. device_number = prescribingNumberInt * drug.MinNumber
  1797. }
  1798. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1799. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1800. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1801. device_number = prescribingNumberInt
  1802. }
  1803. var number_count int64
  1804. if prescribingNumberUnit == drug.MaxUnit {
  1805. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1806. number_count = prescribingNumberInt * drug.MinNumber
  1807. }
  1808. if prescribingNumberUnit == drug.MinUnit {
  1809. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1810. number_count = prescribingNumberInt
  1811. }
  1812. //如果修改的数量大于之前修改的数量
  1813. if (number_count - device_number) > 0 {
  1814. //如果修改的差数量 大于库存数量
  1815. if drug.IsUse != 1 {
  1816. if (number_count - device_number) > total_count {
  1817. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1818. return
  1819. }
  1820. }
  1821. }
  1822. }
  1823. }
  1824. }
  1825. }
  1826. }
  1827. }
  1828. }
  1829. }
  1830. }
  1831. }
  1832. //已发药和已收费限制逻辑
  1833. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1834. //校验库存总量
  1835. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1836. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1837. if len(prescriptions) > 0 {
  1838. for _, item := range prescriptions {
  1839. items := item.(map[string]interface{})
  1840. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1841. advices := items["advices"].([]interface{})
  1842. if len(advices) > 0 {
  1843. for _, advice := range advices {
  1844. var drug_id int64
  1845. var prescribing_number float64
  1846. var prescribingNumberUnit string
  1847. var adviceId int64
  1848. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1849. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1850. }
  1851. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1852. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1853. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1854. }
  1855. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1856. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1857. }
  1858. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1859. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1860. }
  1861. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1862. if drug.ID == 0 {
  1863. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1864. return
  1865. }
  1866. //查询药品的所有库存
  1867. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1868. var total_count int64
  1869. for _, it := range list {
  1870. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1871. }
  1872. totals := strconv.FormatInt(total_count, 10)
  1873. //查询该药品是否存在开药记录
  1874. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1875. //查询最新批次库存
  1876. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1877. var batch_number_count int64
  1878. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1879. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1880. //新增处方
  1881. if advicelist.ID == 0 {
  1882. all_count, _ := strconv.ParseFloat(totals, 64)
  1883. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1884. if prescribingNumberUnit == drug.MinUnit {
  1885. if drug.IsUse != 1 {
  1886. if drug.IsProject == 0 || drug.IsProject == 2 {
  1887. if all_count == 0 {
  1888. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1889. return
  1890. }
  1891. if prescribing_number > all_count {
  1892. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1893. return
  1894. }
  1895. }
  1896. if adminInfo.CurrentOrgId == 10215 {
  1897. if prescribing_number > batch_number_all_count {
  1898. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1899. return
  1900. }
  1901. }
  1902. }
  1903. }
  1904. if prescribingNumberUnit == drug.MaxUnit {
  1905. num := prescribing_number * float64(drug.MinNumber)
  1906. if drug.IsUse != 1 {
  1907. if drug.IsProject == 0 || drug.IsProject == 2 {
  1908. if all_count == 0 {
  1909. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1910. return
  1911. }
  1912. if num > all_count {
  1913. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1914. return
  1915. }
  1916. }
  1917. if adminInfo.CurrentOrgId == 10215 {
  1918. if num > batch_number_all_count {
  1919. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1920. return
  1921. }
  1922. }
  1923. }
  1924. }
  1925. }
  1926. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1927. if drugOutConfig.IsOpen != 1 {
  1928. //修改处方
  1929. for _, advice := range advices {
  1930. var drug_id int64
  1931. var prescribing_number float64
  1932. var prescribingNumberUnit string
  1933. var prescribingNumber string
  1934. var adviceId int64
  1935. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1936. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1937. }
  1938. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1939. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1940. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1941. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1942. }
  1943. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1944. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1945. }
  1946. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1947. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1948. }
  1949. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1950. if drug.ID == 0 {
  1951. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1952. return
  1953. }
  1954. //查询药品的所有库存
  1955. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1956. var total_count int64
  1957. for _, it := range list {
  1958. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1959. }
  1960. totals := strconv.FormatInt(total_count, 10)
  1961. //查询该药品是否存在开药记录
  1962. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1963. //新增处方
  1964. if advicelist.ID == 0 {
  1965. //查询最新批次库存
  1966. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1967. var batch_number_count int64
  1968. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1969. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1970. all_count, _ := strconv.ParseFloat(totals, 64)
  1971. if prescribingNumberUnit == drug.MinUnit {
  1972. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1973. if drug.IsUse != 1 {
  1974. if drug.IsProject == 0 || drug.IsProject == 2 {
  1975. if all_count == 0 {
  1976. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1977. return
  1978. }
  1979. if prescribing_number > all_count {
  1980. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1981. return
  1982. }
  1983. }
  1984. if adminInfo.CurrentOrgId == 10215 {
  1985. if prescribing_number > batch_number_all_count {
  1986. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1987. return
  1988. }
  1989. }
  1990. }
  1991. } else {
  1992. if prescribingNumberUnit == drug.MaxUnit {
  1993. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1994. num := prescribing_number * float64(drug.MinNumber)
  1995. if drug.IsUse != 1 {
  1996. if drug.IsProject == 0 || drug.IsProject == 2 {
  1997. if all_count == 0 {
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1999. return
  2000. }
  2001. if num > all_count {
  2002. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2003. return
  2004. }
  2005. }
  2006. if adminInfo.CurrentOrgId == 10215 {
  2007. if prescribing_number > batch_number_all_count {
  2008. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2009. return
  2010. }
  2011. }
  2012. }
  2013. }
  2014. }
  2015. }
  2016. //修改处方
  2017. if advicelist.ID > 0 {
  2018. //查询最新批次库存
  2019. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2020. var batch_number_count int64
  2021. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2022. var device_number int64
  2023. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2024. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2025. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2026. device_number = prescribingNumberInt * drug.MinNumber
  2027. }
  2028. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2029. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2030. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2031. device_number = prescribingNumberInt
  2032. }
  2033. var number_count int64
  2034. if prescribingNumberUnit == drug.MaxUnit {
  2035. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2036. number_count = prescribingNumberInt * drug.MinNumber
  2037. }
  2038. if prescribingNumberUnit == drug.MinUnit {
  2039. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2040. number_count = prescribingNumberInt
  2041. }
  2042. //如果修改的数量大于之前修改的数量
  2043. if (number_count - device_number) > 0 {
  2044. //如果修改的差数量 大于库存数量
  2045. if drug.IsUse != 1 {
  2046. if drug.IsProject == 0 || drug.IsProject == 2 {
  2047. if total_count == 0 {
  2048. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2049. return
  2050. }
  2051. if (number_count - device_number) > total_count {
  2052. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2053. return
  2054. }
  2055. if (number_count - device_number) > batch_number_count {
  2056. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2057. return
  2058. }
  2059. }
  2060. if adminInfo.CurrentOrgId == 10215 {
  2061. // 查询该药品最后一次出库记录
  2062. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2063. var out_count int64
  2064. var in_count int64
  2065. var stock_max_number int64
  2066. var stock_min_number int64
  2067. for _, it := range outInfo {
  2068. if it.CountUnit == drug.MaxUnit {
  2069. it.Count = it.Count * drug.MinNumber
  2070. }
  2071. out_count += it.Count
  2072. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2073. stock_max_number = warehouseInfoList.StockMaxNumber
  2074. stock_min_number = warehouseInfoList.StockMinNumber
  2075. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2076. }
  2077. if out_count > 0 {
  2078. if (number_count - device_number) > in_count {
  2079. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2080. return
  2081. }
  2082. }
  2083. // 未出库
  2084. if out_count == 0 {
  2085. var sum_in_count int64
  2086. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2087. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2088. fmt.Println("sum_in_count", sum_in_count)
  2089. //如果修改的数量大于有库存的第一个批次
  2090. if number_count > sum_in_count {
  2091. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2092. return
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2099. if pharmacyConfig.IsOpen != 1 {
  2100. if device_number != number_count {
  2101. // 查询该药品最后一次出库记录
  2102. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2103. //回退库存
  2104. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2105. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2106. }
  2107. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2108. var stock_max_number int64
  2109. var stock_min_number int64
  2110. if number_count >= drug.MinNumber {
  2111. stock_max_number = device_number / drug.MinNumber
  2112. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2113. stock_min_number = device_number % drug.MinNumber
  2114. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2115. } else {
  2116. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2117. }
  2118. }
  2119. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2120. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2121. }
  2122. //删除记录
  2123. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2124. //查询默认仓库剩余多少库存
  2125. var sum_count int64
  2126. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2127. for _, its := range stockInfo {
  2128. if its.MaxUnit == drug.MaxUnit {
  2129. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2130. }
  2131. sum_count += its.StockMaxNumber + its.StockMinNumber
  2132. }
  2133. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2134. }
  2135. }
  2136. }
  2137. }
  2138. }
  2139. //保存处方开药
  2140. if drugOutConfig.IsOpen == 1 {
  2141. //修改处方
  2142. for _, advice := range advices {
  2143. var drug_id int64
  2144. var prescribing_number float64
  2145. var prescribingNumberUnit string
  2146. var prescribingNumber string
  2147. var adviceId int64
  2148. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2149. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2150. }
  2151. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2152. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2153. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2154. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2155. }
  2156. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2157. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2158. }
  2159. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2160. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2161. }
  2162. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2163. if drug.ID == 0 {
  2164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2165. return
  2166. }
  2167. //查询药品的所有库存
  2168. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2169. var total_count int64
  2170. for _, it := range list {
  2171. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2172. }
  2173. totals := strconv.FormatInt(total_count, 10)
  2174. //查询该药品是否存在开药记录
  2175. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2176. //新增处方
  2177. if advicelist.ID == 0 {
  2178. //查询最新批次库存
  2179. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2180. var batch_number_count int64
  2181. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2182. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2183. all_count, _ := strconv.ParseFloat(totals, 64)
  2184. if prescribingNumberUnit == drug.MinUnit {
  2185. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2186. if drug.IsUse != 1 {
  2187. if drug.IsProject == 0 || drug.IsProject == 2 {
  2188. if all_count == 0 {
  2189. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2190. return
  2191. }
  2192. if prescribing_number > all_count {
  2193. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2194. return
  2195. }
  2196. }
  2197. if adminInfo.CurrentOrgId == 10215 {
  2198. if prescribing_number > batch_number_all_count {
  2199. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2200. return
  2201. }
  2202. }
  2203. }
  2204. } else {
  2205. if prescribingNumberUnit == drug.MaxUnit {
  2206. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2207. num := prescribing_number * float64(drug.MinNumber)
  2208. if drug.IsUse != 1 {
  2209. if drug.IsProject == 0 || drug.IsProject == 2 {
  2210. if all_count == 0 {
  2211. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2212. return
  2213. }
  2214. if num > all_count {
  2215. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2216. return
  2217. }
  2218. }
  2219. if adminInfo.CurrentOrgId == 10215 {
  2220. if prescribing_number > batch_number_all_count {
  2221. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2222. return
  2223. }
  2224. }
  2225. }
  2226. }
  2227. }
  2228. }
  2229. //修改处方
  2230. if advicelist.ID > 0 {
  2231. //查询最新批次库存
  2232. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2233. var batch_number_count int64
  2234. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2235. var device_number int64
  2236. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2237. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2238. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2239. device_number = prescribingNumberInt * drug.MinNumber
  2240. }
  2241. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2242. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2243. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2244. device_number = prescribingNumberInt
  2245. }
  2246. var number_count int64
  2247. if prescribingNumberUnit == drug.MaxUnit {
  2248. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2249. number_count = prescribingNumberInt * drug.MinNumber
  2250. }
  2251. if prescribingNumberUnit == drug.MinUnit {
  2252. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2253. number_count = prescribingNumberInt
  2254. }
  2255. //如果修改的数量大于之前修改的数量
  2256. if (number_count - device_number) > 0 {
  2257. //如果修改的差数量 大于库存数量
  2258. if drug.IsUse != 1 {
  2259. if drug.IsProject == 0 || drug.IsProject == 2 {
  2260. if total_count == 0 {
  2261. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2262. return
  2263. }
  2264. if (number_count - device_number) > total_count {
  2265. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2266. return
  2267. }
  2268. }
  2269. if adminInfo.CurrentOrgId == 10215 {
  2270. if (number_count - device_number) > batch_number_count {
  2271. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2272. return
  2273. }
  2274. }
  2275. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2276. //查询历史出库数据总批次
  2277. // 查询该药品最后一次出库记录
  2278. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2279. var out_count int64
  2280. var in_count int64
  2281. var stock_max_number int64
  2282. var stock_min_number int64
  2283. for _, it := range outInfo {
  2284. if it.CountUnit == drug.MaxUnit {
  2285. it.Count = it.Count * drug.MinNumber
  2286. }
  2287. out_count += it.Count
  2288. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2289. stock_max_number = warehouseInfoList.StockMaxNumber
  2290. stock_min_number = warehouseInfoList.StockMinNumber
  2291. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2292. }
  2293. if out_count > 0 {
  2294. if (number_count - device_number) > in_count {
  2295. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2296. return
  2297. }
  2298. }
  2299. // 未出库
  2300. if out_count == 0 {
  2301. var sum_in_count int64
  2302. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2303. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2304. if sum_in_count == 0 {
  2305. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2306. return
  2307. }
  2308. //如果修改的数量大于有库存的第一个批次
  2309. if number_count > sum_in_count {
  2310. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2311. return
  2312. }
  2313. }
  2314. }
  2315. }
  2316. }
  2317. }
  2318. }
  2319. }
  2320. }
  2321. }
  2322. }
  2323. }
  2324. }
  2325. }
  2326. }
  2327. //校验耗材库存
  2328. if goodOutConfig.IsOpen == 1 {
  2329. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2330. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2331. if len(prescriptions) > 0 {
  2332. for _, item := range prescriptions {
  2333. items := item.(map[string]interface{})
  2334. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2335. projects := items["project"].([]interface{})
  2336. if len(projects) > 0 {
  2337. for _, project := range projects {
  2338. var project_id int64
  2339. var project_type int64
  2340. var totals float64
  2341. var project_name string
  2342. var parsetotal int64
  2343. var id int64
  2344. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2345. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2346. }
  2347. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2348. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2349. }
  2350. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2351. total, _ := project.(map[string]interface{})["total"].(string)
  2352. totals, _ = strconv.ParseFloat(total, 64)
  2353. }
  2354. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2355. project_name = project.(map[string]interface{})["project_name"].(string)
  2356. }
  2357. if project_type == 3 {
  2358. //查找该耗材的出库记录
  2359. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2360. if len(goodWarehouseInfo) == 0 {
  2361. //查询耗材库存
  2362. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2363. var stock_count int64
  2364. for _, it := range list {
  2365. stock_count += it.StockCount
  2366. }
  2367. stock_counts := strconv.FormatInt(stock_count, 10)
  2368. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2369. if stock_total_count == 0 {
  2370. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2371. return
  2372. }
  2373. if totals > stock_total_count {
  2374. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2375. return
  2376. }
  2377. }
  2378. if len(goodWarehouseInfo) > 0 {
  2379. //查询该患者耗材的历史数据
  2380. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2381. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2382. //数量发生改变
  2383. if parsetotal != count {
  2384. //如果现在的数量大于历史数量,就要看库存是否足够
  2385. if parsetotal > count {
  2386. //查询耗材所有库存
  2387. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2388. var stock_count int64
  2389. for _, it := range list {
  2390. stock_count += it.StockCount
  2391. }
  2392. //库存不足
  2393. if stock_count == 0 {
  2394. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2395. return
  2396. }
  2397. if (parsetotal - count) > stock_count {
  2398. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2399. return
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. //不使用耗材保存处方出库
  2413. if goodOutConfig.IsOpen != 1 {
  2414. if stockConfig.IsOpen == 1 {
  2415. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2416. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2417. if len(prescriptions) > 0 {
  2418. for _, item := range prescriptions {
  2419. items := item.(map[string]interface{})
  2420. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2421. projects := items["project"].([]interface{})
  2422. if len(projects) > 0 {
  2423. for _, project := range projects {
  2424. var project_id int64
  2425. var project_type int64
  2426. var totals float64
  2427. var project_name string
  2428. var parsetotal int64
  2429. var id int64
  2430. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2431. id = int64(project.(map[string]interface{})["id"].(float64))
  2432. }
  2433. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2434. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2435. }
  2436. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2437. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2438. }
  2439. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2440. total, _ := project.(map[string]interface{})["total"].(string)
  2441. totals, _ = strconv.ParseFloat(total, 64)
  2442. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2443. }
  2444. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2445. project_name = project.(map[string]interface{})["project_name"].(string)
  2446. }
  2447. if project_type == 3 {
  2448. //查找该耗材的出库记录
  2449. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2450. //没有出库记录
  2451. if len(goodWarehouseInfo) == 0 {
  2452. //查询耗材库存
  2453. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2454. var stock_count int64
  2455. for _, it := range list {
  2456. stock_count += it.StockCount
  2457. }
  2458. stock_counts := strconv.FormatInt(stock_count, 10)
  2459. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2460. if stock_total_count == 0 {
  2461. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2462. return
  2463. }
  2464. if totals > stock_total_count {
  2465. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2466. return
  2467. }
  2468. //查找今日该患者已经出库的所有耗材
  2469. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2470. for _, item := range goodList {
  2471. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2472. var flush_count int64
  2473. for _, it := range goodListSix {
  2474. flush_count += it.StockCount
  2475. }
  2476. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2477. creater := adminInfo.AdminUser.Id
  2478. if errs != nil {
  2479. goodErrcode := models.XtGoodErrcode{
  2480. UserOrgId: item.OrgId,
  2481. Errcode: "手动出库更新剩余出库失败",
  2482. GoodId: item.GoodId,
  2483. Status: 1,
  2484. Ctime: time.Now().Unix(),
  2485. Mtime: 0,
  2486. Count: 0,
  2487. StockCount: 0,
  2488. Creater: creater,
  2489. BatchNumberId: 0,
  2490. WarehouseOutId: 0,
  2491. }
  2492. service.CreateGoodErrcode(goodErrcode)
  2493. }
  2494. }
  2495. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2496. }
  2497. //有出库记录
  2498. if len(goodWarehouseInfo) > 0 {
  2499. //查询该患者耗材的历史数据
  2500. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2501. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2502. //数量发生改变
  2503. if parsetotal != count {
  2504. //查找今日该患者已经出库的所有耗材
  2505. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2506. for _, item := range goodList {
  2507. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2508. var flush_count int64
  2509. for _, it := range goodListSix {
  2510. flush_count += it.StockCount
  2511. }
  2512. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2513. //减少出库数量
  2514. creater := adminInfo.AdminUser.Id
  2515. if errs != nil {
  2516. goodErrcode := models.XtGoodErrcode{
  2517. UserOrgId: item.OrgId,
  2518. Errcode: "手动出库更新剩余出库失败",
  2519. GoodId: item.GoodId,
  2520. Status: 1,
  2521. Ctime: time.Now().Unix(),
  2522. Mtime: 0,
  2523. Count: 0,
  2524. StockCount: 0,
  2525. Creater: creater,
  2526. BatchNumberId: 0,
  2527. WarehouseOutId: 0,
  2528. }
  2529. service.CreateGoodErrcode(goodErrcode)
  2530. }
  2531. //查询默认仓库
  2532. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2533. var total_count int64
  2534. for _, it := range stockList {
  2535. total_count += it.StockCount
  2536. }
  2537. //基础库插入数据
  2538. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2539. }
  2540. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2541. }
  2542. }
  2543. }
  2544. }
  2545. }
  2546. }
  2547. }
  2548. }
  2549. }
  2550. }
  2551. }
  2552. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2553. var hpInfo models.HisPrescriptionInfo
  2554. if info.ID == 0 {
  2555. var randNum int
  2556. randNum = rand.Intn(10000) + 1000
  2557. timestamp := time.Now().Unix()
  2558. tempTime := time.Unix(timestamp, 0)
  2559. timeFormat := tempTime.Format("20060102150405")
  2560. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2561. hpInfo = models.HisPrescriptionInfo{
  2562. HisPatientId: his_patient_id,
  2563. UserOrgId: adminInfo.CurrentOrgId,
  2564. RecordDate: theTime.Unix(),
  2565. PatientId: patient_id,
  2566. Status: 1,
  2567. Ctime: time.Now().Unix(),
  2568. Mtime: time.Now().Unix(),
  2569. Creator: adminInfo.AdminUser.Id,
  2570. Modifier: adminInfo.AdminUser.Id,
  2571. Diagnosis: diagnose,
  2572. SickHistory: sick_history,
  2573. Departments: department,
  2574. RegisterType: reg_type,
  2575. PrescriptionNumber: p_number,
  2576. PrescriptionStatus: 1,
  2577. Doctor: role.UserName,
  2578. DoctorId: doctor_id,
  2579. SickType: sick_type,
  2580. PType: p_type,
  2581. PatientDiagnosis: patient_diagnose,
  2582. }
  2583. service.SavePatientPrescriptionInfo(hpInfo)
  2584. //创建步骤表
  2585. finish := models.XtDialysisFinish{
  2586. IsFinish: 1,
  2587. UserOrgId: adminInfo.CurrentOrgId,
  2588. Status: 1,
  2589. Ctime: time.Now().Unix(),
  2590. Mtime: 0,
  2591. Module: 4,
  2592. RecordDate: theTime.Unix(),
  2593. Sourse: 1,
  2594. PatientId: patient_id,
  2595. }
  2596. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2597. if dialysisFinish.ID == 0 {
  2598. service.CreateDialysisFinish(finish)
  2599. }
  2600. redis := service.RedisClient()
  2601. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2602. redis.Set(key, "", time.Second)
  2603. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2604. redis.Set(keyOne, "", time.Second)
  2605. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2606. redis.Set(keySeven, "", time.Second)
  2607. defer redis.Close()
  2608. } else {
  2609. hpInfo = models.HisPrescriptionInfo{
  2610. ID: info.ID,
  2611. UserOrgId: adminInfo.CurrentOrgId,
  2612. RecordDate: info.RecordDate,
  2613. PatientId: info.PatientId,
  2614. Status: 1,
  2615. Ctime: info.Ctime,
  2616. Mtime: time.Now().Unix(),
  2617. Creator: info.Creator,
  2618. Modifier: adminInfo.AdminUser.Id,
  2619. Diagnosis: diagnose,
  2620. SickHistory: sick_history,
  2621. Departments: department,
  2622. RegisterType: reg_type,
  2623. PrescriptionNumber: info.PrescriptionNumber,
  2624. Doctor: role.UserName,
  2625. PrescriptionStatus: info.PrescriptionStatus,
  2626. DoctorId: doctor_id,
  2627. SickType: sick_type,
  2628. PType: info.PType,
  2629. HisPatientId: info.HisPatientId,
  2630. PatientDiagnosis: patient_diagnose,
  2631. }
  2632. service.SavePatientPrescriptionInfo(hpInfo)
  2633. //创建步骤表
  2634. finish := models.XtDialysisFinish{
  2635. IsFinish: 1,
  2636. UserOrgId: adminInfo.CurrentOrgId,
  2637. Status: 1,
  2638. Ctime: time.Now().Unix(),
  2639. Mtime: 0,
  2640. Module: 4,
  2641. RecordDate: info.RecordDate,
  2642. Sourse: 1,
  2643. PatientId: info.PatientId,
  2644. }
  2645. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2646. if dialysisFinish.ID == 0 {
  2647. service.CreateDialysisFinish(finish)
  2648. }
  2649. redis := service.RedisClient()
  2650. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2651. redis.Set(key, "", time.Second)
  2652. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2653. redis.Set(keyOne, "", time.Second)
  2654. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2655. redis.Set(keySeven, "", time.Second)
  2656. defer redis.Close()
  2657. }
  2658. //定义切片
  2659. var adviceList []models.HisDoctorAdviceInfo
  2660. var projectList []models.HisPrescriptionProject
  2661. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2662. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2663. var tempPrescription *models.HisPrescription
  2664. if len(prescriptions) > 0 {
  2665. for _, item := range prescriptions {
  2666. items := item.(map[string]interface{})
  2667. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2668. utils.ErrorLog("id")
  2669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2670. return
  2671. }
  2672. id := int64(items["id"].(float64))
  2673. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2674. tempPrescription = &new_prescription
  2675. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2676. utils.ErrorLog("type")
  2677. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2678. return
  2679. }
  2680. types := int64(items["type"].(float64))
  2681. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2682. utils.ErrorLog("med_type")
  2683. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2684. return
  2685. }
  2686. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2687. if med_type == "0" {
  2688. med_type = "14"
  2689. }
  2690. //if order_status == 0 {
  2691. // order_status = 1
  2692. //}
  2693. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2694. utils.ErrorLog("pre_time")
  2695. }
  2696. preTime, _ := items["pre_time"].(string)
  2697. timeLayout := "2006-01-02"
  2698. loc, _ := time.LoadLocation("Local")
  2699. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2700. if err != nil {
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2702. return
  2703. }
  2704. pTime := theTime2.Unix()
  2705. ctime := time.Now().Unix()
  2706. if tempPrescription.ID == 0 {
  2707. prescription := &models.HisPrescription{
  2708. ID: 0,
  2709. PatientId: patient_id,
  2710. UserOrgId: adminInfo.CurrentOrgId,
  2711. RecordDate: recordDateTime,
  2712. Ctime: ctime,
  2713. Mtime: ctime,
  2714. Type: types,
  2715. Modifier: adminInfo.AdminUser.Id,
  2716. Creator: adminInfo.AdminUser.Id,
  2717. Status: 1,
  2718. Doctor: role.UserName,
  2719. HisPatientId: his_patient_id,
  2720. OrderStatus: 1,
  2721. BatchNumber: "",
  2722. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2723. PreTime: pTime,
  2724. PType: p_type,
  2725. MedType: med_type,
  2726. }
  2727. tempPrescription = prescription
  2728. service.SaveHisPrescription(tempPrescription)
  2729. redis := service.RedisClient()
  2730. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2731. redis.Set(key, "", time.Second)
  2732. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2733. redis.Set(keyOne, "", time.Second)
  2734. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2735. redis.Set(keySeven, "", time.Second)
  2736. defer redis.Close()
  2737. } else {
  2738. tempPrescription.ID = id
  2739. tempPrescription.Type = types
  2740. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2741. tempPrescription.Mtime = time.Now().Unix()
  2742. tempPrescription.Doctor = role.UserName
  2743. //tempPrescription.OrderStatus = order_status
  2744. tempPrescription.PreTime = pTime
  2745. tempPrescription.MedType = med_type
  2746. service.SaveHisPrescription(tempPrescription)
  2747. redis := service.RedisClient()
  2748. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2749. redis.Set(key, "", time.Second)
  2750. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2751. redis.Set(keyOne, "", time.Second)
  2752. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2753. redis.Set(keySeven, "", time.Second)
  2754. defer redis.Close()
  2755. }
  2756. //service.SaveHisPrescription(prescription)
  2757. //更改患者挂号状态
  2758. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2759. fmt.Println("更改失败", err2)
  2760. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2761. advices := items["advices"].([]interface{})
  2762. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2763. groupNo := int64(0)
  2764. ctime := time.Now().Unix()
  2765. mtime := ctime
  2766. if len(advices) > 0 {
  2767. for _, advice := range advices {
  2768. var s models.HisDoctorAdviceInfo
  2769. s.PrescriptionId = tempPrescription.ID
  2770. s.AdviceType = 2
  2771. s.AdviceDoctor = doctor_id
  2772. s.StopState = 2
  2773. s.ExecutionState = 2
  2774. s.AdviceDate = recordDateTime
  2775. s.Status = 1
  2776. s.UserOrgId = adminInfo.CurrentOrgId
  2777. s.RecordDate = recordDateTime
  2778. s.StartTime = tempPrescription.PreTime
  2779. s.Groupno = groupNo
  2780. s.CreatedTime = ctime
  2781. s.UpdatedTime = mtime
  2782. s.PatientId = patient_id
  2783. s.HisPatientId = his_patient_id
  2784. s.StartTime = pTime
  2785. s.IsSettle = 2
  2786. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2787. if errcode > 0 {
  2788. c.ServeFailJSONWithSGJErrorCode(errcode)
  2789. return
  2790. }
  2791. s.StartTime = pTime
  2792. var total_count int64 //处方总库存
  2793. //查询改药品信息
  2794. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2795. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2796. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2797. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2798. total_count += prescribingNumberSeven * medical.MinNumber
  2799. }
  2800. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2801. total_count += prescribingNumberSeven
  2802. }
  2803. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2804. total_count += prescribingNumberSeven
  2805. }
  2806. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2807. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2808. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2809. if s.Price != lastWarehouse.RetailPrice {
  2810. s.Price = lastWarehouse.RetailPrice
  2811. }
  2812. if s.Price == 0 {
  2813. s.Price = lastWarehouse.RetailPrice
  2814. }
  2815. }
  2816. service.CreateHisDoctorAdvice(&s)
  2817. //记录日志
  2818. byterequest, _ := json.Marshal(s)
  2819. adviceLog := models.XtDoctorAdviceLog{
  2820. UserOrgId: s.UserOrgId,
  2821. PatientId: s.PatientId,
  2822. AdminUserId: adminInfo.AdminUser.Id,
  2823. Module: 1,
  2824. ErrLog: string(byterequest),
  2825. Status: 1,
  2826. Ctime: time.Now().Unix(),
  2827. Mtime: 0,
  2828. Source: "电脑端新建his医嘱",
  2829. RecordDate: s.AdviceDate,
  2830. }
  2831. service.CreateDoctorAdviceLog(adviceLog)
  2832. //存储切片中
  2833. adviceList = append(adviceList, s)
  2834. redis := service.RedisClient()
  2835. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2836. redis.Set(key, "", time.Second)
  2837. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2838. redis.Set(keyOne, "", time.Second)
  2839. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2840. redis.Set(keySeven, "", time.Second)
  2841. var randNum int
  2842. randNum = rand.Intn(10000) + 1000
  2843. timestamp := time.Now().Unix()
  2844. tempTime := time.Unix(timestamp, 0)
  2845. timeFormat := tempTime.Format("20060102150405")
  2846. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2847. service.CreateHisDoctorAdvice(&s)
  2848. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2849. redis.Set(keySix, "", time.Second)
  2850. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2851. redis.Set(keyFive, "", time.Second)
  2852. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2853. redis.Set(keyEight, "", time.Second)
  2854. defer redis.Close()
  2855. }
  2856. }
  2857. }
  2858. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2859. projects := items["project"].([]interface{})
  2860. if len(projects) > 0 {
  2861. for _, project := range projects {
  2862. var p models.HisPrescriptionProject
  2863. p.PrescriptionId = tempPrescription.ID
  2864. p.Ctime = time.Now().Unix()
  2865. p.Mtime = time.Now().Unix()
  2866. p.PatientId = patient_id
  2867. p.RecordDate = recordDateTime
  2868. p.Doctor = doctor_id
  2869. p.UserOrgId = adminInfo.CurrentOrgId
  2870. p.HisPatientId = his_patient_id
  2871. p.Status = 1
  2872. p.StartTime = pTime
  2873. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2874. if errcode > 0 {
  2875. c.ServeFailJSONWithSGJErrorCode(errcode)
  2876. return
  2877. }
  2878. if p.ID == 0 {
  2879. p.IsOut = 2
  2880. }
  2881. if p.ID > 0 {
  2882. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2883. p.IsOut = projectDetail.IsOut
  2884. }
  2885. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2886. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2887. if p.Type == 3 {
  2888. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2889. if p.Price != lastWarehouse.PackingPrice {
  2890. p.Price = lastWarehouse.PackingPrice
  2891. }
  2892. if p.Unit == "" {
  2893. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2894. p.Unit = goodInfoOne.PackingUnit
  2895. }
  2896. }
  2897. }
  2898. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2899. //
  2900. // if p.Type == 3 {
  2901. // //查询该耗材是否停用
  2902. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2903. // //表示该耗材已经停用,不能保存
  2904. // if goodInfoSeven.ID == 0 {
  2905. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2906. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2907. // return
  2908. // }
  2909. // }
  2910. //
  2911. //}
  2912. service.CreateHisProjectTwo(&p)
  2913. //记录日志
  2914. byterequest, _ := json.Marshal(p)
  2915. adviceLog := models.XtDoctorAdviceLog{
  2916. UserOrgId: p.UserOrgId,
  2917. PatientId: p.PatientId,
  2918. AdminUserId: adminInfo.AdminUser.Id,
  2919. Module: 1,
  2920. ErrLog: string(byterequest),
  2921. Status: 1,
  2922. Ctime: time.Now().Unix(),
  2923. Mtime: 0,
  2924. Source: "电脑端新建his项目",
  2925. RecordDate: p.RecordDate,
  2926. }
  2927. service.CreateDoctorAdviceLog(adviceLog)
  2928. projectList = append(projectList, p)
  2929. var randNum int
  2930. randNum = rand.Intn(10000) + 1000
  2931. timestamp := time.Now().Unix()
  2932. tempTime := time.Unix(timestamp, 0)
  2933. timeFormat := tempTime.Format("20060102150405")
  2934. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2935. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2936. //新增或者编辑项目,修改对应的标签数据
  2937. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2938. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2939. var label models.HisLabelPrintInfo
  2940. project, _ := service.GetProjectDetail(p.ProjectId)
  2941. if project.CostClassify == 3 { //类别为检验检查
  2942. if p.TeamId > 0 { //检验检查组套
  2943. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2944. if tempLabel.ID == 0 {
  2945. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2946. label.Number = tempPrescription.PrescriptionNumber
  2947. label.ProjectId = project.ID
  2948. label.Status = 1
  2949. label.IsPrint = 2
  2950. label.DoctorId = info.DoctorId
  2951. label.UserOrgId = p.UserOrgId
  2952. label.PatientId = patient_id
  2953. label.RecordDate = recordDateTime
  2954. label.Ctime = time.Now().Unix()
  2955. label.Mtime = time.Now().Unix()
  2956. label.ItemId = p.TeamId
  2957. label.FeedetlSn = p.FeedetlSn
  2958. label.PProjectId = p.ID
  2959. label.ProjectName = team.ProjectTeam
  2960. label.PatientName = patient.Name
  2961. service.CreateHisLabelRecord(&label)
  2962. }
  2963. } else { //单条检验检查项目
  2964. label.Number = tempPrescription.PrescriptionNumber
  2965. label.ProjectId = project.ID
  2966. label.Status = 1
  2967. label.DoctorId = info.DoctorId
  2968. label.UserOrgId = p.UserOrgId
  2969. label.PatientId = patient_id
  2970. label.RecordDate = recordDateTime
  2971. label.IsPrint = 2
  2972. label.Ctime = time.Now().Unix()
  2973. label.Mtime = time.Now().Unix()
  2974. label.FeedetlSn = p.FeedetlSn
  2975. label.PProjectId = p.ID
  2976. label.ItemId = p.TeamId
  2977. label.ProjectName = project.ProjectName
  2978. label.PatientName = patient.Name
  2979. service.CreateHisLabelRecord(&label)
  2980. }
  2981. }
  2982. }
  2983. }
  2984. service.SaveHisProjectTwo(&p)
  2985. }
  2986. }
  2987. }
  2988. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2989. // addition := items["addition"].([]interface{})
  2990. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2991. // ctime := time.Now().Unix()
  2992. // mtime := ctime
  2993. // if len(addition) > 0 {
  2994. // for _, item := range addition {
  2995. // var s models.HisAdditionalCharge
  2996. // s.PrescriptionId = tempPrescription.ID
  2997. // s.Status = 1
  2998. // s.UserOrgId = adminInfo.CurrentOrgId
  2999. // s.RecordDate = recordDateTime
  3000. // s.CreatedTime = ctime
  3001. // s.UpdatedTime = mtime
  3002. // s.PatientId = patient_id
  3003. // s.HisPatientId = his_patient_id
  3004. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3005. // if errcode > 0 {
  3006. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3007. // return
  3008. // }
  3009. // service.CreateAdditionalCharge(&s)
  3010. // var randNum int
  3011. // randNum = rand.Intn(10000) + 1000
  3012. // timestamp := time.Now().Unix()
  3013. // tempTime := time.Unix(timestamp, 0)
  3014. // timeFormat := tempTime.Format("20060102150405")
  3015. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3016. // service.CreateAdditionalCharge(&s)
  3017. //
  3018. // }
  3019. // }
  3020. //}
  3021. }
  3022. }
  3023. //查询今日该患者开的药品处方
  3024. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3025. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3026. //药品出库
  3027. if drugOutConfig.IsOpen == 1 {
  3028. for _, item := range hisdoctorlist {
  3029. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3030. // 查询该药品最后一次出库记录
  3031. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3032. if len(druginfo) > 0 {
  3033. //回退库存
  3034. for _, it := range druginfo {
  3035. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3036. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3037. }
  3038. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3039. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3040. }
  3041. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3042. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3043. }
  3044. }
  3045. }
  3046. //删除记录
  3047. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3048. //查询最后一次数据
  3049. if drugOutConfig.IsOpen == 1 {
  3050. //出库
  3051. if drug.IsUse == 2 {
  3052. creater := adminInfo.AdminUser.Id
  3053. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3054. }
  3055. //更新字典里面的库存
  3056. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3057. var sum_count int64
  3058. for _, its := range stockInfo {
  3059. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3060. if its.MaxUnit == baseDrug.MaxUnit {
  3061. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3062. }
  3063. sum_count += its.StockMaxNumber + its.StockMinNumber
  3064. }
  3065. //更新基础库存
  3066. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3067. //剩余库存
  3068. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3069. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3070. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3071. }
  3072. }
  3073. }
  3074. //耗材保存处方出库
  3075. if goodOutConfig.IsOpen == 1 {
  3076. //查询今日耗材出库数量
  3077. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3078. for _, item := range hisgoodlist {
  3079. //查询历史出库数据
  3080. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3081. var out_count_five int64
  3082. for _, item := range flowGood {
  3083. out_count_five += item.Count
  3084. }
  3085. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3086. if out_count_five != parseIntCount {
  3087. //查询耗材最后一次出库记录
  3088. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3089. //查询默认出库仓库库存
  3090. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3091. if len(wareOut) > 0 {
  3092. for _, it := range wareOut {
  3093. //回退库存
  3094. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3095. //删除出库记录
  3096. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3097. }
  3098. }
  3099. timeStr := time.Now().Format("2006-01-02")
  3100. timeArr := strings.Split(timeStr, "-")
  3101. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3102. total = total + 1
  3103. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3104. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3105. number = number + total
  3106. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3107. operation_time := time.Now().Unix()
  3108. creater := c.GetAdminUserInfo().AdminUser.Id
  3109. recordDateStr := time.Now().Format("2006-01-02")
  3110. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3111. nowtime := recordDate.Unix()
  3112. warehouseOut := models.WarehouseOut{
  3113. WarehouseOutOrderNumber: warehousing_out_order,
  3114. OperationTime: operation_time,
  3115. OrgId: adminInfo.CurrentOrgId,
  3116. Creater: creater,
  3117. Ctime: time.Now().Unix(),
  3118. Status: 1,
  3119. WarehouseOutTime: nowtime,
  3120. Type: 1,
  3121. StorehouseId: storeConfig.StorehouseOutInfo,
  3122. IsCheck: 1,
  3123. IsSys: 1,
  3124. }
  3125. //查询是否生成出库单
  3126. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3127. if out.ID == 0 {
  3128. service.AddSigleWarehouseOut(&warehouseOut)
  3129. }
  3130. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3131. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3132. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3133. dialyPrepareOne := models.DialysisBeforePrepare{
  3134. GoodTypeId: goodObj.GoodTypeId,
  3135. GoodId: item.ProjectId,
  3136. PatientId: item.PatientId,
  3137. RecordDate: item.RecordDate,
  3138. UserOrgId: adminInfo.CurrentOrgId,
  3139. Count: parseIntCount,
  3140. Ctime: time.Now().Unix(),
  3141. Creater: creater,
  3142. Status: 1,
  3143. StorehouseId: houseConfig.StorehouseOutInfo,
  3144. ProjectId: item.ID,
  3145. }
  3146. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3147. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3148. //查询历史出库数据
  3149. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3150. var out_count int64
  3151. for _, item := range flowGood {
  3152. out_count += item.Count
  3153. }
  3154. //如果历史数和当前数据不想等才进行退库出库
  3155. if out_count != parseIntCount {
  3156. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3157. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3158. detail := models.AutomaticReduceDetail{
  3159. WarehouseOutId: 0,
  3160. WarehouseOutOrderNumber: "",
  3161. PatientId: item.PatientId,
  3162. Ctime: time.Now().Unix(),
  3163. Mtime: 0,
  3164. Status: 1,
  3165. RecordTime: item.RecordDate,
  3166. OrgId: item.UserOrgId,
  3167. GoodId: item.ProjectId,
  3168. GoodTypeId: 0,
  3169. Count: parseIntCount,
  3170. Type: 0,
  3171. ProjectId: item.ID,
  3172. StorehouseId: 0,
  3173. }
  3174. service.CreateAutoDetail(detail)
  3175. //查询剩余库存
  3176. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3177. var sum_count int64
  3178. for _, item := range goodList {
  3179. sum_count += item.StockCount
  3180. }
  3181. //更新剩余库存
  3182. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3183. //耗材
  3184. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3185. }
  3186. }
  3187. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3188. //查询历史出库数据
  3189. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3190. var out_count int64
  3191. for _, item := range flowGood {
  3192. out_count += item.Count
  3193. }
  3194. //如果历史数和当前数据不想等才进行退库出库
  3195. if out_count != parseIntCount {
  3196. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3197. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3198. detail := models.AutomaticReduceDetail{
  3199. WarehouseOutId: 0,
  3200. WarehouseOutOrderNumber: "",
  3201. PatientId: item.PatientId,
  3202. Ctime: time.Now().Unix(),
  3203. Mtime: 0,
  3204. Status: 1,
  3205. RecordTime: item.RecordDate,
  3206. OrgId: item.UserOrgId,
  3207. GoodId: item.ProjectId,
  3208. GoodTypeId: 0,
  3209. Count: parseIntCount,
  3210. Type: 0,
  3211. ProjectId: item.ID,
  3212. StorehouseId: 0,
  3213. }
  3214. service.CreateAutoDetail(detail)
  3215. //查询剩余库存
  3216. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3217. var sum_count int64
  3218. for _, item := range goodList {
  3219. sum_count += item.StockCount
  3220. }
  3221. //更新剩余库存
  3222. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3223. //耗材
  3224. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3225. }
  3226. }
  3227. }
  3228. }
  3229. }
  3230. }
  3231. //redisClient := service.RedisClient()
  3232. //defer redisClient.Close()
  3233. //
  3234. //list := models.HisList{
  3235. // Patient_id: patient_id,
  3236. // Advice_id:0,
  3237. // Record_date: 0,
  3238. // Advice: adviceList,
  3239. // Project: nil,
  3240. //}
  3241. //hisLis = append(hisLis, list)
  3242. //
  3243. //advice_json, _ := json.Marshal(&hisLis)
  3244. //redisClient.RPush("111", advice_json).Result()
  3245. //result, _ := redisClient.RPop("111").Result()
  3246. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3247. //
  3248. //var dat []map[string]interface{}
  3249. //json.Unmarshal([]byte(result), &dat)
  3250. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3251. //
  3252. //for k,v:=range dat{
  3253. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3254. //}
  3255. //project_json, _ := json.Marshal(&projectList)
  3256. //redisClient.LPush("222", project_json).Result()
  3257. if err == nil {
  3258. c.ServeSuccessJSON(map[string]interface{}{
  3259. "msg": "保存成功",
  3260. })
  3261. return
  3262. } else {
  3263. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3264. return
  3265. }
  3266. }
  3267. func (c *HisApiController) EditHisPrescription() {
  3268. record_date := c.GetString("record_date")
  3269. patient_id, _ := c.GetInt64("patient_id")
  3270. reg_type, _ := c.GetInt64("reg_type")
  3271. //diagnose, _ := c.GetInt64("diagnose", 0)
  3272. diagnose := c.GetString("diagnose")
  3273. sick_type, _ := c.GetInt64("sick_type")
  3274. sick_history := c.GetString("sick_history")
  3275. doctor_id, _ := c.GetInt64("doctor", 0)
  3276. department, _ := c.GetInt64("department", 0)
  3277. his_patient_id, _ := c.GetInt64("his_patient_id")
  3278. p_type, _ := c.GetInt64("p_type")
  3279. dataBody := make(map[string]interface{}, 0)
  3280. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3281. if err != nil {
  3282. utils.ErrorLog(err.Error())
  3283. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3284. return
  3285. }
  3286. timeLayout := "2006-01-02"
  3287. loc, _ := time.LoadLocation("Local")
  3288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3289. if err != nil {
  3290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3291. return
  3292. }
  3293. adminInfo := c.GetAdminUserInfo()
  3294. recordDateTime := theTime.Unix()
  3295. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3296. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3297. var hpInfo models.HisPrescriptionInfo
  3298. if info.ID == 0 {
  3299. var randNum int
  3300. randNum = rand.Intn(10000) + 1000
  3301. timestamp := time.Now().Unix()
  3302. tempTime := time.Unix(timestamp, 0)
  3303. timeFormat := tempTime.Format("20060102150405")
  3304. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3305. hpInfo = models.HisPrescriptionInfo{
  3306. UserOrgId: adminInfo.CurrentOrgId,
  3307. RecordDate: theTime.Unix(),
  3308. PatientId: patient_id,
  3309. Status: 1,
  3310. Ctime: time.Now().Unix(),
  3311. Mtime: time.Now().Unix(),
  3312. Creator: adminInfo.AdminUser.Id,
  3313. Modifier: adminInfo.AdminUser.Id,
  3314. Diagnosis: diagnose,
  3315. SickHistory: sick_history,
  3316. Departments: department,
  3317. RegisterType: reg_type,
  3318. PrescriptionNumber: p_number,
  3319. PrescriptionStatus: 1,
  3320. Doctor: role.UserName,
  3321. DoctorId: doctor_id,
  3322. SickType: sick_type,
  3323. PType: p_type,
  3324. }
  3325. service.SavePatientPrescriptionInfo(hpInfo)
  3326. } else {
  3327. hpInfo = models.HisPrescriptionInfo{
  3328. ID: info.ID,
  3329. UserOrgId: adminInfo.CurrentOrgId,
  3330. RecordDate: info.RecordDate,
  3331. PatientId: info.PatientId,
  3332. Status: 1,
  3333. Ctime: info.Ctime,
  3334. Mtime: time.Now().Unix(),
  3335. Creator: info.Creator,
  3336. Modifier: adminInfo.AdminUser.Id,
  3337. Diagnosis: diagnose,
  3338. SickHistory: sick_history,
  3339. Departments: department,
  3340. RegisterType: reg_type,
  3341. PrescriptionNumber: info.PrescriptionNumber,
  3342. Doctor: role.UserName,
  3343. PrescriptionStatus: info.PrescriptionStatus,
  3344. DoctorId: doctor_id,
  3345. SickType: sick_type,
  3346. PType: info.PType,
  3347. }
  3348. service.SavePatientPrescriptionInfo(hpInfo)
  3349. }
  3350. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3351. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3352. if len(prescriptions) > 0 {
  3353. for _, item := range prescriptions {
  3354. items := item.(map[string]interface{})
  3355. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3356. utils.ErrorLog("id")
  3357. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3358. return
  3359. }
  3360. id := int64(items["id"].(float64))
  3361. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3362. utils.ErrorLog("type")
  3363. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3364. return
  3365. }
  3366. types := int64(items["type"].(float64))
  3367. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3368. utils.ErrorLog("med_type")
  3369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3370. return
  3371. }
  3372. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3373. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3374. ctime := time.Now().Unix()
  3375. prescription := &models.HisPrescription{
  3376. ID: id,
  3377. PatientId: patient_id,
  3378. UserOrgId: adminInfo.CurrentOrgId,
  3379. RecordDate: recordDateTime,
  3380. Ctime: ctime,
  3381. Mtime: ctime,
  3382. Type: types,
  3383. Modifier: adminInfo.AdminUser.Id,
  3384. Creator: adminInfo.AdminUser.Id,
  3385. Status: 1,
  3386. Doctor: role.UserName,
  3387. HisPatientId: his_patient_id,
  3388. OrderStatus: 1,
  3389. BatchNumber: "",
  3390. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3391. PType: hpInfo.PType,
  3392. MedType: med_type,
  3393. }
  3394. if historyPrescription.ID > 0 {
  3395. prescription.PreTime = historyPrescription.PreTime
  3396. }
  3397. service.SaveHisPrescription(prescription)
  3398. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3399. advices := items["advices"].([]interface{})
  3400. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3401. groupNo := int64(0)
  3402. ctime := time.Now().Unix()
  3403. mtime := ctime
  3404. if len(advices) > 0 {
  3405. for _, advice := range advices {
  3406. var s models.HisDoctorAdviceInfo
  3407. s.PrescriptionId = prescription.ID
  3408. s.AdviceType = 2
  3409. s.AdviceDoctor = adminInfo.AdminUser.Id
  3410. s.StopState = 2
  3411. s.ExecutionState = 2
  3412. s.AdviceDate = recordDateTime
  3413. s.Status = 1
  3414. s.UserOrgId = adminInfo.CurrentOrgId
  3415. s.RecordDate = recordDateTime
  3416. s.StartTime = prescription.PreTime
  3417. s.Groupno = groupNo
  3418. s.CreatedTime = ctime
  3419. s.UpdatedTime = mtime
  3420. s.PatientId = patient_id
  3421. s.HisPatientId = his_patient_id
  3422. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3423. if errcode > 0 {
  3424. c.ServeFailJSONWithSGJErrorCode(errcode)
  3425. return
  3426. }
  3427. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3428. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3429. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3430. if s.Price == 0 {
  3431. s.Price = lastWarehouse.RetailPrice
  3432. }
  3433. }
  3434. service.CreateHisDoctorAdvice(&s)
  3435. //记录日志
  3436. byterequest, _ := json.Marshal(s)
  3437. adviceLog := models.XtDoctorAdviceLog{
  3438. UserOrgId: s.UserOrgId,
  3439. PatientId: s.PatientId,
  3440. AdminUserId: adminInfo.AdminUser.Id,
  3441. Module: 1,
  3442. ErrLog: string(byterequest),
  3443. Status: 1,
  3444. Ctime: time.Now().Unix(),
  3445. Mtime: 0,
  3446. Source: "电脑端his医嘱修改",
  3447. RecordDate: s.AdviceDate,
  3448. }
  3449. service.CreateDoctorAdviceLog(adviceLog)
  3450. redis := service.RedisClient()
  3451. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3452. redis.Set(key, "", time.Second)
  3453. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3454. fmt.Println("keyOne", keyOne)
  3455. redis.Set(keyOne, "", time.Second)
  3456. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3457. redis.Set(keySeven, "", time.Second)
  3458. redis.Close()
  3459. }
  3460. }
  3461. }
  3462. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3463. projects := items["project"].([]interface{})
  3464. if len(projects) > 0 {
  3465. for _, project := range projects {
  3466. var p models.HisPrescriptionProject
  3467. p.PrescriptionId = prescription.ID
  3468. p.Ctime = time.Now().Unix()
  3469. p.Mtime = time.Now().Unix()
  3470. p.PatientId = patient_id
  3471. p.RecordDate = recordDateTime
  3472. p.UserOrgId = adminInfo.CurrentOrgId
  3473. p.HisPatientId = his_patient_id
  3474. p.Status = 1
  3475. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3476. if errcode > 0 {
  3477. c.ServeFailJSONWithSGJErrorCode(errcode)
  3478. return
  3479. }
  3480. service.CreateHisProjectTwo(&p)
  3481. //记录日志
  3482. byterequest, _ := json.Marshal(p)
  3483. adviceLog := models.XtDoctorAdviceLog{
  3484. UserOrgId: p.UserOrgId,
  3485. PatientId: p.PatientId,
  3486. AdminUserId: adminInfo.AdminUser.Id,
  3487. Module: 1,
  3488. ErrLog: string(byterequest),
  3489. Status: 1,
  3490. Ctime: time.Now().Unix(),
  3491. Mtime: 0,
  3492. Source: "电脑端his项目修改",
  3493. RecordDate: p.RecordDate,
  3494. }
  3495. service.CreateDoctorAdviceLog(adviceLog)
  3496. }
  3497. }
  3498. }
  3499. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3500. addition := items["addition"].([]interface{})
  3501. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3502. ctime := time.Now().Unix()
  3503. mtime := ctime
  3504. if len(addition) > 0 {
  3505. for _, item := range addition {
  3506. var s models.HisAdditionalCharge
  3507. s.PrescriptionId = prescription.ID
  3508. s.Status = 1
  3509. s.UserOrgId = adminInfo.CurrentOrgId
  3510. s.RecordDate = recordDateTime
  3511. s.CreatedTime = ctime
  3512. s.UpdatedTime = mtime
  3513. s.PatientId = patient_id
  3514. s.HisPatientId = his_patient_id
  3515. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3516. if errcode > 0 {
  3517. c.ServeFailJSONWithSGJErrorCode(errcode)
  3518. return
  3519. }
  3520. service.CreateAdditionalCharge(&s)
  3521. }
  3522. }
  3523. }
  3524. }
  3525. }
  3526. }
  3527. if err == nil {
  3528. c.ServeSuccessJSON(map[string]interface{}{
  3529. "msg": "保存成功",
  3530. })
  3531. return
  3532. } else {
  3533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3534. return
  3535. }
  3536. }
  3537. func (c *HisApiController) DeletePrescription() {
  3538. prescription_id, _ := c.GetInt64("id")
  3539. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3540. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3541. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3542. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3543. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3544. //耗材保存处方出库
  3545. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3546. //已收费和已发药限制逻辑
  3547. isCharge := false
  3548. isMedicine := false
  3549. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3550. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3551. for _, item := range new_prescriptions {
  3552. if item.IsMedicine == 1 {
  3553. isMedicine = true
  3554. }
  3555. }
  3556. for _, item := range new_prescriptions {
  3557. if item.OrderStatus == 4 {
  3558. isCharge = true
  3559. }
  3560. }
  3561. if p_err != nil {
  3562. if new_prescription.ID > 0 {
  3563. if new_prescription.OrderStatus == 2 {
  3564. isCharge = true
  3565. }
  3566. }
  3567. }
  3568. for _, item := range advices {
  3569. if item.IsMedicine == 1 {
  3570. isMedicine = true
  3571. }
  3572. }
  3573. if isCharge {
  3574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3575. return
  3576. }
  3577. if isMedicine {
  3578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3579. return
  3580. }
  3581. //已收费和已发药限制逻辑
  3582. if len(projects) > 0 {
  3583. for _, item := range projects {
  3584. service.DeletePrintInfo(item.ID) //删除打印信息
  3585. if goodOutConfig.IsOpen != 1 {
  3586. if stockConfig.IsOpen == 1 {
  3587. if item.Type == 3 && item.IsOut == 1 {
  3588. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3589. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3590. good.Total = good.Total + f_count
  3591. service.UpdateGoodInfo(&good)
  3592. operation_time := time.Now().Unix()
  3593. creater := c.GetAdminUserInfo().AdminUser.Id
  3594. //创建退库单
  3595. timeStr := time.Now().Format("2006-01-02")
  3596. timeArr := strings.Split(timeStr, "-")
  3597. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3598. total = total + 1
  3599. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3600. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3601. cancelStock := models.CancelStock{
  3602. OrderNumber: orderNumber,
  3603. OperaTime: operation_time,
  3604. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3605. Creater: creater,
  3606. Ctime: time.Now().Unix(),
  3607. Status: 1,
  3608. ReturnTime: item.RecordDate,
  3609. Type: 1,
  3610. StorehouseId: houseConfig.StorehouseOutInfo,
  3611. IsCheck: 1,
  3612. }
  3613. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3614. if msgerrkonde == gorm.ErrRecordNotFound {
  3615. service.AddSigleCancelStock(&cancelStock)
  3616. }
  3617. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3618. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3619. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3620. //查询该耗材是否出库
  3621. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3622. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3623. deaerler, _ := service.GetDealerById(info.Dealer)
  3624. var total_count int64
  3625. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3626. total_count += count
  3627. if info.ID > 0 {
  3628. if info.Count >= total_count {
  3629. //回退库存
  3630. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3631. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3632. var flush_count int64
  3633. for _, it := range goodList {
  3634. flush_count += it.StockCount
  3635. }
  3636. cancelStockInfo := models.CancelStockInfo{
  3637. GoodId: item.ProjectId,
  3638. CancelStockId: cancel.ID,
  3639. GoodTypeId: good.GoodTypeId,
  3640. Count: prescribingNumber,
  3641. Price: info.Price,
  3642. Total: 0,
  3643. ProductDate: info.ProductDate,
  3644. ExpiryDate: info.ExpiryDate,
  3645. Ctime: time.Now().Unix(),
  3646. Status: 1,
  3647. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3648. OrderNumber: cancel.OrderNumber,
  3649. Type: 0,
  3650. Dealer: deaerler.DealerName,
  3651. Manufacturer: manufacturer.ManufacturerName,
  3652. Number: info.Number,
  3653. RegisterAccount: "",
  3654. Remark: "",
  3655. WarehouseInfoId: info.WarehouseInfotId,
  3656. PatientId: info.PatientId,
  3657. RecordDate: info.SysRecordTime,
  3658. StorehouseId: houseConfig.StorehouseOutInfo,
  3659. IsCheck: 1,
  3660. }
  3661. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3662. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3663. flow := models.VmStockFlow{
  3664. WarehousingId: info.WarehouseInfotId,
  3665. GoodId: item.ProjectId,
  3666. Number: info.Number,
  3667. LicenseNumber: info.LicenseNumber,
  3668. Count: prescribingNumber,
  3669. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3670. PatientId: item.PatientId,
  3671. SystemTime: info.SysRecordTime,
  3672. ConsumableType: 7,
  3673. IsSys: 0,
  3674. WarehousingOrder: "",
  3675. WarehouseOutId: info.WarehouseOutId,
  3676. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3677. IsEdit: 0,
  3678. CancelStockId: cancel.ID,
  3679. CancelOrderNumber: cancel.OrderNumber,
  3680. Manufacturer: manufacturer.ID,
  3681. Dealer: 0,
  3682. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3683. UpdateCreator: 0,
  3684. Status: 1,
  3685. Ctime: time.Now().Unix(),
  3686. Mtime: 0,
  3687. Price: info.Price,
  3688. WarehousingDetailId: info.WarehouseInfotId,
  3689. WarehouseOutDetailId: info.ID,
  3690. CancelOutDetailId: cancelInfo.ID,
  3691. ProductDate: info.ProductDate,
  3692. ExpireDate: info.ExpiryDate,
  3693. StorehouseId: houseConfig.StorehouseOutInfo,
  3694. OverCount: flush_count,
  3695. }
  3696. service.CreateStockFlowOne(flow)
  3697. //退库数量增加
  3698. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3699. //出库数量减少
  3700. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3701. }
  3702. if info.Count < total_count {
  3703. //回退库存
  3704. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3705. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3706. var flush_count int64
  3707. for _, it := range goodList {
  3708. flush_count += it.StockCount
  3709. }
  3710. cancelStockInfo := models.CancelStockInfo{
  3711. GoodId: item.ProjectId,
  3712. CancelStockId: cancel.ID,
  3713. GoodTypeId: good.GoodTypeId,
  3714. Count: info.Count,
  3715. Price: info.Price,
  3716. Total: 0,
  3717. ProductDate: info.ProductDate,
  3718. ExpiryDate: info.ExpiryDate,
  3719. Ctime: time.Now().Unix(),
  3720. Status: 1,
  3721. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3722. OrderNumber: cancel.OrderNumber,
  3723. Type: 0,
  3724. Dealer: deaerler.DealerName,
  3725. Manufacturer: manufacturer.ManufacturerName,
  3726. Number: info.Number,
  3727. RegisterAccount: "",
  3728. Remark: "",
  3729. WarehouseInfoId: info.WarehouseInfotId,
  3730. PatientId: info.PatientId,
  3731. RecordDate: info.SysRecordTime,
  3732. StorehouseId: houseConfig.StorehouseOutInfo,
  3733. IsCheck: 1,
  3734. }
  3735. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3736. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3737. flow := models.VmStockFlow{
  3738. WarehousingId: info.WarehouseInfotId,
  3739. GoodId: item.ProjectId,
  3740. Number: info.Number,
  3741. LicenseNumber: info.LicenseNumber,
  3742. Count: info.Count,
  3743. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3744. PatientId: item.PatientId,
  3745. SystemTime: info.SysRecordTime,
  3746. ConsumableType: 7,
  3747. IsSys: 0,
  3748. WarehousingOrder: "",
  3749. WarehouseOutId: info.WarehouseOutId,
  3750. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3751. IsEdit: 0,
  3752. CancelStockId: cancel.ID,
  3753. CancelOrderNumber: cancel.OrderNumber,
  3754. Manufacturer: manufacturer.ID,
  3755. Dealer: 0,
  3756. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3757. UpdateCreator: 0,
  3758. Status: 1,
  3759. Ctime: time.Now().Unix(),
  3760. Mtime: 0,
  3761. Price: info.Price,
  3762. WarehousingDetailId: info.WarehouseInfotId,
  3763. WarehouseOutDetailId: info.ID,
  3764. CancelOutDetailId: cancelInfo.ID,
  3765. ProductDate: info.ProductDate,
  3766. ExpireDate: info.ExpiryDate,
  3767. StorehouseId: houseConfig.StorehouseOutInfo,
  3768. OverCount: flush_count,
  3769. }
  3770. service.CreateStockFlowOne(flow)
  3771. //退库数量增加
  3772. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3773. //出库数量减少
  3774. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3775. }
  3776. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3777. var flush_count int64
  3778. for _, it := range goodList {
  3779. flush_count += it.StockCount
  3780. }
  3781. //查询已出库数量
  3782. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3783. if prescribingNumber < dialysisInfo.Count {
  3784. //改变数量
  3785. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3786. }
  3787. if prescribingNumber >= dialysisInfo.Count {
  3788. //删除出库表
  3789. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3790. }
  3791. //更新库存
  3792. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3793. //更新基础库库存
  3794. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3795. }
  3796. }
  3797. }
  3798. }
  3799. //保存耗材出库
  3800. if goodOutConfig.IsOpen == 1 {
  3801. if item.Type == 3 {
  3802. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3803. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3804. good.Total = good.Total + f_count
  3805. service.UpdateGoodInfo(&good)
  3806. operation_time := time.Now().Unix()
  3807. creater := c.GetAdminUserInfo().AdminUser.Id
  3808. //创建退库单
  3809. timeStr := time.Now().Format("2006-01-02")
  3810. timeArr := strings.Split(timeStr, "-")
  3811. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3812. total = total + 1
  3813. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3814. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3815. cancelStock := models.CancelStock{
  3816. OrderNumber: orderNumber,
  3817. OperaTime: operation_time,
  3818. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3819. Creater: creater,
  3820. Ctime: time.Now().Unix(),
  3821. Status: 1,
  3822. ReturnTime: item.RecordDate,
  3823. Type: 1,
  3824. StorehouseId: houseConfig.StorehouseOutInfo,
  3825. IsCheck: 1,
  3826. }
  3827. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3828. if msgerrkonde == gorm.ErrRecordNotFound {
  3829. service.AddSigleCancelStock(&cancelStock)
  3830. }
  3831. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3832. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3833. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3834. //查询该耗材是否出库
  3835. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3836. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3837. deaerler, _ := service.GetDealerById(info.Dealer)
  3838. var total_count int64
  3839. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3840. total_count += count
  3841. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3842. var flush_count int64
  3843. for _, it := range goodList {
  3844. flush_count += it.StockCount
  3845. }
  3846. fmt.Println("历史出库数据", info.Count)
  3847. fmt.Println("出库数量", total_count)
  3848. if info.ID > 0 {
  3849. cancelStockInfo := models.CancelStockInfo{
  3850. GoodId: item.ProjectId,
  3851. CancelStockId: cancel.ID,
  3852. GoodTypeId: good.GoodTypeId,
  3853. Count: prescribingNumber,
  3854. Price: info.Price,
  3855. Total: 0,
  3856. ProductDate: info.ProductDate,
  3857. ExpiryDate: info.ExpiryDate,
  3858. Ctime: time.Now().Unix(),
  3859. Status: 1,
  3860. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3861. OrderNumber: cancel.OrderNumber,
  3862. Type: 0,
  3863. Dealer: deaerler.DealerName,
  3864. Manufacturer: manufacturer.ManufacturerName,
  3865. Number: info.Number,
  3866. RegisterAccount: "",
  3867. Remark: "",
  3868. WarehouseInfoId: info.WarehouseInfotId,
  3869. PatientId: info.PatientId,
  3870. RecordDate: info.SysRecordTime,
  3871. StorehouseId: houseConfig.StorehouseOutInfo,
  3872. IsCheck: 1,
  3873. }
  3874. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3875. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3876. //查询出库数量
  3877. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3878. //出库数据 大于 退库数量
  3879. if len(list) > 0 {
  3880. for _, it := range list {
  3881. //回退库存
  3882. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3883. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3884. var flush_count_one int64
  3885. for _, it := range goodList {
  3886. flush_count_one += it.StockCount
  3887. }
  3888. //查询该批次是否有退库数据
  3889. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3890. creater := c.GetAdminUserInfo().AdminUser.Id
  3891. flow := models.VmStockFlow{
  3892. WarehousingId: it.WarehouseInfotId,
  3893. GoodId: it.GoodId,
  3894. Number: it.Number,
  3895. LicenseNumber: it.LicenseNumber,
  3896. Count: it.Count,
  3897. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3898. PatientId: it.PatientId,
  3899. SystemTime: it.SysRecordTime,
  3900. ConsumableType: 7,
  3901. IsSys: 0,
  3902. WarehousingOrder: "",
  3903. WarehouseOutId: it.WarehouseOutId,
  3904. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3905. IsEdit: 0,
  3906. CancelStockId: cancel.ID,
  3907. CancelOrderNumber: cancel.OrderNumber,
  3908. Manufacturer: manufacturer.ID,
  3909. Dealer: 0,
  3910. Creator: creater,
  3911. UpdateCreator: 0,
  3912. Status: 1,
  3913. Ctime: time.Now().Unix(),
  3914. Mtime: 0,
  3915. Price: it.Price,
  3916. WarehousingDetailId: it.WarehouseInfotId,
  3917. WarehouseOutDetailId: it.ID,
  3918. CancelOutDetailId: cancelInfo.ID,
  3919. ProductDate: it.ProductDate,
  3920. ExpireDate: it.ExpiryDate,
  3921. StorehouseId: houseConfig.StorehouseOutInfo,
  3922. OverCount: flush_count_one,
  3923. }
  3924. service.CreateStockFlowOne(flow)
  3925. //if flow.ID > 0 {
  3926. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3927. //}
  3928. }
  3929. }
  3930. //flow := models.VmStockFlow{
  3931. // WarehousingId: info.WarehouseInfotId,
  3932. // GoodId: item.ProjectId,
  3933. // Number: info.Number,
  3934. // LicenseNumber: info.LicenseNumber,
  3935. // Count: prescribingNumber,
  3936. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3937. // PatientId: item.PatientId,
  3938. // SystemTime: info.SysRecordTime,
  3939. // ConsumableType: 7,
  3940. // IsSys: 0,
  3941. // WarehousingOrder: "",
  3942. // WarehouseOutId: info.WarehouseOutId,
  3943. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3944. // IsEdit: 0,
  3945. // CancelStockId: cancel.ID,
  3946. // CancelOrderNumber: cancel.OrderNumber,
  3947. // Manufacturer: manufacturer.ID,
  3948. // Dealer: 0,
  3949. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3950. // UpdateCreator: 0,
  3951. // Status: 1,
  3952. // Ctime: time.Now().Unix(),
  3953. // Mtime: 0,
  3954. // Price: info.Price,
  3955. // WarehousingDetailId: info.WarehouseInfotId,
  3956. // WarehouseOutDetailId: info.ID,
  3957. // CancelOutDetailId: cancelInfo.ID,
  3958. // ProductDate: info.ProductDate,
  3959. // ExpireDate: info.ExpiryDate,
  3960. // StorehouseId: houseConfig.StorehouseOutInfo,
  3961. // OverCount: flush_count,
  3962. //}
  3963. //service.CreateStockFlowOne(flow)
  3964. //退库数量增加
  3965. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3966. //出库数量减少
  3967. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3968. //查询已出库数量
  3969. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3970. if prescribingNumber < dialysisInfo.Count {
  3971. //改变数量
  3972. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3973. }
  3974. if prescribingNumber >= dialysisInfo.Count {
  3975. //删除出库表
  3976. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3977. }
  3978. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3979. var flush_count_one int64
  3980. for _, it := range goodList {
  3981. flush_count_one += it.StockCount
  3982. }
  3983. //更新库存
  3984. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  3985. fmt.Println("msgerrkonde23332323", msgerrkonde)
  3986. //更新基础库库存
  3987. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  3988. }
  3989. }
  3990. }
  3991. }
  3992. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3993. fmt.Println(err)
  3994. }
  3995. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3996. fmt.Println(err)
  3997. if len(advices) > 0 {
  3998. for _, item := range advices {
  3999. redis := service.RedisClient()
  4000. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4001. redis.Set(keyFive, "", time.Second)
  4002. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4003. redis.Set(keyOne, "", time.Second)
  4004. redis.Close()
  4005. }
  4006. }
  4007. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4008. if len(advices) > 0 {
  4009. for _, item := range advices {
  4010. creater := c.GetAdminUserInfo().AdminUser.Id
  4011. service.DrugAutoAddCancelInfo(item, creater)
  4012. }
  4013. }
  4014. } else {
  4015. if drugOutConfig.IsOpen == 1 {
  4016. if len(advices) > 0 {
  4017. for _, item := range advices {
  4018. creater := c.GetAdminUserInfo().AdminUser.Id
  4019. service.DrugAutoAddCancelInfo(item, creater)
  4020. }
  4021. }
  4022. } else {
  4023. if len(advices) > 0 {
  4024. for _, item := range advices {
  4025. creater := c.GetAdminUserInfo().AdminUser.Id
  4026. service.DrugAutoAddCancelInfo(item, creater)
  4027. }
  4028. }
  4029. }
  4030. }
  4031. c.ServeSuccessJSON(map[string]interface{}{
  4032. "msg": "删除成功",
  4033. })
  4034. return
  4035. }
  4036. func (c *HisApiController) DeleteDoctorAdvice() {
  4037. id, _ := c.GetInt64("id")
  4038. advice, _ := service.GetHisDoctorAdvicesById(id)
  4039. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4040. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4041. //已收费和已发药的限制逻辑
  4042. isCharge := false
  4043. isMedicine := false
  4044. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4045. //获取今天该患者所有处方,判断是否发药或者收费
  4046. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4047. for _, item := range new_prescriptions {
  4048. if item.IsMedicine == 1 {
  4049. isMedicine = true
  4050. }
  4051. }
  4052. for _, item := range new_prescriptions {
  4053. if item.OrderStatus == 4 {
  4054. isCharge = true
  4055. }
  4056. }
  4057. if isMedicine {
  4058. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4059. return
  4060. }
  4061. if isCharge {
  4062. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4063. return
  4064. }
  4065. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4066. for _, item := range advices {
  4067. if item.IsMedicine == 1 {
  4068. isMedicine = true
  4069. }
  4070. }
  4071. if isMedicine {
  4072. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4073. return
  4074. }
  4075. if new_prescription.ID > 0 {
  4076. if new_prescription.OrderStatus == 2 {
  4077. isCharge = true
  4078. }
  4079. }
  4080. if isCharge {
  4081. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4082. return
  4083. }
  4084. //已收费和已发药的限制逻辑
  4085. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4086. redis := service.RedisClient()
  4087. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4088. redis.Set(keyFive, "", time.Second)
  4089. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4090. redis.Set(keyOne, "", time.Second)
  4091. defer redis.Close()
  4092. if err == nil {
  4093. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4094. //查询是否在处方中出库
  4095. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4096. if openConfig.IsOpen != 1 {
  4097. //判断该医嘱是否执行了
  4098. if advice.ExecutionState == 1 {
  4099. creater := c.GetAdminUserInfo().AdminUser.Id
  4100. service.DrugAutoAddCancelInfo(&advice, creater)
  4101. }
  4102. }
  4103. //开启保存处方扣减功能
  4104. if openConfig.IsOpen == 1 {
  4105. creater := c.GetAdminUserInfo().AdminUser.Id
  4106. service.DrugAutoAddCancelInfo(&advice, creater)
  4107. }
  4108. } else {
  4109. if drugOutConfig.IsOpen == 1 {
  4110. //查询是否在处方中出库
  4111. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4112. if openConfig.IsOpen != 1 {
  4113. //判断该医嘱是否执行了
  4114. if advice.ExecutionState == 1 {
  4115. creater := c.GetAdminUserInfo().AdminUser.Id
  4116. service.DrugAutoAddCancelInfo(&advice, creater)
  4117. }
  4118. }
  4119. //开启保存处方扣减功能
  4120. if openConfig.IsOpen == 1 {
  4121. creater := c.GetAdminUserInfo().AdminUser.Id
  4122. service.DrugAutoAddCancelInfo(&advice, creater)
  4123. }
  4124. } else {
  4125. //判断该医嘱是否执行了
  4126. if advice.ExecutionState == 1 {
  4127. creater := c.GetAdminUserInfo().AdminUser.Id
  4128. service.DrugAutoAddCancelInfo(&advice, creater)
  4129. }
  4130. }
  4131. }
  4132. c.ServeSuccessJSON(map[string]interface{}{
  4133. "msg": "删除成功",
  4134. })
  4135. return
  4136. } else {
  4137. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4138. return
  4139. }
  4140. }
  4141. func (c *HisApiController) DeleteProject() {
  4142. id, _ := c.GetInt64("id")
  4143. adminInfo := c.GetAdminUserInfo()
  4144. project, _ := service.GetHisProjectByID(id)
  4145. // var consumable models.DialysisBeforePrepare
  4146. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4147. //耗材保存处方出库
  4148. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4149. isCharge := false
  4150. isMedicine := false
  4151. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4152. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4153. for _, item := range new_prescriptions {
  4154. if item.IsMedicine == 1 {
  4155. isMedicine = true
  4156. }
  4157. }
  4158. for _, item := range new_prescriptions {
  4159. if item.OrderStatus == 4 {
  4160. isCharge = true
  4161. }
  4162. }
  4163. if isMedicine {
  4164. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4165. return
  4166. }
  4167. if isCharge {
  4168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4169. return
  4170. }
  4171. if new_prescription.ID > 0 {
  4172. if new_prescription.OrderStatus == 2 {
  4173. isCharge = true
  4174. }
  4175. }
  4176. if isCharge {
  4177. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4178. return
  4179. }
  4180. service.DeletePrintInfo(id)
  4181. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4182. label.Status = 0
  4183. service.CreateHisLabelRecord(&label)
  4184. fmt.Println(goodOutConfig.IsOpen)
  4185. if goodOutConfig.IsOpen != 1 {
  4186. if stockConfig.IsOpen == 1 {
  4187. if project.Type == 2 {
  4188. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4189. fmt.Println(err)
  4190. }
  4191. if project.Type == 3 && project.IsOut == 1 {
  4192. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4193. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4194. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4195. operation_time := time.Now().Unix()
  4196. creater := adminInfo.AdminUser.Id
  4197. //创建退库单
  4198. timeStr := time.Now().Format("2006-01-02")
  4199. timeArr := strings.Split(timeStr, "-")
  4200. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4201. total = total + 1
  4202. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4203. cancelStock := models.CancelStock{
  4204. OrderNumber: orderNumber,
  4205. OperaTime: operation_time,
  4206. OrgId: adminInfo.CurrentOrgId,
  4207. Creater: creater,
  4208. Ctime: time.Now().Unix(),
  4209. Status: 1,
  4210. ReturnTime: project.RecordDate,
  4211. Type: 1,
  4212. StorehouseId: houseConfig.StorehouseOutInfo,
  4213. IsCheck: 1,
  4214. }
  4215. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4216. if msgerrkonde == gorm.ErrRecordNotFound {
  4217. service.AddSigleCancelStock(&cancelStock)
  4218. }
  4219. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4220. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4221. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4222. //查询是否有出库
  4223. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4224. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4225. deaerler, _ := service.GetDealerById(info.Dealer)
  4226. if info.ID > 0 {
  4227. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4228. if info.Count >= prescribingNumber {
  4229. cancelStockInfo := models.CancelStockInfo{
  4230. GoodId: project.ProjectId,
  4231. CancelStockId: cancel.ID,
  4232. GoodTypeId: good.GoodTypeId,
  4233. Count: prescribingNumber,
  4234. Price: info.Price,
  4235. Total: 0,
  4236. ProductDate: info.ProductDate,
  4237. ExpiryDate: info.ExpiryDate,
  4238. Ctime: time.Now().Unix(),
  4239. Status: 1,
  4240. OrgId: adminInfo.CurrentOrgId,
  4241. OrderNumber: cancel.OrderNumber,
  4242. Type: 0,
  4243. Dealer: deaerler.DealerName,
  4244. Manufacturer: manufacturer.ManufacturerName,
  4245. Number: info.Number,
  4246. RegisterAccount: "",
  4247. Remark: "",
  4248. WarehouseInfoId: info.WarehouseInfotId,
  4249. PatientId: info.PatientId,
  4250. RecordDate: info.SysRecordTime,
  4251. StorehouseId: houseConfig.StorehouseOutInfo,
  4252. IsCheck: 1,
  4253. }
  4254. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4255. //回退库存
  4256. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4257. //退库数量增加
  4258. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4259. //出库数量减少
  4260. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4261. }
  4262. if info.Count < prescribingNumber {
  4263. cancelStockInfo := models.CancelStockInfo{
  4264. GoodId: project.ProjectId,
  4265. CancelStockId: cancel.ID,
  4266. GoodTypeId: good.GoodTypeId,
  4267. Count: info.Count,
  4268. Price: info.Price,
  4269. Total: 0,
  4270. ProductDate: info.ProductDate,
  4271. ExpiryDate: info.ExpiryDate,
  4272. Ctime: time.Now().Unix(),
  4273. Status: 1,
  4274. OrgId: adminInfo.CurrentOrgId,
  4275. OrderNumber: cancel.OrderNumber,
  4276. Type: 0,
  4277. Dealer: deaerler.DealerName,
  4278. Manufacturer: manufacturer.ManufacturerName,
  4279. Number: info.Number,
  4280. RegisterAccount: "",
  4281. Remark: "",
  4282. WarehouseInfoId: info.WarehouseInfotId,
  4283. PatientId: info.PatientId,
  4284. RecordDate: info.SysRecordTime,
  4285. StorehouseId: houseConfig.StorehouseOutInfo,
  4286. IsCheck: 1,
  4287. }
  4288. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4289. //回退库存
  4290. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4291. //退库数量增加
  4292. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4293. //出库数量减少
  4294. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4295. }
  4296. //查询剩余库存
  4297. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4298. var over_count int64
  4299. for _, it := range goodList {
  4300. over_count += it.StockCount
  4301. }
  4302. //出库数据 大于 退库数量
  4303. if info.Count >= prescribingNumber {
  4304. flow := models.VmStockFlow{
  4305. WarehousingId: info.WarehouseInfotId,
  4306. GoodId: project.ProjectId,
  4307. Number: info.Number,
  4308. LicenseNumber: info.LicenseNumber,
  4309. Count: prescribingNumber,
  4310. UserOrgId: adminInfo.CurrentOrgId,
  4311. PatientId: project.PatientId,
  4312. SystemTime: info.SysRecordTime,
  4313. ConsumableType: 7,
  4314. IsSys: 0,
  4315. WarehousingOrder: "",
  4316. WarehouseOutId: info.WarehouseOutId,
  4317. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4318. IsEdit: 0,
  4319. CancelStockId: cancel.ID,
  4320. CancelOrderNumber: cancel.OrderNumber,
  4321. Manufacturer: manufacturer.ID,
  4322. Dealer: 0,
  4323. Creator: adminInfo.AdminUser.Id,
  4324. UpdateCreator: 0,
  4325. Status: 1,
  4326. Ctime: time.Now().Unix(),
  4327. Mtime: 0,
  4328. Price: info.Price,
  4329. WarehousingDetailId: info.WarehouseInfotId,
  4330. WarehouseOutDetailId: info.ID,
  4331. CancelOutDetailId: cancelInfo.ID,
  4332. ProductDate: info.ProductDate,
  4333. ExpireDate: info.ExpiryDate,
  4334. StorehouseId: houseConfig.StorehouseOutInfo,
  4335. OverCount: over_count,
  4336. }
  4337. service.CreateStockFlowOne(flow)
  4338. }
  4339. //出库数据小于退库数据
  4340. if info.Count < prescribingNumber {
  4341. flow := models.VmStockFlow{
  4342. WarehousingId: info.WarehouseInfotId,
  4343. GoodId: project.ProjectId,
  4344. Number: info.Number,
  4345. LicenseNumber: info.LicenseNumber,
  4346. Count: info.Count,
  4347. UserOrgId: adminInfo.CurrentOrgId,
  4348. PatientId: project.PatientId,
  4349. SystemTime: info.SysRecordTime,
  4350. ConsumableType: 7,
  4351. IsSys: 0,
  4352. WarehousingOrder: "",
  4353. WarehouseOutId: info.WarehouseOutId,
  4354. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4355. IsEdit: 0,
  4356. CancelStockId: cancel.ID,
  4357. CancelOrderNumber: cancel.OrderNumber,
  4358. Manufacturer: manufacturer.ID,
  4359. Dealer: 0,
  4360. Creator: adminInfo.AdminUser.Id,
  4361. UpdateCreator: 0,
  4362. Status: 1,
  4363. Ctime: time.Now().Unix(),
  4364. Mtime: 0,
  4365. Price: info.Price,
  4366. WarehousingDetailId: info.WarehouseInfotId,
  4367. WarehouseOutDetailId: info.ID,
  4368. CancelOutDetailId: cancelInfo.ID,
  4369. ProductDate: info.ProductDate,
  4370. ExpireDate: info.ExpiryDate,
  4371. StorehouseId: houseConfig.StorehouseOutInfo,
  4372. OverCount: over_count,
  4373. }
  4374. service.CreateStockFlowOne(flow)
  4375. }
  4376. //查询已出库数量
  4377. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4378. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4379. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4380. if prescribingNumber < dialysisInfo.Count {
  4381. //改变数量
  4382. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4383. }
  4384. if prescribingNumber >= dialysisInfo.Count {
  4385. //删除出库表
  4386. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4387. }
  4388. //更新剩余库存
  4389. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4390. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4391. var total_count_one int64
  4392. for _, it := range stockList {
  4393. total_count_one += it.StockCount
  4394. }
  4395. //基础库插入数据
  4396. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4397. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4398. var flush_count int64
  4399. for _, it := range goodListOne {
  4400. flush_count += it.StockCount
  4401. }
  4402. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4403. if errs != nil {
  4404. goodErrcode := models.XtGoodErrcode{
  4405. UserOrgId: project.UserOrgId,
  4406. Errcode: "手动出库更新剩余出库失败",
  4407. GoodId: project.ProjectId,
  4408. Status: 1,
  4409. Ctime: time.Now().Unix(),
  4410. Mtime: 0,
  4411. Count: 0,
  4412. StockCount: 0,
  4413. Creater: creater,
  4414. BatchNumberId: 0,
  4415. WarehouseOutId: 0,
  4416. }
  4417. service.CreateGoodErrcode(goodErrcode)
  4418. }
  4419. }
  4420. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4421. fmt.Println(err)
  4422. } else {
  4423. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4424. fmt.Println(err)
  4425. }
  4426. } else {
  4427. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4428. fmt.Println(err)
  4429. }
  4430. }
  4431. //保存处方出库
  4432. if goodOutConfig.IsOpen == 1 {
  4433. if project.Type == 3 {
  4434. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4435. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4436. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4437. operation_time := time.Now().Unix()
  4438. creater := adminInfo.AdminUser.Id
  4439. //创建退库单
  4440. timeStr := time.Now().Format("2006-01-02")
  4441. timeArr := strings.Split(timeStr, "-")
  4442. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4443. total = total + 1
  4444. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4445. cancelStock := models.CancelStock{
  4446. OrderNumber: orderNumber,
  4447. OperaTime: operation_time,
  4448. OrgId: adminInfo.CurrentOrgId,
  4449. Creater: creater,
  4450. Ctime: time.Now().Unix(),
  4451. Status: 1,
  4452. ReturnTime: project.RecordDate,
  4453. Type: 1,
  4454. StorehouseId: houseConfig.StorehouseOutInfo,
  4455. IsCheck: 1,
  4456. }
  4457. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4458. if msgerrkonde == gorm.ErrRecordNotFound {
  4459. service.AddSigleCancelStock(&cancelStock)
  4460. }
  4461. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4462. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4463. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4464. //获取出库数据
  4465. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4466. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4467. deaerler, _ := service.GetDealerById(info.Dealer)
  4468. if info.ID > 0 {
  4469. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4470. if info.Count >= prescribingNumber {
  4471. cancelStockInfo := models.CancelStockInfo{
  4472. GoodId: project.ProjectId,
  4473. CancelStockId: cancel.ID,
  4474. GoodTypeId: good.GoodTypeId,
  4475. Count: prescribingNumber,
  4476. Price: info.Price,
  4477. Total: 0,
  4478. ProductDate: info.ProductDate,
  4479. ExpiryDate: info.ExpiryDate,
  4480. Ctime: time.Now().Unix(),
  4481. Status: 1,
  4482. OrgId: adminInfo.CurrentOrgId,
  4483. OrderNumber: cancel.OrderNumber,
  4484. Type: 0,
  4485. Dealer: deaerler.DealerName,
  4486. Manufacturer: manufacturer.ManufacturerName,
  4487. Number: info.Number,
  4488. RegisterAccount: "",
  4489. Remark: "",
  4490. WarehouseInfoId: info.WarehouseInfotId,
  4491. PatientId: info.PatientId,
  4492. RecordDate: info.SysRecordTime,
  4493. StorehouseId: houseConfig.StorehouseOutInfo,
  4494. IsCheck: 1,
  4495. }
  4496. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4497. //退库数量增加
  4498. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4499. //出库数量减少
  4500. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4501. }
  4502. if info.Count < prescribingNumber {
  4503. cancelStockInfo := models.CancelStockInfo{
  4504. GoodId: project.ProjectId,
  4505. CancelStockId: cancel.ID,
  4506. GoodTypeId: good.GoodTypeId,
  4507. Count: prescribingNumber,
  4508. Price: info.Price,
  4509. Total: 0,
  4510. ProductDate: info.ProductDate,
  4511. ExpiryDate: info.ExpiryDate,
  4512. Ctime: time.Now().Unix(),
  4513. Status: 1,
  4514. OrgId: adminInfo.CurrentOrgId,
  4515. OrderNumber: cancel.OrderNumber,
  4516. Type: 0,
  4517. Dealer: deaerler.DealerName,
  4518. Manufacturer: manufacturer.ManufacturerName,
  4519. Number: info.Number,
  4520. RegisterAccount: "",
  4521. Remark: "",
  4522. WarehouseInfoId: info.WarehouseInfotId,
  4523. PatientId: info.PatientId,
  4524. RecordDate: info.SysRecordTime,
  4525. StorehouseId: houseConfig.StorehouseOutInfo,
  4526. IsCheck: 1,
  4527. }
  4528. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4529. //回退库存
  4530. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4531. }
  4532. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4533. var over_count int64
  4534. for _, it := range goodList {
  4535. over_count += it.StockCount
  4536. }
  4537. //查询出库数量
  4538. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4539. //出库数据 大于 退库数量
  4540. if len(list) > 0 {
  4541. for _, it := range list {
  4542. //回退库存
  4543. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4544. //退库数量增加
  4545. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4546. //出库数量减少
  4547. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4548. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4549. var over_count_one int64
  4550. for _, it := range goodList {
  4551. over_count_one += it.StockCount
  4552. }
  4553. //查询该批次是否有退库数据
  4554. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4555. flow := models.VmStockFlow{
  4556. WarehousingId: it.WarehouseInfotId,
  4557. GoodId: it.GoodId,
  4558. Number: it.Number,
  4559. LicenseNumber: it.LicenseNumber,
  4560. Count: it.Count,
  4561. UserOrgId: adminInfo.CurrentOrgId,
  4562. PatientId: it.PatientId,
  4563. SystemTime: it.SysRecordTime,
  4564. ConsumableType: 7,
  4565. IsSys: 0,
  4566. WarehousingOrder: "",
  4567. WarehouseOutId: it.WarehouseOutId,
  4568. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4569. IsEdit: 0,
  4570. CancelStockId: cancel.ID,
  4571. CancelOrderNumber: cancel.OrderNumber,
  4572. Manufacturer: manufacturer.ID,
  4573. Dealer: 0,
  4574. Creator: adminInfo.AdminUser.Id,
  4575. UpdateCreator: 0,
  4576. Status: 1,
  4577. Ctime: time.Now().Unix(),
  4578. Mtime: 0,
  4579. Price: it.Price,
  4580. WarehousingDetailId: it.WarehouseInfotId,
  4581. WarehouseOutDetailId: it.ID,
  4582. CancelOutDetailId: cancelInfo.ID,
  4583. ProductDate: it.ProductDate,
  4584. ExpireDate: it.ExpiryDate,
  4585. StorehouseId: houseConfig.StorehouseOutInfo,
  4586. OverCount: over_count_one,
  4587. }
  4588. service.CreateStockFlowOne(flow)
  4589. }
  4590. }
  4591. //查询已出库数量
  4592. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4593. if prescribingNumber < dialysisInfo.Count {
  4594. //改变数量
  4595. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4596. }
  4597. if prescribingNumber >= dialysisInfo.Count {
  4598. //删除出库表
  4599. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4600. }
  4601. //更新剩余库存
  4602. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4603. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4604. var total_count_one int64
  4605. for _, it := range stockList {
  4606. total_count_one += it.StockCount
  4607. }
  4608. //基础库插入数据
  4609. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4610. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4611. var flush_count int64
  4612. for _, it := range goodListOne {
  4613. flush_count += it.StockCount
  4614. }
  4615. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4616. if errs != nil {
  4617. goodErrcode := models.XtGoodErrcode{
  4618. UserOrgId: project.UserOrgId,
  4619. Errcode: "手动出库更新剩余出库失败",
  4620. GoodId: project.ProjectId,
  4621. Status: 1,
  4622. Ctime: time.Now().Unix(),
  4623. Mtime: 0,
  4624. Count: 0,
  4625. StockCount: 0,
  4626. Creater: creater,
  4627. BatchNumberId: 0,
  4628. WarehouseOutId: 0,
  4629. }
  4630. service.CreateGoodErrcode(goodErrcode)
  4631. }
  4632. }
  4633. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4634. fmt.Println(err)
  4635. } else {
  4636. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4637. fmt.Println(err)
  4638. }
  4639. }
  4640. c.ServeSuccessJSON(map[string]interface{}{
  4641. "msg": "删除成功",
  4642. })
  4643. return
  4644. }
  4645. func (c *HisApiController) CreateHisAdditionalCharge() {
  4646. his_patient_id, _ := c.GetInt64("his_patient_id")
  4647. patient_id, _ := c.GetInt64("patient_id")
  4648. record_date := c.GetString("record_date")
  4649. timeLayout := "2006-01-02"
  4650. loc, _ := time.LoadLocation("Local")
  4651. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4652. if err != nil {
  4653. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4654. return
  4655. }
  4656. adminInfo := c.GetAdminUserInfo()
  4657. recordDateTime := theTime.Unix()
  4658. dataBody := make(map[string]interface{}, 0)
  4659. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4660. if err != nil {
  4661. utils.ErrorLog(err.Error())
  4662. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4663. return
  4664. }
  4665. var additions []*models.HisAdditionalCharge
  4666. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4667. additions, _ := dataBody["addition"].([]interface{})
  4668. if len(additions) > 0 {
  4669. for _, item := range additions {
  4670. items := item.(map[string]interface{})
  4671. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4672. utils.ErrorLog("item_id")
  4673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4674. return
  4675. }
  4676. item_id := int64(items["item_id"].(float64))
  4677. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4678. utils.ErrorLog("item_name")
  4679. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4680. return
  4681. }
  4682. item_name := items["item_name"].(string)
  4683. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4684. utils.ErrorLog("price")
  4685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4686. return
  4687. }
  4688. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4689. ctime := time.Now().Unix()
  4690. additional := &models.HisAdditionalCharge{
  4691. PatientId: patient_id,
  4692. HisPatientId: his_patient_id,
  4693. UserOrgId: adminInfo.CurrentOrgId,
  4694. RecordDate: recordDateTime,
  4695. CreatedTime: ctime,
  4696. UpdatedTime: ctime,
  4697. Modifier: adminInfo.AdminUser.Id,
  4698. Creator: adminInfo.AdminUser.Id,
  4699. Price: price,
  4700. ItemName: item_name,
  4701. ItemId: item_id,
  4702. Status: 1,
  4703. }
  4704. additions = append(additions, additional)
  4705. }
  4706. }
  4707. }
  4708. for _, item := range additions {
  4709. service.CreateAddtionalCharge(item)
  4710. }
  4711. c.ServeSuccessJSON(map[string]interface{}{
  4712. "msg": "创建成功",
  4713. })
  4714. }
  4715. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4716. blood_fat := c.GetString("blood_fat")
  4717. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4718. blood_sugar := c.GetString("blood_sugar")
  4719. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4720. chief_conplaint := c.GetString("chief_conplaint")
  4721. dbp := c.GetString("dbp")
  4722. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4723. delivery_way, _ := c.GetInt64("delivery_way")
  4724. diagnostic := c.GetString("diagnostic")
  4725. family_history := c.GetString("family_history")
  4726. height := c.GetString("height")
  4727. history_of_present_illness := c.GetString("history_of_present_illness")
  4728. is_infect, _ := c.GetInt64("is_infect")
  4729. past_history := c.GetString("past_history")
  4730. patient_id, _ := c.GetInt64("patient_id")
  4731. his_patient_id, _ := c.GetInt64("his_patient_id")
  4732. personal_history := c.GetString("personal_history")
  4733. pulse := c.GetString("pulse")
  4734. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4735. sbp := c.GetString("sbp")
  4736. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4737. heightfloat, _ := strconv.ParseFloat(height, 64)
  4738. sicktype := c.GetString("sick_type")
  4739. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4740. symptom := c.GetString("symptom")
  4741. sick_date := c.GetString("sick_date")
  4742. temperatures := c.GetString("temperature")
  4743. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4744. record_date := c.GetString("record_date")
  4745. breathing := c.GetString("breathing")
  4746. doctor_advice := c.GetString("doctor_advice")
  4747. remark := c.GetString("remark")
  4748. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4749. sick, _ := c.GetInt64("sick")
  4750. diagnose, _ := c.GetInt64("diagnose")
  4751. //id, _ := c.GetInt64("id")
  4752. timeLayout := "2006-01-02"
  4753. loc, _ := time.LoadLocation("Local")
  4754. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4755. allergic_history := c.GetString("allergic_history")
  4756. if err != nil {
  4757. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4758. return
  4759. }
  4760. recordDateTime := theTime.Unix()
  4761. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4762. if err != nil {
  4763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4764. return
  4765. }
  4766. sickTimes := sickTime.Unix()
  4767. ctime := time.Now().Unix()
  4768. primary_disease := c.GetString("primary_disease")
  4769. confirm_failure_date := c.GetString("confirm_failure_date")
  4770. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4771. drug_allergy_history := c.GetString("drug_allergy_history")
  4772. physical_examination := c.GetString("physical_examination")
  4773. special_inspection := c.GetString("special_inspection")
  4774. lab_apparatus := c.GetString("lab_apparatus")
  4775. caseHistory := models.HisPatientCaseHistory{
  4776. HisPatientId: his_patient_id,
  4777. PatientId: patient_id,
  4778. Temperature: temperature,
  4779. BloodSugar: bloodsugarfloat,
  4780. Pulse: pulsefloat,
  4781. Sbp: sbpfloat,
  4782. Dbp: dbpfloat,
  4783. Height: heightfloat,
  4784. BloodFat: bloodfatfloat,
  4785. SickType: sick_type,
  4786. Symptom: symptom,
  4787. SickDate: sickTimes,
  4788. IsInfect: is_infect,
  4789. HistoryOfPresentIllness: history_of_present_illness,
  4790. PastHistory: past_history,
  4791. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4792. ChiefConplaint: chief_conplaint,
  4793. PersonalHistory: personal_history,
  4794. FamilyHistory: family_history,
  4795. Diagnostic: diagnostic,
  4796. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4797. Status: 1,
  4798. Ctime: ctime,
  4799. Mtime: ctime,
  4800. RecordDate: recordDateTime,
  4801. DeliveryWay: delivery_way,
  4802. Breathing: breathingfloat,
  4803. DoctorAdvice: doctor_advice,
  4804. Remark: remark,
  4805. Sick: sick,
  4806. Diagnose: diagnose,
  4807. AllergicHistory: allergic_history,
  4808. PrimaryDisease: primary_disease,
  4809. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4810. DrugAllergyHistory: drug_allergy_history,
  4811. PhysicalExamination: physical_examination,
  4812. SpecialInspection: special_inspection,
  4813. LabApparatus: lab_apparatus,
  4814. }
  4815. //查询该患者是否有病历
  4816. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4817. if errcodes == gorm.ErrRecordNotFound {
  4818. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4819. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4820. if err != nil {
  4821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4822. return
  4823. }
  4824. c.ServeSuccessJSON(map[string]interface{}{
  4825. "caseHistory": caseHistory,
  4826. "historyInfo": historyInfo,
  4827. })
  4828. return
  4829. } else if errcodes == nil {
  4830. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4831. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4832. if err != nil {
  4833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4834. return
  4835. }
  4836. c.ServeSuccessJSON(map[string]interface{}{
  4837. "caseHistory": caseHistory,
  4838. "historyInfo": historyInfo,
  4839. })
  4840. }
  4841. //查询该患者是否有病历
  4842. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4843. //if errcode == gorm.ErrRecordNotFound {
  4844. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4845. // if err != nil {
  4846. // c.ServeSuccessJSON(map[string]interface{}{
  4847. // "msg": "保存成功",
  4848. // })
  4849. // }
  4850. //} else if errcode == nil {
  4851. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4852. // return
  4853. //}
  4854. }
  4855. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4856. patient_id, _ := c.GetInt64("patient_id", 0)
  4857. adminUser := c.GetAdminUserInfo()
  4858. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4859. c.ServeSuccessJSON(map[string]interface{}{
  4860. "list": caseHistorys,
  4861. })
  4862. }
  4863. func (c *HisApiController) GetHisPatientCaseHistory() {
  4864. record_date, _ := c.GetInt64("record_date", 0)
  4865. patient_id, _ := c.GetInt64("patient_id", 0)
  4866. admin := c.GetAdminUserInfo()
  4867. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4868. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4869. c.ServeSuccessJSON(map[string]interface{}{
  4870. "info": info,
  4871. "case_history": case_history,
  4872. })
  4873. }
  4874. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4875. template_name := c.GetString("template_name")
  4876. template_remark := c.GetString("template_remark")
  4877. doctor := c.GetAdminUserInfo().AdminUser.Id
  4878. diagnostic := c.GetString("diagnostic")
  4879. chief_conplaint := c.GetString("chief_conplain")
  4880. history_of_present_illness := c.GetString("history_of_present_illness")
  4881. past_history := c.GetString("past_history")
  4882. personal_history := c.GetString("personal_history")
  4883. family_history := c.GetString("family_history")
  4884. user_name := c.GetString("user_name")
  4885. doctor_advice := c.GetString("doctor_advice")
  4886. remark := c.GetString("remark")
  4887. //record_date := c.GetString("record_date")
  4888. //fmt.Println("record_date--------",record_date)
  4889. //timeLayout := "2006-01-02"
  4890. //loc, _ := time.LoadLocation("Local")
  4891. //
  4892. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4893. //if err != nil {
  4894. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4895. // return
  4896. //}
  4897. //recordDateTime := theTime.Unix()
  4898. ctime := time.Now().Unix()
  4899. template := models.HisCaseHistoryTemplate{
  4900. HistoryOfPresentIllness: history_of_present_illness,
  4901. PastHistory: past_history,
  4902. ChiefConplaint: chief_conplaint,
  4903. PersonalHistory: personal_history,
  4904. FamilyHistory: family_history,
  4905. Diagnostic: diagnostic,
  4906. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4907. Status: 1,
  4908. Ctime: ctime,
  4909. Mtime: ctime,
  4910. RecordDate: time.Now().Unix(),
  4911. TemplateName: template_name,
  4912. TemplateRemark: template_remark,
  4913. Creator: doctor,
  4914. Modifier: doctor,
  4915. UserName: user_name,
  4916. DoctorAdvice: doctor_advice,
  4917. Remark: remark,
  4918. }
  4919. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4920. if err == nil {
  4921. c.ServeSuccessJSON(map[string]interface{}{
  4922. "msg": "保存成功",
  4923. })
  4924. } else {
  4925. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4926. return
  4927. }
  4928. }
  4929. func (c *HisApiController) GetCaseHistoryTemplate() {
  4930. timeLayout := "2006-01-02"
  4931. loc, _ := time.LoadLocation("Local")
  4932. keyword := c.GetString("keyword")
  4933. start_time := c.GetString("start_time")
  4934. end_time := c.GetString("end_time")
  4935. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4936. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4937. admin := c.GetAdminUserInfo()
  4938. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4939. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4940. c.ServeSuccessJSON(map[string]interface{}{
  4941. "template": template,
  4942. //"history": history,
  4943. })
  4944. }
  4945. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4946. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4947. utils.ErrorLog("drug_name")
  4948. return enums.ErrorCodeParamWrong
  4949. }
  4950. adviceName, _ := json["drug_name"].(string)
  4951. if len(adviceName) == 0 {
  4952. utils.ErrorLog("len(advice_name) == 0")
  4953. return enums.ErrorCodeParamWrong
  4954. }
  4955. advice.AdviceName = adviceName
  4956. adviceDesc, _ := json["advice_desc"].(string)
  4957. advice.AdviceDesc = adviceDesc
  4958. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4959. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4960. advice.DrugSpec = drugSpec
  4961. }
  4962. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4963. remark, _ := json["remark"].(string)
  4964. advice.Remark = remark
  4965. }
  4966. if json["id"] == nil {
  4967. advice.DrugId = 0
  4968. } else {
  4969. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4970. drug_id := int64(json["id"].(float64))
  4971. advice.DrugId = drug_id
  4972. }
  4973. }
  4974. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4975. advice_id := int64(json["advice_id"].(float64))
  4976. advice.ID = advice_id
  4977. if advice.ID > 0 {
  4978. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4979. if err == nil {
  4980. if hisAdvice.ID > 0 {
  4981. advice.ExecutionTime = hisAdvice.ExecutionTime
  4982. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4983. advice.ExecutionState = hisAdvice.ExecutionState
  4984. advice.CheckTime = hisAdvice.CheckTime
  4985. advice.Checker = hisAdvice.Checker
  4986. advice.CheckState = hisAdvice.CheckState
  4987. advice.StartTime = hisAdvice.StartTime
  4988. advice.FeedetlSn = hisAdvice.FeedetlSn
  4989. }
  4990. }
  4991. }
  4992. }
  4993. //
  4994. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4995. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4996. // advice.ExecutionTime = execution_time
  4997. //}
  4998. //
  4999. //
  5000. //
  5001. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5002. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5003. // advice.ExecutionStaff = execution_staff
  5004. //}
  5005. //
  5006. //
  5007. //
  5008. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5009. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5010. // advice.ExecutionState = execution_state
  5011. //}
  5012. //
  5013. //
  5014. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5015. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5016. // advice.CheckTime = check_time
  5017. //}
  5018. //
  5019. //
  5020. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5021. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5022. // advice.CheckState = check_state
  5023. //}
  5024. //
  5025. //
  5026. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5027. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5028. // advice.Checker = checker
  5029. //}
  5030. //
  5031. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5032. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5033. // advice.StartTime = start_time
  5034. //}
  5035. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5036. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5037. advice.IsSelfDrug = is_self_drug
  5038. }
  5039. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5040. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5041. drug_way_count, _ := json["drug_way_count"].(string)
  5042. advice.DrugWayCount = drug_way_count
  5043. }
  5044. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5045. drugSpecUnit, _ := json["min_unit"].(string)
  5046. advice.DrugSpecUnit = drugSpecUnit
  5047. }
  5048. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5049. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5050. advice.SingleDose = singleDose
  5051. }
  5052. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5053. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5054. advice.SingleDoseUnit = singleDoseUnit
  5055. }
  5056. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5057. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5058. advice.PrescribingNumber = prescribingNumber
  5059. }
  5060. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5061. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5062. advice.PrescribingNumberUnit = prescribingNumberUnit
  5063. }
  5064. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5065. deliveryWay, _ := json["delivery_way"].(string)
  5066. advice.DeliveryWay = deliveryWay
  5067. }
  5068. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5069. executionFrequency, _ := json["execution_frequency"].(string)
  5070. advice.ExecutionFrequency = executionFrequency
  5071. }
  5072. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5073. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5074. advice.Price = price
  5075. }
  5076. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5077. med_list_codg, _ := json["medical_insurance_number"].(string)
  5078. advice.MedListCodg = med_list_codg
  5079. }
  5080. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5081. day := int64(json["day"].(float64))
  5082. advice.Day = day
  5083. }
  5084. return 0
  5085. }
  5086. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5087. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5088. id := int64(json["id"].(float64))
  5089. project.ID = id
  5090. historyProject, _ := service.GetHisProjectByID(id)
  5091. project.FeedetlSn = historyProject.FeedetlSn
  5092. }
  5093. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5094. project_id := int64(json["project_id"].(float64))
  5095. project.ProjectId = project_id
  5096. }
  5097. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5098. // price := int64(json["price"].(float64))
  5099. // formatInt_price := strconv.FormatInt(price, 10)
  5100. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5101. // project.Price = float_price
  5102. // }
  5103. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5104. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5105. project.Price = price
  5106. }
  5107. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5108. total, _ := json["total"].(string)
  5109. project.Count = total
  5110. }
  5111. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5112. medical_code, _ := json["medical_code"].(string)
  5113. project.MedListCodg = medical_code
  5114. }
  5115. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5116. single_dose, _ := json["single_dose"].(string)
  5117. project.SingleDose = single_dose
  5118. }
  5119. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5120. delivery_way, _ := json["delivery_way"].(string)
  5121. project.DeliveryWay = delivery_way
  5122. }
  5123. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5124. execution_frequency, _ := json["execution_frequency"].(string)
  5125. project.ExecutionFrequency = execution_frequency
  5126. }
  5127. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5128. remark, _ := json["remark"].(string)
  5129. project.Remark = remark
  5130. }
  5131. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5132. day, _ := json["number_days"].(string)
  5133. project.Day = day
  5134. }
  5135. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5136. unit, _ := json["unit"].(string)
  5137. project.Unit = unit
  5138. }
  5139. return 0
  5140. }
  5141. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5142. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5143. id := int64(json["id"].(float64))
  5144. historyAddtions, _ := service.GetHisAdditionByID(id)
  5145. additionalCharge.ID = id
  5146. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5147. }
  5148. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5149. item_id := int64(json["item_id"].(float64))
  5150. additionalCharge.ItemId = item_id
  5151. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5152. if config.ID > 0 {
  5153. if len(config.Code) > 0 {
  5154. additionalCharge.MedListCodg = config.Code
  5155. }
  5156. }
  5157. }
  5158. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5159. // price := int64(json["price"].(float64))
  5160. // formatInt_price := strconv.FormatInt(price, 10)
  5161. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5162. // additionalCharge.Price = float_price
  5163. // }
  5164. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5165. // price := int64(json["price"].(float64))
  5166. // formatInt_price := strconv.FormatInt(price, 10)
  5167. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5168. // additionalCharge.Price = float_price
  5169. //}
  5170. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5171. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5172. additionalCharge.Price = price
  5173. }
  5174. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5175. count, _ := json["count"].(string)
  5176. counts, _ := strconv.ParseInt(count, 10, 64)
  5177. additionalCharge.Count = counts
  5178. }
  5179. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5180. item_name, _ := json["item_name"].(string)
  5181. additionalCharge.ItemName = item_name
  5182. }
  5183. return 0
  5184. }
  5185. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5186. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5187. utils.ErrorLog("drug_name")
  5188. return enums.ErrorCodeParamWrong
  5189. }
  5190. adviceName, _ := json["drug_name"].(string)
  5191. if len(adviceName) == 0 {
  5192. utils.ErrorLog("len(advice_name) == 0")
  5193. return enums.ErrorCodeParamWrong
  5194. }
  5195. advice.AdviceName = adviceName
  5196. adviceDesc, _ := json["advice_desc"].(string)
  5197. advice.AdviceDesc = adviceDesc
  5198. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5199. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5200. advice.DrugSpec = drugSpec
  5201. }
  5202. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5203. remark, _ := json["remark"].(string)
  5204. advice.Remark = remark
  5205. }
  5206. if json["id"] == nil {
  5207. advice.DrugId = 0
  5208. } else {
  5209. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5210. drug_id := int64(json["id"].(float64))
  5211. advice.DrugId = drug_id
  5212. }
  5213. }
  5214. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5215. groupno := int64(json["groupno"].(float64))
  5216. advice.Groupno = groupno
  5217. }
  5218. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5219. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5220. advice.IsSelfDrug = is_self_drug
  5221. }
  5222. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5223. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5224. drug_way_count, _ := json["drug_way_count"].(string)
  5225. advice.DrugWayCount = drug_way_count
  5226. }
  5227. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5228. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5229. advice.HospApprFlag = hosp_appr_flag
  5230. }
  5231. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5232. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5233. advice.PrescribingNumber = prescribingNumber
  5234. }
  5235. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5236. // frequency_type := int64(json["frequency_type"].(float64))
  5237. // advice.FrequencyType = frequency_type
  5238. //}
  5239. //
  5240. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5241. // day_count := int64(json["day_count"].(float64))
  5242. // advice.DayCount = day_count
  5243. //}
  5244. //
  5245. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5246. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5247. // week_day, _ := json["week_day"].(string)
  5248. // advice.WeekDay = week_day
  5249. //}
  5250. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5251. drugSpecUnit, _ := json["min_unit"].(string)
  5252. advice.DrugSpecUnit = drugSpecUnit
  5253. }
  5254. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5255. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5256. advice.SingleDose = singleDose
  5257. }
  5258. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5259. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5260. advice.SingleDoseUnit = singleDoseUnit
  5261. }
  5262. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5263. deliveryWay, _ := json["delivery_way"].(string)
  5264. advice.DeliveryWay = deliveryWay
  5265. }
  5266. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5267. executionFrequency, _ := json["execution_frequency"].(string)
  5268. advice.ExecutionFrequency = executionFrequency
  5269. }
  5270. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5271. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5272. advice.Price = price
  5273. }
  5274. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5275. med_list_codg, _ := json["medical_insurance_number"].(string)
  5276. advice.MedListCodg = med_list_codg
  5277. }
  5278. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5279. day := int64(json["day"].(float64))
  5280. advice.Day = day
  5281. }
  5282. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5283. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5284. advice.PrescribingNumberUnit = prescribingNumberUnit
  5285. }
  5286. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5287. advice_id := int64(json["advice_id"].(float64))
  5288. advice.ID = advice_id
  5289. if advice.ID > 0 {
  5290. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5291. if err == nil {
  5292. if hisAdvice.ID > 0 {
  5293. advice.ExecutionTime = hisAdvice.ExecutionTime
  5294. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5295. advice.ExecutionState = hisAdvice.ExecutionState
  5296. advice.CheckTime = hisAdvice.CheckTime
  5297. advice.Checker = hisAdvice.Checker
  5298. advice.CheckState = hisAdvice.CheckState
  5299. advice.StartTime = hisAdvice.StartTime
  5300. advice.HospApprFlag = hisAdvice.HospApprFlag
  5301. advice.IsMedicine = hisAdvice.IsMedicine
  5302. if hisAdvice.UserOrgId == 10028 {
  5303. 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 {
  5304. advice.ExecutionTime = 0
  5305. advice.ExecutionStaff = 0
  5306. advice.ExecutionState = 2
  5307. advice.CheckTime = 0
  5308. advice.Checker = 0
  5309. advice.CheckState = 2
  5310. }
  5311. } else {
  5312. 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 {
  5313. advice.ExecutionTime = 0
  5314. advice.ExecutionStaff = 0
  5315. advice.ExecutionState = 2
  5316. advice.CheckTime = 0
  5317. advice.Checker = 0
  5318. advice.CheckState = 2
  5319. }
  5320. }
  5321. //advice.Groupno = hisAdvice.Groupno
  5322. }
  5323. }
  5324. }
  5325. }
  5326. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5327. //
  5328. //if drugStockConfig.IsOpen == 1 {
  5329. //
  5330. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5331. // if advice.ID == 0 { //医嘱不存在
  5332. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5333. // drug.Total = drug.Total - advice.PrescribingNumber
  5334. // service.UpdateBaseDrugLib(&drug)
  5335. //
  5336. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5337. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5338. // drug.Total = drug.Total - num
  5339. // service.UpdateBaseDrugLib(&drug)
  5340. // }
  5341. //
  5342. // } else if advice.ID > 0 { //医嘱存在
  5343. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5344. // var num float64
  5345. //
  5346. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5347. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5348. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5349. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5350. // drug.Total = drug.Total + num
  5351. // service.UpdateBaseDrugLib(&drug)
  5352. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5353. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5354. // drug.Total = drug.Total - num
  5355. // service.UpdateBaseDrugLib(&drug)
  5356. // }
  5357. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5358. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5359. // if num2 > advice.PrescribingNumber {
  5360. // num = num2 - advice.PrescribingNumber
  5361. // drug.Total = drug.Total + num
  5362. // service.UpdateBaseDrugLib(&drug)
  5363. // } else if num2 < advice.PrescribingNumber {
  5364. // num = advice.PrescribingNumber - num2
  5365. // drug.Total = drug.Total - num
  5366. // service.UpdateBaseDrugLib(&drug)
  5367. // }
  5368. //
  5369. // }
  5370. //
  5371. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5372. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5373. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5374. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5375. // if num1 > num2 {
  5376. // num = num1 - num2
  5377. // drug.Total = drug.Total + num
  5378. // service.UpdateBaseDrugLib(&drug)
  5379. // } else if num1 < num2 {
  5380. // num = num2 - num1
  5381. // drug.Total = drug.Total - num
  5382. // service.UpdateBaseDrugLib(&drug)
  5383. // }
  5384. //
  5385. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5386. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5387. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5388. // if hisAdvice.PrescribingNumber > num2 {
  5389. // num = hisAdvice.PrescribingNumber - num2
  5390. // drug.Total = drug.Total + num
  5391. // service.UpdateBaseDrugLib(&drug)
  5392. // } else if num2 < advice.PrescribingNumber {
  5393. // num = num2 - hisAdvice.PrescribingNumber
  5394. // drug.Total = drug.Total - num
  5395. // service.UpdateBaseDrugLib(&drug)
  5396. // }
  5397. //
  5398. // }
  5399. // }
  5400. // }
  5401. //}
  5402. //
  5403. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5404. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5405. // advice.ExecutionTime = execution_time
  5406. //}
  5407. //
  5408. //
  5409. //
  5410. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5411. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5412. // advice.ExecutionStaff = execution_staff
  5413. //}
  5414. //
  5415. //
  5416. //
  5417. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5418. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5419. // advice.ExecutionState = execution_state
  5420. //}
  5421. //
  5422. //
  5423. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5424. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5425. // advice.CheckTime = check_time
  5426. //}
  5427. //
  5428. //
  5429. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5430. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5431. // advice.CheckState = check_state
  5432. //}
  5433. //
  5434. //
  5435. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5436. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5437. // advice.Checker = checker
  5438. //}
  5439. //
  5440. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5441. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5442. // advice.StartTime = start_time
  5443. //}
  5444. return 0
  5445. }
  5446. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5447. project.ExecutionStaff = 0
  5448. project.ExecutionState = 2
  5449. project.ExecutionTime = 0
  5450. project.Checker = 0
  5451. project.CheckState = 2
  5452. project.CheckTime = 0
  5453. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5454. id := int64(json["id"].(float64))
  5455. project.ID = id
  5456. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5457. project.ExecutionStaff = temp_project.ExecutionStaff
  5458. project.ExecutionState = temp_project.ExecutionState
  5459. project.ExecutionTime = temp_project.ExecutionTime
  5460. project.Checker = temp_project.Checker
  5461. project.CheckState = temp_project.CheckState
  5462. project.CheckTime = temp_project.CheckTime
  5463. project.TeamId = temp_project.TeamId
  5464. }
  5465. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5466. types := int64(json["type"].(float64))
  5467. project.Type = types
  5468. }
  5469. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5470. project_id := int64(json["project_id"].(float64))
  5471. project.ProjectId = project_id
  5472. }
  5473. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5474. team_id := int64(json["team_id"].(float64))
  5475. project.TeamId = team_id
  5476. }
  5477. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5478. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5479. project.Price = price
  5480. }
  5481. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5482. total, _ := json["total"].(string)
  5483. //totals, _ := strconv.ParseInt(total, 10, 64)
  5484. project.Count = total
  5485. }
  5486. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5487. medical_code, _ := json["medical_code"].(string)
  5488. project.MedListCodg = medical_code
  5489. }
  5490. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5491. single_dose, _ := json["single_dose"].(string)
  5492. project.SingleDose = single_dose
  5493. }
  5494. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5495. delivery_way, _ := json["delivery_way"].(string)
  5496. project.DeliveryWay = delivery_way
  5497. }
  5498. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5499. execution_frequency, _ := json["execution_frequency"].(string)
  5500. project.ExecutionFrequency = execution_frequency
  5501. }
  5502. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5503. remark, _ := json["remark"].(string)
  5504. project.Remark = remark
  5505. }
  5506. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5507. day, _ := json["number_days"].(string)
  5508. project.Day = day
  5509. }
  5510. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5511. unit, _ := json["unit"].(string)
  5512. project.Unit = unit
  5513. }
  5514. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5515. // frequency_type := int64(json["frequency_type"].(float64))
  5516. // project.FrequencyType = frequency_type
  5517. //}
  5518. //
  5519. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5520. // day_count := int64(json["day_count"].(float64))
  5521. // project.DayCount = day_count
  5522. //}
  5523. //
  5524. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5525. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5526. // week_day, _ := json["week_day"].(string)
  5527. // project.WeekDay = week_day
  5528. //}
  5529. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5530. //
  5531. //if project.ID == 0 {
  5532. // if stockConfig.IsOpen == 1 {
  5533. // if project.Type == 3 {
  5534. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5535. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5536. // good.Total = good.Total - f_count
  5537. // service.UpdateGoodInfo(&good)
  5538. // }
  5539. // }
  5540. //
  5541. //} else {
  5542. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5543. //
  5544. // if stockConfig.IsOpen == 1 {
  5545. // if project.Type == 3 {
  5546. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5547. // if project.Count < temp_project.Count {
  5548. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5549. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5550. //
  5551. // other_count := f_count_two - f_count_one
  5552. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5553. // good.Total = good.Total + other_count_two
  5554. // service.UpdateGoodInfo(&good)
  5555. // } else if project.Count > temp_project.Count {
  5556. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5557. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5558. //
  5559. // other_count := f_count_one - f_count_two
  5560. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5561. // good.Total = good.Total - other_count_two
  5562. // service.UpdateGoodInfo(&good)
  5563. // }
  5564. //
  5565. // }
  5566. // }
  5567. //
  5568. //}
  5569. return 0
  5570. }
  5571. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5572. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5573. id := int64(json["id"].(float64))
  5574. additionalCharge.ID = id
  5575. }
  5576. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5577. item_id := int64(json["item_id"].(float64))
  5578. additionalCharge.ItemId = item_id
  5579. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5580. if config.ID > 0 {
  5581. if len(config.Code) > 0 {
  5582. additionalCharge.MedListCodg = config.Code
  5583. }
  5584. }
  5585. }
  5586. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5587. // price := int64(json["price"].(float64))
  5588. // formatInt_price := strconv.FormatInt(price, 10)
  5589. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5590. // additionalCharge.Price = float_price
  5591. // }
  5592. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5593. // price := int64(json["price"].(float64))
  5594. // formatInt_price := strconv.FormatInt(price, 10)
  5595. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5596. // additionalCharge.Price = float_price
  5597. //}
  5598. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5599. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5600. additionalCharge.Price = price
  5601. }
  5602. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5603. count, _ := json["count"].(string)
  5604. counts, _ := strconv.ParseInt(count, 10, 64)
  5605. additionalCharge.Count = counts
  5606. }
  5607. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5608. item_name, _ := json["item_name"].(string)
  5609. additionalCharge.ItemName = item_name
  5610. }
  5611. return 0
  5612. }
  5613. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5614. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5615. utils.ErrorLog("drug_name")
  5616. return enums.ErrorCodeParamWrong
  5617. }
  5618. adviceName, _ := json["drug_name"].(string)
  5619. if len(adviceName) == 0 {
  5620. utils.ErrorLog("len(advice_name) == 0")
  5621. return enums.ErrorCodeParamWrong
  5622. }
  5623. advice.AdviceName = adviceName
  5624. adviceDesc, _ := json["advice_desc"].(string)
  5625. advice.AdviceDesc = adviceDesc
  5626. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5627. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5628. advice.DrugSpec = drugSpec
  5629. }
  5630. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5631. remark, _ := json["remark"].(string)
  5632. advice.Remark = remark
  5633. }
  5634. if json["id"] == nil {
  5635. advice.DrugId = 0
  5636. } else {
  5637. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5638. drug_id := int64(json["id"].(float64))
  5639. advice.DrugId = drug_id
  5640. }
  5641. }
  5642. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5643. groupno := int64(json["groupno"].(float64))
  5644. advice.Groupno = groupno
  5645. }
  5646. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5647. drugSpecUnit, _ := json["min_unit"].(string)
  5648. advice.DrugSpecUnit = drugSpecUnit
  5649. }
  5650. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5651. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5652. advice.SingleDose = singleDose
  5653. }
  5654. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5655. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5656. advice.SingleDoseUnit = singleDoseUnit
  5657. }
  5658. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5659. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5660. advice.PrescribingNumber = prescribingNumber
  5661. }
  5662. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5663. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5664. advice.PrescribingNumberUnit = prescribingNumberUnit
  5665. }
  5666. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5667. deliveryWay, _ := json["delivery_way"].(string)
  5668. advice.DeliveryWay = deliveryWay
  5669. }
  5670. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5671. executionFrequency, _ := json["execution_frequency"].(string)
  5672. advice.ExecutionFrequency = executionFrequency
  5673. }
  5674. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5675. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5676. advice.Price = price
  5677. }
  5678. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5679. med_list_codg, _ := json["medical_insurance_number"].(string)
  5680. advice.MedListCodg = med_list_codg
  5681. }
  5682. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5683. day := int64(json["day"].(float64))
  5684. advice.Day = day
  5685. }
  5686. advice.FrequencyType = 1
  5687. return 0
  5688. }
  5689. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5690. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5691. types := int64(json["type"].(float64))
  5692. project.Type = types
  5693. }
  5694. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5695. project_id := int64(json["project_id"].(float64))
  5696. project.ProjectId = project_id
  5697. }
  5698. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5699. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5700. project.Price = price
  5701. }
  5702. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5703. total, _ := json["total"].(string)
  5704. //totals, _ := strconv.ParseInt(total, 10, 64)
  5705. project.Count = total
  5706. }
  5707. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5708. medical_code, _ := json["medical_code"].(string)
  5709. project.MedListCodg = medical_code
  5710. }
  5711. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5712. single_dose, _ := json["single_dose"].(string)
  5713. project.SingleDose = single_dose
  5714. }
  5715. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5716. delivery_way, _ := json["delivery_way"].(string)
  5717. project.DeliveryWay = delivery_way
  5718. }
  5719. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5720. execution_frequency, _ := json["execution_frequency"].(string)
  5721. project.ExecutionFrequency = execution_frequency
  5722. }
  5723. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5724. remark, _ := json["remark"].(string)
  5725. project.Remark = remark
  5726. }
  5727. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5728. day, _ := json["number_days"].(string)
  5729. project.Day = day
  5730. }
  5731. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5732. unit, _ := json["unit"].(string)
  5733. project.Unit = unit
  5734. }
  5735. project.FrequencyType = 1
  5736. return 0
  5737. }
  5738. func (c *HisApiController) GetHisOrderList() {
  5739. page, _ := c.GetInt64("page", -1)
  5740. limit, _ := c.GetInt64("limit", -1)
  5741. start_time := c.GetString("start_time")
  5742. end_time := c.GetString("end_time")
  5743. types, _ := c.GetInt64("type", 0)
  5744. keywords := c.GetString("keywords")
  5745. p_type, _ := c.GetInt64("p_type", 0)
  5746. sort_type, _ := c.GetInt64("sort_type", 0)
  5747. charge_type, _ := c.GetInt64("charge_type", 0)
  5748. sch_type, _ := c.GetInt64("sch_type", 0)
  5749. zone_type, _ := c.GetInt64("zone_type", 0)
  5750. med_type, _ := c.GetInt64("med_type", 0)
  5751. timeLayout := "2006-01-02"
  5752. loc, _ := time.LoadLocation("Local")
  5753. var startTime int64
  5754. if len(start_time) > 0 {
  5755. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5756. if err != nil {
  5757. //fmt.Println(err)
  5758. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5759. return
  5760. }
  5761. startTime = theTime.Unix()
  5762. }
  5763. var endTime int64
  5764. if len(end_time) > 0 {
  5765. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5766. if err != nil {
  5767. utils.ErrorLog(err.Error())
  5768. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5769. return
  5770. }
  5771. endTime = theTime.Unix()
  5772. }
  5773. adminUser := c.GetAdminUserInfo()
  5774. org_id := adminUser.CurrentOrgId
  5775. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  5776. order2, _ := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  5777. for _, item := range order {
  5778. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5779. item.DoctorName = info.Doctor
  5780. item.DepartmentName = info.XtHisDepartment.Name
  5781. }
  5782. if err == nil {
  5783. c.ServeSuccessJSON(map[string]interface{}{
  5784. "order": order,
  5785. "order2": order2,
  5786. "total": total,
  5787. })
  5788. } else {
  5789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5790. return
  5791. }
  5792. }
  5793. func (c *HisApiController) GetHisOrder() {
  5794. patient_id, _ := c.GetInt64("patient_id", 0)
  5795. number := c.GetString("number")
  5796. adminInfo := c.GetAdminUserInfo()
  5797. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5798. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5799. if err == nil {
  5800. c.ServeSuccessJSON(map[string]interface{}{
  5801. "order": order,
  5802. "prescription": prescriptions,
  5803. })
  5804. } else {
  5805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5806. return
  5807. }
  5808. }
  5809. func (c *HisApiController) GetHisPrescriptionList() {
  5810. record_date := c.GetString("record_date")
  5811. keywords := c.GetString("keywords")
  5812. page, _ := c.GetInt64("page")
  5813. limit, _ := c.GetInt64("limit")
  5814. sch_type, _ := c.GetInt64("sch_type")
  5815. timeLayout := "2006-01-02"
  5816. loc, _ := time.LoadLocation("Local")
  5817. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5818. if err != nil {
  5819. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5820. return
  5821. }
  5822. recordDateTime := theTime.Unix()
  5823. adminInfo := c.GetAdminUserInfo()
  5824. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5825. //adminInfo := c.GetAdminUserInfo()
  5826. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5827. //fmt.Println(prescriptionOrder)
  5828. if err == nil {
  5829. c.ServeSuccessJSON(map[string]interface{}{
  5830. "order": prescriptionOrder,
  5831. "total": total,
  5832. })
  5833. } else {
  5834. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5835. return
  5836. }
  5837. }
  5838. func (c *HisApiController) GetHisPrescriptionInfo() {
  5839. id, _ := c.GetInt64("id")
  5840. adminInfo := c.GetAdminUserInfo()
  5841. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5842. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5843. if err == nil {
  5844. c.ServeSuccessJSON(map[string]interface{}{
  5845. "order": prescriptionOrder,
  5846. "prescription": prescription,
  5847. })
  5848. } else {
  5849. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5850. return
  5851. }
  5852. }
  5853. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5854. adminUser := c.GetAdminUserInfo()
  5855. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5856. c.ServeSuccessJSON(map[string]interface{}{
  5857. "config": config,
  5858. })
  5859. }
  5860. type ResultTwo struct {
  5861. ErrMsg interface{} `json:"err_msg"`
  5862. InfRefmsgid string `json:"inf_refmsgid"`
  5863. Infcode int64 `json:"infcode"`
  5864. Output struct {
  5865. Baseinfo struct {
  5866. Age float64 `json:"age"`
  5867. Brdy string `json:"brdy"`
  5868. Certno string `json:"certno"`
  5869. Gend string `json:"gend"`
  5870. Naty string `json:"naty"`
  5871. PsnCertType string `json:"psn_cert_type"`
  5872. PsnName string `json:"psn_name"`
  5873. PsnNo string `json:"psn_no"`
  5874. } `json:"baseinfo"`
  5875. Idetinfo []interface{} `json:"idetinfo"`
  5876. Iinfo []struct {
  5877. Balc float64 `json:"balc"`
  5878. CvlservFlag string `json:"cvlserv_flag"`
  5879. EmpName string `json:"emp_name"`
  5880. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5881. Insutype string `json:"insutype"`
  5882. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5883. PausInsuDate interface{} `json:"paus_insu_date"`
  5884. PsnInsuDate string `json:"psn_insu_date"`
  5885. PsnInsuStas string `json:"psn_insu_stas"`
  5886. PsnType string `json:"psn_type"`
  5887. } `json:"insuinfo"`
  5888. } `json:"output"`
  5889. RefmsgTime string `json:"refmsg_time"`
  5890. RespondTime string `json:"respond_time"`
  5891. Signtype interface{} `json:"signtype"`
  5892. WarnInfo interface{} `json:"warn_info"`
  5893. }
  5894. type ResultThree struct {
  5895. Cainfo interface{} `json:"cainfo"`
  5896. ErrMsg interface{} `json:"err_msg"`
  5897. InfRefmsgid string `json:"inf_refmsgid"`
  5898. Infcode int64 `json:"infcode"`
  5899. Output struct {
  5900. Data struct {
  5901. IptOtpNo string `json:"ipt_otp_no"`
  5902. MdtrtID string `json:"mdtrt_id"`
  5903. PsnNo string `json:"psn_no"`
  5904. } `json:"data"`
  5905. } `json:"output"`
  5906. RefmsgTime string `json:"refmsg_time"`
  5907. RespondTime string `json:"respond_time"`
  5908. Signtype interface{} `json:"signtype"`
  5909. WarnMsg interface{} `json:"warn_msg"`
  5910. }
  5911. type ResultFour struct {
  5912. Cainfo string `json:"cainfo"`
  5913. ErrMsg string `json:"err_msg"`
  5914. InfRefmsgid string `json:"inf_refmsgid"`
  5915. Infcode int64 `json:"infcode"`
  5916. Output struct {
  5917. Result []struct {
  5918. BasMednFlag string `json:"bas_medn_flag"`
  5919. ChldMedcFlag string `json:"chld_medc_flag"`
  5920. ChrgitmLv string `json:"chrgitm_lv"`
  5921. Cnt float64 `json:"cnt"`
  5922. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5923. DrtReimFlag string `json:"drt_reim_flag"`
  5924. FeedetlSn string `json:"feedetl_sn"`
  5925. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5926. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5927. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5928. ListSpItemFlag string `json:"list_sp_item_flag"`
  5929. LmtUsedFlag string `json:"lmt_used_flag"`
  5930. MedChrgitmType string `json:"med_chrgitm_type"`
  5931. Memo string `json:"memo"`
  5932. OverlmtAmt float64 `json:"overlmt_amt"`
  5933. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5934. Pric float64 `json:"pric"`
  5935. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5936. SelfpayProp float64 `json:"selfpay_prop"`
  5937. } `json:"result"`
  5938. } `json:"output"`
  5939. RefmsgTime string `json:"refmsg_time"`
  5940. RespondTime string `json:"respond_time"`
  5941. Signtype string `json:"signtype"`
  5942. WarnMsg string `json:"warn_msg"`
  5943. }
  5944. type ResultFive struct {
  5945. Insutype string `json:"insutype"`
  5946. }
  5947. type ResultSix struct {
  5948. Cainfo interface{} `json:"cainfo"`
  5949. ErrMsg interface{} `json:"err_msg"`
  5950. InfRefmsgid string `json:"inf_refmsgid"`
  5951. Infcode int64 `json:"infcode"`
  5952. Output struct {
  5953. } `json:"output"`
  5954. RefmsgTime string `json:"refmsg_time"`
  5955. RespondTime string `json:"respond_time"`
  5956. Signtype interface{} `json:"signtype"`
  5957. WarnMsg interface{} `json:"warn_msg"`
  5958. }
  5959. type ResultSeven struct {
  5960. Cainfo string `json:"cainfo"`
  5961. ErrMsg string `json:"err_msg"`
  5962. InfRefmsgid string `json:"inf_refmsgid"`
  5963. Infcode int64 `json:"infcode"`
  5964. Output struct {
  5965. Setldetail []interface{} `json:"setldetail"`
  5966. Setlinfo struct {
  5967. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5968. AcctPay float64 `json:"acct_pay"`
  5969. ActPayDedc float64 `json:"act_pay_dedc"`
  5970. Age float64 `json:"age"`
  5971. Balc float64 `json:"balc"`
  5972. Brdy string `json:"brdy"`
  5973. Certno string `json:"certno"`
  5974. ClrOptins string `json:"clr_optins"`
  5975. ClrType string `json:"clr_type"`
  5976. ClrWay string `json:"clr_way"`
  5977. CvlservFlag string `json:"cvlserv_flag"`
  5978. CvlservPay float64 `json:"cvlserv_pay"`
  5979. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5980. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5981. Gend string `json:"gend"`
  5982. HifesPay float64 `json:"hifes_pay"`
  5983. HifmiPay float64 `json:"hifmi_pay"`
  5984. HifobPay float64 `json:"hifob_pay"`
  5985. HifpPay float64 `json:"hifp_pay"`
  5986. HospPartAmt float64 `json:"hosp_part_amt"`
  5987. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5988. Insutype string `json:"insutype"`
  5989. MafPay float64 `json:"maf_pay"`
  5990. MdtrtCertType string `json:"mdtrt_cert_type"`
  5991. MdtrtID string `json:"mdtrt_id"`
  5992. MedType string `json:"med_type"`
  5993. MedfeeSumamt float64 `json:"medfee_sumamt"`
  5994. MedinsSetlID string `json:"medins_setl_id"`
  5995. Naty string `json:"naty"`
  5996. OthPay float64 `json:"oth_pay"`
  5997. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  5998. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  5999. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6000. PsnCashPay float64 `json:"psn_cash_pay"`
  6001. PsnCertType string `json:"psn_cert_type"`
  6002. PsnName string `json:"psn_name"`
  6003. PsnNo string `json:"psn_no"`
  6004. PsnPartAmt float64 `json:"psn_part_amt"`
  6005. PsnType string `json:"psn_type"`
  6006. SetlID string `json:"setl_id"`
  6007. SetlTime string `json:"setl_time"`
  6008. } `json:"setlinfo"`
  6009. } `json:"output"`
  6010. RefmsgTime string `json:"refmsg_time"`
  6011. RespondTime string `json:"respond_time"`
  6012. Signtype interface{} `json:"signtype"`
  6013. WarnMsg interface{} `json:"warn_msg"`
  6014. }
  6015. type ResultEight struct {
  6016. Cainfo string `json:"cainfo"`
  6017. ErrMsg string `json:"err_msg"`
  6018. InfRefmsgid string `json:"inf_refmsgid"`
  6019. Infcode int64 `json:"infcode"`
  6020. Output struct {
  6021. Stmtinfo struct {
  6022. SetlOptins string `json:"setl_optins"`
  6023. StmtRslt string `json:"stmt_rslt"`
  6024. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6025. } `json:"stmtinfo"`
  6026. } `json:"output"`
  6027. RefmsgTime string `json:"refmsg_time"`
  6028. RespondTime string `json:"respond_time"`
  6029. Signtype interface{} `json:"signtype"`
  6030. WarnMsg interface{} `json:"warn_msg"`
  6031. }
  6032. type ResultNine struct {
  6033. Cainfo string `json:"cainfo"`
  6034. ErrMsg string `json:"err_msg"`
  6035. InfRefmsgid string `json:"inf_refmsgid"`
  6036. Infcode int64 `json:"infcode"`
  6037. Output struct {
  6038. FileQuryNo string `json:"file_qury_no"`
  6039. } `json:"output"`
  6040. RefmsgTime string `json:"refmsg_time"`
  6041. RespondTime string `json:"respond_time"`
  6042. Signtype interface{} `json:"signtype"`
  6043. WarnMsg interface{} `json:"warn_msg"`
  6044. }
  6045. type ResultTen struct {
  6046. Cainfo string `json:"cainfo"`
  6047. ErrMsg string `json:"err_msg"`
  6048. InfRefmsgid string `json:"inf_refmsgid"`
  6049. Infcode int64 `json:"infcode"`
  6050. Output struct {
  6051. DldEndtime string `json:"dld_endtime"`
  6052. FileQuryNo string `json:"file_qury_no"`
  6053. Filename string `json:"filename"`
  6054. } `json:"output"`
  6055. RefmsgTime string `json:"refmsg_time"`
  6056. RespondTime string `json:"respond_time"`
  6057. Signtype interface{} `json:"signtype"`
  6058. WarnMsg interface{} `json:"warn_msg"`
  6059. }
  6060. type ResultEleven struct {
  6061. Cainfo string `json:"cainfo"`
  6062. ErrMsg string `json:"err_msg"`
  6063. InfRefmsgid string `json:"inf_refmsgid"`
  6064. Infcode int64 `json:"infcode"`
  6065. Output struct {
  6066. Setlinfo struct {
  6067. FixmedinsName string `json:"fixmedins_name"`
  6068. FixmedinsCode string `json:"fixmedins_code"`
  6069. PsnNo string `json:"psn_no"`
  6070. PsnName string `json:"psn_name"`
  6071. HifobPay float64 `json:"hifob_pay"`
  6072. Gend string `json:"gend"`
  6073. Brdy string `json:"brdy"`
  6074. PsnCertType string `json:"psn_cert_type"`
  6075. PsnType string `json:"psn_type"`
  6076. EmpName string `json:"emp_name"`
  6077. Certno string `json:"certno"`
  6078. Insutype string `json:"insutype"`
  6079. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6080. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6081. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6082. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6083. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6084. ActPayDedc float64 `json:"act_pay_dedc"`
  6085. HifpPay float64 `json:"hifp_pay"`
  6086. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6087. CvlservPay float64 `json:"cvlserv_pay"`
  6088. HifesPay float64 `json:"hifes_pay"`
  6089. HifmiPay float64 `json:"hifmi_pay"`
  6090. MafPay float64 `json:"maf_pay"`
  6091. OthPay float64 `json:"oth_pay"`
  6092. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6093. PsnPay float64 `json:"psn_pay"`
  6094. AcctPay float64 `json:"acct_pay"`
  6095. CashPayamt float64 `json:"cash_payamt"`
  6096. Balc float64 `json:"balc"`
  6097. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6098. MedinsSetlId string `json:"medins_setl_id"`
  6099. RefdSetlFlag string `json:"refd_setl_flag"`
  6100. SetlTime string `json:"setl_time"`
  6101. MedType string `json:"med_type"`
  6102. } `json:"setlinfo"`
  6103. } `json:"output"`
  6104. RefmsgTime string `json:"refmsg_time"`
  6105. RespondTime string `json:"respond_time"`
  6106. Signtype interface{} `json:"signtype"`
  6107. WarnMsg interface{} `json:"warn_msg"`
  6108. }
  6109. type Custom struct {
  6110. DetItemFeeSumamt string
  6111. Cut string
  6112. FeedetlSn string
  6113. Price string
  6114. MedListCodg string
  6115. Type int64
  6116. AdviceId int64
  6117. ProjectId int64
  6118. ItemId int64
  6119. }
  6120. // 获取个人信息----挂号-----上传就诊信息
  6121. func (c *HisApiController) GetRegisterInfo() {
  6122. id, _ := c.GetInt64("id")
  6123. record_time := c.GetString("record_time")
  6124. settlementValue, _ := c.GetInt64("settlement_value")
  6125. medical_insurance_card := c.GetString("medical_insurance_card")
  6126. name := c.GetString("name")
  6127. id_card_type, _ := c.GetInt64("id_card_type")
  6128. certificates, _ := c.GetInt64("certificates")
  6129. medical_care, _ := c.GetInt64("medical_care")
  6130. birthday := c.GetString("birthday")
  6131. age, _ := c.GetInt64("age")
  6132. id_card := c.GetString("id_card")
  6133. register_type, _ := c.GetInt64("register")
  6134. doctor, _ := c.GetInt64("doctor")
  6135. department, _ := c.GetInt64("department")
  6136. gender, _ := c.GetInt64("sex")
  6137. phone := c.GetString("phone")
  6138. registration_fee, _ := c.GetFloat("registration_fee")
  6139. medical_expenses, _ := c.GetFloat("medical_expenses")
  6140. social_type, _ := c.GetInt64("social_type")
  6141. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6142. diagnosis_ids := c.GetString("diagnosis")
  6143. sick_type, _ := c.GetInt64("sick_type")
  6144. reg_type := c.GetString("p_type")
  6145. timeLayout := "2006-01-02"
  6146. loc, _ := time.LoadLocation("Local")
  6147. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6148. birthUnix := birthdays.Unix()
  6149. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6150. if err != nil {
  6151. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6152. return
  6153. }
  6154. recordDateTime := theTime.Unix()
  6155. adminInfo := c.GetAdminUserInfo()
  6156. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6157. if tempPatient.ID == 0 {
  6158. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6159. return
  6160. }
  6161. var patient service.Patients
  6162. if id == 0 {
  6163. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6164. } else {
  6165. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6166. }
  6167. if patient.ID == 0 {
  6168. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6169. return
  6170. }
  6171. if len(patient.IdCardNo) == 0 {
  6172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6173. return
  6174. }
  6175. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6176. if len(his) >= 1 {
  6177. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6178. if len(his) >= 1 && order.ID == 0 {
  6179. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6180. return
  6181. }
  6182. }
  6183. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6184. fmt.Println(timeStr)
  6185. timeArr := strings.Split(timeStr, " ")
  6186. fmt.Println(timeArr)
  6187. timeArrTwo := strings.Split(timeArr[0], "-")
  6188. timeArrThree := strings.Split(timeArr[1], ":")
  6189. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6190. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6191. if len(lists) == 0 {
  6192. var hisPatient models.XtHisPatient
  6193. hisPatient = models.XtHisPatient{
  6194. Name: name,
  6195. Age: age,
  6196. Gender: gender,
  6197. Birthday: birthUnix,
  6198. Phone: phone,
  6199. MedicalTreatmentType: medical_care,
  6200. IdType: certificates,
  6201. IdCardNo: id_card,
  6202. BalanceAccountsType: settlementValue,
  6203. SocialType: social_type,
  6204. MedicalInsuranceNumber: medical_insurance_card,
  6205. RegisterType: register_type,
  6206. RegisterCost: registration_fee,
  6207. TreatmentCost: medical_expenses,
  6208. AdminUserId: adminInfo.AdminUser.Id,
  6209. UserOrgId: adminInfo.CurrentOrgId,
  6210. Status: 1,
  6211. RecordDate: recordDateTime,
  6212. IsReturn: 1,
  6213. PatientId: patient.ID,
  6214. Ctime: time.Now().Unix(),
  6215. Mtime: time.Now().Unix(),
  6216. Number: str,
  6217. IdCardType: id_card_type,
  6218. Departments: department,
  6219. Doctor: doctor,
  6220. PType: reg_type,
  6221. Diagnosis: diagnosis_ids,
  6222. SickType: sick_type,
  6223. }
  6224. service.CreateHisPatient(&hisPatient)
  6225. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6226. c.ServeSuccessJSON(map[string]interface{}{
  6227. "his_info": hisPatient,
  6228. })
  6229. } else {
  6230. //chrgBchno := rand.Intn(1000000) + 10000
  6231. var hisPatient models.XtHisPatient
  6232. hisPatient = models.XtHisPatient{
  6233. Name: name,
  6234. Age: age,
  6235. Gender: gender,
  6236. Birthday: birthUnix,
  6237. Phone: phone,
  6238. MedicalTreatmentType: medical_care,
  6239. IdType: certificates,
  6240. IdCardNo: id_card,
  6241. BalanceAccountsType: settlementValue,
  6242. SocialType: social_type,
  6243. MedicalInsuranceNumber: medical_insurance_card,
  6244. RegisterType: register_type,
  6245. RegisterCost: registration_fee,
  6246. TreatmentCost: medical_expenses,
  6247. AdminUserId: adminInfo.AdminUser.Id,
  6248. UserOrgId: adminInfo.CurrentOrgId,
  6249. Status: 1,
  6250. RecordDate: recordDateTime,
  6251. IsReturn: 1,
  6252. PatientId: patient.ID,
  6253. Ctime: time.Now().Unix(),
  6254. Mtime: time.Now().Unix(),
  6255. Number: str,
  6256. IdCardType: id_card_type,
  6257. Departments: department,
  6258. Doctor: doctor,
  6259. PType: reg_type,
  6260. Diagnosis: diagnosis_ids,
  6261. SickType: sick_type,
  6262. }
  6263. service.CreateHisPatient(&hisPatient)
  6264. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6265. c.ServeSuccessJSON(map[string]interface{}{
  6266. "his_info": hisPatient,
  6267. })
  6268. }
  6269. }
  6270. // 上传明细----结算
  6271. func (c *HisApiController) GetUploadInfo() {
  6272. id, _ := c.GetInt64("id")
  6273. record_time := c.GetString("record_time")
  6274. his_patient_id, _ := c.GetInt64("his_patient_id")
  6275. oth_desc := c.GetString("oth_desc")
  6276. pay_way, _ := c.GetInt64("pay_way")
  6277. pay_ways := c.GetString("pay_ways")
  6278. pay_price, _ := c.GetFloat("pay_price")
  6279. pay_card_no := c.GetString("pay_card_no")
  6280. discount_price, _ := c.GetFloat("discount_price")
  6281. preferential_price, _ := c.GetFloat("preferential_price")
  6282. reality_price, _ := c.GetFloat("reality_price")
  6283. found_price, _ := c.GetFloat("found_price")
  6284. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6285. private_price, _ := c.GetFloat("private_price")
  6286. timeLayout := "2006-01-02"
  6287. loc, _ := time.LoadLocation("Local")
  6288. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6289. fapiao_code := c.GetString("fapiao_code")
  6290. fapiao_number := c.GetString("fapiao_number")
  6291. diagnosis_id := c.GetString("diagnosis")
  6292. sick_type, _ := c.GetInt64("sick_type")
  6293. reg_type, _ := c.GetInt64("p_type")
  6294. order_id, _ := c.GetInt64("order_id")
  6295. cash_pay := c.GetString("cash_pay")
  6296. wechat_pay := c.GetString("wechat_pay")
  6297. ali_pay := c.GetString("ali_pay")
  6298. jifen_pay := c.GetString("jifen_pay")
  6299. band_card_pay := c.GetString("band_card_pay")
  6300. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6301. tmp_decimal := c.GetString("tmp_decimal")
  6302. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6303. var decimal float64 //本次使用的押金
  6304. var errmsg error
  6305. tx := service.XTWriteDB().Begin() //开了事务
  6306. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6307. defer func() {
  6308. if errmsg != nil {
  6309. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6310. tx.Rollback()
  6311. } else {
  6312. tx.Commit()
  6313. }
  6314. }()
  6315. fmt.Println("dec_way", dec_way)
  6316. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6317. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6318. return
  6319. }
  6320. if len(tmp_decimal) > 0 {
  6321. if tmp_decimal[0] == 45 {
  6322. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6323. return
  6324. }
  6325. }
  6326. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6327. fmt.Println(errs)
  6328. decimal = tt
  6329. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6330. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6331. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6332. if err != nil {
  6333. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6334. return
  6335. }
  6336. recordDateTime := theTime.Unix()
  6337. adminUser := c.GetAdminUserInfo()
  6338. var prescriptions []*models.HisPrescription
  6339. var prescriptionsOne []*models.HisPrescription
  6340. var start_time int64
  6341. var end_time int64
  6342. ids_str := c.GetString("ids")
  6343. ids_arr := strings.Split(ids_str, ",")
  6344. if tempOrder.ID == 0 {
  6345. if settle_accounts_type == 1 { //日结
  6346. fmt.Println(reg_type)
  6347. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6348. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6349. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6350. } else {
  6351. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6352. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6353. }
  6354. } else { //月结
  6355. start_time_str := c.GetString("start_time")
  6356. end_time_str := c.GetString("end_time")
  6357. timeLayout := "2006-01-02"
  6358. loc, _ := time.LoadLocation("Local")
  6359. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6360. if err != nil {
  6361. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6362. return
  6363. }
  6364. recordStartTime := theStartTime.Unix()
  6365. start_time = recordStartTime
  6366. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6367. if err != nil {
  6368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6369. return
  6370. }
  6371. recordEndTime := theEndTime.Unix()
  6372. end_time = recordEndTime
  6373. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6374. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6375. }
  6376. var goods []*models.DialysisBeforePrepareGoods
  6377. var newGoods []*models.NewDialysisBeforePrepareGoods
  6378. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6379. var infos []*models.HisDoctorAdviceInfo
  6380. var infoList []*models.HisDoctorAdviceInfo
  6381. var hisAdvice []*models.HisDoctorAdviceInfo
  6382. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6383. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6384. //判断库存不足
  6385. //结算出库开关
  6386. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6387. if settConfig.IsOpen == 1 {
  6388. //判断库存的地方
  6389. for _, info := range prescriptions {
  6390. if info.Type == 1 {
  6391. infos = append(infos, info.HisDoctorAdviceInfo...)
  6392. }
  6393. if info.Type == 2 {
  6394. for _, sumItem := range info.HisPrescriptionProject {
  6395. if sumItem.Type == 3 {
  6396. var good models.DialysisBeforePrepareGoods
  6397. var newGood models.NewDialysisBeforePrepareGoods
  6398. good.GoodId = sumItem.GoodInfo.ID
  6399. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6400. count, _ := strconv.Atoi(sumItem.Count)
  6401. good.Count = int64(count)
  6402. good.StorehouseId = houseConfig.StorehouseOutInfo
  6403. good.ProjectId = sumItem.ID
  6404. goods = append(goods, &good)
  6405. newGood.GoodId = sumItem.GoodInfo.ID
  6406. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6407. count2, _ := strconv.Atoi(sumItem.Count)
  6408. newGood.Count = int64(count2)
  6409. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6410. newGood.ProjectId = sumItem.ID
  6411. newGoods = append(newGoods, &newGood)
  6412. }
  6413. }
  6414. }
  6415. }
  6416. for _, info := range prescriptionsOne {
  6417. if info.Type == 1 {
  6418. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6419. }
  6420. if info.Type == 2 {
  6421. for _, sumItem := range info.HisPrescriptionProject {
  6422. if sumItem.Type == 3 {
  6423. var newGood models.NewDialysisBeforePrepareGoods
  6424. newGood.GoodId = sumItem.GoodInfo.ID
  6425. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6426. count2, _ := strconv.Atoi(sumItem.Count)
  6427. newGood.Count = int64(count2)
  6428. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6429. newGood.ProjectId = sumItem.ID
  6430. newGoodOne = append(newGoodOne, &newGood)
  6431. }
  6432. }
  6433. }
  6434. }
  6435. //判断
  6436. for _, itemOne := range infos {
  6437. for _, itemTwo := range hisAdvice {
  6438. if itemOne.DrugId == itemTwo.DrugId {
  6439. itemTwo.Child = append(itemTwo.Child, itemOne)
  6440. }
  6441. }
  6442. }
  6443. for _, itemTwo := range hisAdvice {
  6444. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6445. var sum_out_count int64
  6446. for _, itemThree := range itemTwo.Child {
  6447. var prescribing_number int64
  6448. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6449. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6450. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6451. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6452. }
  6453. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6454. prescribing_number = parseIntPrescribingNumber
  6455. }
  6456. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6457. prescribing_number = parseIntPrescribingNumber
  6458. }
  6459. sum_out_count += prescribing_number
  6460. }
  6461. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6462. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6463. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6464. if sum_out_count > drugStockOut.FlushCount {
  6465. c.ServeSuccessJSON(map[string]interface{}{
  6466. "msg": "2",
  6467. "drug": medical,
  6468. })
  6469. return
  6470. }
  6471. }
  6472. fmt.Println("newGoods99999988882os", newGoods)
  6473. for _, itemOne := range newGoods {
  6474. for _, item := range newGoodOne {
  6475. if itemOne.GoodId == item.GoodId {
  6476. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6477. }
  6478. }
  6479. }
  6480. for _, item := range newGoodOne {
  6481. var sum_out_count_one int64
  6482. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6483. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6484. sum_out_count_one += itemOne.Count
  6485. }
  6486. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6487. fmt.Println("sum_out_count_one", sum_out_count_one)
  6488. fmt.Println("list.FlushCount", list.FlushCount)
  6489. if sum_out_count_one > list.FlushCount {
  6490. c.ServeSuccessJSON(map[string]interface{}{
  6491. "msg": "3",
  6492. "good": good,
  6493. })
  6494. return
  6495. }
  6496. }
  6497. }
  6498. timestamp := time.Now().Unix()
  6499. tempTime := time.Unix(timestamp, 0)
  6500. timeFormat := tempTime.Format("20060102150405")
  6501. chrgBchno := rand.Intn(100000) + 10000
  6502. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6503. strconv.FormatInt(his.PatientId, 10)
  6504. var ids []int64
  6505. for _, item := range prescriptions {
  6506. ids = append(ids, item.ID)
  6507. }
  6508. var total float64
  6509. for _, item := range prescriptions {
  6510. fmt.Println(item)
  6511. if item.Type == 1 { //药品
  6512. for _, subItem := range item.HisDoctorAdviceInfo {
  6513. total = total + (subItem.Price * subItem.PrescribingNumber)
  6514. }
  6515. }
  6516. if item.Type == 2 { //项目
  6517. for _, subItem := range item.HisPrescriptionProject {
  6518. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6519. total = total + (subItem.Price * cnt)
  6520. }
  6521. }
  6522. for _, subItem := range item.HisAdditionalCharge {
  6523. total = total + (subItem.Price * float64(subItem.Count))
  6524. }
  6525. }
  6526. if reg_type == 1111 || reg_type == 1112 {
  6527. reg_type = 11
  6528. }
  6529. tm := time.Unix(time.Now().Unix(), 0)
  6530. allTotal := fmt.Sprintf("%.4f", total)
  6531. totals, _ := strconv.ParseFloat(allTotal, 64)
  6532. order := &models.HisOrder{
  6533. UserOrgId: adminUser.CurrentOrgId,
  6534. HisPatientId: his.ID,
  6535. PatientId: id,
  6536. SettleAccountsDate: recordDateTime,
  6537. Ctime: time.Now().Unix(),
  6538. Mtime: time.Now().Unix(),
  6539. Status: 1,
  6540. OrderStatus: 2,
  6541. MdtrtId: his.Number,
  6542. Number: chrg_bchno,
  6543. MedfeeSumamt: totals,
  6544. PayWay: pay_way,
  6545. PayWays: pay_ways,
  6546. PayPrice: pay_price,
  6547. MedType: strconv.Itoa(int(reg_type)),
  6548. PayCardNo: pay_card_no,
  6549. DiscountPrice: discount_price,
  6550. PreferentialPrice: preferential_price,
  6551. RealityPrice: reality_price,
  6552. FoundPrice: found_price,
  6553. MedicalInsurancePrice: medical_insurance_price,
  6554. PrivatePrice: private_price,
  6555. SettleEndTime: end_time,
  6556. SettleStartTime: start_time,
  6557. PsnPartAmt: totals,
  6558. PsnCashPay: totals,
  6559. SettleType: settle_accounts_type,
  6560. FaPiaoCode: fapiao_code,
  6561. FaPiaoNumber: fapiao_number,
  6562. Diagnosis: diagnosis_id,
  6563. PType: 2,
  6564. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6565. Decimal: decimal,
  6566. OthDesc: oth_desc,
  6567. CashPay: cash_pay,
  6568. WechatPay: wechat_pay,
  6569. AliPay: ali_pay,
  6570. JifenPay: jifen_pay,
  6571. BandCardPay: band_card_pay,
  6572. Creator: adminUser.AdminUser.Id,
  6573. }
  6574. err = service.CreateOrderTX(order, tx)
  6575. if err != nil {
  6576. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6577. return
  6578. }
  6579. var customs []*Custom
  6580. for _, item := range prescriptions {
  6581. if item.Type == 1 { //药品a
  6582. for _, subItem := range item.HisDoctorAdviceInfo {
  6583. cus := &Custom{
  6584. AdviceId: subItem.ID,
  6585. ProjectId: 0,
  6586. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6587. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6588. FeedetlSn: subItem.FeedetlSn,
  6589. Price: fmt.Sprintf("%.4f", subItem.Price),
  6590. MedListCodg: subItem.MedListCodg,
  6591. Type: 1,
  6592. }
  6593. customs = append(customs, cus)
  6594. }
  6595. }
  6596. if item.Type == 2 { //项目
  6597. for _, subItem := range item.HisPrescriptionProject {
  6598. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6599. cus := &Custom{
  6600. AdviceId: 0,
  6601. ProjectId: subItem.ID,
  6602. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6603. Cut: fmt.Sprintf("%.4f", cnt),
  6604. FeedetlSn: subItem.FeedetlSn,
  6605. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6606. MedListCodg: subItem.MedListCodg,
  6607. Type: 2,
  6608. }
  6609. customs = append(customs, cus)
  6610. }
  6611. }
  6612. for _, item := range item.HisAdditionalCharge {
  6613. cus := &Custom{
  6614. ItemId: item.ID,
  6615. AdviceId: 0,
  6616. ProjectId: 0,
  6617. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6618. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6619. FeedetlSn: item.FeedetlSn,
  6620. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6621. MedListCodg: item.XtHisAddtionConfig.Code,
  6622. Type: 3,
  6623. }
  6624. customs = append(customs, cus)
  6625. }
  6626. }
  6627. for _, item := range customs {
  6628. var advice_id int64 = 0
  6629. var project_id int64 = 0
  6630. var item_id int64 = 0
  6631. var types int64 = 0
  6632. if item.Type == 1 {
  6633. advice_id = item.AdviceId
  6634. project_id = 0
  6635. item_id = 0
  6636. } else if item.Type == 2 {
  6637. advice_id = 0
  6638. item_id = 0
  6639. project_id = item.ProjectId
  6640. } else if item.Type == 3 {
  6641. advice_id = 0
  6642. item_id = item.ItemId
  6643. project_id = 0
  6644. }
  6645. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6646. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6647. pric, _ := strconv.ParseFloat(item.Price, 32)
  6648. info := &models.HisOrderInfo{
  6649. OrderNumber: order.Number,
  6650. UploadDate: time.Now().Unix(),
  6651. AdviceId: advice_id,
  6652. DetItemFeeSumamt: detItemFeeSumamt,
  6653. Cnt: cut,
  6654. Pric: pric,
  6655. PatientId: id,
  6656. Status: 1,
  6657. Mtime: time.Now().Unix(),
  6658. Ctime: time.Now().Unix(),
  6659. UserOrgId: adminUser.CurrentOrgId,
  6660. HisPatientId: his.ID,
  6661. OrderId: order.ID,
  6662. ProjectId: project_id,
  6663. Type: types,
  6664. ItemId: item_id,
  6665. }
  6666. service.CreateOrderInfoTX(info, tx)
  6667. }
  6668. his.Diagnosis = diagnosis_id
  6669. his.SickType = sick_type
  6670. his.RegisterType = reg_type
  6671. his.MedicalTreatmentType = reg_type
  6672. service.UpdataHisPateintTX(&his, tx)
  6673. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6674. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6675. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6676. //判断是否使用了押金
  6677. if dec_way == "true" {
  6678. tmpstring := strconv.FormatInt(order.ID, 10)
  6679. //扣押金
  6680. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6681. order.Decimal = decimal
  6682. service.UpDateOrderTwo(order, tx)
  6683. if errmsg != nil {
  6684. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6685. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6686. return
  6687. }
  6688. }
  6689. if err == nil {
  6690. for _, info := range prescriptions {
  6691. if info.Type == 1 {
  6692. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6693. }
  6694. if info.Type == 2 {
  6695. for _, sumItem := range info.HisPrescriptionProject {
  6696. if sumItem.Type == 3 {
  6697. var good models.DialysisBeforePrepareGoods
  6698. var newGood models.NewDialysisBeforePrepareGoods
  6699. var oldGood models.OldDialysisBeforePrepareGoods
  6700. good.GoodId = sumItem.GoodInfo.ID
  6701. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6702. count, _ := strconv.Atoi(sumItem.Count)
  6703. good.Count = int64(count)
  6704. good.StorehouseId = houseConfig.StorehouseOutInfo
  6705. good.ProjectId = sumItem.ID
  6706. good.PatientId = sumItem.PatientId
  6707. goods = append(goods, &good)
  6708. newGood.GoodId = sumItem.GoodInfo.ID
  6709. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6710. count2, _ := strconv.Atoi(sumItem.Count)
  6711. newGood.Count = int64(count2)
  6712. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6713. newGood.ProjectId = sumItem.ID
  6714. newGood.PatientId = sumItem.HisPatientId
  6715. newGoods = append(newGoods, &newGood)
  6716. oldGood.GoodId = sumItem.GoodInfo.ID
  6717. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6718. count3, _ := strconv.Atoi(sumItem.Count)
  6719. oldGood.Count = int64(count3)
  6720. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6721. oldGood.ProjectId = sumItem.ID
  6722. oldGood.RecordDate = sumItem.RecordDate
  6723. oldGood.PatientId = sumItem.HisPatientId
  6724. oldGoods = append(oldGoods, &oldGood)
  6725. }
  6726. }
  6727. }
  6728. }
  6729. if settConfig.IsOpen == 1 {
  6730. for _, item := range infoList {
  6731. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6732. if medical.IsUse == 2 {
  6733. //药品出库
  6734. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6735. //查询默认仓库
  6736. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6737. //查询默认仓库剩余多少库存
  6738. var sum_count int64
  6739. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6740. for _, its := range stockInfo {
  6741. if its.MaxUnit == medical.MaxUnit {
  6742. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6743. }
  6744. sum_count += its.StockMaxNumber + its.StockMinNumber
  6745. }
  6746. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6747. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6748. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6749. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6750. }
  6751. }
  6752. orgId := c.GetAdminUserInfo().CurrentOrgId
  6753. if len(oldGoods) > 0 {
  6754. timeStr := time.Now().Format("2006-01-02")
  6755. timeArr := strings.Split(timeStr, "-")
  6756. total, _ := service.FindAllWarehouseOut(orgId)
  6757. total = total + 1
  6758. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6759. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6760. number = number + total
  6761. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6762. operation_time := time.Now().Unix()
  6763. creater := c.GetAdminUserInfo().AdminUser.Id
  6764. //查询默认出库仓库库存
  6765. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6766. recordDateStr := time.Now().Format("2006-01-02")
  6767. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6768. nowtime := recordDate.Unix()
  6769. warehouseOut := models.WarehouseOut{
  6770. WarehouseOutOrderNumber: warehousing_out_order,
  6771. OperationTime: operation_time,
  6772. OrgId: orgId,
  6773. Creater: creater,
  6774. Ctime: time.Now().Unix(),
  6775. Status: 1,
  6776. WarehouseOutTime: nowtime,
  6777. Type: 1,
  6778. StorehouseId: storeConfig.StorehouseOutInfo,
  6779. IsCheck: 1,
  6780. OrderId: order.ID,
  6781. IsSys: 5,
  6782. }
  6783. //查询是否生成出库单
  6784. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6785. if out.ID == 0 {
  6786. service.AddSigleWarehouseOut(&warehouseOut)
  6787. }
  6788. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6789. for _, item := range oldGoods {
  6790. dialyPrepareOne := models.DialysisBeforePrepare{
  6791. GoodTypeId: item.GoodTypeId,
  6792. GoodId: item.GoodId,
  6793. PatientId: his.PatientId,
  6794. RecordDate: item.RecordDate,
  6795. UserOrgId: adminUser.CurrentOrgId,
  6796. Count: item.Count,
  6797. Ctime: time.Now().Unix(),
  6798. Creater: adminUser.AdminUser.Id,
  6799. CommdityCode: item.CommdityCode,
  6800. Status: 1,
  6801. StorehouseId: houseConfig.StorehouseOutInfo,
  6802. }
  6803. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6804. //非零用
  6805. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6806. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6807. //查询剩余库存
  6808. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6809. var sum_count int64
  6810. for _, item := range goodList {
  6811. sum_count += item.StockCount
  6812. }
  6813. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6814. //耗材
  6815. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6816. }
  6817. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6818. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6819. //查询剩余库存
  6820. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6821. var sum_count int64
  6822. for _, item := range goodList {
  6823. sum_count += item.StockCount
  6824. }
  6825. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6826. //耗材
  6827. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6828. }
  6829. }
  6830. }
  6831. }
  6832. c.ServeSuccessJSON(map[string]interface{}{
  6833. "msg": "结算成功",
  6834. })
  6835. }
  6836. }
  6837. }
  6838. // 退款
  6839. func (c *HisApiController) Refund() {
  6840. order_id, _ := c.GetInt64("order_id")
  6841. order, _ := service.GetHisOrderByID(order_id)
  6842. adminUser := c.GetAdminUserInfo()
  6843. orgid := c.GetAdminUserInfo().CurrentOrgId
  6844. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6845. if err != nil {
  6846. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6847. return
  6848. }
  6849. tmp := strconv.FormatInt(order.ID, 10)
  6850. //当押金不为零时产生退费记录
  6851. if order.Decimal != 0 {
  6852. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6853. if err != nil {
  6854. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6855. return
  6856. }
  6857. }
  6858. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6859. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6860. var goods []*models.DialysisBeforePrepareGoods
  6861. var newGoods []*models.NewDialysisBeforePrepareGoods
  6862. var infos []*models.HisDoctorAdviceInfo
  6863. for _, info := range orders {
  6864. if info.AdviceId > 0 && info.ProjectId == 0 {
  6865. infos = append(infos, &info.HisDoctorAdviceInfo)
  6866. }
  6867. if info.ProjectId > 0 && info.AdviceId == 0 {
  6868. if info.HisPrescriptionProject.Type == 3 {
  6869. var good models.DialysisBeforePrepareGoods
  6870. var newGood models.NewDialysisBeforePrepareGoods
  6871. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6872. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6873. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6874. good.Count = int64(count)
  6875. good.StorehouseId = houseConfig.StorehouseOutInfo
  6876. good.ProjectId = info.HisPrescriptionProject.ID
  6877. good.PatientId = info.PatientId
  6878. good.OrderId = order_id
  6879. goods = append(goods, &good)
  6880. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6881. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6882. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6883. newGood.Count = int64(count2)
  6884. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6885. newGood.ProjectId = info.HisPrescriptionProject.ID
  6886. newGood.RecordDate = order.SettleAccountsDate
  6887. newGood.UserOrgId = order.UserOrgId
  6888. newGood.PatientId = info.PatientId
  6889. newGood.OrderId = order_id
  6890. newGoods = append(newGoods, &newGood)
  6891. }
  6892. }
  6893. }
  6894. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6895. if settConfig.IsOpen == 1 {
  6896. for _, item := range infos {
  6897. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6898. }
  6899. for _, item := range newGoods {
  6900. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6901. }
  6902. }
  6903. c.ServeSuccessJSON(map[string]interface{}{
  6904. "msg": "退费成功",
  6905. })
  6906. }
  6907. func (c *HisApiController) RefundNumber() {
  6908. his_patient_id, _ := c.GetInt64("id")
  6909. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6910. info.Status = 0
  6911. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6912. if count > 0 {
  6913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6914. return
  6915. }
  6916. err := service.SaveHisPatient(info)
  6917. if err == nil {
  6918. c.ServeSuccessJSON(map[string]interface{}{
  6919. "msg": "退号成功",
  6920. })
  6921. } else {
  6922. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6923. return
  6924. }
  6925. }
  6926. func (this *HisApiController) AdditionalCharge() {
  6927. dataBody := make(map[string]interface{}, 0)
  6928. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6929. fmt.Println(err)
  6930. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6931. patient_id := int64(dataBody["patient_id"].(float64))
  6932. medicineData, _ := dataBody["medicineData"].([]interface{})
  6933. adminUserInfo := this.GetAdminUserInfo()
  6934. orgId := adminUserInfo.CurrentOrgId
  6935. admin_user_id := adminUserInfo.AdminUser.Id
  6936. timeStr := time.Now().Format("2006-01-02")
  6937. timeLayout := "2006-01-02 15:04:05"
  6938. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6939. timenow := timeStringToTime.Unix()
  6940. var additionalCharges []*models.HisAdditionalCharge
  6941. for _, item := range medicineData {
  6942. var randNum int
  6943. randNum = rand.Intn(10000) + 1000
  6944. timestamp := time.Now().Unix()
  6945. tempTime := time.Unix(timestamp, 0)
  6946. timeFormat := tempTime.Format("20060102150405")
  6947. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6948. items := item.(map[string]interface{})
  6949. money := items["price"].(string)
  6950. item_id_str := items["item_id"].(string)
  6951. name := items["name"].(string)
  6952. id_str := items["id"].(string)
  6953. moneys, _ := strconv.ParseInt(money, 10, 64)
  6954. monStr := strconv.FormatInt(moneys, 10)
  6955. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6956. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6957. id, _ := strconv.ParseInt(id_str, 10, 64)
  6958. additionalCharge := &models.HisAdditionalCharge{
  6959. ID: id,
  6960. HisPatientId: his_patient_id,
  6961. UserOrgId: orgId,
  6962. PatientId: patient_id,
  6963. RecordDate: timenow,
  6964. Price: monneyStr,
  6965. Status: 1,
  6966. ItemName: name,
  6967. ItemId: item_id,
  6968. AdminUserId: admin_user_id,
  6969. CreatedTime: time.Now().Unix(),
  6970. OrderStatus: 0,
  6971. PrescriptionNumber: "",
  6972. BatchNumber: "",
  6973. FeedetlSn: p_number,
  6974. }
  6975. service.CreateAdditionalCharge(additionalCharge)
  6976. additionalCharges = append(additionalCharges, additionalCharge)
  6977. }
  6978. this.ServeSuccessJSON(map[string]interface{}{
  6979. "msg": "添加成功",
  6980. "additional_charges": additionalCharges,
  6981. })
  6982. }
  6983. func (this *HisApiController) DeleteAddition() {
  6984. id, _ := this.GetInt64("id")
  6985. //TODO 需要判断是否已经结算
  6986. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6987. if err == nil {
  6988. this.ServeSuccessJSON(map[string]interface{}{
  6989. "msg": "删除成功",
  6990. })
  6991. return
  6992. } else {
  6993. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6994. return
  6995. }
  6996. }
  6997. func (this *HisApiController) GetAdminUsers() {
  6998. adminUser := this.GetAdminUserInfo()
  6999. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  7000. this.ServeSuccessJSON(map[string]interface{}{
  7001. "doctors": doctors,
  7002. })
  7003. }
  7004. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7005. change_type, _ := this.GetInt64("type", 0)
  7006. record_date := this.GetString("record_time")
  7007. patient_id, _ := this.GetInt64("patient_id", 0)
  7008. p_type, _ := this.GetInt64("p_type", 0)
  7009. timeLayout := "2006-01-02"
  7010. loc, _ := time.LoadLocation("Local")
  7011. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7012. record_time := theAdviceRecordTime.Unix()
  7013. adminUserInfo := this.GetAdminUserInfo()
  7014. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7015. if err == nil {
  7016. if len(prescriptions) == 0 {
  7017. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7018. return
  7019. } else {
  7020. this.ServeSuccessJSON(map[string]interface{}{
  7021. "prescriptions": prescriptions,
  7022. })
  7023. return
  7024. }
  7025. } else {
  7026. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7027. return
  7028. }
  7029. }
  7030. func (this *HisApiController) GetCallHisPrescription() {
  7031. patient_id, _ := this.GetInt64("patient_id", 0)
  7032. timeLayout := "2006-01-02"
  7033. loc, _ := time.LoadLocation("Local")
  7034. start_time := this.GetString("start_time")
  7035. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7036. end_time := this.GetString("end_time")
  7037. p_type, _ := this.GetInt64("p_type")
  7038. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7039. adminUserInfo := this.GetAdminUserInfo()
  7040. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7041. if err == nil {
  7042. this.ServeSuccessJSON(map[string]interface{}{
  7043. "prescriptions": prescriptions,
  7044. })
  7045. return
  7046. } else {
  7047. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7048. return
  7049. }
  7050. }
  7051. func (this *HisApiController) GetHisDayPrescription() {
  7052. timeLayout := "2006-01-02"
  7053. loc, _ := time.LoadLocation("Local")
  7054. start_time := this.GetString("start_time")
  7055. patient_id, _ := this.GetInt64("patient_id", 0)
  7056. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7057. end_time := this.GetString("end_time")
  7058. p_type, _ := this.GetInt64("p_type")
  7059. order_status, _ := this.GetInt64("type")
  7060. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7061. adminUserInfo := this.GetAdminUserInfo()
  7062. var dayHisPrescription []*models.HisPrescription
  7063. var err error
  7064. if order_status == 1 || order_status == 0 {
  7065. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7066. } else if order_status == 2 {
  7067. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7068. }
  7069. var settle_total float64
  7070. for _, item := range dayHisPrescription {
  7071. if len(item.HisPrescriptionProject) > 0 {
  7072. for _, subItem := range item.HisPrescriptionProject {
  7073. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7074. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7075. settle_total = settle_total + total
  7076. }
  7077. }
  7078. if len(item.HisDoctorAdviceInfo) > 0 {
  7079. for _, subItem := range item.HisDoctorAdviceInfo {
  7080. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7081. settle_total = settle_total + total
  7082. }
  7083. }
  7084. }
  7085. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7086. if err == nil {
  7087. this.ServeSuccessJSON(map[string]interface{}{
  7088. "day_prescription": dayHisPrescription,
  7089. "settle_total": settle_total,
  7090. })
  7091. return
  7092. } else {
  7093. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7094. return
  7095. }
  7096. }
  7097. func (c *HisApiController) GetHisChargePatientList() {
  7098. record_date := c.GetString("record_date")
  7099. order_status, _ := c.GetInt64("type")
  7100. sch_type, _ := c.GetInt64("sch_type")
  7101. timeLayout := "2006-01-02"
  7102. loc, _ := time.LoadLocation("Local")
  7103. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7104. if err != nil {
  7105. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7106. return
  7107. }
  7108. recordDateTime := theTime.Unix()
  7109. adminInfo := c.GetAdminUserInfo()
  7110. var tempPatients []*service.NewTempPatients
  7111. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7112. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7113. if order_status != 2 {
  7114. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7115. } else {
  7116. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7117. }
  7118. } else {
  7119. if order_status != 2 {
  7120. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7121. } else {
  7122. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7123. }
  7124. }
  7125. var patients []*service.NewTempPatients
  7126. var patients_two []*service.NewTempPatients
  7127. for _, item := range tempPatients {
  7128. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7129. //过滤掉没挂号的和没开处方的
  7130. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7131. patients = append(patients, item)
  7132. }
  7133. //过滤掉没挂号的
  7134. if len(item.HisPatient) > 0 {
  7135. patients_two = append(patients_two, item)
  7136. }
  7137. } else {
  7138. if len(item.HisPrescription) > 0 {
  7139. patients = append(patients, item)
  7140. }
  7141. }
  7142. }
  7143. c.ServeSuccessJSON(map[string]interface{}{
  7144. "list": patients,
  7145. "list_two": patients_two,
  7146. })
  7147. }
  7148. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7149. record_date := c.GetString("record_date")
  7150. timeLayout := "2006-01-02"
  7151. loc, _ := time.LoadLocation("Local")
  7152. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7153. if err != nil {
  7154. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7155. return
  7156. }
  7157. recordDateTime := theTime.Unix()
  7158. adminUser := c.GetAdminUserInfo()
  7159. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7160. var patients []*service.Patients
  7161. for _, item := range tempPatients {
  7162. if item.HisPatient.ID == 0 {
  7163. patients = append(patients, item)
  7164. }
  7165. }
  7166. c.ServeSuccessJSON(map[string]interface{}{
  7167. "list": patients,
  7168. //"list_two": patients_two,
  7169. })
  7170. }
  7171. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7172. newArr = make([]*service.Patients, 0)
  7173. for i := 0; i < len(patient); i++ {
  7174. repeat := false
  7175. for j := i + 1; j < len(patient); j++ {
  7176. if patient[i].ID == patient[j].ID {
  7177. repeat = true
  7178. break
  7179. }
  7180. }
  7181. if !repeat {
  7182. newArr = append(newArr, patient[i])
  7183. }
  7184. }
  7185. return
  7186. }
  7187. func (c *HisApiController) GetHisChargePatientInfo() {
  7188. patient_id, _ := c.GetInt64("patient_id")
  7189. his_patient_id, _ := c.GetInt64("his_patient_id")
  7190. record_date := c.GetString("record_date")
  7191. //start_time := c.GetString("start_time")
  7192. //end_time := c.GetString("end_time")
  7193. order_status, _ := c.GetInt64("type", 0)
  7194. p_type, _ := c.GetInt64("p_type", 0)
  7195. order_id, _ := c.GetInt64("order_id", 0)
  7196. timeLayout := "2006-01-02"
  7197. loc, _ := time.LoadLocation("Local")
  7198. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7199. if err != nil {
  7200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7201. return
  7202. }
  7203. recordDateTime := theTime.Unix()
  7204. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7205. //if err != nil {
  7206. //
  7207. //}
  7208. //startRecordDateTime := startTime.Unix()
  7209. //
  7210. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7211. //if err != nil {
  7212. //
  7213. //}
  7214. //endRecordDateTime := endTime.Unix()
  7215. admin := c.GetAdminUserInfo()
  7216. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7217. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7218. var prescriptions []*models.HisPrescription
  7219. //var unChargeMonthPrescriptions []*models.HisPrescription
  7220. order, _ := service.GetHisOrderByID(order_id)
  7221. if order_status == 1 || order_status == 0 {
  7222. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7223. } else if order_status == 2 {
  7224. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7225. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7226. }
  7227. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7228. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7229. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7230. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7231. //获取所有科室信息
  7232. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7233. c.ServeSuccessJSON(map[string]interface{}{
  7234. "his_info": his_patient_info,
  7235. "xt_info": xt_patient_info,
  7236. "prescription": prescriptions,
  7237. "case_history": case_history,
  7238. "info": patientPrescriptionInfo,
  7239. "last_info": lastPatientPrescriptionInfo,
  7240. "order": order,
  7241. "doctors": doctors,
  7242. "department": department,
  7243. })
  7244. return
  7245. }
  7246. func (c *HisApiController) GetAllOrderDetail() {
  7247. order_id, _ := c.GetInt64("id", 0)
  7248. order, _ := service.GetHisOrderByID(order_id)
  7249. if order.ID == 0 {
  7250. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7251. return
  7252. }
  7253. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7254. org_id := c.GetAdminUserInfo().CurrentOrgId
  7255. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7256. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7257. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7258. c.ServeSuccessJSON(map[string]interface{}{
  7259. "order": order,
  7260. "order_info": order_info,
  7261. "patient": patient,
  7262. "admin_info": adminInfo,
  7263. "hospital_record": record,
  7264. })
  7265. return
  7266. }
  7267. func (c *HisApiController) GetAllOrderDetailCollect() {
  7268. order_id, _ := c.GetInt64("id", 0)
  7269. order, _ := service.GetHisOrderByID(order_id)
  7270. if order.ID == 0 {
  7271. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7272. return
  7273. }
  7274. org_id := c.GetAdminUserInfo().CurrentOrgId
  7275. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7276. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7277. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7278. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7279. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7280. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7281. var bedCostTotal float64 = 0 //床位总费
  7282. //var bedCostSelfTotal float64 = 0 //床位自费
  7283. var operationCostTotal float64 = 0 //手术费
  7284. //var operationCostSelfTotal float64 = 0 //手术费
  7285. var otherCostTotal float64 = 0 //其他费用
  7286. //var otherCostSelfTotal float64 = 0 //其他费用
  7287. var materialCostTotal float64 = 0 //材料费
  7288. //var materialCostSelfTotal float64 = 0 //材料费
  7289. var westernMedicineCostTotal float64 = 0 //西药费
  7290. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7291. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7292. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7293. var checkCostTotal float64 = 0 //检查费
  7294. //var checkCostSelfTotal float64 = 0 //检查费
  7295. var laboratoryCostTotal float64 = 0 //化验费
  7296. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7297. var treatCostTotal float64 = 0 //治疗费用
  7298. //var treatCostSelfTotal float64 = 0 //治疗费用
  7299. var zhenChaCostTotal float64 = 0 //其他费用
  7300. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7301. decimal.DivisionPrecision = 2
  7302. var BalanceAccountsType int64
  7303. if his.ID > 0 {
  7304. BalanceAccountsType = his.BalanceAccountsType
  7305. } else {
  7306. BalanceAccountsType = record.BalanceAccountsType
  7307. }
  7308. if BalanceAccountsType != 2 {
  7309. for _, item := range order_info {
  7310. if org_id == 10215 {
  7311. if item.MedChrgitmType == "01" { //床位费
  7312. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7313. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7314. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7315. }
  7316. if item.MedChrgitmType == "02" { //诊察费
  7317. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7318. //zhenChaCostSelfTotal = zhenChaCostTotal
  7319. }
  7320. if item.MedChrgitmType == "03" { //检查费
  7321. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7322. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7323. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7324. }
  7325. //if item.MedChrgitmType == "02" { //检查费
  7326. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7327. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7328. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7329. //}
  7330. if item.MedChrgitmType == "04" { //化验费
  7331. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7332. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7333. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7334. }
  7335. if item.MedChrgitmType == "05" { //治疗费
  7336. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7337. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7338. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7339. }
  7340. if item.MedChrgitmType == "06" { //手术费
  7341. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7342. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7343. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7344. }
  7345. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7346. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7347. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7348. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7349. }
  7350. if item.MedChrgitmType == "09" { //西药费
  7351. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7352. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7353. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7354. }
  7355. if item.MedChrgitmType == "11" { //中成费
  7356. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7357. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7358. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7359. }
  7360. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7361. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7362. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7363. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7364. }
  7365. } else if org_id == 10188 || org_id == 10217 {
  7366. if item.MedChrgitmType == "01" { //床位费
  7367. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7368. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7369. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7370. }
  7371. if item.MedChrgitmType == "02" { //诊察费
  7372. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7373. //zhenChaCostSelfTotal = zhenChaCostTotal
  7374. }
  7375. if item.MedChrgitmType == "03" { //检查费
  7376. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7377. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7378. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7379. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7380. }
  7381. //if item.MedChrgitmType == "02" { //检查费
  7382. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7383. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7384. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7385. //}
  7386. if item.MedChrgitmType == "04" { //化验费
  7387. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7388. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7389. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7390. }
  7391. if item.MedChrgitmType == "05" { //治疗费
  7392. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7393. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7394. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7395. }
  7396. if item.MedChrgitmType == "06" { //手术费
  7397. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7398. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7399. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7400. }
  7401. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7402. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7403. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7404. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7405. }
  7406. if item.MedChrgitmType == "09" { //西药费
  7407. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7408. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7409. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7410. }
  7411. if item.MedChrgitmType == "11" { //中成费
  7412. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7413. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7414. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7415. }
  7416. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7417. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7418. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7419. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7420. }
  7421. } else {
  7422. if item.MedChrgitmType == "01" { //床位费
  7423. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7424. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7425. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7426. }
  7427. //if item.MedChrgitmType == "02" { //诊察费
  7428. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7429. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7430. //}
  7431. if item.MedChrgitmType == "03" { //检查费
  7432. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7433. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7434. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7435. }
  7436. //if item.MedChrgitmType == "02" { //检查费
  7437. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7438. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7439. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7440. //}
  7441. if item.MedChrgitmType == "04" { //化验费
  7442. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7443. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7444. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7445. }
  7446. if item.MedChrgitmType == "05" { //治疗费
  7447. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7448. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7449. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7450. }
  7451. if item.MedChrgitmType == "06" { //手术费
  7452. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7453. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7454. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7455. }
  7456. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7457. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7458. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7459. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7460. }
  7461. if item.MedChrgitmType == "09" { //西药费
  7462. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7463. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7464. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7465. }
  7466. if item.MedChrgitmType == "11" { //中成费
  7467. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7468. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7469. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7470. }
  7471. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7472. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7473. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7474. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7475. }
  7476. }
  7477. }
  7478. c.ServeSuccessJSON(map[string]interface{}{
  7479. "order": order,
  7480. "order_info": order_info,
  7481. "patient": patient,
  7482. "admin_info": adminInfo,
  7483. "his_hospital": record,
  7484. "bedCostTotal": bedCostTotal,
  7485. "operationCostTotal": operationCostTotal,
  7486. "otherCostTotal": otherCostTotal,
  7487. "materialCostTotal": materialCostTotal,
  7488. "westernMedicineCostTotal": westernMedicineCostTotal,
  7489. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7490. "checkCostTotal": checkCostTotal,
  7491. "zhenChaCostTotal": zhenChaCostTotal,
  7492. "laboratoryCostTotal": laboratoryCostTotal,
  7493. "treatCostTotal": treatCostTotal,
  7494. })
  7495. } else {
  7496. for _, item := range order_info {
  7497. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7498. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7499. item.MedChrgitmType = "09"
  7500. }
  7501. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7502. if item.HisPrescriptionProject.Type == 2 {
  7503. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7504. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7505. case 0:
  7506. item.MedChrgitmType = "0"
  7507. break
  7508. case 1:
  7509. item.MedChrgitmType = "14"
  7510. break
  7511. case 2:
  7512. item.MedChrgitmType = "05"
  7513. break
  7514. case 3:
  7515. item.MedChrgitmType = "03"
  7516. break
  7517. case 4:
  7518. item.MedChrgitmType = "03"
  7519. break
  7520. case 5:
  7521. item.MedChrgitmType = "08"
  7522. break
  7523. case 6:
  7524. item.MedChrgitmType = "14"
  7525. break
  7526. case 7:
  7527. item.MedChrgitmType = "14"
  7528. break
  7529. case 8:
  7530. item.MedChrgitmType = "03"
  7531. break
  7532. case 9:
  7533. item.MedChrgitmType = "14"
  7534. break
  7535. case 10:
  7536. item.MedChrgitmType = "14"
  7537. break
  7538. case 11:
  7539. item.MedChrgitmType = "06"
  7540. break
  7541. case 12:
  7542. item.MedChrgitmType = "12"
  7543. break
  7544. case 13:
  7545. item.MedChrgitmType = "01"
  7546. break
  7547. case 14:
  7548. item.MedChrgitmType = "04"
  7549. break
  7550. case 15:
  7551. item.MedChrgitmType = "14"
  7552. break
  7553. }
  7554. } else {
  7555. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7556. case 1:
  7557. item.MedChrgitmType = "14"
  7558. break
  7559. case 2:
  7560. item.MedChrgitmType = "05"
  7561. break
  7562. case 3:
  7563. item.MedChrgitmType = "04"
  7564. break
  7565. case 4:
  7566. item.MedChrgitmType = "14"
  7567. break
  7568. case 5:
  7569. item.MedChrgitmType = "08"
  7570. break
  7571. case 6:
  7572. item.MedChrgitmType = "14"
  7573. break
  7574. case 7:
  7575. item.MedChrgitmType = "14"
  7576. break
  7577. case 8:
  7578. item.MedChrgitmType = "03"
  7579. break
  7580. case 9:
  7581. item.MedChrgitmType = "14"
  7582. break
  7583. }
  7584. }
  7585. } else if item.HisPrescriptionProject.Type == 3 {
  7586. item.MedChrgitmType = "08"
  7587. }
  7588. }
  7589. }
  7590. for _, item := range order_info {
  7591. if org_id == 10215 {
  7592. if item.MedChrgitmType == "01" { //床位费
  7593. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7594. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7595. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7596. }
  7597. if item.MedChrgitmType == "02" { //诊察费
  7598. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7599. //zhenChaCostSelfTotal = zhenChaCostTotal
  7600. }
  7601. if item.MedChrgitmType == "03" { //检查费
  7602. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7603. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7604. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7605. }
  7606. //if item.MedChrgitmType == "02" { //检查费
  7607. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7608. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7609. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7610. //}
  7611. if item.MedChrgitmType == "04" { //化验费
  7612. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7613. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7614. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7615. }
  7616. if item.MedChrgitmType == "05" { //治疗费
  7617. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7618. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7619. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7620. }
  7621. if item.MedChrgitmType == "06" { //手术费
  7622. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7623. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7624. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7625. }
  7626. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7627. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7628. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7629. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7630. }
  7631. if item.MedChrgitmType == "09" { //西药费
  7632. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7633. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7634. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7635. }
  7636. if item.MedChrgitmType == "11" { //中成费
  7637. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7638. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7639. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7640. }
  7641. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7642. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7643. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7644. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7645. }
  7646. } else {
  7647. if item.MedChrgitmType == "01" { //床位费
  7648. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7649. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7650. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7651. }
  7652. //if item.MedChrgitmType == "02" { //诊察费
  7653. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7654. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7655. //}
  7656. if item.MedChrgitmType == "03" { //检查费
  7657. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7658. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7659. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7660. }
  7661. //if item.MedChrgitmType == "02" { //检查费
  7662. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7663. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7664. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7665. //}
  7666. if item.MedChrgitmType == "04" { //化验费
  7667. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7668. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7669. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7670. }
  7671. if item.MedChrgitmType == "05" { //治疗费
  7672. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7673. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7674. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7675. }
  7676. if item.MedChrgitmType == "06" { //手术费
  7677. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7678. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7679. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7680. }
  7681. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7682. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7683. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7684. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7685. }
  7686. if item.MedChrgitmType == "09" { //西药费
  7687. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7688. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7689. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7690. }
  7691. if item.MedChrgitmType == "11" { //中成费
  7692. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7693. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7694. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7695. }
  7696. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7697. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7698. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7699. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7700. }
  7701. }
  7702. }
  7703. c.ServeSuccessJSON(map[string]interface{}{
  7704. "order": order,
  7705. "order_info": order_info,
  7706. "patient": patient,
  7707. "admin_info": adminInfo,
  7708. "his_hospital": record,
  7709. "bedCostTotal": bedCostTotal,
  7710. "operationCostTotal": operationCostTotal,
  7711. "otherCostTotal": otherCostTotal,
  7712. "materialCostTotal": materialCostTotal,
  7713. "westernMedicineCostTotal": westernMedicineCostTotal,
  7714. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7715. "checkCostTotal": checkCostTotal,
  7716. "zhenChaCostTotal": zhenChaCostTotal,
  7717. "laboratoryCostTotal": laboratoryCostTotal,
  7718. "treatCostTotal": treatCostTotal,
  7719. })
  7720. }
  7721. }
  7722. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7723. page, _ := c.GetInt64("page")
  7724. limit, _ := c.GetInt64("limit")
  7725. keywords := c.GetString("keywords")
  7726. start_time := c.GetString("start_time")
  7727. end_time := c.GetString("end_time")
  7728. //clr_type := c.GetString("clr_type")
  7729. insutype := c.GetString("insutype")
  7730. timeLayout := "2006-01-02"
  7731. loc, _ := time.LoadLocation("Local")
  7732. var theStartTIme int64
  7733. if len(start_time) > 0 {
  7734. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7735. theStartTIme = theTime.Unix()
  7736. }
  7737. var theEndtTIme int64
  7738. if len(end_time) > 0 {
  7739. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7740. theEndtTIme = theTime.Unix()
  7741. }
  7742. if page <= 0 {
  7743. page = 1
  7744. }
  7745. if limit <= 0 {
  7746. limit = 10
  7747. }
  7748. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7749. c.ServeSuccessJSON(map[string]interface{}{
  7750. "total": total,
  7751. "list": list,
  7752. })
  7753. return
  7754. }
  7755. func (c *HisApiController) GetPutOnRecordList() {
  7756. page, _ := c.GetInt64("page")
  7757. limit, _ := c.GetInt64("limit")
  7758. keywords := c.GetString("keywords")
  7759. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7760. if page <= 0 {
  7761. page = 1
  7762. }
  7763. if limit <= 0 {
  7764. limit = 10
  7765. }
  7766. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7767. c.ServeSuccessJSON(map[string]interface{}{
  7768. "total": total,
  7769. "list": list,
  7770. })
  7771. return
  7772. }
  7773. func (c *HisApiController) GetCompareData() {
  7774. start_time := c.GetString("start_time")
  7775. end_time := c.GetString("end_time")
  7776. insutype := c.GetString("insutype")
  7777. clr_type := c.GetString("clr_type")
  7778. timeLayout := "2006-01-02"
  7779. loc, _ := time.LoadLocation("Local")
  7780. var theStartTIme int64
  7781. if len(start_time) > 0 {
  7782. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7783. if err != nil {
  7784. theStartTIme = 0
  7785. }
  7786. theStartTIme = theTime.Unix()
  7787. }
  7788. var theEndtTIme int64
  7789. if len(end_time) > 0 {
  7790. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7791. if err != nil {
  7792. theEndtTIme = 0
  7793. }
  7794. theEndtTIme = theTime.Unix()
  7795. }
  7796. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7797. fmt.Println(err)
  7798. if err == nil {
  7799. c.ServeSuccessJSON(map[string]interface{}{
  7800. "list": formData,
  7801. })
  7802. } else {
  7803. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7804. return
  7805. }
  7806. }
  7807. func (c *HisApiController) GetFaPiaoData() {
  7808. order_id, _ := c.GetInt64("order_id")
  7809. patient_id, _ := c.GetInt64("patient_id")
  7810. //number := c.GetString("number")
  7811. adminUser := c.GetAdminUserInfo()
  7812. order, _ := service.GetHisOrderByID(order_id)
  7813. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7814. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7815. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7816. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7817. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7818. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7819. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7820. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7821. var bedCostTotal float64 = 0 //床位总费
  7822. var bedCostSelfTotal float64 = 0 //床位自费
  7823. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7824. var operationCostTotal float64 = 0 //手术费
  7825. var operationCostSelfTotal float64 = 0 //手术费
  7826. var operationCostPartSelfTotal float64 = 0 //手术费
  7827. var otherCostTotal float64 = 0 //其他费用
  7828. var otherCostSelfTotal float64 = 0 //其他费用
  7829. var otherCostPartSelfTotal float64 = 0 //其他费用
  7830. var materialCostTotal float64 = 0 //材料费
  7831. var materialCostSelfTotal float64 = 0 //材料费
  7832. var materialCostPartSelfTotal float64 = 0 //材料费
  7833. var westernMedicineCostTotal float64 = 0 //西药费
  7834. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7835. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7836. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7837. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7838. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7839. var checkCostTotal float64 = 0 //检查费
  7840. var checkCostSelfTotal float64 = 0 //检查费
  7841. var checkCostPartSelfTotal float64 = 0 //检查费
  7842. var hiliCostTotal float64 = 0 //护理费
  7843. var hiliCostSelfTotal float64 = 0 //护理费
  7844. var hiliCostPartSelfTotal float64 = 0 //护理费
  7845. var laboratoryCostTotal float64 = 0 //化验费
  7846. var laboratoryCostSelfTotal float64 = 0 //化验费
  7847. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7848. var treatCostTotal float64 = 0 //治疗费用
  7849. var treatCostSelfTotal float64 = 0 //治疗费用
  7850. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7851. var zhenChaCostTotal float64 = 0 //其他费用
  7852. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7853. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7854. decimal.DivisionPrecision = 2
  7855. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7856. var balanceAccountsType int64
  7857. if his.ID > 0 {
  7858. balanceAccountsType = his.BalanceAccountsType
  7859. } else {
  7860. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7861. }
  7862. if balanceAccountsType == 2 {
  7863. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7864. for _, item := range orderInfos_two {
  7865. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7866. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7867. item.MedChrgitmType = "09"
  7868. }
  7869. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7870. if item.HisPrescriptionProject.Type == 2 {
  7871. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7872. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7873. case 0:
  7874. item.MedChrgitmType = "0"
  7875. break
  7876. case 1:
  7877. item.MedChrgitmType = "14"
  7878. break
  7879. case 2:
  7880. item.MedChrgitmType = "05"
  7881. break
  7882. case 3:
  7883. item.MedChrgitmType = "03"
  7884. break
  7885. case 4:
  7886. item.MedChrgitmType = "03"
  7887. break
  7888. case 5:
  7889. item.MedChrgitmType = "08"
  7890. break
  7891. case 6:
  7892. item.MedChrgitmType = "14"
  7893. break
  7894. case 7:
  7895. item.MedChrgitmType = "14"
  7896. break
  7897. case 8:
  7898. item.MedChrgitmType = "03"
  7899. break
  7900. case 9:
  7901. item.MedChrgitmType = "14"
  7902. break
  7903. case 10:
  7904. item.MedChrgitmType = "14"
  7905. break
  7906. case 11:
  7907. item.MedChrgitmType = "06"
  7908. break
  7909. case 12:
  7910. item.MedChrgitmType = "12"
  7911. break
  7912. case 13:
  7913. item.MedChrgitmType = "01"
  7914. break
  7915. case 14:
  7916. item.MedChrgitmType = "04"
  7917. break
  7918. case 15:
  7919. item.MedChrgitmType = "02"
  7920. break
  7921. }
  7922. } else {
  7923. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7924. case 1:
  7925. item.MedChrgitmType = "14"
  7926. break
  7927. case 2:
  7928. item.MedChrgitmType = "05"
  7929. break
  7930. case 3:
  7931. item.MedChrgitmType = "03"
  7932. break
  7933. case 4:
  7934. item.MedChrgitmType = "03"
  7935. break
  7936. case 5:
  7937. item.MedChrgitmType = "08"
  7938. break
  7939. case 6:
  7940. item.MedChrgitmType = "14"
  7941. break
  7942. case 7:
  7943. item.MedChrgitmType = "14"
  7944. break
  7945. case 8:
  7946. item.MedChrgitmType = "03"
  7947. break
  7948. case 9:
  7949. item.MedChrgitmType = "14"
  7950. break
  7951. }
  7952. }
  7953. } else if item.HisPrescriptionProject.Type == 3 {
  7954. item.MedChrgitmType = "08"
  7955. }
  7956. }
  7957. }
  7958. for _, item := range orderInfos_two {
  7959. fmt.Println(item.MedChrgitmType)
  7960. if item.MedChrgitmType == "07" { //床位费
  7961. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7962. hiliCostSelfTotal = hiliCostTotal
  7963. }
  7964. if item.MedChrgitmType == "01" { //床位费
  7965. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7966. bedCostSelfTotal = bedCostTotal
  7967. }
  7968. if item.MedChrgitmType == "02" { //诊察费
  7969. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7970. zhenChaCostSelfTotal = zhenChaCostTotal
  7971. }
  7972. if item.MedChrgitmType == "03" { //检查费
  7973. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7974. checkCostSelfTotal = checkCostTotal
  7975. }
  7976. if item.MedChrgitmType == "04" { //化验费
  7977. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7978. laboratoryCostSelfTotal = laboratoryCostTotal
  7979. }
  7980. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7981. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7982. treatCostSelfTotal = treatCostTotal
  7983. }
  7984. if item.MedChrgitmType == "06" { //手术费
  7985. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7986. operationCostSelfTotal = treatCostTotal
  7987. }
  7988. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7989. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7990. materialCostSelfTotal = materialCostTotal
  7991. }
  7992. if item.MedChrgitmType == "09" { //西药费
  7993. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7994. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7995. }
  7996. if item.MedChrgitmType == "11" { //中成费
  7997. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7998. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7999. }
  8000. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8001. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8002. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8003. otherCostSelfTotal = otherCostTotal
  8004. }
  8005. } else {
  8006. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8007. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8008. otherCostSelfTotal = otherCostTotal
  8009. }
  8010. }
  8011. }
  8012. } else {
  8013. for _, item := range orderInfos {
  8014. if item.MedChrgitmType == "01" { //床位费
  8015. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8016. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8017. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8018. }
  8019. if item.MedChrgitmType == "02" { //诊察费
  8020. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8021. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8022. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8023. }
  8024. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8025. if item.MedChrgitmType == "03" { //检查费
  8026. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8027. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8028. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8029. }
  8030. } else {
  8031. if item.MedChrgitmType == "03" { //检查费
  8032. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8033. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8034. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8035. }
  8036. }
  8037. if item.MedChrgitmType == "04" { //化验费
  8038. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8039. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8040. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8041. }
  8042. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8043. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8044. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8045. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8046. }
  8047. if item.MedChrgitmType == "06" { //手术费
  8048. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8049. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8050. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8051. }
  8052. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8053. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8054. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8055. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8056. }
  8057. if item.MedChrgitmType == "07" { //西药费
  8058. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8059. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8060. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8061. }
  8062. if item.MedChrgitmType == "09" { //西药费
  8063. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8064. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8065. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8066. }
  8067. if item.MedChrgitmType == "11" { //中成费
  8068. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8069. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8070. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8071. }
  8072. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8073. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8074. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8075. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8076. }
  8077. }
  8078. }
  8079. timeLayout := "2006-01-02"
  8080. loc, _ := time.LoadLocation("Local")
  8081. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8082. if err != nil {
  8083. }
  8084. startRecordDateTime := startTime.Unix()
  8085. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8086. if err != nil {
  8087. }
  8088. endRecordDateTime := endTime.Unix()
  8089. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8090. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8091. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8092. c.ServeSuccessJSON(map[string]interface{}{
  8093. "order_number": order.Number, //业务流水号
  8094. "id_card_no": his.IdCardNo, //社会保障号
  8095. "patient": patient,
  8096. "department_name": department.Name, //科室
  8097. "number": his.Number, //门诊号
  8098. "date": order.SettleAccountsDate, //结算日期
  8099. "name": order.PsnName, //姓名
  8100. "gender": patient.Gender, //性别
  8101. "psn_cash_money": order.PsnCashPay, //个人支付
  8102. "pay_way": "门诊", //结算方式
  8103. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8104. "admin_user_name": admin.UserName, //收款员
  8105. "order": order,
  8106. "order_info": orderInfos_two,
  8107. "his": his,
  8108. "bedCostTotal": bedCostTotal,
  8109. "bedCostSelfTotal": bedCostSelfTotal,
  8110. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8111. "operationCostTotal": operationCostTotal,
  8112. "operationCostSelfTotal": operationCostSelfTotal,
  8113. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8114. "otherCostTotal": otherCostTotal,
  8115. "otherCostSelfTotal": otherCostSelfTotal,
  8116. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8117. "materialCostTotal": materialCostTotal,
  8118. "materialCostSelfTotal": materialCostSelfTotal,
  8119. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8120. "westernMedicineCostTotal": westernMedicineCostTotal,
  8121. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8122. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8123. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8124. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8125. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8126. "checkCostTotal": checkCostTotal,
  8127. "checkCostSelfTotal": checkCostSelfTotal,
  8128. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8129. "laboratoryCostTotal": laboratoryCostTotal,
  8130. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8131. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8132. "treatCostTotal": treatCostTotal,
  8133. "treatCostSelfTotal": treatCostSelfTotal,
  8134. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8135. "zhenChaCostTotal": zhenChaCostTotal,
  8136. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8137. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8138. "his_hospital_record": his_hospital_record,
  8139. "pre_pay_money": pre_pay_money,
  8140. "refund_sum": sum,
  8141. "doctor_info": doctor_info,
  8142. "hiliCostTotal": hiliCostTotal,
  8143. "hiliCostSelfTotal": hiliCostSelfTotal,
  8144. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8145. })
  8146. }
  8147. //func (c *HisApiController) GetFaPiaoDatas() {
  8148. // order_ids := c.GetString("order_ids")
  8149. // patient_id, _ := c.GetInt64("patient_id")
  8150. // adminUser := c.GetAdminUserInfo()
  8151. //
  8152. // orders := strings.Split(order_ids, ",")
  8153. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8154. //
  8155. // for _, item := range orders {
  8156. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8157. // order, _ := service.GetHisOrderByID(order_id)
  8158. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8159. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8160. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8161. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8162. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8163. //
  8164. // }
  8165. //
  8166. // var bedCostTotal float64 = 0 //床位总费
  8167. // var bedCostSelfTotal float64 = 0 //床位自费
  8168. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8169. //
  8170. // var operationCostTotal float64 = 0 //手术费
  8171. // var operationCostSelfTotal float64 = 0 //手术费
  8172. // var operationCostPartSelfTotal float64 = 0 //手术费
  8173. //
  8174. // var otherCostTotal float64 = 0 //其他费用
  8175. // var otherCostSelfTotal float64 = 0 //其他费用
  8176. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8177. //
  8178. // var materialCostTotal float64 = 0 //材料费
  8179. // var materialCostSelfTotal float64 = 0 //材料费
  8180. // var materialCostPartSelfTotal float64 = 0 //材料费
  8181. //
  8182. // var westernMedicineCostTotal float64 = 0 //西药费
  8183. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8184. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8185. //
  8186. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8187. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8188. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8189. //
  8190. // var checkCostTotal float64 = 0 //检查费
  8191. // var checkCostSelfTotal float64 = 0 //检查费
  8192. // var checkCostPartSelfTotal float64 = 0 //检查费
  8193. //
  8194. // var laboratoryCostTotal float64 = 0 //化验费
  8195. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8196. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8197. //
  8198. // var treatCostTotal float64 = 0 //治疗费用
  8199. // var treatCostSelfTotal float64 = 0 //治疗费用
  8200. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8201. //
  8202. // var zhenChaCostTotal float64 = 0 //其他费用
  8203. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8204. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8205. //
  8206. // decimal.DivisionPrecision = 2
  8207. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8208. //
  8209. // var balanceAccountsType int64
  8210. // if his.ID > 0 {
  8211. // balanceAccountsType = his.BalanceAccountsType
  8212. // } else {
  8213. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8214. // }
  8215. // if balanceAccountsType == 2 {
  8216. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8217. // for _, item := range orderInfos_two {
  8218. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8219. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8220. // item.MedChrgitmType = "09"
  8221. // }
  8222. //
  8223. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8224. // if item.HisPrescriptionProject.Type == 2 {
  8225. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8226. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8227. // case 0:
  8228. // item.MedChrgitmType = "0"
  8229. // break
  8230. // case 1:
  8231. // item.MedChrgitmType = "14"
  8232. // break
  8233. // case 2:
  8234. // item.MedChrgitmType = "05"
  8235. //
  8236. // break
  8237. // case 3:
  8238. // item.MedChrgitmType = "03"
  8239. //
  8240. // break
  8241. // case 4:
  8242. // item.MedChrgitmType = "03"
  8243. //
  8244. // break
  8245. // case 5:
  8246. // item.MedChrgitmType = "08"
  8247. //
  8248. // break
  8249. // case 6:
  8250. // item.MedChrgitmType = "14"
  8251. //
  8252. // break
  8253. // case 7:
  8254. // item.MedChrgitmType = "14"
  8255. //
  8256. // break
  8257. // case 8:
  8258. // item.MedChrgitmType = "03"
  8259. // break
  8260. // case 9:
  8261. // item.MedChrgitmType = "14"
  8262. // break
  8263. // case 10:
  8264. // item.MedChrgitmType = "14"
  8265. // break
  8266. // case 11:
  8267. // item.MedChrgitmType = "06"
  8268. // break
  8269. // case 12:
  8270. // item.MedChrgitmType = "12"
  8271. // break
  8272. // case 13:
  8273. // item.MedChrgitmType = "01"
  8274. // break
  8275. // case 14:
  8276. // item.MedChrgitmType = "04"
  8277. // break
  8278. // case 15:
  8279. // item.MedChrgitmType = "02"
  8280. // break
  8281. //
  8282. // }
  8283. //
  8284. // } else {
  8285. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8286. //
  8287. // case 1:
  8288. // item.MedChrgitmType = "14"
  8289. // break
  8290. // case 2:
  8291. // item.MedChrgitmType = "05"
  8292. //
  8293. // break
  8294. // case 3:
  8295. // item.MedChrgitmType = "03"
  8296. //
  8297. // break
  8298. // case 4:
  8299. // item.MedChrgitmType = "03"
  8300. //
  8301. // break
  8302. // case 5:
  8303. // item.MedChrgitmType = "08"
  8304. //
  8305. // break
  8306. // case 6:
  8307. // item.MedChrgitmType = "14"
  8308. //
  8309. // break
  8310. // case 7:
  8311. // item.MedChrgitmType = "14"
  8312. //
  8313. // break
  8314. // case 8:
  8315. // item.MedChrgitmType = "03"
  8316. // break
  8317. // case 9:
  8318. // item.MedChrgitmType = "14"
  8319. // break
  8320. //
  8321. // }
  8322. //
  8323. // }
  8324. //
  8325. // } else if item.HisPrescriptionProject.Type == 3 {
  8326. // item.MedChrgitmType = "08"
  8327. // }
  8328. // }
  8329. // }
  8330. //
  8331. // for _, item := range orderInfos_two {
  8332. // fmt.Println(item.MedChrgitmType)
  8333. // if item.MedChrgitmType == "01" { //床位费
  8334. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8335. // bedCostSelfTotal = bedCostTotal
  8336. // }
  8337. //
  8338. // if item.MedChrgitmType == "02" { //诊察费
  8339. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8340. // zhenChaCostSelfTotal = zhenChaCostTotal
  8341. // }
  8342. //
  8343. // if item.MedChrgitmType == "03" { //检查费
  8344. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8345. // checkCostSelfTotal = checkCostTotal
  8346. // }
  8347. //
  8348. // if item.MedChrgitmType == "04" { //化验费
  8349. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8350. // laboratoryCostSelfTotal = laboratoryCostTotal
  8351. // }
  8352. //
  8353. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8354. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8355. // treatCostSelfTotal = treatCostTotal
  8356. // }
  8357. //
  8358. // if item.MedChrgitmType == "06" { //手术费
  8359. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8360. // operationCostSelfTotal = treatCostTotal
  8361. // }
  8362. //
  8363. // if item.MedChrgitmType == "08" { //材料费
  8364. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8365. // materialCostSelfTotal = materialCostTotal
  8366. // }
  8367. //
  8368. // if item.MedChrgitmType == "09" { //西药费
  8369. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8370. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8371. // }
  8372. //
  8373. // if item.MedChrgitmType == "11" { //中成费
  8374. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8375. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8376. // }
  8377. //
  8378. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8379. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8380. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8381. // otherCostSelfTotal = otherCostTotal
  8382. // }
  8383. // } else {
  8384. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8385. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8386. // otherCostSelfTotal = otherCostTotal
  8387. // }
  8388. //
  8389. // }
  8390. //
  8391. // }
  8392. //
  8393. // } else {
  8394. // for _, item := range orderInfos {
  8395. // if item.MedChrgitmType == "01" { //床位费
  8396. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8397. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8398. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8399. // }
  8400. //
  8401. // if item.MedChrgitmType == "02" { //诊察费
  8402. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8403. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8404. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8405. // }
  8406. //
  8407. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8408. // if item.MedChrgitmType == "03" { //检查费
  8409. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8410. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8411. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8412. //
  8413. // }
  8414. // } else {
  8415. // if item.MedChrgitmType == "03" { //检查费
  8416. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8417. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8418. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8419. // }
  8420. //
  8421. // }
  8422. //
  8423. // if item.MedChrgitmType == "04" { //化验费
  8424. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8425. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8426. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8427. //
  8428. // }
  8429. //
  8430. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8431. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8432. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8433. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8434. //
  8435. // }
  8436. //
  8437. // if item.MedChrgitmType == "06" { //手术费
  8438. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8439. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8440. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8441. // }
  8442. //
  8443. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8444. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8445. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8446. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8447. // }
  8448. //
  8449. // if item.MedChrgitmType == "09" { //西药费
  8450. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8451. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8452. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8453. // }
  8454. //
  8455. // if item.MedChrgitmType == "11" { //中成费
  8456. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8457. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8458. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8459. // }
  8460. //
  8461. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8462. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8463. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8464. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8465. // }
  8466. //
  8467. // }
  8468. // }
  8469. // timeLayout := "2006-01-02"
  8470. // loc, _ := time.LoadLocation("Local")
  8471. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8472. // if err != nil {
  8473. // }
  8474. // startRecordDateTime := startTime.Unix()
  8475. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8476. // if err != nil {
  8477. // }
  8478. // endRecordDateTime := endTime.Unix()
  8479. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8480. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8481. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8482. //
  8483. // c.ServeSuccessJSON(map[string]interface{}{
  8484. // "order_number": order.Number, //业务流水号
  8485. // "id_card_no": his.IdCardNo, //社会保障号
  8486. // "department_name": department.Name, //科室
  8487. // "number": his.Number, //门诊号
  8488. // "date": order.SettleAccountsDate, //结算日期
  8489. // "name": order.PsnName, //姓名
  8490. // "gender": patient.Gender, //性别
  8491. // "psn_cash_money": order.PsnCashPay, //个人支付
  8492. // "pay_way": "门诊", //结算方式
  8493. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8494. // "admin_user_name": admin.UserName, //收款员
  8495. // "order": order,
  8496. // "order_info": orderInfos_two,
  8497. // "his": his,
  8498. // "bedCostTotal": bedCostTotal,
  8499. // "bedCostSelfTotal": bedCostSelfTotal,
  8500. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8501. // "operationCostTotal": operationCostTotal,
  8502. // "operationCostSelfTotal": operationCostSelfTotal,
  8503. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8504. // "otherCostTotal": otherCostTotal,
  8505. // "otherCostSelfTotal": otherCostSelfTotal,
  8506. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8507. // "materialCostTotal": materialCostTotal,
  8508. // "materialCostSelfTotal": materialCostSelfTotal,
  8509. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8510. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8511. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8512. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8513. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8514. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8515. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8516. // "checkCostTotal": checkCostTotal,
  8517. // "checkCostSelfTotal": checkCostSelfTotal,
  8518. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8519. // "laboratoryCostTotal": laboratoryCostTotal,
  8520. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8521. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8522. // "treatCostTotal": treatCostTotal,
  8523. // "treatCostSelfTotal": treatCostSelfTotal,
  8524. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8525. // "zhenChaCostTotal": zhenChaCostTotal,
  8526. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8527. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8528. // "his_hospital_record": his_hospital_record,
  8529. // "pre_pay_money": pre_pay_money,
  8530. // "refund_sum": sum,
  8531. // })
  8532. //
  8533. //}
  8534. func (this *HisApiController) GetIncomeStatisticsData() {
  8535. start_time := this.GetString("start_time")
  8536. end_time := this.GetString("end_time")
  8537. key_words := this.GetString("key_words")
  8538. limit, _ := this.GetInt64("limit")
  8539. page, _ := this.GetInt64("page")
  8540. if page <= 0 {
  8541. page = 1
  8542. }
  8543. if limit <= 0 {
  8544. limit = 10
  8545. }
  8546. statistics_type, _ := this.GetInt64("statistics_type")
  8547. admin := this.GetAdminUserInfo()
  8548. timeLayout := "2006-01-02"
  8549. loc, _ := time.LoadLocation("Local")
  8550. var theStartTIme int64
  8551. if len(start_time) > 0 {
  8552. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8553. if err != nil {
  8554. theStartTIme = 0
  8555. }
  8556. theStartTIme = theTime.Unix()
  8557. }
  8558. var theEndtTIme int64
  8559. if len(end_time) > 0 {
  8560. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8561. if err != nil {
  8562. theEndtTIme = 0
  8563. }
  8564. theEndtTIme = theTime.Unix()
  8565. }
  8566. if statistics_type == 1 {
  8567. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8568. this.ServeSuccessJSON(map[string]interface{}{
  8569. "list": list,
  8570. "total": total,
  8571. })
  8572. } else {
  8573. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8574. this.ServeSuccessJSON(map[string]interface{}{
  8575. "list": list,
  8576. "total": total,
  8577. })
  8578. }
  8579. }
  8580. func (c *HisApiController) PostProjectInformation() {
  8581. adminUser := c.GetAdminUserInfo()
  8582. orgId := adminUser.CurrentOrgId
  8583. dataBody := make(map[string]interface{}, 0)
  8584. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8585. if err != nil {
  8586. utils.ErrorLog(err.Error())
  8587. return
  8588. }
  8589. utils.ErrorLog("%v", dataBody)
  8590. var projectList []*models.HisProject
  8591. var total_goods []interface{}
  8592. tempProjects := dataBody["projects"].([]interface{})
  8593. total_goods = tempProjects
  8594. for index, projectMap := range tempProjects {
  8595. projectM := projectMap.(map[string]interface{})
  8596. var project models.HisProject
  8597. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8598. utils.ErrorLog("project_name")
  8599. return
  8600. }
  8601. project_name, _ := projectM["project_name"].(string)
  8602. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8603. err_log := models.ExportErrLog{
  8604. LogType: 6,
  8605. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8606. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8607. Status: 1,
  8608. CreateTime: time.Now().Unix(),
  8609. UpdateTime: time.Now().Unix(),
  8610. ExportTime: time.Now().Unix(),
  8611. }
  8612. service.CreateExportErrLog(&err_log)
  8613. continue
  8614. }
  8615. project.ProjectName = project_name
  8616. prices := projectM["price"].(string)
  8617. price, _ := strconv.ParseFloat(prices, 64)
  8618. if price <= 0 { //名字为空则生成一条导入错误日志
  8619. err_log := models.ExportErrLog{
  8620. LogType: 6,
  8621. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8622. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8623. Status: 1,
  8624. CreateTime: time.Now().Unix(),
  8625. UpdateTime: time.Now().Unix(),
  8626. ExportTime: time.Now().Unix(),
  8627. }
  8628. service.CreateExportErrLog(&err_log)
  8629. continue
  8630. }
  8631. project.Price = price
  8632. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8633. utils.ErrorLog("unit_id")
  8634. return
  8635. }
  8636. unit := projectM["unit"].(string)
  8637. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8638. err_log := models.ExportErrLog{
  8639. LogType: 6,
  8640. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8641. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8642. Status: 1,
  8643. CreateTime: time.Now().Unix(),
  8644. UpdateTime: time.Now().Unix(),
  8645. ExportTime: time.Now().Unix(),
  8646. }
  8647. service.CreateExportErrLog(&err_log)
  8648. continue
  8649. }
  8650. project.Unit = unit
  8651. cost_classify := projectM["cost_classify"].(string)
  8652. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8653. err_log := models.ExportErrLog{
  8654. LogType: 6,
  8655. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8656. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8657. Status: 1,
  8658. CreateTime: time.Now().Unix(),
  8659. UpdateTime: time.Now().Unix(),
  8660. ExportTime: time.Now().Unix(),
  8661. }
  8662. service.CreateExportErrLog(&err_log)
  8663. continue
  8664. }
  8665. var costClassify = "费用类别"
  8666. var cost_classify_id int64
  8667. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8668. if len(cost_classify) != 0 {
  8669. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8670. if errcode == gorm.ErrRecordNotFound {
  8671. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8672. dataconfig := models.DictDataconfig{
  8673. ParentId: costClassifyConfig.ID,
  8674. Module: "system",
  8675. OrgId: orgId,
  8676. Name: cost_classify,
  8677. FieldName: "",
  8678. Value: costConfig.Value + 1,
  8679. CreatedTime: "",
  8680. UpdatedTime: "",
  8681. CreateUserId: adminUser.AdminUser.Id,
  8682. Status: 1,
  8683. Remark: "",
  8684. DeleteIdSystem: 0,
  8685. Title: "",
  8686. Content: "",
  8687. Order: 0,
  8688. Code: "",
  8689. }
  8690. service.CreatedDicConfig(&dataconfig)
  8691. }
  8692. }
  8693. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8694. for _, it := range costClassList {
  8695. if cost_classify == it.Name {
  8696. cost_classify_id = int64(it.Value)
  8697. }
  8698. }
  8699. project.CostClassify = cost_classify_id
  8700. executive_section := projectM["executive_section"].(string)
  8701. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8702. err_log := models.ExportErrLog{
  8703. LogType: 6,
  8704. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8705. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8706. Status: 1,
  8707. CreateTime: time.Now().Unix(),
  8708. UpdateTime: time.Now().Unix(),
  8709. ExportTime: time.Now().Unix(),
  8710. }
  8711. service.CreateExportErrLog(&err_log)
  8712. continue
  8713. }
  8714. if len(executive_section) != 0 {
  8715. //查找科室是否有内容
  8716. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8717. if errcodedepart == gorm.ErrRecordNotFound {
  8718. department := models.XtHisDepartment{
  8719. Name: executive_section,
  8720. Status: 1,
  8721. UserOrgId: adminUser.CurrentOrgId,
  8722. CreatedTime: time.Now().Unix(),
  8723. }
  8724. service.CreateDePartment(&department)
  8725. }
  8726. }
  8727. var executive_section_id int64
  8728. departMentList, _ := service.GetAllDepartMent(orgId)
  8729. for _, it := range departMentList {
  8730. if executive_section == it.Name {
  8731. executive_section_id = it.ID
  8732. }
  8733. }
  8734. project.ExecutiveSection = executive_section_id
  8735. medical_coverage := projectM["medical_coverage"].(string)
  8736. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8737. err_log := models.ExportErrLog{
  8738. LogType: 6,
  8739. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8740. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8741. Status: 1,
  8742. CreateTime: time.Now().Unix(),
  8743. UpdateTime: time.Now().Unix(),
  8744. ExportTime: time.Now().Unix(),
  8745. }
  8746. service.CreateExportErrLog(&err_log)
  8747. continue
  8748. }
  8749. var medicalCoverage = "医保等级"
  8750. var medical_coverage_id int64
  8751. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8752. if len(medical_coverage) != 0 {
  8753. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8754. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8755. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8756. dataconfig := models.DictDataconfig{
  8757. ParentId: medicalCoverageConfig.ID,
  8758. Module: "system",
  8759. OrgId: orgId,
  8760. Name: medical_coverage,
  8761. FieldName: "",
  8762. Value: medicalCoverageConfig.Value + 1,
  8763. CreatedTime: "",
  8764. UpdatedTime: "",
  8765. CreateUserId: adminUser.AdminUser.Id,
  8766. Status: 1,
  8767. Remark: "",
  8768. DeleteIdSystem: 0,
  8769. Title: "",
  8770. Content: "",
  8771. Order: 0,
  8772. Code: "",
  8773. }
  8774. service.CreatedDicConfig(&dataconfig)
  8775. }
  8776. }
  8777. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8778. for _, it := range medicalCoverageList {
  8779. if medical_coverage == it.Name {
  8780. medical_coverage_id = int64(it.Value)
  8781. }
  8782. }
  8783. project.MedicalCoverage = medical_coverage_id
  8784. pinyin := projectM["pinyin"].(string)
  8785. project.Pinyin = pinyin
  8786. wubi := projectM["wubi"].(string)
  8787. project.Wubi = wubi
  8788. statistical_classification := projectM["statistical_classification"].(string)
  8789. var statisticalClassification = "统计分类"
  8790. var statistical_classification_id int64
  8791. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8792. if len(statistical_classification) != 0 {
  8793. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8794. if classificationerrcodes == gorm.ErrRecordNotFound {
  8795. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8796. dataconfig := models.DictDataconfig{
  8797. ParentId: classiFication.ID,
  8798. Module: "system",
  8799. OrgId: orgId,
  8800. Name: statistical_classification,
  8801. FieldName: "",
  8802. Value: classiFicationConfig.Value + 1,
  8803. CreatedTime: "",
  8804. UpdatedTime: "",
  8805. CreateUserId: adminUser.AdminUser.Id,
  8806. Status: 1,
  8807. Remark: "",
  8808. DeleteIdSystem: 0,
  8809. Title: "",
  8810. Content: "",
  8811. Order: 0,
  8812. Code: "",
  8813. }
  8814. service.CreatedDicConfig(&dataconfig)
  8815. }
  8816. }
  8817. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8818. for _, it := range classiFicationList {
  8819. if statistical_classification == it.Name {
  8820. statistical_classification_id = int64(it.Value)
  8821. }
  8822. }
  8823. project.StatisticalClassification = statistical_classification_id
  8824. disease_directory := int64(projectM["disease_directory"].(float64))
  8825. project.DiseaseDirectory = disease_directory
  8826. is_record := int64(projectM["is_record"].(float64))
  8827. project.IsRecord = is_record
  8828. medical_code := projectM["medical_code"].(string)
  8829. project.MedicalCode = medical_code
  8830. tube_color := projectM["tube_color"].(string)
  8831. var tubeColor = "试管颜色"
  8832. var tube_color_id int64
  8833. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8834. if len(tube_color) != 0 {
  8835. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8836. if errcodetube == gorm.ErrRecordNotFound {
  8837. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8838. dataconfig := models.DictDataconfig{
  8839. ParentId: tubeColorConfig.ID,
  8840. Module: "system",
  8841. OrgId: orgId,
  8842. Name: tube_color,
  8843. FieldName: "",
  8844. Value: tubeConfig.Value + 1,
  8845. CreatedTime: "",
  8846. UpdatedTime: "",
  8847. CreateUserId: adminUser.AdminUser.Id,
  8848. Status: 1,
  8849. Remark: "",
  8850. DeleteIdSystem: 0,
  8851. Title: "",
  8852. Content: "",
  8853. Order: 0,
  8854. Code: "",
  8855. }
  8856. service.CreatedDicConfig(&dataconfig)
  8857. }
  8858. }
  8859. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8860. for _, it := range tubeColorList {
  8861. if tube_color == it.Name {
  8862. tube_color_id = int64(it.Value)
  8863. }
  8864. }
  8865. project.TubeColor = tube_color_id
  8866. single_dose := projectM["single_dose"].(string)
  8867. project.SingleDose = single_dose
  8868. execution_frequency := projectM["execution_frequency"].(string)
  8869. project.ExecutionFrequency = execution_frequency
  8870. delivery_way := projectM["delivery_way"].(string)
  8871. project.DeliveryWay = delivery_way
  8872. number_days := projectM["number_days"].(string)
  8873. project.NumberDays = number_days
  8874. total := projectM["total"].(string)
  8875. project.Total = total
  8876. medical_status := int64(projectM["medical_status"].(float64))
  8877. project.MedicalStatus = medical_status
  8878. category := int64(projectM["category"].(float64))
  8879. project.Category = category
  8880. specail_project := int64(projectM["specail_project"].(float64))
  8881. project.SpecailProject = specail_project
  8882. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8883. project.SocialSecurityDirectoryCode = social_security_directory_code
  8884. remark := projectM["remark"].(string)
  8885. project.Remark = remark
  8886. record_date := projectM["record_date"].(string)
  8887. timeLayout := "2006-01-02"
  8888. loc, _ := time.LoadLocation("Local")
  8889. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8890. project.RecordDate = theTime.Unix()
  8891. projectList = append(projectList, &project)
  8892. }
  8893. export_time := time.Now().Unix()
  8894. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8895. if len(projectList) > 0 {
  8896. for _, item := range projectList {
  8897. project := models.HisProject{
  8898. ProjectName: item.ProjectName,
  8899. Price: item.Price,
  8900. Unit: item.Unit,
  8901. CostClassify: item.CostClassify,
  8902. ExecutiveSection: item.ExecutiveSection,
  8903. MedicalCoverage: item.MedicalCoverage,
  8904. UserOrgId: orgId,
  8905. Status: 1,
  8906. CreatedTime: time.Now().Unix(),
  8907. Pinyin: item.Pinyin,
  8908. Wubi: item.Wubi,
  8909. StatisticalClassification: item.StatisticalClassification,
  8910. DiseaseDirectory: item.DiseaseDirectory,
  8911. IsRecord: item.IsRecord,
  8912. MedicalCode: item.MedicalCode,
  8913. TubeColor: item.TubeColor,
  8914. SingleDose: item.SingleDose,
  8915. DeliveryWay: item.DeliveryWay,
  8916. NumberDays: item.NumberDays,
  8917. Total: item.Total,
  8918. Category: item.Category,
  8919. MedicalStatus: item.MedicalStatus,
  8920. SpecailProject: item.SpecailProject,
  8921. RecordDate: item.RecordDate,
  8922. Remark: item.Remark,
  8923. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8924. ExecutionFrequency: item.ExecutionFrequency,
  8925. }
  8926. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8927. if errcodeproject == gorm.ErrRecordNotFound {
  8928. service.CreateProjectInfomation(&project)
  8929. } else if errcodeproject == nil {
  8930. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8931. }
  8932. log := models.ExportLog{
  8933. LogType: 6,
  8934. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8935. TotalNum: int64(len(total_goods)),
  8936. FailNum: int64(len(errLogs)),
  8937. SuccessNum: int64(len(projectList)),
  8938. CreateTime: time.Now().Unix(),
  8939. UpdateTime: time.Now().Unix(),
  8940. ExportTime: export_time,
  8941. Status: 1,
  8942. }
  8943. service.CreateExportLog(&log)
  8944. c.ServeSuccessJSON(map[string]interface{}{
  8945. "msg": "导入成功",
  8946. "total_num": len(total_goods),
  8947. "success_num": len(projectList),
  8948. "fail_num": int64(len(errLogs)),
  8949. })
  8950. }
  8951. } else {
  8952. log := models.ExportLog{
  8953. LogType: 6,
  8954. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8955. TotalNum: int64(len(total_goods)),
  8956. FailNum: int64(len(errLogs)),
  8957. SuccessNum: int64(len(projectList)),
  8958. CreateTime: time.Now().Unix(),
  8959. UpdateTime: time.Now().Unix(),
  8960. ExportTime: export_time,
  8961. Status: 1,
  8962. }
  8963. service.CreateExportLog(&log)
  8964. c.ServeSuccessJSON(map[string]interface{}{
  8965. "msg": "导入成功",
  8966. "total_num": len(total_goods),
  8967. "success_num": len(projectList),
  8968. "fail_num": int64(len(errLogs)),
  8969. })
  8970. }
  8971. }
  8972. //func (this *HisApiController) EditProjectInformation(){
  8973. //
  8974. // id, _ := this.GetInt64("id")
  8975. // project_team := this.GetString("project_team")
  8976. // price := this.GetString("price")
  8977. // price_float, _ := strconv.ParseFloat(price, 64)
  8978. // pinyin := this.GetString("pinyin")
  8979. // wubi := this.GetString("wubi")
  8980. // tube_color, _ := this.GetInt64("tube_color")
  8981. // team_type, _ := this.GetInt64("team_type")
  8982. // remark := this.GetString("remark")
  8983. // ids := this.GetString("ids")
  8984. // item_id := this.GetString("item_id")
  8985. // projectTeam := models.XtHisProjectTeam{
  8986. // ProjectTeam: project_team,
  8987. // Price: price_float,
  8988. // Pinyin: pinyin,
  8989. // Wubi: wubi,
  8990. // TubeColor: tube_color,
  8991. // TeamType: team_type,
  8992. // Remark: remark,
  8993. // ProjectId: ids,
  8994. // ItemId: item_id,
  8995. // }
  8996. //
  8997. //
  8998. // dataBody := make(map[string]interface{}, 0)
  8999. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9000. // if err != nil {
  9001. // utils.ErrorLog(err.Error())
  9002. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9003. // return
  9004. // }
  9005. //
  9006. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9007. //
  9008. //
  9009. // if err != nil {
  9010. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9011. // return
  9012. // }
  9013. //
  9014. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9015. // infos, _ := dataBody["info"].([]interface{})
  9016. // if len(infos) > 0 {
  9017. // var ids []string
  9018. //
  9019. // for _, item := range infos {
  9020. // items := item.(map[string]interface{})
  9021. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9022. // utils.ErrorLog("id")
  9023. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9024. // return
  9025. // }
  9026. // id := int64(items["id"].(float64))
  9027. //
  9028. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9029. // utils.ErrorLog("type")
  9030. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9031. // return
  9032. // }
  9033. // types := int64(items["type"].(float64))
  9034. //
  9035. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9036. // utils.ErrorLog("number")
  9037. // }
  9038. //
  9039. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9040. //
  9041. // projectList := models.XtHisProjectList{
  9042. // Number: number,
  9043. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9044. // ProjectId: id,
  9045. // Status: 1,
  9046. // CreatedTime: time.Now().Unix(),
  9047. // UpdatedTime: time.Now().Unix(),
  9048. // TeamId: projectTeam.ID,
  9049. // Type: types,
  9050. // }
  9051. // list := projectList
  9052. //
  9053. // service.CreateProjectList(&list)
  9054. //
  9055. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9056. //
  9057. // }
  9058. // ids_str := strings.Join(ids, ",")
  9059. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9060. // service.SaveProjectTeam(&projectTeam)
  9061. // this.ServeSuccessJSON(map[string]interface{}{
  9062. // "projectTeam": projectTeam,
  9063. // })
  9064. // }
  9065. // }
  9066. //}
  9067. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9068. name := c.GetString("name")
  9069. mode_id, _ := c.GetInt64("mode", 0)
  9070. types, _ := c.GetInt64("type", 0)
  9071. patient_id, _ := c.GetInt64("patient_id", 0)
  9072. types = 1
  9073. adminInfo := c.GetAdminUserInfo()
  9074. template := &models.HisPrescriptionTemplate{
  9075. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9076. PatientId: patient_id,
  9077. Type: types,
  9078. Status: 1,
  9079. Ctime: time.Now().Unix(),
  9080. Mtime: time.Now().Unix(),
  9081. Name: name,
  9082. Mode: mode_id,
  9083. }
  9084. dataBody := make(map[string]interface{}, 0)
  9085. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9086. if err != nil {
  9087. utils.ErrorLog(err.Error())
  9088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9089. return
  9090. }
  9091. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9092. //如果已经存在记录则删除处方
  9093. if template_one.ID > 0 {
  9094. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9095. var ids []int64
  9096. var org_id int64
  9097. for _, item := range ps {
  9098. org_id = c.GetAdminUserInfo().CurrentOrgId
  9099. ids = append(ids, item.ID)
  9100. }
  9101. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  9102. if err2 == nil {
  9103. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9104. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9105. if len(prescriptions) > 0 {
  9106. for _, item := range prescriptions {
  9107. items := item.(map[string]interface{})
  9108. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9109. utils.ErrorLog("type")
  9110. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9111. return
  9112. }
  9113. types := int64(items["type"].(float64))
  9114. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9115. utils.ErrorLog("med_type")
  9116. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9117. return
  9118. }
  9119. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9120. ctime := time.Now().Unix()
  9121. prescription := &models.HisPrescriptionInfoTemplate{
  9122. PatientId: patient_id,
  9123. UserOrgId: adminInfo.CurrentOrgId,
  9124. Ctime: ctime,
  9125. Mtime: ctime,
  9126. Type: types,
  9127. Modifier: adminInfo.AdminUser.Id,
  9128. Creator: adminInfo.AdminUser.Id,
  9129. Status: 1,
  9130. PTemplateId: template_one.ID,
  9131. MedType: med_type,
  9132. }
  9133. service.CreateHisPrescriptionInfoTemplate(prescription)
  9134. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9135. advices := items["advices"].([]interface{})
  9136. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9137. ctime := time.Now().Unix()
  9138. mtime := ctime
  9139. if len(advices) > 0 {
  9140. for _, advice := range advices {
  9141. var s models.HisPrescriptionAdviceTemplate
  9142. s.PrescriptionId = prescription.ID
  9143. s.AdviceType = 2
  9144. s.StopState = 2
  9145. s.ExecutionState = 2
  9146. s.Status = 1
  9147. s.UserOrgId = adminInfo.CurrentOrgId
  9148. s.CreatedTime = ctime
  9149. s.UpdatedTime = mtime
  9150. s.PatientId = patient_id
  9151. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9152. if errcode > 0 {
  9153. c.ServeFailJSONWithSGJErrorCode(errcode)
  9154. return
  9155. }
  9156. service.CreateHisPrescriptionAdviceTemplate(&s)
  9157. }
  9158. }
  9159. }
  9160. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9161. projects := items["project"].([]interface{})
  9162. if len(projects) > 0 {
  9163. for _, project := range projects {
  9164. var p models.HisPrescriptionProjectTemplate
  9165. p.PrescriptionId = prescription.ID
  9166. p.Ctime = time.Now().Unix()
  9167. p.Mtime = time.Now().Unix()
  9168. p.PatientId = patient_id
  9169. p.UserOrgId = adminInfo.CurrentOrgId
  9170. p.Status = 1
  9171. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9172. if errcode > 0 {
  9173. c.ServeFailJSONWithSGJErrorCode(errcode)
  9174. return
  9175. }
  9176. service.CreateHisPrescriptionProjectTemplate(&p)
  9177. }
  9178. }
  9179. }
  9180. }
  9181. c.ServeSuccessJSON(map[string]interface{}{
  9182. "msg": "创建成功",
  9183. })
  9184. }
  9185. }
  9186. } else {
  9187. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9188. return
  9189. }
  9190. } else {
  9191. err3 := service.CreateHisPrescriptionTemplate(template)
  9192. if err3 == nil {
  9193. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9194. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9195. if len(prescriptions) > 0 {
  9196. for _, item := range prescriptions {
  9197. items := item.(map[string]interface{})
  9198. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9199. utils.ErrorLog("type")
  9200. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9201. return
  9202. }
  9203. types := int64(items["type"].(float64))
  9204. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9205. utils.ErrorLog("med_type")
  9206. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9207. return
  9208. }
  9209. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9210. ctime := time.Now().Unix()
  9211. prescription := &models.HisPrescriptionInfoTemplate{
  9212. PatientId: patient_id,
  9213. UserOrgId: adminInfo.CurrentOrgId,
  9214. Ctime: ctime,
  9215. Mtime: ctime,
  9216. Type: types,
  9217. Modifier: adminInfo.AdminUser.Id,
  9218. Creator: adminInfo.AdminUser.Id,
  9219. Status: 1,
  9220. PTemplateId: template.ID,
  9221. MedType: med_type,
  9222. }
  9223. service.CreateHisPrescriptionInfoTemplate(prescription)
  9224. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9225. advices := items["advices"].([]interface{})
  9226. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9227. ctime := time.Now().Unix()
  9228. mtime := ctime
  9229. if len(advices) > 0 {
  9230. for _, advice := range advices {
  9231. var s models.HisPrescriptionAdviceTemplate
  9232. s.PrescriptionId = prescription.ID
  9233. s.AdviceType = 2
  9234. s.StopState = 2
  9235. s.ExecutionState = 2
  9236. s.Status = 1
  9237. s.UserOrgId = adminInfo.CurrentOrgId
  9238. s.CreatedTime = ctime
  9239. s.UpdatedTime = mtime
  9240. s.PatientId = patient_id
  9241. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9242. if errcode > 0 {
  9243. c.ServeFailJSONWithSGJErrorCode(errcode)
  9244. return
  9245. }
  9246. service.CreateHisPrescriptionAdviceTemplate(&s)
  9247. }
  9248. }
  9249. }
  9250. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9251. projects := items["project"].([]interface{})
  9252. if len(projects) > 0 {
  9253. for _, project := range projects {
  9254. var p models.HisPrescriptionProjectTemplate
  9255. p.PrescriptionId = prescription.ID
  9256. p.Ctime = time.Now().Unix()
  9257. p.Mtime = time.Now().Unix()
  9258. p.PatientId = patient_id
  9259. p.UserOrgId = adminInfo.CurrentOrgId
  9260. p.Status = 1
  9261. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9262. if errcode > 0 {
  9263. c.ServeFailJSONWithSGJErrorCode(errcode)
  9264. return
  9265. }
  9266. service.CreateHisPrescriptionProjectTemplate(&p)
  9267. }
  9268. }
  9269. }
  9270. }
  9271. c.ServeSuccessJSON(map[string]interface{}{
  9272. "msg": "创建成功",
  9273. })
  9274. }
  9275. }
  9276. } else {
  9277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9278. return
  9279. }
  9280. }
  9281. }
  9282. func (c *HisApiController) PreSettle() {
  9283. id, _ := c.GetInt64("id")
  9284. record_time := c.GetString("record_time")
  9285. his_patient_id, _ := c.GetInt64("his_patient_id")
  9286. timeLayout := "2006-01-02"
  9287. loc, _ := time.LoadLocation("Local")
  9288. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9289. diagnosis_id := c.GetString("diagnosis")
  9290. sick_type, _ := c.GetInt64("sick_type")
  9291. reg_type, _ := c.GetInt64("p_type")
  9292. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9293. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9294. if err != nil {
  9295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9296. return
  9297. }
  9298. recordDateTime := theTime.Unix()
  9299. adminUser := c.GetAdminUserInfo()
  9300. var prescriptions []*models.HisPrescription
  9301. var start_time int64
  9302. var end_time int64
  9303. ids_str := c.GetString("ids")
  9304. ids_arr := strings.Split(ids_str, ",")
  9305. fmt.Println(reg_type)
  9306. if settle_accounts_type == 1 { //日结
  9307. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9308. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9309. } else {
  9310. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9311. }
  9312. fmt.Println(prescriptions)
  9313. } else { //月结
  9314. start_time_str := c.GetString("start_time")
  9315. end_time_str := c.GetString("end_time")
  9316. timeLayout := "2006-01-02"
  9317. loc, _ := time.LoadLocation("Local")
  9318. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9319. if err != nil {
  9320. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9321. return
  9322. }
  9323. recordStartTime := theStartTime.Unix()
  9324. start_time = recordStartTime
  9325. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9326. if err != nil {
  9327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9328. return
  9329. }
  9330. recordEndTime := theEndTime.Unix()
  9331. end_time = recordEndTime
  9332. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9333. }
  9334. if reg_type == 1111 || reg_type == 1112 {
  9335. reg_type = 11
  9336. }
  9337. timestamp := time.Now().Unix()
  9338. tempTime := time.Unix(timestamp, 0)
  9339. timeFormat := tempTime.Format("20060102150405")
  9340. chrgBchno := rand.Intn(100000) + 10000
  9341. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9342. strconv.FormatInt(his.PatientId, 10)
  9343. var ids []int64
  9344. for _, item := range prescriptions {
  9345. ids = append(ids, item.ID)
  9346. }
  9347. fmt.Println(ids)
  9348. var total float64
  9349. for _, item := range prescriptions {
  9350. fmt.Println(item)
  9351. if item.Type == 1 { //药品
  9352. for _, subItem := range item.HisDoctorAdviceInfo {
  9353. total = total + (subItem.Price * subItem.PrescribingNumber)
  9354. }
  9355. }
  9356. if item.Type == 2 { //项目
  9357. for _, subItem := range item.HisPrescriptionProject {
  9358. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9359. total = total + (subItem.Price * cnt)
  9360. }
  9361. }
  9362. for _, subItem := range item.HisAdditionalCharge {
  9363. total = total + (subItem.Price * float64(subItem.Count))
  9364. }
  9365. }
  9366. allTotal := fmt.Sprintf("%.2f", total)
  9367. totals, _ := strconv.ParseFloat(allTotal, 64)
  9368. order := &models.HisOrder{
  9369. UserOrgId: adminUser.CurrentOrgId,
  9370. HisPatientId: his.ID,
  9371. PatientId: id,
  9372. SettleAccountsDate: recordDateTime,
  9373. Ctime: time.Now().Unix(),
  9374. Mtime: time.Now().Unix(),
  9375. Status: 1,
  9376. OrderStatus: 1,
  9377. MdtrtId: his.Number,
  9378. Number: chrg_bchno,
  9379. MedfeeSumamt: totals,
  9380. SettleEndTime: end_time,
  9381. SettleStartTime: start_time,
  9382. SettleType: settle_accounts_type,
  9383. PsnPartAmt: totals,
  9384. PsnCashPay: totals,
  9385. PType: 2,
  9386. IsPre: 1,
  9387. MedType: strconv.Itoa(int(reg_type)),
  9388. Diagnosis: diagnosis_id,
  9389. }
  9390. err = service.CreateOrder(order)
  9391. if err != nil {
  9392. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9393. return
  9394. }
  9395. var customs []*Custom
  9396. for _, item := range prescriptions {
  9397. fmt.Println(item.Type)
  9398. if item.Type == 1 { //药品
  9399. for _, subItem := range item.HisDoctorAdviceInfo {
  9400. cus := &Custom{
  9401. AdviceId: subItem.ID,
  9402. ProjectId: 0,
  9403. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9404. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9405. FeedetlSn: subItem.FeedetlSn,
  9406. Price: fmt.Sprintf("%.2f", subItem.Price),
  9407. MedListCodg: subItem.MedListCodg,
  9408. Type: 1,
  9409. }
  9410. customs = append(customs, cus)
  9411. }
  9412. }
  9413. if item.Type == 2 { //项目
  9414. for _, subItem := range item.HisPrescriptionProject {
  9415. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9416. cus := &Custom{
  9417. AdviceId: 0,
  9418. ProjectId: subItem.ID,
  9419. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9420. Cut: fmt.Sprintf("%.2f", cnt),
  9421. FeedetlSn: subItem.FeedetlSn,
  9422. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9423. MedListCodg: subItem.MedListCodg,
  9424. Type: 2,
  9425. }
  9426. customs = append(customs, cus)
  9427. }
  9428. }
  9429. for _, item := range item.HisAdditionalCharge {
  9430. cus := &Custom{
  9431. ItemId: item.ID,
  9432. AdviceId: 0,
  9433. ProjectId: 0,
  9434. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9435. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9436. FeedetlSn: item.FeedetlSn,
  9437. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9438. MedListCodg: item.XtHisAddtionConfig.Code,
  9439. Type: 3,
  9440. }
  9441. customs = append(customs, cus)
  9442. }
  9443. }
  9444. fmt.Println(customs)
  9445. for _, item := range customs {
  9446. var advice_id int64 = 0
  9447. var project_id int64 = 0
  9448. var item_id int64 = 0
  9449. var types int64 = 0
  9450. if item.Type == 1 {
  9451. advice_id = item.AdviceId
  9452. project_id = 0
  9453. item_id = 0
  9454. } else if item.Type == 2 {
  9455. advice_id = 0
  9456. item_id = 0
  9457. project_id = item.ProjectId
  9458. } else if item.Type == 3 {
  9459. advice_id = 0
  9460. item_id = item.ItemId
  9461. project_id = 0
  9462. }
  9463. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9464. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9465. pric, _ := strconv.ParseFloat(item.Price, 32)
  9466. info := &models.HisOrderInfo{
  9467. OrderNumber: order.Number,
  9468. UploadDate: time.Now().Unix(),
  9469. AdviceId: advice_id,
  9470. DetItemFeeSumamt: detItemFeeSumamt,
  9471. Cnt: cut,
  9472. Pric: pric,
  9473. PatientId: id,
  9474. Status: 1,
  9475. Mtime: time.Now().Unix(),
  9476. Ctime: time.Now().Unix(),
  9477. UserOrgId: adminUser.CurrentOrgId,
  9478. HisPatientId: his.ID,
  9479. OrderId: order.ID,
  9480. ProjectId: project_id,
  9481. Type: types,
  9482. ItemId: item_id,
  9483. }
  9484. service.CreateOrderInfo(info)
  9485. }
  9486. his.SickType = sick_type
  9487. service.UpdataHisPateint(&his)
  9488. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9489. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9490. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9491. if err == nil {
  9492. c.ServeSuccessJSON(map[string]interface{}{
  9493. "msg": "结算成功",
  9494. })
  9495. }
  9496. }
  9497. type CustomOrderInfo struct {
  9498. Name string
  9499. Spec string
  9500. Unit string
  9501. Count float64
  9502. Price float64
  9503. Total float64
  9504. }
  9505. func (c *HisApiController) GetPrivateExpensesInfo() {
  9506. order_id, _ := c.GetInt64("id", 0)
  9507. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9508. order, _ := service.GetHisOrderByID(order_id)
  9509. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9510. if order.ID == 0 {
  9511. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9512. return
  9513. }
  9514. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9515. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9516. org_id := c.GetAdminUserInfo().CurrentOrgId
  9517. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9518. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9519. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9520. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9521. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9522. //var orderInfos_four []*models.HisOrderInfoTwo
  9523. //for _, item := range orderInfos_three {
  9524. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9525. // item.HisPrescriptionProject.IsCheckTeam = 1
  9526. // orderInfos_four = append(orderInfos_four, item)
  9527. //
  9528. // }
  9529. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9530. // item.HisPrescriptionProject.IsCheckTeam = 2
  9531. // orderInfos_two = append(orderInfos_two, item)
  9532. // }
  9533. //}
  9534. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9535. //var cus_slice []CustomOrderInfo
  9536. //for _, item := range new_order_info {
  9537. // var cus CustomOrderInfo
  9538. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9539. // cus.Unit = ""
  9540. // cus.Spec = ""
  9541. // var total float64
  9542. // for _, subItem := range orderInfos_four {
  9543. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9544. // total = total + subItem.DetItemFeeSumamt
  9545. // fmt.Println(subItem.DetItemFeeSumamt)
  9546. // }
  9547. // }
  9548. // cus.Count = 1
  9549. // cus.Total = total
  9550. // cus_slice = append(cus_slice, cus)
  9551. //}
  9552. orderInfos = append(orderInfos, orderInfos_two...)
  9553. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9554. //orderInfos = append(orderInfos, orderInfos_three...)
  9555. //}/**/
  9556. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9557. c.ServeSuccessJSON(map[string]interface{}{
  9558. "order": order,
  9559. "order_info": orderInfos,
  9560. "patient": patient,
  9561. "admin_info": adminInfo,
  9562. "his": his,
  9563. "current_admin": role,
  9564. "org_config": miConfig,
  9565. //"new_order_info": cus_slice,
  9566. })
  9567. }
  9568. func (this *HisApiController) ChangeMedType() {
  9569. med_type := this.GetString("med_type")
  9570. old_med_type := this.GetString("old_med_type")
  9571. ids := this.GetString("ids")
  9572. settle_type, _ := this.GetInt64("settle_type")
  9573. start_time := this.GetString("start_time")
  9574. end_time := this.GetString("end_time")
  9575. ids_arr := strings.Split(ids, ",")
  9576. if settle_type == 1 { //日结
  9577. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9578. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9579. prescription.MedType = med_type
  9580. err := service.SaveHisPrescription(&prescription)
  9581. if err == nil {
  9582. this.ServeSuccessJSON(map[string]interface{}{
  9583. "msg": "修改成功",
  9584. })
  9585. } else {
  9586. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9587. return
  9588. }
  9589. } else if settle_type == 2 {
  9590. timeLayout := "2006-01-02"
  9591. loc, _ := time.LoadLocation("Local")
  9592. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9593. if err != nil {
  9594. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9595. return
  9596. }
  9597. recordStartTime := theStartTime.Unix()
  9598. start_time_timestamp := recordStartTime
  9599. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9600. if err != nil {
  9601. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9602. return
  9603. }
  9604. recordEndTime := theEndTime.Unix()
  9605. end_time_timestamp := recordEndTime
  9606. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9607. if updateErr == nil {
  9608. this.ServeSuccessJSON(map[string]interface{}{
  9609. "msg": "修改成功",
  9610. })
  9611. } else {
  9612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9613. return
  9614. }
  9615. }
  9616. }
  9617. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9618. patient_id, _ := c.GetInt64("patient_id")
  9619. his_patient_id, _ := c.GetInt64("his_patient_id")
  9620. record_date := c.GetString("record_date")
  9621. start_time := c.GetString("start_time")
  9622. end_time := c.GetString("end_time")
  9623. order_status, _ := c.GetInt64("type", 0)
  9624. p_type, _ := c.GetInt64("p_type", 0)
  9625. order_id, _ := c.GetInt64("order_id", 0)
  9626. timeLayout := "2006-01-02"
  9627. loc, _ := time.LoadLocation("Local")
  9628. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9629. if err != nil {
  9630. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9631. return
  9632. }
  9633. recordDateTime := theTime.Unix()
  9634. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9635. if err != nil {
  9636. }
  9637. startRecordDateTime := startTime.Unix()
  9638. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9639. if err != nil {
  9640. }
  9641. endRecordDateTime := endTime.Unix()
  9642. admin := c.GetAdminUserInfo()
  9643. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9644. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9645. order, _ := service.GetHisOrderByID(order_id)
  9646. var monthPrescriptions []*models.HisPrescription
  9647. if order_status == 1 || order_status == 0 {
  9648. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9649. } else if order_status == 2 {
  9650. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9651. }
  9652. var settle_total float64
  9653. for _, item := range monthPrescriptions {
  9654. if len(item.HisPrescriptionProject) > 0 {
  9655. for _, subItem := range item.HisPrescriptionProject {
  9656. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9657. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9658. settle_total = settle_total + total
  9659. }
  9660. }
  9661. if len(item.HisDoctorAdviceInfo) > 0 {
  9662. for _, subItem := range item.HisDoctorAdviceInfo {
  9663. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9664. settle_total = settle_total + total
  9665. }
  9666. }
  9667. }
  9668. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9669. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9670. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9671. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9672. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9673. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9674. //获取所有科室信息
  9675. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9676. var dia string
  9677. for _, item := range month_p_info {
  9678. if len(dia) == 0 {
  9679. dia = item.Diagnosis
  9680. } else {
  9681. dia = dia + "," + item.Diagnosis
  9682. }
  9683. }
  9684. dia_arr := removeDuplicates(strings.Split(dia, ","))
  9685. dia_arr = removeEmptyStrings(dia_arr)
  9686. c.ServeSuccessJSON(map[string]interface{}{
  9687. "his_info": his_patient_info,
  9688. "xt_info": xt_patient_info,
  9689. "case_history": case_history,
  9690. "info": patientPrescriptionInfo,
  9691. "last_info": lastPatientPrescriptionInfo,
  9692. "month_prescriptions": monthPrescriptions,
  9693. "order": order,
  9694. "doctors": doctors,
  9695. "department": department,
  9696. "settle_total": settle_total,
  9697. "dia_arr": dia_arr,
  9698. })
  9699. return
  9700. }
  9701. func removeEmptyStrings(input []string) []string {
  9702. var output []string
  9703. for _, s := range input {
  9704. if s != "" {
  9705. output = append(output, s)
  9706. }
  9707. }
  9708. return output
  9709. }
  9710. func removeDuplicates(input []string) []string {
  9711. seen := make(map[string]bool)
  9712. output := []string{}
  9713. for _, s := range input {
  9714. if _, exists := seen[s]; !exists {
  9715. seen[s] = true
  9716. output = append(output, s)
  9717. }
  9718. }
  9719. return output
  9720. }
  9721. func (c *HisApiController) GetHisMonthPatientInfo() {
  9722. patient_id, _ := c.GetInt64("patient_id")
  9723. his_patient_id, _ := c.GetInt64("his_patient_id")
  9724. record_date := c.GetString("record_date")
  9725. number := c.GetString("number")
  9726. start_time := c.GetString("start_time")
  9727. end_time := c.GetString("end_time")
  9728. p_type, _ := c.GetInt64("p_type")
  9729. timeLayout := "2006-01-02"
  9730. loc, _ := time.LoadLocation("Local")
  9731. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9732. if err != nil {
  9733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9734. return
  9735. }
  9736. recordDateTime := theTime.Unix()
  9737. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9738. if err != nil {
  9739. }
  9740. startRecordDateTime := startTime.Unix()
  9741. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9742. if err != nil {
  9743. }
  9744. endRecordDateTime := endTime.Unix()
  9745. admin := c.GetAdminUserInfo()
  9746. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9747. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9748. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9749. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9750. var settle_total float64
  9751. for _, item := range monthPrescriptions {
  9752. if len(item.HisPrescriptionProject) > 0 {
  9753. for _, subItem := range item.HisPrescriptionProject {
  9754. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9755. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9756. settle_total = settle_total + total
  9757. }
  9758. }
  9759. if len(item.HisDoctorAdviceInfo) > 0 {
  9760. for _, subItem := range item.HisDoctorAdviceInfo {
  9761. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9762. settle_total = settle_total + total
  9763. }
  9764. }
  9765. }
  9766. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9767. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9768. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9769. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9770. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9771. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9772. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9773. //获取所有科室信息
  9774. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9775. c.ServeSuccessJSON(map[string]interface{}{
  9776. "his_info": his_patient_info,
  9777. "xt_info": xt_patient_info,
  9778. "case_history": case_history,
  9779. "info": patientPrescriptionInfo,
  9780. "month_prescriptions": monthPrescriptions,
  9781. "order": order,
  9782. "doctors": doctors,
  9783. "department": department,
  9784. "count": count,
  9785. "drugStockConfig": drugStockConfig,
  9786. "last_info": lastPatientPrescriptionInfo,
  9787. "settle_total": settle_total,
  9788. })
  9789. return
  9790. }
  9791. func (c *HisApiController) GetAllOrder() {
  9792. org_id := c.GetAdminUserInfo().CurrentOrgId
  9793. orders, _ := service.GetNewHisOrderList(org_id)
  9794. c.ServeSuccessJSON(map[string]interface{}{
  9795. "order": orders,
  9796. })
  9797. return
  9798. }
  9799. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9800. newArr = make([]*models.HisOrderInfoTwo, 0)
  9801. for i := 0; i < len(arr); i++ {
  9802. repeat := false
  9803. for j := i + 1; j < len(arr); j++ {
  9804. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9805. repeat = true
  9806. break
  9807. }
  9808. }
  9809. if !repeat {
  9810. newArr = append(newArr, arr[i])
  9811. }
  9812. }
  9813. return
  9814. }
  9815. // 修改处方退库操作 参数传修改之前的处方数据
  9816. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9817. if advice.ExecutionState == 1 {
  9818. //查询该病人该药品是否有库存记录
  9819. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9820. if errcode == gorm.ErrRecordNotFound {
  9821. } else {
  9822. //退库
  9823. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9824. if advice.PrescribingNumberUnit == drug.MinUnit {
  9825. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9826. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9827. //退库
  9828. warehouseInfo := models.DrugWarehouseInfo{
  9829. StockMinNumber: prescribingNumber,
  9830. }
  9831. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9832. operation_time := time.Now().Unix()
  9833. creater := advice.AdviceDoctor
  9834. ctime := time.Now().Unix()
  9835. timeStr := time.Now().Format("2006-01-02")
  9836. timeArr := strings.Split(timeStr, "-")
  9837. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9838. total = total + 1
  9839. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9840. cancelStock := models.DrugCancelStock{
  9841. OrderNumber: orderNumber,
  9842. OperaTime: operation_time,
  9843. OrgId: advice.UserOrgId,
  9844. Creater: creater,
  9845. Ctime: ctime,
  9846. Status: 1,
  9847. ReturnTime: advice.AdviceDate,
  9848. Dealer: info.Dealer,
  9849. Manufacturer: info.Manufacturer,
  9850. Type: 1,
  9851. }
  9852. service.AddSigleDrugCancelStock(&cancelStock)
  9853. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9854. dealer, _ := service.GetDealerById(info.Dealer)
  9855. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9856. cancelStockInfo := models.DrugCancelStockInfo{
  9857. OrderNumber: cancelInfo.OrderNumber,
  9858. CancelStockId: cancelInfo.ID,
  9859. DrugId: info.DrugId,
  9860. Count: info.Count,
  9861. Status: 1,
  9862. Ctime: ctime,
  9863. OrgId: advice.UserOrgId,
  9864. Type: 1,
  9865. Manufacturer: manufactureName.ManufacturerName,
  9866. Dealer: dealer.DealerName,
  9867. Total: 0,
  9868. RetailPrice: info.RetailPrice,
  9869. RetailTotalPrice: info.RetailTotalPrice,
  9870. Price: info.Price,
  9871. RegisterAccount: "",
  9872. Remark: info.Remark,
  9873. BatchNumber: info.BatchNumber,
  9874. MaxUnit: info.CountUnit,
  9875. ProductDate: info.ProductDate,
  9876. ExpiryDate: info.ExpiryDate,
  9877. BatchNumberId: info.WarehouseInfoId,
  9878. }
  9879. flow := models.DrugFlow{
  9880. WarehousingId: 0,
  9881. DrugId: info.DrugId,
  9882. Number: "",
  9883. BatchNumber: info.BatchNumber,
  9884. Count: info.Count,
  9885. UserOrgId: advice.UserOrgId,
  9886. PatientId: 0,
  9887. SystemTime: ctime,
  9888. ConsumableType: 4,
  9889. IsSys: 0,
  9890. WarehousingOrder: "",
  9891. WarehouseOutId: 0,
  9892. WarehouseOutOrderNumber: "",
  9893. IsEdit: 0,
  9894. CancelStockId: cancelStock.ID,
  9895. CancelOrderNumber: cancelStock.OrderNumber,
  9896. Manufacturer: info.Manufacturer,
  9897. Dealer: info.Dealer,
  9898. Creator: advice.UserOrgId,
  9899. UpdateCreator: 0,
  9900. Status: 1,
  9901. Ctime: time.Now().Unix(),
  9902. Mtime: 0,
  9903. Price: info.Price,
  9904. WarehousingDetailId: 0,
  9905. WarehouseOutDetailId: 0,
  9906. CancelOutDetailId: 0,
  9907. ExpireDate: info.ExpiryDate,
  9908. ProductDate: info.ProductDate,
  9909. MaxUnit: info.CountUnit,
  9910. MinUnit: "",
  9911. }
  9912. service.CreatedCancelStock(cancelStockInfo)
  9913. service.CreateDrugFlowOne(flow)
  9914. } else {
  9915. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9916. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9917. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9918. warehouseInfo := models.DrugWarehouseInfo{
  9919. StockMinNumber: prescribingNumber,
  9920. }
  9921. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9922. }
  9923. operation_time := time.Now().Unix()
  9924. creater := advice.AdviceDoctor
  9925. ctime := time.Now().Unix()
  9926. timeStr := time.Now().Format("2006-01-02")
  9927. timeArr := strings.Split(timeStr, "-")
  9928. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9929. total = total + 1
  9930. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9931. cancelStock := models.DrugCancelStock{
  9932. OrderNumber: orderNumber,
  9933. OperaTime: operation_time,
  9934. OrgId: advice.UserOrgId,
  9935. Creater: creater,
  9936. Ctime: ctime,
  9937. Status: 1,
  9938. ReturnTime: advice.AdviceDate,
  9939. Dealer: info.Dealer,
  9940. Manufacturer: info.Manufacturer,
  9941. Type: 1,
  9942. }
  9943. service.AddSigleDrugCancelStock(&cancelStock)
  9944. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9945. dealer, _ := service.GetDealerById(info.Dealer)
  9946. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9947. cancelStockInfo := models.DrugCancelStockInfo{
  9948. OrderNumber: cancelInfo.OrderNumber,
  9949. CancelStockId: cancelInfo.ID,
  9950. DrugId: info.DrugId,
  9951. Count: info.Count,
  9952. Status: 1,
  9953. Ctime: ctime,
  9954. OrgId: advice.UserOrgId,
  9955. Type: 1,
  9956. Manufacturer: manufactureName.ManufacturerName,
  9957. Dealer: dealer.DealerName,
  9958. Total: 0,
  9959. RetailPrice: info.RetailPrice,
  9960. RetailTotalPrice: info.RetailTotalPrice,
  9961. Price: info.Price,
  9962. RegisterAccount: "",
  9963. Remark: info.Remark,
  9964. BatchNumber: info.BatchNumber,
  9965. MaxUnit: info.CountUnit,
  9966. ProductDate: info.ProductDate,
  9967. ExpiryDate: info.ExpiryDate,
  9968. BatchNumberId: info.WarehouseInfoId,
  9969. }
  9970. flow := models.DrugFlow{
  9971. WarehousingId: 0,
  9972. DrugId: info.DrugId,
  9973. Number: "",
  9974. BatchNumber: info.BatchNumber,
  9975. Count: info.Count,
  9976. UserOrgId: advice.UserOrgId,
  9977. PatientId: 0,
  9978. SystemTime: ctime,
  9979. ConsumableType: 4,
  9980. IsSys: 0,
  9981. WarehousingOrder: "",
  9982. WarehouseOutId: 0,
  9983. WarehouseOutOrderNumber: "",
  9984. IsEdit: 0,
  9985. CancelStockId: cancelStock.ID,
  9986. CancelOrderNumber: cancelStock.OrderNumber,
  9987. Manufacturer: info.Manufacturer,
  9988. Dealer: info.Dealer,
  9989. Creator: advice.AdviceDoctor,
  9990. UpdateCreator: 0,
  9991. Status: 1,
  9992. Ctime: time.Now().Unix(),
  9993. Mtime: 0,
  9994. Price: info.Price,
  9995. WarehousingDetailId: 0,
  9996. WarehouseOutDetailId: 0,
  9997. CancelOutDetailId: 0,
  9998. ExpireDate: info.ExpiryDate,
  9999. ProductDate: info.ProductDate,
  10000. MaxUnit: info.CountUnit,
  10001. MinUnit: "",
  10002. }
  10003. service.CreatedCancelStock(cancelStockInfo)
  10004. service.CreateDrugFlowOne(flow)
  10005. }
  10006. }
  10007. }
  10008. return err
  10009. }
  10010. func (this *HisApiController) DeleteNCDS() {
  10011. id, _ := this.GetInt64("id", 0)
  10012. if id > 0 {
  10013. service.DeletePsnNCDSRecordById(id)
  10014. this.ServeSuccessJSON(map[string]interface{}{
  10015. "msg": "删除成功",
  10016. })
  10017. } else {
  10018. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10019. return
  10020. }
  10021. }
  10022. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10023. id, _ := c.GetInt64("id")
  10024. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10025. c.ServeSuccessJSON(map[string]interface{}{
  10026. "advice": advice,
  10027. })
  10028. return
  10029. }
  10030. func (c *HisApiController) GetHisMonthChargePatientList() {
  10031. record_date := c.GetString("record_date")
  10032. start_time := c.GetString("start_time")
  10033. end_time := c.GetString("end_time")
  10034. timeLayout := "2006-01-02"
  10035. loc, _ := time.LoadLocation("Local")
  10036. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10037. if err != nil {
  10038. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10039. return
  10040. }
  10041. if err != nil {
  10042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10043. return
  10044. }
  10045. recordDateTime := theTime.Unix()
  10046. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10047. if err != nil {
  10048. }
  10049. startRecordDateTime := startTime.Unix()
  10050. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10051. if err != nil {
  10052. }
  10053. endRecordDateTime := endTime.Unix()
  10054. adminInfo := c.GetAdminUserInfo()
  10055. var tempMonthChargePatients []*service.MonthChargePatients
  10056. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10057. for _, item := range tempPatients {
  10058. //过滤没有处方的
  10059. if len(item.HisPrescription) == 0 {
  10060. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10061. }
  10062. }
  10063. c.ServeSuccessJSON(map[string]interface{}{
  10064. "list": tempMonthChargePatients,
  10065. })
  10066. }