his_api_controller.go 441KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384
  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. type CustomFundPay struct {
  795. FundPayType string `json:"fund_pay_type"`
  796. FundPayamt float64 `json:"fund_payamt"`
  797. InscpScpAmt float64 `json:"inscp_scp_amt"`
  798. }
  799. func (c *PublicApiController) GetBaiLinExportData() {
  800. data := service.GetBaiLinOrderData()
  801. fmt.Println(len(data))
  802. var new_data []*models.NewCustomHisOrder
  803. for _, item := range data {
  804. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  805. new_data = append(new_data, item)
  806. }
  807. }
  808. fmt.Println(len(new_data))
  809. c.ServeSuccessJSON(map[string]interface{}{
  810. "list": new_data,
  811. })
  812. }
  813. func (c *HisApiController) GetHisUnChargePatientList() {
  814. record_date := c.GetString("record_date")
  815. sch_type, _ := c.GetInt64("sch_type")
  816. timeLayout := "2006-01-02"
  817. loc, _ := time.LoadLocation("Local")
  818. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  819. if err != nil {
  820. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  821. return
  822. }
  823. recordDateTime := theTime.Unix()
  824. adminInfo := c.GetAdminUserInfo()
  825. var tempPatients []*service.NewTempPatients
  826. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  827. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  828. var patients []*service.NewTempPatients
  829. var patients_two []*service.NewTempPatients
  830. for _, item := range tempPatients {
  831. //过滤掉没挂号的和没开处方的
  832. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  833. patients = append(patients, item)
  834. }
  835. //过滤掉没挂号的
  836. if len(item.HisPatient) > 0 {
  837. patients_two = append(patients_two, item)
  838. }
  839. }
  840. c.ServeSuccessJSON(map[string]interface{}{
  841. "list": patients,
  842. "list_two": patients_two,
  843. })
  844. }
  845. func (c *HisApiController) GetPrivateExpensesOrder() {
  846. //id, _ := c.GetInt64("id")
  847. //record_time := c.GetString("record_time")
  848. order_id, _ := c.GetInt64("order_id")
  849. admin_user_id, _ := c.GetInt64("admin_user_id")
  850. //timeLayout := "2006-01-02"
  851. //loc, _ := time.LoadLocation("Local")
  852. //
  853. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  854. //if err != nil {
  855. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  856. // return
  857. //}
  858. //recordDateTime := theTime.Unix()
  859. adminUser := c.GetAdminUserInfo()
  860. order, _ := service.GetHisOrderByID(order_id)
  861. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  862. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  863. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  864. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  865. //var config []*models.HisXtDiagnoseConfig
  866. var name string
  867. if order.PType == 1 {
  868. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  869. for _, item := range diagnosis_ids {
  870. id, _ := strconv.ParseInt(item, 10, 64)
  871. diagnosisConfig, _ := service.FindDiagnoseById(id)
  872. if len(name) == 0 {
  873. name = diagnosisConfig.ClassName
  874. } else {
  875. name = name + "," + diagnosisConfig.ClassName
  876. }
  877. }
  878. } else {
  879. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  880. for _, item := range diagnosis_ids {
  881. id, _ := strconv.ParseInt(item, 10, 64)
  882. diagnosisConfig, _ := service.FindDiagnoseById(id)
  883. if len(name) == 0 {
  884. name = diagnosisConfig.ClassName
  885. } else {
  886. name = name + "," + diagnosisConfig.ClassName
  887. }
  888. }
  889. }
  890. var bedCostTotal float64 = 0 //床位总费
  891. //var bedCostSelfTotal float64 = 0 //床位自费
  892. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  893. var operationCostTotal float64 = 0 //手术费
  894. //var operationCostSelfTotal float64 = 0 //手术费
  895. var operationCostPartSelfTotal float64 = 0 //手术费
  896. var otherCostTotal float64 = 0 //其他费用
  897. //var otherCostSelfTotal float64 = 0 //其他费用
  898. var otherCostPartSelfTotal float64 = 0 //其他费用
  899. var materialCostTotal float64 = 0 //材料费
  900. //var materialCostSelfTotal float64 = 0 //材料费
  901. var materialCostPartSelfTotal float64 = 0 //材料费
  902. var westernMedicineCostTotal float64 = 0 //西药费
  903. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  904. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  905. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  906. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  907. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  908. var checkCostTotal float64 = 0 //检查费
  909. //var checkCostSelfTotal float64 = 0 //检查费
  910. var checkCostPartSelfTotal float64 = 0 //检查费
  911. var laboratoryCostTotal float64 = 0 //化验费
  912. //var laboratoryCostSelfTotal float64 = 0 //化验费
  913. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  914. var treatCostTotal float64 = 0 //治疗费用
  915. //var treatCostSelfTotal float64 = 0 //治疗费用
  916. var treatCostPartSelfTotal float64 = 0 //治疗费用
  917. var zhenChaCostTotal float64 = 0 //其他费用
  918. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  919. decimal.DivisionPrecision = 2
  920. for _, item := range orderInfos {
  921. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  922. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  923. item.MedChrgitmType = "09"
  924. }
  925. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  926. if item.HisPrescriptionProject.Type == 2 {
  927. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  928. fmt.Println("CostClassify")
  929. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  930. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  931. case 0:
  932. item.MedChrgitmType = "0"
  933. break
  934. case 1:
  935. item.MedChrgitmType = "14"
  936. break
  937. case 2:
  938. item.MedChrgitmType = "05"
  939. break
  940. case 3:
  941. item.MedChrgitmType = "03"
  942. break
  943. case 4:
  944. item.MedChrgitmType = "03"
  945. break
  946. case 5:
  947. item.MedChrgitmType = "08"
  948. break
  949. case 6:
  950. item.MedChrgitmType = "14"
  951. break
  952. case 7:
  953. item.MedChrgitmType = "14"
  954. break
  955. case 8:
  956. item.MedChrgitmType = "03"
  957. break
  958. case 9:
  959. item.MedChrgitmType = "14"
  960. break
  961. case 10:
  962. item.MedChrgitmType = "14"
  963. break
  964. case 11:
  965. item.MedChrgitmType = "06"
  966. break
  967. case 12:
  968. item.MedChrgitmType = "12"
  969. break
  970. case 13:
  971. item.MedChrgitmType = "01"
  972. break
  973. case 14:
  974. item.MedChrgitmType = "04"
  975. break
  976. case 15:
  977. item.MedChrgitmType = "14"
  978. break
  979. }
  980. } else {
  981. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  982. case 1:
  983. item.MedChrgitmType = "14"
  984. break
  985. case 2:
  986. item.MedChrgitmType = "05"
  987. break
  988. case 3:
  989. item.MedChrgitmType = "04"
  990. break
  991. case 4:
  992. item.MedChrgitmType = "14"
  993. break
  994. case 5:
  995. item.MedChrgitmType = "08"
  996. break
  997. case 6:
  998. item.MedChrgitmType = "14"
  999. break
  1000. case 7:
  1001. item.MedChrgitmType = "14"
  1002. break
  1003. case 8:
  1004. item.MedChrgitmType = "03"
  1005. break
  1006. case 9:
  1007. item.MedChrgitmType = "14"
  1008. break
  1009. default:
  1010. item.MedChrgitmType = "14"
  1011. break
  1012. }
  1013. }
  1014. } else if item.HisPrescriptionProject.Type == 3 {
  1015. item.MedChrgitmType = "08"
  1016. }
  1017. }
  1018. }
  1019. order.PsnCashPay = order.MedfeeSumamt
  1020. for _, item := range orderInfos {
  1021. if item.MedChrgitmType == "01" { //床位费
  1022. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1023. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1024. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1025. }
  1026. if item.MedChrgitmType == "02" { //诊察费
  1027. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1028. //zhenChaCostSelfTotal = zhenChaCostTotal
  1029. }
  1030. if item.MedChrgitmType == "03" { //检查费
  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 == "02" { //检查费
  1036. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1037. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1038. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1039. }
  1040. if item.MedChrgitmType == "04" { //化验费
  1041. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1042. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1043. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1044. }
  1045. if item.MedChrgitmType == "05" { //治疗费
  1046. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1047. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1048. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1049. }
  1050. if item.MedChrgitmType == "06" { //手术费
  1051. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1052. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1053. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1054. }
  1055. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1056. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1057. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1058. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1059. }
  1060. if item.MedChrgitmType == "09" { //西药费
  1061. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1062. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1063. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1064. }
  1065. if item.MedChrgitmType == "11" { //中成费
  1066. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1067. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1068. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1069. }
  1070. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1071. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1072. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1073. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1074. }
  1075. }
  1076. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1077. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1078. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1079. var dia_config []*models.HisXtDiagnoseConfig
  1080. var diagnosis_ids []string
  1081. if his.ID > 0 {
  1082. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1083. } else {
  1084. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1085. }
  1086. for _, item := range diagnosis_ids {
  1087. id, _ := strconv.ParseInt(item, 10, 64)
  1088. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1089. dia_config = append(dia_config, diagnosisConfig)
  1090. }
  1091. var rf []CustomFundPay
  1092. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1093. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1094. c.ServeSuccessJSON(map[string]interface{}{
  1095. "patient": patient,
  1096. "order_infos": orderInfos,
  1097. "diagnosis": name,
  1098. "bedCostTotal": bedCostTotal,
  1099. "bedCostSelfTotal": bedCostTotal,
  1100. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1101. "operationCostTotal": operationCostTotal,
  1102. "operationCostSelfTotal": operationCostTotal,
  1103. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1104. "otherCostTotal": otherCostTotal,
  1105. "otherCostSelfTotal": otherCostTotal,
  1106. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1107. "materialCostTotal": materialCostTotal,
  1108. "materialCostSelfTotal": materialCostTotal,
  1109. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1110. "westernMedicineCostTotal": westernMedicineCostTotal,
  1111. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1112. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1113. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1114. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1115. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1116. "checkCostTotal": checkCostTotal,
  1117. "checkCostSelfTotal": checkCostTotal,
  1118. "zhenChaCostTotal": zhenChaCostTotal,
  1119. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1120. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1121. "laboratoryCostTotal": laboratoryCostTotal,
  1122. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1123. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1124. "treatCostTotal": treatCostTotal,
  1125. "treatCostSelfTotal": treatCostTotal,
  1126. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1127. "charge_admin": charge_admin,
  1128. "printor_admin": printor_admin,
  1129. "org_name": org.OrgName,
  1130. "org_code": miConfig.Code,
  1131. "name": patient.Name,
  1132. "number": order.MdtrtId,
  1133. "date": order.SettleAccountsDate,
  1134. "info": order,
  1135. "new_order": order,
  1136. "his_hospital": his_hospital,
  1137. "his": his,
  1138. "funds": rf,
  1139. "dia_config": dia_config,
  1140. })
  1141. }
  1142. func (c *HisApiController) RefudDetail() {
  1143. order_id, _ := c.GetInt64("order_id")
  1144. order, _ := service.GetHisOrderByID(order_id)
  1145. adminUser := c.GetAdminUserInfo()
  1146. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1147. c.ServeSuccessJSON(map[string]interface{}{
  1148. "msg": "撤销成功",
  1149. })
  1150. }
  1151. func (c *HisApiController) Sscard() {
  1152. //r := CardInit()
  1153. //if r == 0 {
  1154. // GetBaseInfo()
  1155. //}
  1156. //c.ServeSuccessJSON(map[string]interface{}{
  1157. // "list": "11",
  1158. //})
  1159. }
  1160. func GetBaseInfo() error {
  1161. //handle := syscall.MustLoadDLL("SSCard.dll")
  1162. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1163. //
  1164. //str := make([]byte, 256)
  1165. //str1 := make([]byte, 256)
  1166. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1167. //if ferr != nil {
  1168. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1169. // return ferr
  1170. //}
  1171. //
  1172. //fmt.Println(string(str))
  1173. //
  1174. //fmt.Println(r)
  1175. return nil
  1176. }
  1177. func CardInit() int {
  1178. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1179. //add := DllTestDef.MustFindProc("Init")
  1180. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1181. //if err != nil {
  1182. // fmt.Println("SSCard的运算结果为:", ret)
  1183. //}
  1184. //result := int(ret)
  1185. return 0
  1186. }
  1187. func IntPtr(n int) uintptr {
  1188. return uintptr(n)
  1189. }
  1190. func StrPtr(s string) uintptr {
  1191. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1192. }
  1193. func (c *HisApiController) GetHisPatientList() {
  1194. //types, _ := c.GetInt64("type", 0)
  1195. record_date := c.GetString("record_date")
  1196. sch_type, _ := c.GetInt64("sch_type")
  1197. timeLayout := "2006-01-02"
  1198. loc, _ := time.LoadLocation("Local")
  1199. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1200. if err != nil {
  1201. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1202. return
  1203. }
  1204. recordDateTime := theTime.Unix()
  1205. adminInfo := c.GetAdminUserInfo()
  1206. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1207. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1208. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1209. //获取当前用户的信息
  1210. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1211. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1212. //获取所有科室信息
  1213. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1214. c.ServeSuccessJSON(map[string]interface{}{
  1215. "list": patients,
  1216. "list_two": patients_two,
  1217. "info": adminUserInfo,
  1218. "doctors": doctors,
  1219. "department": department,
  1220. })
  1221. }
  1222. type CustomTemplate struct {
  1223. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1224. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1225. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1226. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1227. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1228. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1229. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1230. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1231. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1232. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1233. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1234. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1235. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1236. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1237. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1238. }
  1239. func (c *HisApiController) GetHisPatientInfo() {
  1240. patient_id, _ := c.GetInt64("patient_id")
  1241. his_patient_id, _ := c.GetInt64("his_patient_id")
  1242. record_date := c.GetString("record_date")
  1243. number := c.GetString("number")
  1244. //start_time := c.GetString("start_time")
  1245. //end_time := c.GetString("end_time")
  1246. p_type, _ := c.GetInt64("p_type")
  1247. timeLayout := "2006-01-02"
  1248. loc, _ := time.LoadLocation("Local")
  1249. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1250. if err != nil {
  1251. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1252. return
  1253. }
  1254. recordDateTime := theTime.Unix()
  1255. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1256. //if err != nil {
  1257. //
  1258. //}
  1259. //startRecordDateTime := startTime.Unix()
  1260. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1261. //if err != nil {
  1262. //
  1263. //}
  1264. //endRecordDateTime := endTime.Unix()
  1265. admin := c.GetAdminUserInfo()
  1266. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1267. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1268. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1269. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1270. var prescriptions []*models.HisPrescription
  1271. var last_prescriptions []*models.HisPrescription
  1272. var sch_prescriptions []CustomTemplate
  1273. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. if p_type == 1 { //住院
  1275. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1276. for _, item := range prescriptions {
  1277. for _, subItem := range item.HisDoctorAdviceInfo {
  1278. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1279. if info.RetailPrice > 0 {
  1280. subItem.Drug.MinPrice = info.RetailPrice
  1281. }
  1282. }
  1283. }
  1284. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1285. } else { //门诊
  1286. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1287. for _, item := range prescriptions {
  1288. for _, subItem := range item.HisDoctorAdviceInfo {
  1289. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1290. if info.RetailPrice > 0 {
  1291. subItem.Drug.MinPrice = info.RetailPrice
  1292. }
  1293. }
  1294. }
  1295. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1296. }
  1297. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1298. if sch.ID > 0 {
  1299. var week string
  1300. t := time.Now()
  1301. switch t.Weekday().String() {
  1302. case "Monday":
  1303. week = "周一"
  1304. break
  1305. case "Tuesday":
  1306. week = "周二"
  1307. break
  1308. case "Wednesday":
  1309. week = "周三"
  1310. break
  1311. case "Thursday":
  1312. week = "周四"
  1313. break
  1314. case "Friday":
  1315. week = "周五"
  1316. break
  1317. case "Saturday":
  1318. week = "周六"
  1319. break
  1320. case "Sunday":
  1321. week = "周日"
  1322. break
  1323. }
  1324. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1325. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1326. //根据推送频率组装新的数组
  1327. for _, item := range temp_sch_prescriptions {
  1328. var cus CustomTemplate
  1329. cus.ID = item.ID
  1330. cus.UserOrgId = item.UserOrgId
  1331. cus.PatientId = item.PatientId
  1332. cus.MedType = item.MedType
  1333. cus.RecordDate = item.RecordDate
  1334. cus.Type = item.Type
  1335. cus.PType = item.PType
  1336. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1337. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1338. if subItem.FrequencyType == 1 { //每次必推
  1339. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1340. }
  1341. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1342. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1343. }
  1344. if subItem.FrequencyType == 2 { //按照天数频率
  1345. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1346. now := p.Unix()
  1347. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1348. dayStr2 := "-" + dayStr
  1349. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1350. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1351. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1352. if len(advices) == 0 {
  1353. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1354. }
  1355. }
  1356. }
  1357. }
  1358. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1359. if subItem.Type == 2 {
  1360. if subItem.XtHisProject.MedicalStatus != 1 {
  1361. if subItem.FrequencyType == 1 {
  1362. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1363. }
  1364. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1365. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1366. }
  1367. if subItem.FrequencyType == 2 {
  1368. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1369. now := p.Unix()
  1370. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1371. dayStr2 := "-" + dayStr
  1372. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1373. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1374. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1375. if len(projects) == 0 {
  1376. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1377. }
  1378. }
  1379. }
  1380. } else if subItem.Type == 3 {
  1381. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1382. if subItem.FrequencyType == 1 {
  1383. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1384. }
  1385. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1386. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1387. }
  1388. if subItem.FrequencyType == 2 {
  1389. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1390. now := p.Unix()
  1391. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1392. dayStr2 := "-" + dayStr
  1393. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1394. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1395. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1396. if len(projects) == 0 {
  1397. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. sch_prescriptions = append(sch_prescriptions, cus)
  1404. }
  1405. for _, item := range sch_prescriptions {
  1406. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1407. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1408. }
  1409. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1410. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1411. }
  1412. }
  1413. }
  1414. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1415. if config.ID > 0 && config.IsOpen == 1 {
  1416. for _, item := range sch_prescriptions {
  1417. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1418. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1419. if info.RetailPrice > 0 {
  1420. subItem.Drug.MinPrice = info.RetailPrice
  1421. }
  1422. }
  1423. }
  1424. }
  1425. if config.ID > 0 && config.IsOpen == 1 {
  1426. for _, item := range sch_prescriptions {
  1427. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1428. if subItem.Type == 3 {
  1429. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1430. if info.Price > 0 {
  1431. subItem.GoodInfo.PackingPrice = info.Price
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1438. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1439. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1440. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1441. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1442. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1443. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1444. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1445. //获取所有科室信息
  1446. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1447. c.ServeSuccessJSON(map[string]interface{}{
  1448. "his_info": his_patient_info,
  1449. "xt_info": xt_patient_info,
  1450. "prescription": prescriptions,
  1451. "case_history": case_history,
  1452. "info": patientPrescriptionInfo,
  1453. //"month_prescriptions": monthPrescriptions,
  1454. "order": order,
  1455. "doctors": doctors,
  1456. "department": department,
  1457. "sch_prescriptions": sch_prescriptions,
  1458. "last_prescriptions": last_prescriptions,
  1459. "schedule": sch,
  1460. "count": count,
  1461. "drugStockConfig": drugStockConfig,
  1462. "last_info": lastPatientPrescriptionInfo,
  1463. })
  1464. return
  1465. }
  1466. func (c *HisApiController) GetHisPrescriptionConfig() {
  1467. adminInfo := c.GetAdminUserInfo()
  1468. //获取医嘱模版
  1469. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1470. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1471. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1472. //获取所有基础药
  1473. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1474. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1475. if config.ID > 0 && config.IsOpen == 1 {
  1476. for _, item := range drugs {
  1477. var index = 0
  1478. for _, subItem := range item.OtherDrugWarehouseInfo {
  1479. if index == 0 {
  1480. index = index + 1
  1481. if subItem.RetailPrice > 0 {
  1482. item.MinPrice = subItem.RetailPrice
  1483. }
  1484. }
  1485. }
  1486. }
  1487. }
  1488. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1489. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1490. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1491. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1492. //获取所有科室信息
  1493. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1494. //获取诊断信息
  1495. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1496. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1497. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1498. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1499. //获取是否开启保存耗材出库的开关
  1500. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1501. c.ServeSuccessJSON(map[string]interface{}{
  1502. "drugs": drugs,
  1503. "advices_template": advices,
  1504. "drugways": drugways,
  1505. "efs": efs,
  1506. "doctors": doctors,
  1507. "department": department,
  1508. "sick": sick,
  1509. "additions": additions,
  1510. "diagnose": diagnose,
  1511. "manufacturers": manufacturers,
  1512. "goodOutOpen": goodOutOpen,
  1513. "patientDiagnose": patientDiagnose,
  1514. })
  1515. }
  1516. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1517. //获取所有基础药
  1518. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1519. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1520. if config.ID > 0 && config.IsOpen == 1 {
  1521. for _, item := range drugs {
  1522. var index = 0
  1523. for _, subItem := range item.OtherDrugWarehouseInfo {
  1524. if index == 0 {
  1525. index = index + 1
  1526. if subItem.RetailPrice > 0 {
  1527. item.MinPrice = subItem.RetailPrice
  1528. }
  1529. }
  1530. }
  1531. }
  1532. }
  1533. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1534. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1535. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1536. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1537. //获取所有科室信息
  1538. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1539. //获取诊断信息
  1540. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1541. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1542. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1543. //获取是否开启保存耗材出库的开关
  1544. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1545. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1546. c.ServeSuccessJSON(map[string]interface{}{
  1547. "drugs": drugs,
  1548. "advices_template": advices,
  1549. "drugways": drugways,
  1550. "efs": efs,
  1551. "doctors": doctors,
  1552. "department": department,
  1553. "sick": sick,
  1554. "additions": additions,
  1555. "diagnose": diagnose,
  1556. "manufacturers": manufacturers,
  1557. "goodOutOpen": goodOutOpen,
  1558. "patientDiagnose": patientDiagnose,
  1559. })
  1560. }
  1561. }
  1562. func (c *HisApiController) CreateHisPrescription() {
  1563. record_date := c.GetString("record_date")
  1564. patient_id, _ := c.GetInt64("patient_id")
  1565. reg_type, _ := c.GetInt64("reg_type")
  1566. diagnose := c.GetString("diagnose")
  1567. sick_type, _ := c.GetInt64("sick_type")
  1568. sick_history := c.GetString("sick_history")
  1569. doctor_id, _ := c.GetInt64("doctor", 0)
  1570. department, _ := c.GetInt64("department", 0)
  1571. his_patient_id, _ := c.GetInt64("his_patient_id")
  1572. p_type, _ := c.GetInt64("p_type")
  1573. patient_diagnose := c.GetString("patient_diagnose")
  1574. dataBody := make(map[string]interface{}, 0)
  1575. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1576. if err != nil {
  1577. utils.ErrorLog(err.Error())
  1578. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1579. return
  1580. }
  1581. timeLayout := "2006-01-02"
  1582. loc, _ := time.LoadLocation("Local")
  1583. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1584. if err != nil {
  1585. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1586. return
  1587. }
  1588. adminInfo := c.GetAdminUserInfo()
  1589. recordDateTime := theTime.Unix()
  1590. //查询默认出库仓库库存
  1591. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1592. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1593. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1594. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1595. if len(lists) == 1 {
  1596. his_patient_id = lists[0].ID
  1597. }
  1598. }
  1599. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1600. //保存处方出库
  1601. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1602. //自动出库
  1603. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1604. //耗材保存处方出库
  1605. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1606. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1607. //已发药和已收费限制逻辑
  1608. isMidicine := false
  1609. isCharge := false
  1610. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1611. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1612. if len(prescriptions) > 0 {
  1613. for _, item := range prescriptions {
  1614. items := item.(map[string]interface{})
  1615. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1616. utils.ErrorLog("id")
  1617. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1618. return
  1619. }
  1620. id := int64(items["id"].(float64))
  1621. if id > 0 {
  1622. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1623. if err != nil {
  1624. if new_prescription.OrderStatus == 4 {
  1625. isCharge = true
  1626. }
  1627. }
  1628. }
  1629. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1630. advices := items["advices"].([]interface{})
  1631. if len(advices) > 0 {
  1632. for _, advice := range advices {
  1633. var adviceId int64
  1634. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1635. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1636. }
  1637. if adviceId > 0 {
  1638. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1639. if err == nil {
  1640. if his_advice_info.IsMedicine == 1 {
  1641. isMidicine = true
  1642. }
  1643. }
  1644. }
  1645. }
  1646. }
  1647. }
  1648. }
  1649. }
  1650. }
  1651. if isMidicine == true {
  1652. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1653. return
  1654. }
  1655. if isCharge == true {
  1656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1657. return
  1658. }
  1659. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1660. //药品发药出库
  1661. if pharmacyConfig.IsOpen == 1 {
  1662. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1663. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1664. if len(prescriptions) > 0 {
  1665. for _, item := range prescriptions {
  1666. items := item.(map[string]interface{})
  1667. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1668. advices := items["advices"].([]interface{})
  1669. if len(advices) > 0 {
  1670. for _, advice := range advices {
  1671. var drug_id int64
  1672. var prescribing_number float64
  1673. var prescribingNumberUnit string
  1674. var adviceId int64
  1675. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1676. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1677. }
  1678. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1679. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1680. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1681. }
  1682. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1683. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1684. }
  1685. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1686. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1687. }
  1688. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1689. if drug.ID == 0 {
  1690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1691. return
  1692. }
  1693. //查询药品的所有库存
  1694. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1695. var total_count int64
  1696. for _, it := range list {
  1697. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1698. }
  1699. totals := strconv.FormatInt(total_count, 10)
  1700. //查询该药品是否存在开药记录
  1701. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1702. //新增处方
  1703. if advicelist.ID == 0 {
  1704. all_count, _ := strconv.ParseFloat(totals, 64)
  1705. if prescribingNumberUnit == drug.MinUnit {
  1706. fmt.Println("prescribing_number", prescribing_number)
  1707. fmt.Println("all_count", all_count)
  1708. if drug.IsUse != 1 {
  1709. if drug.IsProject == 0 || drug.IsProject == 2 {
  1710. if all_count == 0 {
  1711. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1712. return
  1713. }
  1714. if prescribing_number > all_count {
  1715. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1716. return
  1717. }
  1718. }
  1719. }
  1720. }
  1721. if prescribingNumberUnit == drug.MaxUnit {
  1722. num := prescribing_number * float64(drug.MinNumber)
  1723. if drug.IsUse != 1 {
  1724. if drug.IsProject == 0 || drug.IsProject == 2 {
  1725. if all_count == 0 {
  1726. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1727. return
  1728. }
  1729. if num > all_count {
  1730. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1731. return
  1732. }
  1733. }
  1734. }
  1735. }
  1736. }
  1737. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1738. if drugOutConfig.IsOpen != 1 {
  1739. //修改处方
  1740. for _, advice := range advices {
  1741. var drug_id int64
  1742. var prescribing_number float64
  1743. var prescribingNumberUnit string
  1744. var prescribingNumber string
  1745. var adviceId int64
  1746. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1747. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1748. }
  1749. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1750. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1751. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1752. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1753. }
  1754. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1755. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1756. }
  1757. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1758. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1759. }
  1760. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1761. if drug.ID == 0 {
  1762. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1763. return
  1764. }
  1765. //查询药品的所有库存
  1766. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1767. var total_count int64
  1768. for _, it := range list {
  1769. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1770. }
  1771. totals := strconv.FormatInt(total_count, 10)
  1772. //查询该药品是否存在开药记录
  1773. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1774. //新增处方
  1775. if advicelist.ID == 0 {
  1776. all_count, _ := strconv.ParseFloat(totals, 64)
  1777. if prescribingNumberUnit == drug.MinUnit {
  1778. if drug.IsUse != 1 {
  1779. if drug.IsProject == 0 || drug.IsProject == 2 {
  1780. if all_count == 0 {
  1781. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1782. return
  1783. }
  1784. if prescribing_number > all_count {
  1785. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1786. return
  1787. }
  1788. }
  1789. }
  1790. } else {
  1791. if prescribingNumberUnit == drug.MaxUnit {
  1792. num := prescribing_number * float64(drug.MinNumber)
  1793. if drug.IsUse != 1 {
  1794. if drug.IsProject == 0 || drug.IsProject == 2 {
  1795. if all_count == 0 {
  1796. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1797. return
  1798. }
  1799. if num > all_count {
  1800. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1801. return
  1802. }
  1803. }
  1804. }
  1805. }
  1806. }
  1807. }
  1808. //修改处方
  1809. if advicelist.ID > 0 {
  1810. var device_number int64
  1811. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1812. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1813. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1814. device_number = prescribingNumberInt * drug.MinNumber
  1815. }
  1816. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1817. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1818. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1819. device_number = prescribingNumberInt
  1820. }
  1821. var number_count int64
  1822. if prescribingNumberUnit == drug.MaxUnit {
  1823. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1824. number_count = prescribingNumberInt * drug.MinNumber
  1825. }
  1826. if prescribingNumberUnit == drug.MinUnit {
  1827. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1828. number_count = prescribingNumberInt
  1829. }
  1830. //如果修改的数量大于之前修改的数量
  1831. if (number_count - device_number) > 0 {
  1832. //如果修改的差数量 大于库存数量
  1833. if drug.IsUse != 1 {
  1834. if (number_count - device_number) > total_count {
  1835. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1836. return
  1837. }
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. }
  1844. }
  1845. }
  1846. }
  1847. }
  1848. }
  1849. }
  1850. //已发药和已收费限制逻辑
  1851. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1852. //校验库存总量
  1853. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1854. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1855. if len(prescriptions) > 0 {
  1856. for _, item := range prescriptions {
  1857. items := item.(map[string]interface{})
  1858. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1859. advices := items["advices"].([]interface{})
  1860. if len(advices) > 0 {
  1861. for _, advice := range advices {
  1862. var drug_id int64
  1863. var prescribing_number float64
  1864. var prescribingNumberUnit string
  1865. var adviceId int64
  1866. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1867. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1868. }
  1869. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1870. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1871. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1872. }
  1873. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1874. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1875. }
  1876. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1877. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1878. }
  1879. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1880. if drug.ID == 0 {
  1881. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1882. return
  1883. }
  1884. //查询药品的所有库存
  1885. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1886. var total_count int64
  1887. for _, it := range list {
  1888. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1889. }
  1890. totals := strconv.FormatInt(total_count, 10)
  1891. //查询该药品是否存在开药记录
  1892. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1893. //查询最新批次库存
  1894. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1895. var batch_number_count int64
  1896. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1897. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1898. //新增处方
  1899. if advicelist.ID == 0 {
  1900. all_count, _ := strconv.ParseFloat(totals, 64)
  1901. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1902. if prescribingNumberUnit == drug.MinUnit {
  1903. if drug.IsUse != 1 {
  1904. if drug.IsProject == 0 || drug.IsProject == 2 {
  1905. if all_count == 0 {
  1906. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1907. return
  1908. }
  1909. if prescribing_number > all_count {
  1910. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1911. return
  1912. }
  1913. }
  1914. if adminInfo.CurrentOrgId == 10215 {
  1915. if prescribing_number > batch_number_all_count {
  1916. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1917. return
  1918. }
  1919. }
  1920. }
  1921. }
  1922. if prescribingNumberUnit == drug.MaxUnit {
  1923. num := prescribing_number * float64(drug.MinNumber)
  1924. if drug.IsUse != 1 {
  1925. if drug.IsProject == 0 || drug.IsProject == 2 {
  1926. if all_count == 0 {
  1927. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1928. return
  1929. }
  1930. if num > all_count {
  1931. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1932. return
  1933. }
  1934. }
  1935. if adminInfo.CurrentOrgId == 10215 {
  1936. if num > batch_number_all_count {
  1937. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1938. return
  1939. }
  1940. }
  1941. }
  1942. }
  1943. }
  1944. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1945. if drugOutConfig.IsOpen != 1 {
  1946. //修改处方
  1947. for _, advice := range advices {
  1948. var drug_id int64
  1949. var prescribing_number float64
  1950. var prescribingNumberUnit string
  1951. var prescribingNumber string
  1952. var adviceId int64
  1953. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1954. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1955. }
  1956. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1957. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1958. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1959. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1960. }
  1961. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1962. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1963. }
  1964. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1965. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1966. }
  1967. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1968. if drug.ID == 0 {
  1969. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1970. return
  1971. }
  1972. //查询药品的所有库存
  1973. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1974. var total_count int64
  1975. for _, it := range list {
  1976. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1977. }
  1978. totals := strconv.FormatInt(total_count, 10)
  1979. //查询该药品是否存在开药记录
  1980. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1981. //新增处方
  1982. if advicelist.ID == 0 {
  1983. //查询最新批次库存
  1984. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1985. var batch_number_count int64
  1986. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1987. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1988. all_count, _ := strconv.ParseFloat(totals, 64)
  1989. if prescribingNumberUnit == drug.MinUnit {
  1990. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1991. if drug.IsUse != 1 {
  1992. if drug.IsProject == 0 || drug.IsProject == 2 {
  1993. if all_count == 0 {
  1994. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1995. return
  1996. }
  1997. if prescribing_number > all_count {
  1998. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1999. return
  2000. }
  2001. }
  2002. if adminInfo.CurrentOrgId == 10215 {
  2003. if prescribing_number > batch_number_all_count {
  2004. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2005. return
  2006. }
  2007. }
  2008. }
  2009. } else {
  2010. if prescribingNumberUnit == drug.MaxUnit {
  2011. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2012. num := prescribing_number * float64(drug.MinNumber)
  2013. if drug.IsUse != 1 {
  2014. if drug.IsProject == 0 || drug.IsProject == 2 {
  2015. if all_count == 0 {
  2016. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2017. return
  2018. }
  2019. if num > all_count {
  2020. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2021. return
  2022. }
  2023. }
  2024. if adminInfo.CurrentOrgId == 10215 {
  2025. if prescribing_number > batch_number_all_count {
  2026. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2027. return
  2028. }
  2029. }
  2030. }
  2031. }
  2032. }
  2033. }
  2034. //修改处方
  2035. if advicelist.ID > 0 {
  2036. //查询最新批次库存
  2037. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2038. var batch_number_count int64
  2039. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2040. var device_number int64
  2041. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2042. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2043. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2044. device_number = prescribingNumberInt * drug.MinNumber
  2045. }
  2046. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2047. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2048. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2049. device_number = prescribingNumberInt
  2050. }
  2051. var number_count int64
  2052. if prescribingNumberUnit == drug.MaxUnit {
  2053. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2054. number_count = prescribingNumberInt * drug.MinNumber
  2055. }
  2056. if prescribingNumberUnit == drug.MinUnit {
  2057. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2058. number_count = prescribingNumberInt
  2059. }
  2060. //如果修改的数量大于之前修改的数量
  2061. if (number_count - device_number) > 0 {
  2062. //如果修改的差数量 大于库存数量
  2063. if drug.IsUse != 1 {
  2064. if drug.IsProject == 0 || drug.IsProject == 2 {
  2065. if total_count == 0 {
  2066. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2067. return
  2068. }
  2069. if (number_count - device_number) > total_count {
  2070. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2071. return
  2072. }
  2073. if (number_count - device_number) > batch_number_count {
  2074. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2075. return
  2076. }
  2077. }
  2078. if adminInfo.CurrentOrgId == 10215 {
  2079. // 查询该药品最后一次出库记录
  2080. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2081. var out_count int64
  2082. var in_count int64
  2083. var stock_max_number int64
  2084. var stock_min_number int64
  2085. for _, it := range outInfo {
  2086. if it.CountUnit == drug.MaxUnit {
  2087. it.Count = it.Count * drug.MinNumber
  2088. }
  2089. out_count += it.Count
  2090. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2091. stock_max_number = warehouseInfoList.StockMaxNumber
  2092. stock_min_number = warehouseInfoList.StockMinNumber
  2093. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2094. }
  2095. if out_count > 0 {
  2096. if (number_count - device_number) > in_count {
  2097. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2098. return
  2099. }
  2100. }
  2101. // 未出库
  2102. if out_count == 0 {
  2103. var sum_in_count int64
  2104. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2105. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2106. fmt.Println("sum_in_count", sum_in_count)
  2107. //如果修改的数量大于有库存的第一个批次
  2108. if number_count > sum_in_count {
  2109. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2110. return
  2111. }
  2112. }
  2113. }
  2114. }
  2115. }
  2116. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2117. if pharmacyConfig.IsOpen != 1 {
  2118. if device_number != number_count {
  2119. // 查询该药品最后一次出库记录
  2120. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2121. //回退库存
  2122. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2123. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2124. }
  2125. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2126. var stock_max_number int64
  2127. var stock_min_number int64
  2128. if number_count >= drug.MinNumber {
  2129. stock_max_number = device_number / drug.MinNumber
  2130. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2131. stock_min_number = device_number % drug.MinNumber
  2132. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2133. } else {
  2134. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2135. }
  2136. }
  2137. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2138. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2139. }
  2140. //删除记录
  2141. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2142. //查询默认仓库剩余多少库存
  2143. var sum_count int64
  2144. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2145. for _, its := range stockInfo {
  2146. if its.MaxUnit == drug.MaxUnit {
  2147. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2148. }
  2149. sum_count += its.StockMaxNumber + its.StockMinNumber
  2150. }
  2151. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2152. }
  2153. }
  2154. }
  2155. }
  2156. }
  2157. //保存处方开药
  2158. if drugOutConfig.IsOpen == 1 {
  2159. //修改处方
  2160. for _, advice := range advices {
  2161. var drug_id int64
  2162. var prescribing_number float64
  2163. var prescribingNumberUnit string
  2164. var prescribingNumber string
  2165. var adviceId int64
  2166. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2167. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2168. }
  2169. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2170. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2171. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2172. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2173. }
  2174. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2175. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2176. }
  2177. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2178. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2179. }
  2180. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2181. if drug.ID == 0 {
  2182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2183. return
  2184. }
  2185. //查询药品的所有库存
  2186. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2187. var total_count int64
  2188. for _, it := range list {
  2189. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2190. }
  2191. totals := strconv.FormatInt(total_count, 10)
  2192. //查询该药品是否存在开药记录
  2193. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2194. //新增处方
  2195. if advicelist.ID == 0 {
  2196. //查询最新批次库存
  2197. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2198. var batch_number_count int64
  2199. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2200. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2201. all_count, _ := strconv.ParseFloat(totals, 64)
  2202. if prescribingNumberUnit == drug.MinUnit {
  2203. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2204. if drug.IsUse != 1 {
  2205. if drug.IsProject == 0 || drug.IsProject == 2 {
  2206. if all_count == 0 {
  2207. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2208. return
  2209. }
  2210. if prescribing_number > all_count {
  2211. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2212. return
  2213. }
  2214. }
  2215. if adminInfo.CurrentOrgId == 10215 {
  2216. if prescribing_number > batch_number_all_count {
  2217. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2218. return
  2219. }
  2220. }
  2221. }
  2222. } else {
  2223. if prescribingNumberUnit == drug.MaxUnit {
  2224. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2225. num := prescribing_number * float64(drug.MinNumber)
  2226. if drug.IsUse != 1 {
  2227. if drug.IsProject == 0 || drug.IsProject == 2 {
  2228. if all_count == 0 {
  2229. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2230. return
  2231. }
  2232. if num > all_count {
  2233. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2234. return
  2235. }
  2236. }
  2237. if adminInfo.CurrentOrgId == 10215 {
  2238. if prescribing_number > batch_number_all_count {
  2239. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2240. return
  2241. }
  2242. }
  2243. }
  2244. }
  2245. }
  2246. }
  2247. //修改处方
  2248. if advicelist.ID > 0 {
  2249. //查询最新批次库存
  2250. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2251. var batch_number_count int64
  2252. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2253. var device_number int64
  2254. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2255. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2256. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2257. device_number = prescribingNumberInt * drug.MinNumber
  2258. }
  2259. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2260. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2261. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2262. device_number = prescribingNumberInt
  2263. }
  2264. var number_count int64
  2265. if prescribingNumberUnit == drug.MaxUnit {
  2266. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2267. number_count = prescribingNumberInt * drug.MinNumber
  2268. }
  2269. if prescribingNumberUnit == drug.MinUnit {
  2270. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2271. number_count = prescribingNumberInt
  2272. }
  2273. //如果修改的数量大于之前修改的数量
  2274. if (number_count - device_number) > 0 {
  2275. //如果修改的差数量 大于库存数量
  2276. if drug.IsUse != 1 {
  2277. if drug.IsProject == 0 || drug.IsProject == 2 {
  2278. if total_count == 0 {
  2279. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2280. return
  2281. }
  2282. if (number_count - device_number) > total_count {
  2283. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2284. return
  2285. }
  2286. }
  2287. if adminInfo.CurrentOrgId == 10215 {
  2288. if (number_count - device_number) > batch_number_count {
  2289. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2290. return
  2291. }
  2292. }
  2293. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2294. //查询历史出库数据总批次
  2295. // 查询该药品最后一次出库记录
  2296. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2297. var out_count int64
  2298. var in_count int64
  2299. var stock_max_number int64
  2300. var stock_min_number int64
  2301. for _, it := range outInfo {
  2302. if it.CountUnit == drug.MaxUnit {
  2303. it.Count = it.Count * drug.MinNumber
  2304. }
  2305. out_count += it.Count
  2306. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2307. stock_max_number = warehouseInfoList.StockMaxNumber
  2308. stock_min_number = warehouseInfoList.StockMinNumber
  2309. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2310. }
  2311. if out_count > 0 {
  2312. if (number_count - device_number) > in_count {
  2313. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2314. return
  2315. }
  2316. }
  2317. // 未出库
  2318. if out_count == 0 {
  2319. var sum_in_count int64
  2320. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2321. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2322. if sum_in_count == 0 {
  2323. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2324. return
  2325. }
  2326. //如果修改的数量大于有库存的第一个批次
  2327. if number_count > sum_in_count {
  2328. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2329. return
  2330. }
  2331. }
  2332. }
  2333. }
  2334. }
  2335. }
  2336. }
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. //校验耗材库存
  2346. if goodOutConfig.IsOpen == 1 {
  2347. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2348. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2349. if len(prescriptions) > 0 {
  2350. for _, item := range prescriptions {
  2351. items := item.(map[string]interface{})
  2352. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2353. projects := items["project"].([]interface{})
  2354. if len(projects) > 0 {
  2355. for _, project := range projects {
  2356. var project_id int64
  2357. var project_type int64
  2358. var totals float64
  2359. var project_name string
  2360. var parsetotal int64
  2361. var id int64
  2362. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2363. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2364. }
  2365. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2366. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2367. }
  2368. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2369. total, _ := project.(map[string]interface{})["total"].(string)
  2370. totals, _ = strconv.ParseFloat(total, 64)
  2371. }
  2372. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2373. project_name = project.(map[string]interface{})["project_name"].(string)
  2374. }
  2375. if project_type == 3 {
  2376. //查找该耗材的出库记录
  2377. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2378. if len(goodWarehouseInfo) == 0 {
  2379. //查询耗材库存
  2380. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2381. var stock_count int64
  2382. for _, it := range list {
  2383. stock_count += it.StockCount
  2384. }
  2385. stock_counts := strconv.FormatInt(stock_count, 10)
  2386. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2387. if stock_total_count == 0 {
  2388. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2389. return
  2390. }
  2391. if totals > stock_total_count {
  2392. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2393. return
  2394. }
  2395. }
  2396. if len(goodWarehouseInfo) > 0 {
  2397. //查询该患者耗材的历史数据
  2398. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2399. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2400. //数量发生改变
  2401. if parsetotal != count {
  2402. //如果现在的数量大于历史数量,就要看库存是否足够
  2403. if parsetotal > count {
  2404. //查询耗材所有库存
  2405. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2406. var stock_count int64
  2407. for _, it := range list {
  2408. stock_count += it.StockCount
  2409. }
  2410. //库存不足
  2411. if stock_count == 0 {
  2412. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2413. return
  2414. }
  2415. if (parsetotal - count) > stock_count {
  2416. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2417. return
  2418. }
  2419. }
  2420. }
  2421. }
  2422. }
  2423. }
  2424. }
  2425. }
  2426. }
  2427. }
  2428. }
  2429. }
  2430. //不使用耗材保存处方出库
  2431. if goodOutConfig.IsOpen != 1 {
  2432. if stockConfig.IsOpen == 1 {
  2433. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2434. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2435. if len(prescriptions) > 0 {
  2436. for _, item := range prescriptions {
  2437. items := item.(map[string]interface{})
  2438. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2439. projects := items["project"].([]interface{})
  2440. if len(projects) > 0 {
  2441. for _, project := range projects {
  2442. var project_id int64
  2443. var project_type int64
  2444. var totals float64
  2445. var project_name string
  2446. var parsetotal int64
  2447. var id int64
  2448. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2449. id = int64(project.(map[string]interface{})["id"].(float64))
  2450. }
  2451. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2452. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2453. }
  2454. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2455. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2456. }
  2457. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2458. total, _ := project.(map[string]interface{})["total"].(string)
  2459. totals, _ = strconv.ParseFloat(total, 64)
  2460. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2461. }
  2462. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2463. project_name = project.(map[string]interface{})["project_name"].(string)
  2464. }
  2465. if project_type == 3 {
  2466. //查找该耗材的出库记录
  2467. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2468. //没有出库记录
  2469. if len(goodWarehouseInfo) == 0 {
  2470. //查询耗材库存
  2471. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2472. var stock_count int64
  2473. for _, it := range list {
  2474. stock_count += it.StockCount
  2475. }
  2476. stock_counts := strconv.FormatInt(stock_count, 10)
  2477. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2478. if stock_total_count == 0 {
  2479. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2480. return
  2481. }
  2482. if totals > stock_total_count {
  2483. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2484. return
  2485. }
  2486. //查找今日该患者已经出库的所有耗材
  2487. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2488. for _, item := range goodList {
  2489. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2490. var flush_count int64
  2491. for _, it := range goodListSix {
  2492. flush_count += it.StockCount
  2493. }
  2494. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2495. creater := adminInfo.AdminUser.Id
  2496. if errs != nil {
  2497. goodErrcode := models.XtGoodErrcode{
  2498. UserOrgId: item.OrgId,
  2499. Errcode: "手动出库更新剩余出库失败",
  2500. GoodId: item.GoodId,
  2501. Status: 1,
  2502. Ctime: time.Now().Unix(),
  2503. Mtime: 0,
  2504. Count: 0,
  2505. StockCount: 0,
  2506. Creater: creater,
  2507. BatchNumberId: 0,
  2508. WarehouseOutId: 0,
  2509. }
  2510. service.CreateGoodErrcode(goodErrcode)
  2511. }
  2512. }
  2513. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2514. }
  2515. //有出库记录
  2516. if len(goodWarehouseInfo) > 0 {
  2517. //查询该患者耗材的历史数据
  2518. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2519. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2520. //数量发生改变
  2521. if parsetotal != count {
  2522. //查找今日该患者已经出库的所有耗材
  2523. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2524. for _, item := range goodList {
  2525. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2526. var flush_count int64
  2527. for _, it := range goodListSix {
  2528. flush_count += it.StockCount
  2529. }
  2530. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2531. //减少出库数量
  2532. creater := adminInfo.AdminUser.Id
  2533. if errs != nil {
  2534. goodErrcode := models.XtGoodErrcode{
  2535. UserOrgId: item.OrgId,
  2536. Errcode: "手动出库更新剩余出库失败",
  2537. GoodId: item.GoodId,
  2538. Status: 1,
  2539. Ctime: time.Now().Unix(),
  2540. Mtime: 0,
  2541. Count: 0,
  2542. StockCount: 0,
  2543. Creater: creater,
  2544. BatchNumberId: 0,
  2545. WarehouseOutId: 0,
  2546. }
  2547. service.CreateGoodErrcode(goodErrcode)
  2548. }
  2549. //查询默认仓库
  2550. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2551. var total_count int64
  2552. for _, it := range stockList {
  2553. total_count += it.StockCount
  2554. }
  2555. //基础库插入数据
  2556. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2557. }
  2558. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2559. }
  2560. }
  2561. }
  2562. }
  2563. }
  2564. }
  2565. }
  2566. }
  2567. }
  2568. }
  2569. }
  2570. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2571. var hpInfo models.HisPrescriptionInfo
  2572. if info.ID == 0 {
  2573. var randNum int
  2574. randNum = rand.Intn(10000) + 1000
  2575. timestamp := time.Now().Unix()
  2576. tempTime := time.Unix(timestamp, 0)
  2577. timeFormat := tempTime.Format("20060102150405")
  2578. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2579. hpInfo = models.HisPrescriptionInfo{
  2580. HisPatientId: his_patient_id,
  2581. UserOrgId: adminInfo.CurrentOrgId,
  2582. RecordDate: theTime.Unix(),
  2583. PatientId: patient_id,
  2584. Status: 1,
  2585. Ctime: time.Now().Unix(),
  2586. Mtime: time.Now().Unix(),
  2587. Creator: adminInfo.AdminUser.Id,
  2588. Modifier: adminInfo.AdminUser.Id,
  2589. Diagnosis: diagnose,
  2590. SickHistory: sick_history,
  2591. Departments: department,
  2592. RegisterType: reg_type,
  2593. PrescriptionNumber: p_number,
  2594. PrescriptionStatus: 1,
  2595. Doctor: role.UserName,
  2596. DoctorId: doctor_id,
  2597. SickType: sick_type,
  2598. PType: p_type,
  2599. PatientDiagnosis: patient_diagnose,
  2600. }
  2601. service.SavePatientPrescriptionInfo(hpInfo)
  2602. //创建步骤表
  2603. finish := models.XtDialysisFinish{
  2604. IsFinish: 1,
  2605. UserOrgId: adminInfo.CurrentOrgId,
  2606. Status: 1,
  2607. Ctime: time.Now().Unix(),
  2608. Mtime: 0,
  2609. Module: 4,
  2610. RecordDate: theTime.Unix(),
  2611. Sourse: 1,
  2612. PatientId: patient_id,
  2613. }
  2614. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2615. if dialysisFinish.ID == 0 {
  2616. service.CreateDialysisFinish(finish)
  2617. }
  2618. redis := service.RedisClient()
  2619. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2620. redis.Set(key, "", time.Second)
  2621. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2622. redis.Set(keyOne, "", time.Second)
  2623. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2624. redis.Set(keySeven, "", time.Second)
  2625. defer redis.Close()
  2626. } else {
  2627. hpInfo = models.HisPrescriptionInfo{
  2628. ID: info.ID,
  2629. UserOrgId: adminInfo.CurrentOrgId,
  2630. RecordDate: info.RecordDate,
  2631. PatientId: info.PatientId,
  2632. Status: 1,
  2633. Ctime: info.Ctime,
  2634. Mtime: time.Now().Unix(),
  2635. Creator: info.Creator,
  2636. Modifier: adminInfo.AdminUser.Id,
  2637. Diagnosis: diagnose,
  2638. SickHistory: sick_history,
  2639. Departments: department,
  2640. RegisterType: reg_type,
  2641. PrescriptionNumber: info.PrescriptionNumber,
  2642. Doctor: role.UserName,
  2643. PrescriptionStatus: info.PrescriptionStatus,
  2644. DoctorId: doctor_id,
  2645. SickType: sick_type,
  2646. PType: info.PType,
  2647. HisPatientId: info.HisPatientId,
  2648. PatientDiagnosis: patient_diagnose,
  2649. }
  2650. service.SavePatientPrescriptionInfo(hpInfo)
  2651. //创建步骤表
  2652. finish := models.XtDialysisFinish{
  2653. IsFinish: 1,
  2654. UserOrgId: adminInfo.CurrentOrgId,
  2655. Status: 1,
  2656. Ctime: time.Now().Unix(),
  2657. Mtime: 0,
  2658. Module: 4,
  2659. RecordDate: info.RecordDate,
  2660. Sourse: 1,
  2661. PatientId: info.PatientId,
  2662. }
  2663. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2664. if dialysisFinish.ID == 0 {
  2665. service.CreateDialysisFinish(finish)
  2666. }
  2667. redis := service.RedisClient()
  2668. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2669. redis.Set(key, "", time.Second)
  2670. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2671. redis.Set(keyOne, "", time.Second)
  2672. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2673. redis.Set(keySeven, "", time.Second)
  2674. defer redis.Close()
  2675. }
  2676. //定义切片
  2677. var adviceList []models.HisDoctorAdviceInfo
  2678. var projectList []models.HisPrescriptionProject
  2679. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2680. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2681. var tempPrescription *models.HisPrescription
  2682. if len(prescriptions) > 0 {
  2683. for _, item := range prescriptions {
  2684. items := item.(map[string]interface{})
  2685. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2686. utils.ErrorLog("id")
  2687. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2688. return
  2689. }
  2690. id := int64(items["id"].(float64))
  2691. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2692. tempPrescription = &new_prescription
  2693. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2694. utils.ErrorLog("type")
  2695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2696. return
  2697. }
  2698. types := int64(items["type"].(float64))
  2699. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2700. utils.ErrorLog("med_type")
  2701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2702. return
  2703. }
  2704. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2705. if med_type == "0" {
  2706. med_type = "14"
  2707. }
  2708. //if order_status == 0 {
  2709. // order_status = 1
  2710. //}
  2711. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2712. utils.ErrorLog("pre_time")
  2713. }
  2714. preTime, _ := items["pre_time"].(string)
  2715. timeLayout := "2006-01-02"
  2716. loc, _ := time.LoadLocation("Local")
  2717. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2718. if err != nil {
  2719. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2720. return
  2721. }
  2722. pTime := theTime2.Unix()
  2723. ctime := time.Now().Unix()
  2724. if tempPrescription.ID == 0 {
  2725. prescription := &models.HisPrescription{
  2726. ID: 0,
  2727. PatientId: patient_id,
  2728. UserOrgId: adminInfo.CurrentOrgId,
  2729. RecordDate: recordDateTime,
  2730. Ctime: ctime,
  2731. Mtime: ctime,
  2732. Type: types,
  2733. Modifier: adminInfo.AdminUser.Id,
  2734. Creator: adminInfo.AdminUser.Id,
  2735. Status: 1,
  2736. Doctor: role.UserName,
  2737. HisPatientId: his_patient_id,
  2738. OrderStatus: 1,
  2739. BatchNumber: "",
  2740. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2741. PreTime: pTime,
  2742. PType: p_type,
  2743. MedType: med_type,
  2744. }
  2745. tempPrescription = prescription
  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. } else {
  2756. tempPrescription.ID = id
  2757. tempPrescription.Type = types
  2758. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2759. tempPrescription.Mtime = time.Now().Unix()
  2760. tempPrescription.Doctor = role.UserName
  2761. //tempPrescription.OrderStatus = order_status
  2762. tempPrescription.PreTime = pTime
  2763. tempPrescription.MedType = med_type
  2764. service.SaveHisPrescription(tempPrescription)
  2765. redis := service.RedisClient()
  2766. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2767. redis.Set(key, "", time.Second)
  2768. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2769. redis.Set(keyOne, "", time.Second)
  2770. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2771. redis.Set(keySeven, "", time.Second)
  2772. defer redis.Close()
  2773. }
  2774. //service.SaveHisPrescription(prescription)
  2775. //更改患者挂号状态
  2776. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2777. fmt.Println("更改失败", err2)
  2778. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2779. advices := items["advices"].([]interface{})
  2780. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2781. groupNo := int64(0)
  2782. ctime := time.Now().Unix()
  2783. mtime := ctime
  2784. if len(advices) > 0 {
  2785. for _, advice := range advices {
  2786. var s models.HisDoctorAdviceInfo
  2787. s.PrescriptionId = tempPrescription.ID
  2788. s.AdviceType = 2
  2789. s.AdviceDoctor = doctor_id
  2790. s.StopState = 2
  2791. s.ExecutionState = 2
  2792. s.AdviceDate = recordDateTime
  2793. s.Status = 1
  2794. s.UserOrgId = adminInfo.CurrentOrgId
  2795. s.RecordDate = recordDateTime
  2796. s.StartTime = tempPrescription.PreTime
  2797. s.Groupno = groupNo
  2798. s.CreatedTime = ctime
  2799. s.UpdatedTime = mtime
  2800. s.PatientId = patient_id
  2801. s.HisPatientId = his_patient_id
  2802. s.StartTime = pTime
  2803. s.IsSettle = 2
  2804. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2805. if errcode > 0 {
  2806. c.ServeFailJSONWithSGJErrorCode(errcode)
  2807. return
  2808. }
  2809. s.StartTime = pTime
  2810. var total_count int64 //处方总库存
  2811. //查询改药品信息
  2812. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2813. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2814. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2815. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2816. total_count += prescribingNumberSeven * medical.MinNumber
  2817. }
  2818. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2819. total_count += prescribingNumberSeven
  2820. }
  2821. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2822. total_count += prescribingNumberSeven
  2823. }
  2824. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2825. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2826. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2827. if s.Price != lastWarehouse.RetailPrice {
  2828. s.Price = lastWarehouse.RetailPrice
  2829. }
  2830. if s.Price == 0 {
  2831. s.Price = lastWarehouse.RetailPrice
  2832. }
  2833. }
  2834. service.CreateHisDoctorAdvice(&s)
  2835. //记录日志
  2836. byterequest, _ := json.Marshal(s)
  2837. adviceLog := models.XtDoctorAdviceLog{
  2838. UserOrgId: s.UserOrgId,
  2839. PatientId: s.PatientId,
  2840. AdminUserId: adminInfo.AdminUser.Id,
  2841. Module: 1,
  2842. ErrLog: string(byterequest),
  2843. Status: 1,
  2844. Ctime: time.Now().Unix(),
  2845. Mtime: 0,
  2846. Source: "电脑端新建his医嘱",
  2847. RecordDate: s.AdviceDate,
  2848. }
  2849. service.CreateDoctorAdviceLog(adviceLog)
  2850. //存储切片中
  2851. adviceList = append(adviceList, s)
  2852. redis := service.RedisClient()
  2853. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2854. redis.Set(key, "", time.Second)
  2855. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2856. redis.Set(keyOne, "", time.Second)
  2857. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2858. redis.Set(keySeven, "", time.Second)
  2859. var randNum int
  2860. randNum = rand.Intn(10000) + 1000
  2861. timestamp := time.Now().Unix()
  2862. tempTime := time.Unix(timestamp, 0)
  2863. timeFormat := tempTime.Format("20060102150405")
  2864. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  2865. service.CreateHisDoctorAdvice(&s)
  2866. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2867. redis.Set(keySix, "", time.Second)
  2868. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2869. redis.Set(keyFive, "", time.Second)
  2870. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2871. redis.Set(keyEight, "", time.Second)
  2872. defer redis.Close()
  2873. }
  2874. }
  2875. }
  2876. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2877. projects := items["project"].([]interface{})
  2878. if len(projects) > 0 {
  2879. for _, project := range projects {
  2880. var p models.HisPrescriptionProject
  2881. p.PrescriptionId = tempPrescription.ID
  2882. p.Ctime = time.Now().Unix()
  2883. p.Mtime = time.Now().Unix()
  2884. p.PatientId = patient_id
  2885. p.RecordDate = recordDateTime
  2886. p.Doctor = doctor_id
  2887. p.UserOrgId = adminInfo.CurrentOrgId
  2888. p.HisPatientId = his_patient_id
  2889. p.Status = 1
  2890. p.StartTime = pTime
  2891. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  2892. if errcode > 0 {
  2893. c.ServeFailJSONWithSGJErrorCode(errcode)
  2894. return
  2895. }
  2896. if p.ID == 0 {
  2897. p.IsOut = 2
  2898. }
  2899. if p.ID > 0 {
  2900. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  2901. p.IsOut = projectDetail.IsOut
  2902. }
  2903. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2904. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2905. if p.Type == 3 {
  2906. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  2907. if p.Price != lastWarehouse.PackingPrice {
  2908. p.Price = lastWarehouse.PackingPrice
  2909. }
  2910. if p.Unit == "" {
  2911. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2912. p.Unit = goodInfoOne.PackingUnit
  2913. }
  2914. }
  2915. }
  2916. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  2917. //
  2918. // if p.Type == 3 {
  2919. // //查询该耗材是否停用
  2920. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  2921. // //表示该耗材已经停用,不能保存
  2922. // if goodInfoSeven.ID == 0 {
  2923. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  2924. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  2925. // return
  2926. // }
  2927. // }
  2928. //
  2929. //}
  2930. service.CreateHisProjectTwo(&p)
  2931. //记录日志
  2932. byterequest, _ := json.Marshal(p)
  2933. adviceLog := models.XtDoctorAdviceLog{
  2934. UserOrgId: p.UserOrgId,
  2935. PatientId: p.PatientId,
  2936. AdminUserId: adminInfo.AdminUser.Id,
  2937. Module: 1,
  2938. ErrLog: string(byterequest),
  2939. Status: 1,
  2940. Ctime: time.Now().Unix(),
  2941. Mtime: 0,
  2942. Source: "电脑端新建his项目",
  2943. RecordDate: p.RecordDate,
  2944. }
  2945. service.CreateDoctorAdviceLog(adviceLog)
  2946. projectList = append(projectList, p)
  2947. var randNum int
  2948. randNum = rand.Intn(10000) + 1000
  2949. timestamp := time.Now().Unix()
  2950. tempTime := time.Unix(timestamp, 0)
  2951. timeFormat := tempTime.Format("20060102150405")
  2952. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  2953. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  2954. //新增或者编辑项目,修改对应的标签数据
  2955. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  2956. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  2957. var label models.HisLabelPrintInfo
  2958. project, _ := service.GetProjectDetail(p.ProjectId)
  2959. if project.CostClassify == 3 { //类别为检验检查
  2960. if p.TeamId > 0 { //检验检查组套
  2961. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  2962. if tempLabel.ID == 0 {
  2963. team, _ := service.GetProjectTeamDetail(p.TeamId)
  2964. label.Number = tempPrescription.PrescriptionNumber
  2965. label.ProjectId = project.ID
  2966. label.Status = 1
  2967. label.IsPrint = 2
  2968. label.DoctorId = info.DoctorId
  2969. label.UserOrgId = p.UserOrgId
  2970. label.PatientId = patient_id
  2971. label.RecordDate = recordDateTime
  2972. label.Ctime = time.Now().Unix()
  2973. label.Mtime = time.Now().Unix()
  2974. label.ItemId = p.TeamId
  2975. label.FeedetlSn = p.FeedetlSn
  2976. label.PProjectId = p.ID
  2977. label.ProjectName = team.ProjectTeam
  2978. label.PatientName = patient.Name
  2979. service.CreateHisLabelRecord(&label)
  2980. }
  2981. } else { //单条检验检查项目
  2982. label.Number = tempPrescription.PrescriptionNumber
  2983. label.ProjectId = project.ID
  2984. label.Status = 1
  2985. label.DoctorId = info.DoctorId
  2986. label.UserOrgId = p.UserOrgId
  2987. label.PatientId = patient_id
  2988. label.RecordDate = recordDateTime
  2989. label.IsPrint = 2
  2990. label.Ctime = time.Now().Unix()
  2991. label.Mtime = time.Now().Unix()
  2992. label.FeedetlSn = p.FeedetlSn
  2993. label.PProjectId = p.ID
  2994. label.ItemId = p.TeamId
  2995. label.ProjectName = project.ProjectName
  2996. label.PatientName = patient.Name
  2997. service.CreateHisLabelRecord(&label)
  2998. }
  2999. }
  3000. }
  3001. }
  3002. service.SaveHisProjectTwo(&p)
  3003. }
  3004. }
  3005. }
  3006. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3007. // addition := items["addition"].([]interface{})
  3008. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3009. // ctime := time.Now().Unix()
  3010. // mtime := ctime
  3011. // if len(addition) > 0 {
  3012. // for _, item := range addition {
  3013. // var s models.HisAdditionalCharge
  3014. // s.PrescriptionId = tempPrescription.ID
  3015. // s.Status = 1
  3016. // s.UserOrgId = adminInfo.CurrentOrgId
  3017. // s.RecordDate = recordDateTime
  3018. // s.CreatedTime = ctime
  3019. // s.UpdatedTime = mtime
  3020. // s.PatientId = patient_id
  3021. // s.HisPatientId = his_patient_id
  3022. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3023. // if errcode > 0 {
  3024. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3025. // return
  3026. // }
  3027. // service.CreateAdditionalCharge(&s)
  3028. // var randNum int
  3029. // randNum = rand.Intn(10000) + 1000
  3030. // timestamp := time.Now().Unix()
  3031. // tempTime := time.Unix(timestamp, 0)
  3032. // timeFormat := tempTime.Format("20060102150405")
  3033. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3034. // service.CreateAdditionalCharge(&s)
  3035. //
  3036. // }
  3037. // }
  3038. //}
  3039. }
  3040. }
  3041. //查询今日该患者开的药品处方
  3042. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3043. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3044. //药品出库
  3045. if drugOutConfig.IsOpen == 1 {
  3046. for _, item := range hisdoctorlist {
  3047. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3048. // 查询该药品最后一次出库记录
  3049. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3050. if len(druginfo) > 0 {
  3051. //回退库存
  3052. for _, it := range druginfo {
  3053. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3054. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3055. }
  3056. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3057. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3058. }
  3059. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3060. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3061. }
  3062. }
  3063. }
  3064. //删除记录
  3065. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3066. //查询最后一次数据
  3067. if drugOutConfig.IsOpen == 1 {
  3068. //出库
  3069. if drug.IsUse == 2 {
  3070. creater := adminInfo.AdminUser.Id
  3071. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3072. }
  3073. //更新字典里面的库存
  3074. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3075. var sum_count int64
  3076. for _, its := range stockInfo {
  3077. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3078. if its.MaxUnit == baseDrug.MaxUnit {
  3079. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3080. }
  3081. sum_count += its.StockMaxNumber + its.StockMinNumber
  3082. }
  3083. //更新基础库存
  3084. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3085. //剩余库存
  3086. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3087. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3088. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3089. }
  3090. }
  3091. }
  3092. //耗材保存处方出库
  3093. if goodOutConfig.IsOpen == 1 {
  3094. //查询今日耗材出库数量
  3095. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3096. for _, item := range hisgoodlist {
  3097. //查询历史出库数据
  3098. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3099. var out_count_five int64
  3100. for _, item := range flowGood {
  3101. out_count_five += item.Count
  3102. }
  3103. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3104. if out_count_five != parseIntCount {
  3105. //查询耗材最后一次出库记录
  3106. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3107. //查询默认出库仓库库存
  3108. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3109. if len(wareOut) > 0 {
  3110. for _, it := range wareOut {
  3111. //回退库存
  3112. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3113. //删除出库记录
  3114. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3115. }
  3116. }
  3117. timeStr := time.Now().Format("2006-01-02")
  3118. timeArr := strings.Split(timeStr, "-")
  3119. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3120. total = total + 1
  3121. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3122. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3123. number = number + total
  3124. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3125. operation_time := time.Now().Unix()
  3126. creater := c.GetAdminUserInfo().AdminUser.Id
  3127. recordDateStr := time.Now().Format("2006-01-02")
  3128. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3129. nowtime := recordDate.Unix()
  3130. warehouseOut := models.WarehouseOut{
  3131. WarehouseOutOrderNumber: warehousing_out_order,
  3132. OperationTime: operation_time,
  3133. OrgId: adminInfo.CurrentOrgId,
  3134. Creater: creater,
  3135. Ctime: time.Now().Unix(),
  3136. Status: 1,
  3137. WarehouseOutTime: nowtime,
  3138. Type: 1,
  3139. StorehouseId: storeConfig.StorehouseOutInfo,
  3140. IsCheck: 1,
  3141. IsSys: 1,
  3142. }
  3143. //查询是否生成出库单
  3144. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3145. if out.ID == 0 {
  3146. service.AddSigleWarehouseOut(&warehouseOut)
  3147. }
  3148. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3149. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3150. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3151. dialyPrepareOne := models.DialysisBeforePrepare{
  3152. GoodTypeId: goodObj.GoodTypeId,
  3153. GoodId: item.ProjectId,
  3154. PatientId: item.PatientId,
  3155. RecordDate: item.RecordDate,
  3156. UserOrgId: adminInfo.CurrentOrgId,
  3157. Count: parseIntCount,
  3158. Ctime: time.Now().Unix(),
  3159. Creater: creater,
  3160. Status: 1,
  3161. StorehouseId: houseConfig.StorehouseOutInfo,
  3162. ProjectId: item.ID,
  3163. }
  3164. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3165. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3166. //查询历史出库数据
  3167. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3168. var out_count int64
  3169. for _, item := range flowGood {
  3170. out_count += item.Count
  3171. }
  3172. //如果历史数和当前数据不想等才进行退库出库
  3173. if out_count != parseIntCount {
  3174. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3175. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3176. detail := models.AutomaticReduceDetail{
  3177. WarehouseOutId: 0,
  3178. WarehouseOutOrderNumber: "",
  3179. PatientId: item.PatientId,
  3180. Ctime: time.Now().Unix(),
  3181. Mtime: 0,
  3182. Status: 1,
  3183. RecordTime: item.RecordDate,
  3184. OrgId: item.UserOrgId,
  3185. GoodId: item.ProjectId,
  3186. GoodTypeId: 0,
  3187. Count: parseIntCount,
  3188. Type: 0,
  3189. ProjectId: item.ID,
  3190. StorehouseId: 0,
  3191. }
  3192. service.CreateAutoDetail(detail)
  3193. //查询剩余库存
  3194. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3195. var sum_count int64
  3196. for _, item := range goodList {
  3197. sum_count += item.StockCount
  3198. }
  3199. //更新剩余库存
  3200. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3201. //耗材
  3202. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3203. }
  3204. }
  3205. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  3206. //查询历史出库数据
  3207. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3208. var out_count int64
  3209. for _, item := range flowGood {
  3210. out_count += item.Count
  3211. }
  3212. //如果历史数和当前数据不想等才进行退库出库
  3213. if out_count != parseIntCount {
  3214. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3215. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3216. detail := models.AutomaticReduceDetail{
  3217. WarehouseOutId: 0,
  3218. WarehouseOutOrderNumber: "",
  3219. PatientId: item.PatientId,
  3220. Ctime: time.Now().Unix(),
  3221. Mtime: 0,
  3222. Status: 1,
  3223. RecordTime: item.RecordDate,
  3224. OrgId: item.UserOrgId,
  3225. GoodId: item.ProjectId,
  3226. GoodTypeId: 0,
  3227. Count: parseIntCount,
  3228. Type: 0,
  3229. ProjectId: item.ID,
  3230. StorehouseId: 0,
  3231. }
  3232. service.CreateAutoDetail(detail)
  3233. //查询剩余库存
  3234. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3235. var sum_count int64
  3236. for _, item := range goodList {
  3237. sum_count += item.StockCount
  3238. }
  3239. //更新剩余库存
  3240. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  3241. //耗材
  3242. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  3243. }
  3244. }
  3245. }
  3246. }
  3247. }
  3248. }
  3249. //redisClient := service.RedisClient()
  3250. //defer redisClient.Close()
  3251. //
  3252. //list := models.HisList{
  3253. // Patient_id: patient_id,
  3254. // Advice_id:0,
  3255. // Record_date: 0,
  3256. // Advice: adviceList,
  3257. // Project: nil,
  3258. //}
  3259. //hisLis = append(hisLis, list)
  3260. //
  3261. //advice_json, _ := json.Marshal(&hisLis)
  3262. //redisClient.RPush("111", advice_json).Result()
  3263. //result, _ := redisClient.RPop("111").Result()
  3264. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  3265. //
  3266. //var dat []map[string]interface{}
  3267. //json.Unmarshal([]byte(result), &dat)
  3268. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  3269. //
  3270. //for k,v:=range dat{
  3271. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  3272. //}
  3273. //project_json, _ := json.Marshal(&projectList)
  3274. //redisClient.LPush("222", project_json).Result()
  3275. if err == nil {
  3276. c.ServeSuccessJSON(map[string]interface{}{
  3277. "msg": "保存成功",
  3278. })
  3279. return
  3280. } else {
  3281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3282. return
  3283. }
  3284. }
  3285. func (c *HisApiController) EditHisPrescription() {
  3286. record_date := c.GetString("record_date")
  3287. patient_id, _ := c.GetInt64("patient_id")
  3288. reg_type, _ := c.GetInt64("reg_type")
  3289. //diagnose, _ := c.GetInt64("diagnose", 0)
  3290. diagnose := c.GetString("diagnose")
  3291. sick_type, _ := c.GetInt64("sick_type")
  3292. sick_history := c.GetString("sick_history")
  3293. doctor_id, _ := c.GetInt64("doctor", 0)
  3294. department, _ := c.GetInt64("department", 0)
  3295. his_patient_id, _ := c.GetInt64("his_patient_id")
  3296. p_type, _ := c.GetInt64("p_type")
  3297. dataBody := make(map[string]interface{}, 0)
  3298. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3299. if err != nil {
  3300. utils.ErrorLog(err.Error())
  3301. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3302. return
  3303. }
  3304. timeLayout := "2006-01-02"
  3305. loc, _ := time.LoadLocation("Local")
  3306. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3307. if err != nil {
  3308. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3309. return
  3310. }
  3311. adminInfo := c.GetAdminUserInfo()
  3312. recordDateTime := theTime.Unix()
  3313. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  3314. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  3315. var hpInfo models.HisPrescriptionInfo
  3316. if info.ID == 0 {
  3317. var randNum int
  3318. randNum = rand.Intn(10000) + 1000
  3319. timestamp := time.Now().Unix()
  3320. tempTime := time.Unix(timestamp, 0)
  3321. timeFormat := tempTime.Format("20060102150405")
  3322. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  3323. hpInfo = models.HisPrescriptionInfo{
  3324. UserOrgId: adminInfo.CurrentOrgId,
  3325. RecordDate: theTime.Unix(),
  3326. PatientId: patient_id,
  3327. Status: 1,
  3328. Ctime: time.Now().Unix(),
  3329. Mtime: time.Now().Unix(),
  3330. Creator: adminInfo.AdminUser.Id,
  3331. Modifier: adminInfo.AdminUser.Id,
  3332. Diagnosis: diagnose,
  3333. SickHistory: sick_history,
  3334. Departments: department,
  3335. RegisterType: reg_type,
  3336. PrescriptionNumber: p_number,
  3337. PrescriptionStatus: 1,
  3338. Doctor: role.UserName,
  3339. DoctorId: doctor_id,
  3340. SickType: sick_type,
  3341. PType: p_type,
  3342. }
  3343. service.SavePatientPrescriptionInfo(hpInfo)
  3344. } else {
  3345. hpInfo = models.HisPrescriptionInfo{
  3346. ID: info.ID,
  3347. UserOrgId: adminInfo.CurrentOrgId,
  3348. RecordDate: info.RecordDate,
  3349. PatientId: info.PatientId,
  3350. Status: 1,
  3351. Ctime: info.Ctime,
  3352. Mtime: time.Now().Unix(),
  3353. Creator: info.Creator,
  3354. Modifier: adminInfo.AdminUser.Id,
  3355. Diagnosis: diagnose,
  3356. SickHistory: sick_history,
  3357. Departments: department,
  3358. RegisterType: reg_type,
  3359. PrescriptionNumber: info.PrescriptionNumber,
  3360. Doctor: role.UserName,
  3361. PrescriptionStatus: info.PrescriptionStatus,
  3362. DoctorId: doctor_id,
  3363. SickType: sick_type,
  3364. PType: info.PType,
  3365. }
  3366. service.SavePatientPrescriptionInfo(hpInfo)
  3367. }
  3368. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3369. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3370. if len(prescriptions) > 0 {
  3371. for _, item := range prescriptions {
  3372. items := item.(map[string]interface{})
  3373. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3374. utils.ErrorLog("id")
  3375. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3376. return
  3377. }
  3378. id := int64(items["id"].(float64))
  3379. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3380. utils.ErrorLog("type")
  3381. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3382. return
  3383. }
  3384. types := int64(items["type"].(float64))
  3385. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3386. utils.ErrorLog("med_type")
  3387. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3388. return
  3389. }
  3390. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3391. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  3392. ctime := time.Now().Unix()
  3393. prescription := &models.HisPrescription{
  3394. ID: id,
  3395. PatientId: patient_id,
  3396. UserOrgId: adminInfo.CurrentOrgId,
  3397. RecordDate: recordDateTime,
  3398. Ctime: ctime,
  3399. Mtime: ctime,
  3400. Type: types,
  3401. Modifier: adminInfo.AdminUser.Id,
  3402. Creator: adminInfo.AdminUser.Id,
  3403. Status: 1,
  3404. Doctor: role.UserName,
  3405. HisPatientId: his_patient_id,
  3406. OrderStatus: 1,
  3407. BatchNumber: "",
  3408. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3409. PType: hpInfo.PType,
  3410. MedType: med_type,
  3411. }
  3412. if historyPrescription.ID > 0 {
  3413. prescription.PreTime = historyPrescription.PreTime
  3414. }
  3415. service.SaveHisPrescription(prescription)
  3416. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3417. advices := items["advices"].([]interface{})
  3418. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3419. groupNo := int64(0)
  3420. ctime := time.Now().Unix()
  3421. mtime := ctime
  3422. if len(advices) > 0 {
  3423. for _, advice := range advices {
  3424. var s models.HisDoctorAdviceInfo
  3425. s.PrescriptionId = prescription.ID
  3426. s.AdviceType = 2
  3427. s.AdviceDoctor = adminInfo.AdminUser.Id
  3428. s.StopState = 2
  3429. s.ExecutionState = 2
  3430. s.AdviceDate = recordDateTime
  3431. s.Status = 1
  3432. s.UserOrgId = adminInfo.CurrentOrgId
  3433. s.RecordDate = recordDateTime
  3434. s.StartTime = prescription.PreTime
  3435. s.Groupno = groupNo
  3436. s.CreatedTime = ctime
  3437. s.UpdatedTime = mtime
  3438. s.PatientId = patient_id
  3439. s.HisPatientId = his_patient_id
  3440. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  3441. if errcode > 0 {
  3442. c.ServeFailJSONWithSGJErrorCode(errcode)
  3443. return
  3444. }
  3445. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3446. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3447. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3448. if s.Price == 0 {
  3449. s.Price = lastWarehouse.RetailPrice
  3450. }
  3451. }
  3452. service.CreateHisDoctorAdvice(&s)
  3453. //记录日志
  3454. byterequest, _ := json.Marshal(s)
  3455. adviceLog := models.XtDoctorAdviceLog{
  3456. UserOrgId: s.UserOrgId,
  3457. PatientId: s.PatientId,
  3458. AdminUserId: adminInfo.AdminUser.Id,
  3459. Module: 1,
  3460. ErrLog: string(byterequest),
  3461. Status: 1,
  3462. Ctime: time.Now().Unix(),
  3463. Mtime: 0,
  3464. Source: "电脑端his医嘱修改",
  3465. RecordDate: s.AdviceDate,
  3466. }
  3467. service.CreateDoctorAdviceLog(adviceLog)
  3468. redis := service.RedisClient()
  3469. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3470. redis.Set(key, "", time.Second)
  3471. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3472. fmt.Println("keyOne", keyOne)
  3473. redis.Set(keyOne, "", time.Second)
  3474. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3475. redis.Set(keySeven, "", time.Second)
  3476. redis.Close()
  3477. }
  3478. }
  3479. }
  3480. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3481. projects := items["project"].([]interface{})
  3482. if len(projects) > 0 {
  3483. for _, project := range projects {
  3484. var p models.HisPrescriptionProject
  3485. p.PrescriptionId = prescription.ID
  3486. p.Ctime = time.Now().Unix()
  3487. p.Mtime = time.Now().Unix()
  3488. p.PatientId = patient_id
  3489. p.RecordDate = recordDateTime
  3490. p.UserOrgId = adminInfo.CurrentOrgId
  3491. p.HisPatientId = his_patient_id
  3492. p.Status = 1
  3493. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  3494. if errcode > 0 {
  3495. c.ServeFailJSONWithSGJErrorCode(errcode)
  3496. return
  3497. }
  3498. service.CreateHisProjectTwo(&p)
  3499. //记录日志
  3500. byterequest, _ := json.Marshal(p)
  3501. adviceLog := models.XtDoctorAdviceLog{
  3502. UserOrgId: p.UserOrgId,
  3503. PatientId: p.PatientId,
  3504. AdminUserId: adminInfo.AdminUser.Id,
  3505. Module: 1,
  3506. ErrLog: string(byterequest),
  3507. Status: 1,
  3508. Ctime: time.Now().Unix(),
  3509. Mtime: 0,
  3510. Source: "电脑端his项目修改",
  3511. RecordDate: p.RecordDate,
  3512. }
  3513. service.CreateDoctorAdviceLog(adviceLog)
  3514. }
  3515. }
  3516. }
  3517. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3518. addition := items["addition"].([]interface{})
  3519. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3520. ctime := time.Now().Unix()
  3521. mtime := ctime
  3522. if len(addition) > 0 {
  3523. for _, item := range addition {
  3524. var s models.HisAdditionalCharge
  3525. s.PrescriptionId = prescription.ID
  3526. s.Status = 1
  3527. s.UserOrgId = adminInfo.CurrentOrgId
  3528. s.RecordDate = recordDateTime
  3529. s.CreatedTime = ctime
  3530. s.UpdatedTime = mtime
  3531. s.PatientId = patient_id
  3532. s.HisPatientId = his_patient_id
  3533. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3534. if errcode > 0 {
  3535. c.ServeFailJSONWithSGJErrorCode(errcode)
  3536. return
  3537. }
  3538. service.CreateAdditionalCharge(&s)
  3539. }
  3540. }
  3541. }
  3542. }
  3543. }
  3544. }
  3545. if err == nil {
  3546. c.ServeSuccessJSON(map[string]interface{}{
  3547. "msg": "保存成功",
  3548. })
  3549. return
  3550. } else {
  3551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3552. return
  3553. }
  3554. }
  3555. func (c *HisApiController) DeletePrescription() {
  3556. prescription_id, _ := c.GetInt64("id")
  3557. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  3558. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  3559. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3560. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3561. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3562. //耗材保存处方出库
  3563. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3564. //已收费和已发药限制逻辑
  3565. isCharge := false
  3566. isMedicine := false
  3567. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  3568. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3569. for _, item := range new_prescriptions {
  3570. if item.IsMedicine == 1 {
  3571. isMedicine = true
  3572. }
  3573. }
  3574. for _, item := range new_prescriptions {
  3575. if item.OrderStatus == 4 {
  3576. isCharge = true
  3577. }
  3578. }
  3579. if p_err != nil {
  3580. if new_prescription.ID > 0 {
  3581. if new_prescription.OrderStatus == 2 {
  3582. isCharge = true
  3583. }
  3584. }
  3585. }
  3586. for _, item := range advices {
  3587. if item.IsMedicine == 1 {
  3588. isMedicine = true
  3589. }
  3590. }
  3591. if isCharge {
  3592. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3593. return
  3594. }
  3595. if isMedicine {
  3596. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3597. return
  3598. }
  3599. //已收费和已发药限制逻辑
  3600. if len(projects) > 0 {
  3601. for _, item := range projects {
  3602. service.DeletePrintInfo(item.ID) //删除打印信息
  3603. if goodOutConfig.IsOpen != 1 {
  3604. if stockConfig.IsOpen == 1 {
  3605. if item.Type == 3 && item.IsOut == 1 {
  3606. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3607. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3608. good.Total = good.Total + f_count
  3609. service.UpdateGoodInfo(&good)
  3610. operation_time := time.Now().Unix()
  3611. creater := c.GetAdminUserInfo().AdminUser.Id
  3612. //创建退库单
  3613. timeStr := time.Now().Format("2006-01-02")
  3614. timeArr := strings.Split(timeStr, "-")
  3615. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3616. total = total + 1
  3617. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3618. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3619. cancelStock := models.CancelStock{
  3620. OrderNumber: orderNumber,
  3621. OperaTime: operation_time,
  3622. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3623. Creater: creater,
  3624. Ctime: time.Now().Unix(),
  3625. Status: 1,
  3626. ReturnTime: item.RecordDate,
  3627. Type: 1,
  3628. StorehouseId: houseConfig.StorehouseOutInfo,
  3629. IsCheck: 1,
  3630. }
  3631. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3632. if msgerrkonde == gorm.ErrRecordNotFound {
  3633. service.AddSigleCancelStock(&cancelStock)
  3634. }
  3635. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3636. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3637. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3638. //查询该耗材是否出库
  3639. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3640. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3641. deaerler, _ := service.GetDealerById(info.Dealer)
  3642. var total_count int64
  3643. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3644. total_count += count
  3645. if info.ID > 0 {
  3646. if info.Count >= total_count {
  3647. //回退库存
  3648. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3649. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3650. var flush_count int64
  3651. for _, it := range goodList {
  3652. flush_count += it.StockCount
  3653. }
  3654. cancelStockInfo := models.CancelStockInfo{
  3655. GoodId: item.ProjectId,
  3656. CancelStockId: cancel.ID,
  3657. GoodTypeId: good.GoodTypeId,
  3658. Count: prescribingNumber,
  3659. Price: info.Price,
  3660. Total: 0,
  3661. ProductDate: info.ProductDate,
  3662. ExpiryDate: info.ExpiryDate,
  3663. Ctime: time.Now().Unix(),
  3664. Status: 1,
  3665. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3666. OrderNumber: cancel.OrderNumber,
  3667. Type: 0,
  3668. Dealer: deaerler.DealerName,
  3669. Manufacturer: manufacturer.ManufacturerName,
  3670. Number: info.Number,
  3671. RegisterAccount: "",
  3672. Remark: "",
  3673. WarehouseInfoId: info.WarehouseInfotId,
  3674. PatientId: info.PatientId,
  3675. RecordDate: info.SysRecordTime,
  3676. StorehouseId: houseConfig.StorehouseOutInfo,
  3677. IsCheck: 1,
  3678. }
  3679. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3680. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3681. flow := models.VmStockFlow{
  3682. WarehousingId: info.WarehouseInfotId,
  3683. GoodId: item.ProjectId,
  3684. Number: info.Number,
  3685. LicenseNumber: info.LicenseNumber,
  3686. Count: prescribingNumber,
  3687. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3688. PatientId: item.PatientId,
  3689. SystemTime: info.SysRecordTime,
  3690. ConsumableType: 7,
  3691. IsSys: 0,
  3692. WarehousingOrder: "",
  3693. WarehouseOutId: info.WarehouseOutId,
  3694. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3695. IsEdit: 0,
  3696. CancelStockId: cancel.ID,
  3697. CancelOrderNumber: cancel.OrderNumber,
  3698. Manufacturer: manufacturer.ID,
  3699. Dealer: 0,
  3700. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3701. UpdateCreator: 0,
  3702. Status: 1,
  3703. Ctime: time.Now().Unix(),
  3704. Mtime: 0,
  3705. Price: info.Price,
  3706. WarehousingDetailId: info.WarehouseInfotId,
  3707. WarehouseOutDetailId: info.ID,
  3708. CancelOutDetailId: cancelInfo.ID,
  3709. ProductDate: info.ProductDate,
  3710. ExpireDate: info.ExpiryDate,
  3711. StorehouseId: houseConfig.StorehouseOutInfo,
  3712. OverCount: flush_count,
  3713. }
  3714. service.CreateStockFlowOne(flow)
  3715. //退库数量增加
  3716. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3717. //出库数量减少
  3718. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3719. }
  3720. if info.Count < total_count {
  3721. //回退库存
  3722. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  3723. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3724. var flush_count int64
  3725. for _, it := range goodList {
  3726. flush_count += it.StockCount
  3727. }
  3728. cancelStockInfo := models.CancelStockInfo{
  3729. GoodId: item.ProjectId,
  3730. CancelStockId: cancel.ID,
  3731. GoodTypeId: good.GoodTypeId,
  3732. Count: info.Count,
  3733. Price: info.Price,
  3734. Total: 0,
  3735. ProductDate: info.ProductDate,
  3736. ExpiryDate: info.ExpiryDate,
  3737. Ctime: time.Now().Unix(),
  3738. Status: 1,
  3739. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3740. OrderNumber: cancel.OrderNumber,
  3741. Type: 0,
  3742. Dealer: deaerler.DealerName,
  3743. Manufacturer: manufacturer.ManufacturerName,
  3744. Number: info.Number,
  3745. RegisterAccount: "",
  3746. Remark: "",
  3747. WarehouseInfoId: info.WarehouseInfotId,
  3748. PatientId: info.PatientId,
  3749. RecordDate: info.SysRecordTime,
  3750. StorehouseId: houseConfig.StorehouseOutInfo,
  3751. IsCheck: 1,
  3752. }
  3753. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3754. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3755. flow := models.VmStockFlow{
  3756. WarehousingId: info.WarehouseInfotId,
  3757. GoodId: item.ProjectId,
  3758. Number: info.Number,
  3759. LicenseNumber: info.LicenseNumber,
  3760. Count: info.Count,
  3761. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3762. PatientId: item.PatientId,
  3763. SystemTime: info.SysRecordTime,
  3764. ConsumableType: 7,
  3765. IsSys: 0,
  3766. WarehousingOrder: "",
  3767. WarehouseOutId: info.WarehouseOutId,
  3768. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3769. IsEdit: 0,
  3770. CancelStockId: cancel.ID,
  3771. CancelOrderNumber: cancel.OrderNumber,
  3772. Manufacturer: manufacturer.ID,
  3773. Dealer: 0,
  3774. Creator: c.GetAdminUserInfo().CurrentOrgId,
  3775. UpdateCreator: 0,
  3776. Status: 1,
  3777. Ctime: time.Now().Unix(),
  3778. Mtime: 0,
  3779. Price: info.Price,
  3780. WarehousingDetailId: info.WarehouseInfotId,
  3781. WarehouseOutDetailId: info.ID,
  3782. CancelOutDetailId: cancelInfo.ID,
  3783. ProductDate: info.ProductDate,
  3784. ExpireDate: info.ExpiryDate,
  3785. StorehouseId: houseConfig.StorehouseOutInfo,
  3786. OverCount: flush_count,
  3787. }
  3788. service.CreateStockFlowOne(flow)
  3789. //退库数量增加
  3790. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3791. //出库数量减少
  3792. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  3793. }
  3794. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3795. var flush_count int64
  3796. for _, it := range goodList {
  3797. flush_count += it.StockCount
  3798. }
  3799. //查询已出库数量
  3800. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3801. if prescribingNumber < dialysisInfo.Count {
  3802. //改变数量
  3803. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3804. }
  3805. if prescribingNumber >= dialysisInfo.Count {
  3806. //删除出库表
  3807. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3808. }
  3809. //更新库存
  3810. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  3811. //更新基础库库存
  3812. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  3813. }
  3814. }
  3815. }
  3816. }
  3817. //保存耗材出库
  3818. if goodOutConfig.IsOpen == 1 {
  3819. if item.Type == 3 {
  3820. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  3821. f_count, _ := strconv.ParseFloat(item.Count, 64)
  3822. good.Total = good.Total + f_count
  3823. service.UpdateGoodInfo(&good)
  3824. operation_time := time.Now().Unix()
  3825. creater := c.GetAdminUserInfo().AdminUser.Id
  3826. //创建退库单
  3827. timeStr := time.Now().Format("2006-01-02")
  3828. timeArr := strings.Split(timeStr, "-")
  3829. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  3830. total = total + 1
  3831. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3832. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3833. cancelStock := models.CancelStock{
  3834. OrderNumber: orderNumber,
  3835. OperaTime: operation_time,
  3836. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3837. Creater: creater,
  3838. Ctime: time.Now().Unix(),
  3839. Status: 1,
  3840. ReturnTime: item.RecordDate,
  3841. Type: 1,
  3842. StorehouseId: houseConfig.StorehouseOutInfo,
  3843. IsCheck: 1,
  3844. }
  3845. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  3846. if msgerrkonde == gorm.ErrRecordNotFound {
  3847. service.AddSigleCancelStock(&cancelStock)
  3848. }
  3849. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  3850. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3851. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3852. //查询该耗材是否出库
  3853. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  3854. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3855. deaerler, _ := service.GetDealerById(info.Dealer)
  3856. var total_count int64
  3857. count, _ := strconv.ParseInt(item.Count, 10, 64)
  3858. total_count += count
  3859. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3860. var flush_count int64
  3861. for _, it := range goodList {
  3862. flush_count += it.StockCount
  3863. }
  3864. fmt.Println("历史出库数据", info.Count)
  3865. fmt.Println("出库数量", total_count)
  3866. if info.ID > 0 {
  3867. cancelStockInfo := models.CancelStockInfo{
  3868. GoodId: item.ProjectId,
  3869. CancelStockId: cancel.ID,
  3870. GoodTypeId: good.GoodTypeId,
  3871. Count: prescribingNumber,
  3872. Price: info.Price,
  3873. Total: 0,
  3874. ProductDate: info.ProductDate,
  3875. ExpiryDate: info.ExpiryDate,
  3876. Ctime: time.Now().Unix(),
  3877. Status: 1,
  3878. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  3879. OrderNumber: cancel.OrderNumber,
  3880. Type: 0,
  3881. Dealer: deaerler.DealerName,
  3882. Manufacturer: manufacturer.ManufacturerName,
  3883. Number: info.Number,
  3884. RegisterAccount: "",
  3885. Remark: "",
  3886. WarehouseInfoId: info.WarehouseInfotId,
  3887. PatientId: info.PatientId,
  3888. RecordDate: info.SysRecordTime,
  3889. StorehouseId: houseConfig.StorehouseOutInfo,
  3890. IsCheck: 1,
  3891. }
  3892. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3893. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  3894. //查询出库数量
  3895. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  3896. //出库数据 大于 退库数量
  3897. if len(list) > 0 {
  3898. for _, it := range list {
  3899. //回退库存
  3900. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3901. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3902. var flush_count_one int64
  3903. for _, it := range goodList {
  3904. flush_count_one += it.StockCount
  3905. }
  3906. //查询该批次是否有退库数据
  3907. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  3908. creater := c.GetAdminUserInfo().AdminUser.Id
  3909. flow := models.VmStockFlow{
  3910. WarehousingId: it.WarehouseInfotId,
  3911. GoodId: it.GoodId,
  3912. Number: it.Number,
  3913. LicenseNumber: it.LicenseNumber,
  3914. Count: it.Count,
  3915. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3916. PatientId: it.PatientId,
  3917. SystemTime: it.SysRecordTime,
  3918. ConsumableType: 7,
  3919. IsSys: 0,
  3920. WarehousingOrder: "",
  3921. WarehouseOutId: it.WarehouseOutId,
  3922. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3923. IsEdit: 0,
  3924. CancelStockId: cancel.ID,
  3925. CancelOrderNumber: cancel.OrderNumber,
  3926. Manufacturer: manufacturer.ID,
  3927. Dealer: 0,
  3928. Creator: creater,
  3929. UpdateCreator: 0,
  3930. Status: 1,
  3931. Ctime: time.Now().Unix(),
  3932. Mtime: 0,
  3933. Price: it.Price,
  3934. WarehousingDetailId: it.WarehouseInfotId,
  3935. WarehouseOutDetailId: it.ID,
  3936. CancelOutDetailId: cancelInfo.ID,
  3937. ProductDate: it.ProductDate,
  3938. ExpireDate: it.ExpiryDate,
  3939. StorehouseId: houseConfig.StorehouseOutInfo,
  3940. OverCount: flush_count_one,
  3941. }
  3942. service.CreateStockFlowOne(flow)
  3943. //if flow.ID > 0 {
  3944. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  3945. //}
  3946. }
  3947. }
  3948. //flow := models.VmStockFlow{
  3949. // WarehousingId: info.WarehouseInfotId,
  3950. // GoodId: item.ProjectId,
  3951. // Number: info.Number,
  3952. // LicenseNumber: info.LicenseNumber,
  3953. // Count: prescribingNumber,
  3954. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3955. // PatientId: item.PatientId,
  3956. // SystemTime: info.SysRecordTime,
  3957. // ConsumableType: 7,
  3958. // IsSys: 0,
  3959. // WarehousingOrder: "",
  3960. // WarehouseOutId: info.WarehouseOutId,
  3961. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3962. // IsEdit: 0,
  3963. // CancelStockId: cancel.ID,
  3964. // CancelOrderNumber: cancel.OrderNumber,
  3965. // Manufacturer: manufacturer.ID,
  3966. // Dealer: 0,
  3967. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  3968. // UpdateCreator: 0,
  3969. // Status: 1,
  3970. // Ctime: time.Now().Unix(),
  3971. // Mtime: 0,
  3972. // Price: info.Price,
  3973. // WarehousingDetailId: info.WarehouseInfotId,
  3974. // WarehouseOutDetailId: info.ID,
  3975. // CancelOutDetailId: cancelInfo.ID,
  3976. // ProductDate: info.ProductDate,
  3977. // ExpireDate: info.ExpiryDate,
  3978. // StorehouseId: houseConfig.StorehouseOutInfo,
  3979. // OverCount: flush_count,
  3980. //}
  3981. //service.CreateStockFlowOne(flow)
  3982. //退库数量增加
  3983. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  3984. //出库数量减少
  3985. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  3986. //查询已出库数量
  3987. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  3988. if prescribingNumber < dialysisInfo.Count {
  3989. //改变数量
  3990. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  3991. }
  3992. if prescribingNumber >= dialysisInfo.Count {
  3993. //删除出库表
  3994. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  3995. }
  3996. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  3997. var flush_count_one int64
  3998. for _, it := range goodList {
  3999. flush_count_one += it.StockCount
  4000. }
  4001. //更新库存
  4002. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4003. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4004. //更新基础库库存
  4005. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4006. }
  4007. }
  4008. }
  4009. }
  4010. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4011. fmt.Println(err)
  4012. }
  4013. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4014. fmt.Println(err)
  4015. if len(advices) > 0 {
  4016. for _, item := range advices {
  4017. redis := service.RedisClient()
  4018. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4019. redis.Set(keyFive, "", time.Second)
  4020. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4021. redis.Set(keyOne, "", time.Second)
  4022. redis.Close()
  4023. }
  4024. }
  4025. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4026. if len(advices) > 0 {
  4027. for _, item := range advices {
  4028. creater := c.GetAdminUserInfo().AdminUser.Id
  4029. service.DrugAutoAddCancelInfo(item, creater)
  4030. }
  4031. }
  4032. } else {
  4033. if drugOutConfig.IsOpen == 1 {
  4034. if len(advices) > 0 {
  4035. for _, item := range advices {
  4036. creater := c.GetAdminUserInfo().AdminUser.Id
  4037. service.DrugAutoAddCancelInfo(item, creater)
  4038. }
  4039. }
  4040. } else {
  4041. if len(advices) > 0 {
  4042. for _, item := range advices {
  4043. creater := c.GetAdminUserInfo().AdminUser.Id
  4044. service.DrugAutoAddCancelInfo(item, creater)
  4045. }
  4046. }
  4047. }
  4048. }
  4049. c.ServeSuccessJSON(map[string]interface{}{
  4050. "msg": "删除成功",
  4051. })
  4052. return
  4053. }
  4054. func (c *HisApiController) DeleteDoctorAdvice() {
  4055. id, _ := c.GetInt64("id")
  4056. advice, _ := service.GetHisDoctorAdvicesById(id)
  4057. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4058. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4059. //已收费和已发药的限制逻辑
  4060. isCharge := false
  4061. isMedicine := false
  4062. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4063. //获取今天该患者所有处方,判断是否发药或者收费
  4064. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4065. for _, item := range new_prescriptions {
  4066. if item.IsMedicine == 1 {
  4067. isMedicine = true
  4068. }
  4069. }
  4070. for _, item := range new_prescriptions {
  4071. if item.OrderStatus == 4 {
  4072. isCharge = true
  4073. }
  4074. }
  4075. if isMedicine {
  4076. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4077. return
  4078. }
  4079. if isCharge {
  4080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4081. return
  4082. }
  4083. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4084. for _, item := range advices {
  4085. if item.IsMedicine == 1 {
  4086. isMedicine = true
  4087. }
  4088. }
  4089. if isMedicine {
  4090. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4091. return
  4092. }
  4093. if new_prescription.ID > 0 {
  4094. if new_prescription.OrderStatus == 2 {
  4095. isCharge = true
  4096. }
  4097. }
  4098. if isCharge {
  4099. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4100. return
  4101. }
  4102. //已收费和已发药的限制逻辑
  4103. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4104. redis := service.RedisClient()
  4105. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4106. redis.Set(keyFive, "", time.Second)
  4107. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4108. redis.Set(keyOne, "", time.Second)
  4109. defer redis.Close()
  4110. if err == nil {
  4111. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4112. //查询是否在处方中出库
  4113. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4114. if openConfig.IsOpen != 1 {
  4115. //判断该医嘱是否执行了
  4116. if advice.ExecutionState == 1 {
  4117. creater := c.GetAdminUserInfo().AdminUser.Id
  4118. service.DrugAutoAddCancelInfo(&advice, creater)
  4119. }
  4120. }
  4121. //开启保存处方扣减功能
  4122. if openConfig.IsOpen == 1 {
  4123. creater := c.GetAdminUserInfo().AdminUser.Id
  4124. service.DrugAutoAddCancelInfo(&advice, creater)
  4125. }
  4126. } else {
  4127. if drugOutConfig.IsOpen == 1 {
  4128. //查询是否在处方中出库
  4129. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4130. if openConfig.IsOpen != 1 {
  4131. //判断该医嘱是否执行了
  4132. if advice.ExecutionState == 1 {
  4133. creater := c.GetAdminUserInfo().AdminUser.Id
  4134. service.DrugAutoAddCancelInfo(&advice, creater)
  4135. }
  4136. }
  4137. //开启保存处方扣减功能
  4138. if openConfig.IsOpen == 1 {
  4139. creater := c.GetAdminUserInfo().AdminUser.Id
  4140. service.DrugAutoAddCancelInfo(&advice, creater)
  4141. }
  4142. } else {
  4143. //判断该医嘱是否执行了
  4144. if advice.ExecutionState == 1 {
  4145. creater := c.GetAdminUserInfo().AdminUser.Id
  4146. service.DrugAutoAddCancelInfo(&advice, creater)
  4147. }
  4148. }
  4149. }
  4150. c.ServeSuccessJSON(map[string]interface{}{
  4151. "msg": "删除成功",
  4152. })
  4153. return
  4154. } else {
  4155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4156. return
  4157. }
  4158. }
  4159. func (c *HisApiController) DeleteProject() {
  4160. id, _ := c.GetInt64("id")
  4161. adminInfo := c.GetAdminUserInfo()
  4162. project, _ := service.GetHisProjectByID(id)
  4163. // var consumable models.DialysisBeforePrepare
  4164. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4165. //耗材保存处方出库
  4166. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4167. isCharge := false
  4168. isMedicine := false
  4169. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4170. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4171. for _, item := range new_prescriptions {
  4172. if item.IsMedicine == 1 {
  4173. isMedicine = true
  4174. }
  4175. }
  4176. for _, item := range new_prescriptions {
  4177. if item.OrderStatus == 4 {
  4178. isCharge = true
  4179. }
  4180. }
  4181. if isMedicine {
  4182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4183. return
  4184. }
  4185. if isCharge {
  4186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4187. return
  4188. }
  4189. if new_prescription.ID > 0 {
  4190. if new_prescription.OrderStatus == 2 {
  4191. isCharge = true
  4192. }
  4193. }
  4194. if isCharge {
  4195. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4196. return
  4197. }
  4198. service.DeletePrintInfo(id)
  4199. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4200. label.Status = 0
  4201. service.CreateHisLabelRecord(&label)
  4202. fmt.Println(goodOutConfig.IsOpen)
  4203. if goodOutConfig.IsOpen != 1 {
  4204. if stockConfig.IsOpen == 1 {
  4205. if project.Type == 2 {
  4206. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4207. fmt.Println(err)
  4208. }
  4209. if project.Type == 3 && project.IsOut == 1 {
  4210. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4211. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4212. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4213. operation_time := time.Now().Unix()
  4214. creater := adminInfo.AdminUser.Id
  4215. //创建退库单
  4216. timeStr := time.Now().Format("2006-01-02")
  4217. timeArr := strings.Split(timeStr, "-")
  4218. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4219. total = total + 1
  4220. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4221. cancelStock := models.CancelStock{
  4222. OrderNumber: orderNumber,
  4223. OperaTime: operation_time,
  4224. OrgId: adminInfo.CurrentOrgId,
  4225. Creater: creater,
  4226. Ctime: time.Now().Unix(),
  4227. Status: 1,
  4228. ReturnTime: project.RecordDate,
  4229. Type: 1,
  4230. StorehouseId: houseConfig.StorehouseOutInfo,
  4231. IsCheck: 1,
  4232. }
  4233. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4234. if msgerrkonde == gorm.ErrRecordNotFound {
  4235. service.AddSigleCancelStock(&cancelStock)
  4236. }
  4237. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4238. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4239. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4240. //查询是否有出库
  4241. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4242. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4243. deaerler, _ := service.GetDealerById(info.Dealer)
  4244. if info.ID > 0 {
  4245. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4246. if info.Count >= prescribingNumber {
  4247. cancelStockInfo := models.CancelStockInfo{
  4248. GoodId: project.ProjectId,
  4249. CancelStockId: cancel.ID,
  4250. GoodTypeId: good.GoodTypeId,
  4251. Count: prescribingNumber,
  4252. Price: info.Price,
  4253. Total: 0,
  4254. ProductDate: info.ProductDate,
  4255. ExpiryDate: info.ExpiryDate,
  4256. Ctime: time.Now().Unix(),
  4257. Status: 1,
  4258. OrgId: adminInfo.CurrentOrgId,
  4259. OrderNumber: cancel.OrderNumber,
  4260. Type: 0,
  4261. Dealer: deaerler.DealerName,
  4262. Manufacturer: manufacturer.ManufacturerName,
  4263. Number: info.Number,
  4264. RegisterAccount: "",
  4265. Remark: "",
  4266. WarehouseInfoId: info.WarehouseInfotId,
  4267. PatientId: info.PatientId,
  4268. RecordDate: info.SysRecordTime,
  4269. StorehouseId: houseConfig.StorehouseOutInfo,
  4270. IsCheck: 1,
  4271. }
  4272. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4273. //回退库存
  4274. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  4275. //退库数量增加
  4276. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4277. //出库数量减少
  4278. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4279. }
  4280. if info.Count < prescribingNumber {
  4281. cancelStockInfo := models.CancelStockInfo{
  4282. GoodId: project.ProjectId,
  4283. CancelStockId: cancel.ID,
  4284. GoodTypeId: good.GoodTypeId,
  4285. Count: info.Count,
  4286. Price: info.Price,
  4287. Total: 0,
  4288. ProductDate: info.ProductDate,
  4289. ExpiryDate: info.ExpiryDate,
  4290. Ctime: time.Now().Unix(),
  4291. Status: 1,
  4292. OrgId: adminInfo.CurrentOrgId,
  4293. OrderNumber: cancel.OrderNumber,
  4294. Type: 0,
  4295. Dealer: deaerler.DealerName,
  4296. Manufacturer: manufacturer.ManufacturerName,
  4297. Number: info.Number,
  4298. RegisterAccount: "",
  4299. Remark: "",
  4300. WarehouseInfoId: info.WarehouseInfotId,
  4301. PatientId: info.PatientId,
  4302. RecordDate: info.SysRecordTime,
  4303. StorehouseId: houseConfig.StorehouseOutInfo,
  4304. IsCheck: 1,
  4305. }
  4306. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4307. //回退库存
  4308. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4309. //退库数量增加
  4310. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4311. //出库数量减少
  4312. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  4313. }
  4314. //查询剩余库存
  4315. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4316. var over_count int64
  4317. for _, it := range goodList {
  4318. over_count += it.StockCount
  4319. }
  4320. //出库数据 大于 退库数量
  4321. if info.Count >= prescribingNumber {
  4322. flow := models.VmStockFlow{
  4323. WarehousingId: info.WarehouseInfotId,
  4324. GoodId: project.ProjectId,
  4325. Number: info.Number,
  4326. LicenseNumber: info.LicenseNumber,
  4327. Count: prescribingNumber,
  4328. UserOrgId: adminInfo.CurrentOrgId,
  4329. PatientId: project.PatientId,
  4330. SystemTime: info.SysRecordTime,
  4331. ConsumableType: 7,
  4332. IsSys: 0,
  4333. WarehousingOrder: "",
  4334. WarehouseOutId: info.WarehouseOutId,
  4335. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4336. IsEdit: 0,
  4337. CancelStockId: cancel.ID,
  4338. CancelOrderNumber: cancel.OrderNumber,
  4339. Manufacturer: manufacturer.ID,
  4340. Dealer: 0,
  4341. Creator: adminInfo.AdminUser.Id,
  4342. UpdateCreator: 0,
  4343. Status: 1,
  4344. Ctime: time.Now().Unix(),
  4345. Mtime: 0,
  4346. Price: info.Price,
  4347. WarehousingDetailId: info.WarehouseInfotId,
  4348. WarehouseOutDetailId: info.ID,
  4349. CancelOutDetailId: cancelInfo.ID,
  4350. ProductDate: info.ProductDate,
  4351. ExpireDate: info.ExpiryDate,
  4352. StorehouseId: houseConfig.StorehouseOutInfo,
  4353. OverCount: over_count,
  4354. }
  4355. service.CreateStockFlowOne(flow)
  4356. }
  4357. //出库数据小于退库数据
  4358. if info.Count < prescribingNumber {
  4359. flow := models.VmStockFlow{
  4360. WarehousingId: info.WarehouseInfotId,
  4361. GoodId: project.ProjectId,
  4362. Number: info.Number,
  4363. LicenseNumber: info.LicenseNumber,
  4364. Count: info.Count,
  4365. UserOrgId: adminInfo.CurrentOrgId,
  4366. PatientId: project.PatientId,
  4367. SystemTime: info.SysRecordTime,
  4368. ConsumableType: 7,
  4369. IsSys: 0,
  4370. WarehousingOrder: "",
  4371. WarehouseOutId: info.WarehouseOutId,
  4372. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4373. IsEdit: 0,
  4374. CancelStockId: cancel.ID,
  4375. CancelOrderNumber: cancel.OrderNumber,
  4376. Manufacturer: manufacturer.ID,
  4377. Dealer: 0,
  4378. Creator: adminInfo.AdminUser.Id,
  4379. UpdateCreator: 0,
  4380. Status: 1,
  4381. Ctime: time.Now().Unix(),
  4382. Mtime: 0,
  4383. Price: info.Price,
  4384. WarehousingDetailId: info.WarehouseInfotId,
  4385. WarehouseOutDetailId: info.ID,
  4386. CancelOutDetailId: cancelInfo.ID,
  4387. ProductDate: info.ProductDate,
  4388. ExpireDate: info.ExpiryDate,
  4389. StorehouseId: houseConfig.StorehouseOutInfo,
  4390. OverCount: over_count,
  4391. }
  4392. service.CreateStockFlowOne(flow)
  4393. }
  4394. //查询已出库数量
  4395. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4396. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  4397. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  4398. if prescribingNumber < dialysisInfo.Count {
  4399. //改变数量
  4400. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4401. }
  4402. if prescribingNumber >= dialysisInfo.Count {
  4403. //删除出库表
  4404. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4405. }
  4406. //更新剩余库存
  4407. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4408. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4409. var total_count_one int64
  4410. for _, it := range stockList {
  4411. total_count_one += it.StockCount
  4412. }
  4413. //基础库插入数据
  4414. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4415. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4416. var flush_count int64
  4417. for _, it := range goodListOne {
  4418. flush_count += it.StockCount
  4419. }
  4420. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4421. if errs != nil {
  4422. goodErrcode := models.XtGoodErrcode{
  4423. UserOrgId: project.UserOrgId,
  4424. Errcode: "手动出库更新剩余出库失败",
  4425. GoodId: project.ProjectId,
  4426. Status: 1,
  4427. Ctime: time.Now().Unix(),
  4428. Mtime: 0,
  4429. Count: 0,
  4430. StockCount: 0,
  4431. Creater: creater,
  4432. BatchNumberId: 0,
  4433. WarehouseOutId: 0,
  4434. }
  4435. service.CreateGoodErrcode(goodErrcode)
  4436. }
  4437. }
  4438. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4439. fmt.Println(err)
  4440. } else {
  4441. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4442. fmt.Println(err)
  4443. }
  4444. } else {
  4445. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4446. fmt.Println(err)
  4447. }
  4448. }
  4449. //保存处方出库
  4450. if goodOutConfig.IsOpen == 1 {
  4451. if project.Type == 3 {
  4452. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4453. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4454. f_count, _ := strconv.ParseFloat(project.Count, 64)
  4455. operation_time := time.Now().Unix()
  4456. creater := adminInfo.AdminUser.Id
  4457. //创建退库单
  4458. timeStr := time.Now().Format("2006-01-02")
  4459. timeArr := strings.Split(timeStr, "-")
  4460. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  4461. total = total + 1
  4462. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4463. cancelStock := models.CancelStock{
  4464. OrderNumber: orderNumber,
  4465. OperaTime: operation_time,
  4466. OrgId: adminInfo.CurrentOrgId,
  4467. Creater: creater,
  4468. Ctime: time.Now().Unix(),
  4469. Status: 1,
  4470. ReturnTime: project.RecordDate,
  4471. Type: 1,
  4472. StorehouseId: houseConfig.StorehouseOutInfo,
  4473. IsCheck: 1,
  4474. }
  4475. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  4476. if msgerrkonde == gorm.ErrRecordNotFound {
  4477. service.AddSigleCancelStock(&cancelStock)
  4478. }
  4479. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  4480. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4481. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4482. //获取出库数据
  4483. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  4484. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4485. deaerler, _ := service.GetDealerById(info.Dealer)
  4486. if info.ID > 0 {
  4487. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  4488. if info.Count >= prescribingNumber {
  4489. cancelStockInfo := models.CancelStockInfo{
  4490. GoodId: project.ProjectId,
  4491. CancelStockId: cancel.ID,
  4492. GoodTypeId: good.GoodTypeId,
  4493. Count: prescribingNumber,
  4494. Price: info.Price,
  4495. Total: 0,
  4496. ProductDate: info.ProductDate,
  4497. ExpiryDate: info.ExpiryDate,
  4498. Ctime: time.Now().Unix(),
  4499. Status: 1,
  4500. OrgId: adminInfo.CurrentOrgId,
  4501. OrderNumber: cancel.OrderNumber,
  4502. Type: 0,
  4503. Dealer: deaerler.DealerName,
  4504. Manufacturer: manufacturer.ManufacturerName,
  4505. Number: info.Number,
  4506. RegisterAccount: "",
  4507. Remark: "",
  4508. WarehouseInfoId: info.WarehouseInfotId,
  4509. PatientId: info.PatientId,
  4510. RecordDate: info.SysRecordTime,
  4511. StorehouseId: houseConfig.StorehouseOutInfo,
  4512. IsCheck: 1,
  4513. }
  4514. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4515. //退库数量增加
  4516. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  4517. //出库数量减少
  4518. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  4519. }
  4520. if info.Count < prescribingNumber {
  4521. cancelStockInfo := models.CancelStockInfo{
  4522. GoodId: project.ProjectId,
  4523. CancelStockId: cancel.ID,
  4524. GoodTypeId: good.GoodTypeId,
  4525. Count: prescribingNumber,
  4526. Price: info.Price,
  4527. Total: 0,
  4528. ProductDate: info.ProductDate,
  4529. ExpiryDate: info.ExpiryDate,
  4530. Ctime: time.Now().Unix(),
  4531. Status: 1,
  4532. OrgId: adminInfo.CurrentOrgId,
  4533. OrderNumber: cancel.OrderNumber,
  4534. Type: 0,
  4535. Dealer: deaerler.DealerName,
  4536. Manufacturer: manufacturer.ManufacturerName,
  4537. Number: info.Number,
  4538. RegisterAccount: "",
  4539. Remark: "",
  4540. WarehouseInfoId: info.WarehouseInfotId,
  4541. PatientId: info.PatientId,
  4542. RecordDate: info.SysRecordTime,
  4543. StorehouseId: houseConfig.StorehouseOutInfo,
  4544. IsCheck: 1,
  4545. }
  4546. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4547. //回退库存
  4548. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  4549. }
  4550. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4551. var over_count int64
  4552. for _, it := range goodList {
  4553. over_count += it.StockCount
  4554. }
  4555. //查询出库数量
  4556. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  4557. //出库数据 大于 退库数量
  4558. if len(list) > 0 {
  4559. for _, it := range list {
  4560. //回退库存
  4561. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4562. //退库数量增加
  4563. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  4564. //出库数量减少
  4565. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  4566. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4567. var over_count_one int64
  4568. for _, it := range goodList {
  4569. over_count_one += it.StockCount
  4570. }
  4571. //查询该批次是否有退库数据
  4572. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  4573. flow := models.VmStockFlow{
  4574. WarehousingId: it.WarehouseInfotId,
  4575. GoodId: it.GoodId,
  4576. Number: it.Number,
  4577. LicenseNumber: it.LicenseNumber,
  4578. Count: it.Count,
  4579. UserOrgId: adminInfo.CurrentOrgId,
  4580. PatientId: it.PatientId,
  4581. SystemTime: it.SysRecordTime,
  4582. ConsumableType: 7,
  4583. IsSys: 0,
  4584. WarehousingOrder: "",
  4585. WarehouseOutId: it.WarehouseOutId,
  4586. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4587. IsEdit: 0,
  4588. CancelStockId: cancel.ID,
  4589. CancelOrderNumber: cancel.OrderNumber,
  4590. Manufacturer: manufacturer.ID,
  4591. Dealer: 0,
  4592. Creator: adminInfo.AdminUser.Id,
  4593. UpdateCreator: 0,
  4594. Status: 1,
  4595. Ctime: time.Now().Unix(),
  4596. Mtime: 0,
  4597. Price: it.Price,
  4598. WarehousingDetailId: it.WarehouseInfotId,
  4599. WarehouseOutDetailId: it.ID,
  4600. CancelOutDetailId: cancelInfo.ID,
  4601. ProductDate: it.ProductDate,
  4602. ExpireDate: it.ExpiryDate,
  4603. StorehouseId: houseConfig.StorehouseOutInfo,
  4604. OverCount: over_count_one,
  4605. }
  4606. service.CreateStockFlowOne(flow)
  4607. }
  4608. }
  4609. //查询已出库数量
  4610. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  4611. if prescribingNumber < dialysisInfo.Count {
  4612. //改变数量
  4613. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  4614. }
  4615. if prescribingNumber >= dialysisInfo.Count {
  4616. //删除出库表
  4617. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  4618. }
  4619. //更新剩余库存
  4620. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  4621. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  4622. var total_count_one int64
  4623. for _, it := range stockList {
  4624. total_count_one += it.StockCount
  4625. }
  4626. //基础库插入数据
  4627. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  4628. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  4629. var flush_count int64
  4630. for _, it := range goodListOne {
  4631. flush_count += it.StockCount
  4632. }
  4633. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  4634. if errs != nil {
  4635. goodErrcode := models.XtGoodErrcode{
  4636. UserOrgId: project.UserOrgId,
  4637. Errcode: "手动出库更新剩余出库失败",
  4638. GoodId: project.ProjectId,
  4639. Status: 1,
  4640. Ctime: time.Now().Unix(),
  4641. Mtime: 0,
  4642. Count: 0,
  4643. StockCount: 0,
  4644. Creater: creater,
  4645. BatchNumberId: 0,
  4646. WarehouseOutId: 0,
  4647. }
  4648. service.CreateGoodErrcode(goodErrcode)
  4649. }
  4650. }
  4651. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4652. fmt.Println(err)
  4653. } else {
  4654. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  4655. fmt.Println(err)
  4656. }
  4657. }
  4658. c.ServeSuccessJSON(map[string]interface{}{
  4659. "msg": "删除成功",
  4660. })
  4661. return
  4662. }
  4663. func (c *HisApiController) CreateHisAdditionalCharge() {
  4664. his_patient_id, _ := c.GetInt64("his_patient_id")
  4665. patient_id, _ := c.GetInt64("patient_id")
  4666. record_date := c.GetString("record_date")
  4667. timeLayout := "2006-01-02"
  4668. loc, _ := time.LoadLocation("Local")
  4669. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4670. if err != nil {
  4671. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4672. return
  4673. }
  4674. adminInfo := c.GetAdminUserInfo()
  4675. recordDateTime := theTime.Unix()
  4676. dataBody := make(map[string]interface{}, 0)
  4677. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4678. if err != nil {
  4679. utils.ErrorLog(err.Error())
  4680. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4681. return
  4682. }
  4683. var additions []*models.HisAdditionalCharge
  4684. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  4685. additions, _ := dataBody["addition"].([]interface{})
  4686. if len(additions) > 0 {
  4687. for _, item := range additions {
  4688. items := item.(map[string]interface{})
  4689. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  4690. utils.ErrorLog("item_id")
  4691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4692. return
  4693. }
  4694. item_id := int64(items["item_id"].(float64))
  4695. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  4696. utils.ErrorLog("item_name")
  4697. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4698. return
  4699. }
  4700. item_name := items["item_name"].(string)
  4701. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  4702. utils.ErrorLog("price")
  4703. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4704. return
  4705. }
  4706. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  4707. ctime := time.Now().Unix()
  4708. additional := &models.HisAdditionalCharge{
  4709. PatientId: patient_id,
  4710. HisPatientId: his_patient_id,
  4711. UserOrgId: adminInfo.CurrentOrgId,
  4712. RecordDate: recordDateTime,
  4713. CreatedTime: ctime,
  4714. UpdatedTime: ctime,
  4715. Modifier: adminInfo.AdminUser.Id,
  4716. Creator: adminInfo.AdminUser.Id,
  4717. Price: price,
  4718. ItemName: item_name,
  4719. ItemId: item_id,
  4720. Status: 1,
  4721. }
  4722. additions = append(additions, additional)
  4723. }
  4724. }
  4725. }
  4726. for _, item := range additions {
  4727. service.CreateAddtionalCharge(item)
  4728. }
  4729. c.ServeSuccessJSON(map[string]interface{}{
  4730. "msg": "创建成功",
  4731. })
  4732. }
  4733. func (c *HisApiController) CreateHisPatientCaseHistory() {
  4734. blood_fat := c.GetString("blood_fat")
  4735. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  4736. blood_sugar := c.GetString("blood_sugar")
  4737. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  4738. chief_conplaint := c.GetString("chief_conplaint")
  4739. dbp := c.GetString("dbp")
  4740. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  4741. delivery_way, _ := c.GetInt64("delivery_way")
  4742. diagnostic := c.GetString("diagnostic")
  4743. family_history := c.GetString("family_history")
  4744. height := c.GetString("height")
  4745. history_of_present_illness := c.GetString("history_of_present_illness")
  4746. is_infect, _ := c.GetInt64("is_infect")
  4747. past_history := c.GetString("past_history")
  4748. patient_id, _ := c.GetInt64("patient_id")
  4749. his_patient_id, _ := c.GetInt64("his_patient_id")
  4750. personal_history := c.GetString("personal_history")
  4751. pulse := c.GetString("pulse")
  4752. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  4753. sbp := c.GetString("sbp")
  4754. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  4755. heightfloat, _ := strconv.ParseFloat(height, 64)
  4756. sicktype := c.GetString("sick_type")
  4757. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  4758. symptom := c.GetString("symptom")
  4759. sick_date := c.GetString("sick_date")
  4760. temperatures := c.GetString("temperature")
  4761. temperature, _ := strconv.ParseFloat(temperatures, 64)
  4762. record_date := c.GetString("record_date")
  4763. breathing := c.GetString("breathing")
  4764. doctor_advice := c.GetString("doctor_advice")
  4765. remark := c.GetString("remark")
  4766. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  4767. sick, _ := c.GetInt64("sick")
  4768. diagnose, _ := c.GetInt64("diagnose")
  4769. //id, _ := c.GetInt64("id")
  4770. timeLayout := "2006-01-02"
  4771. loc, _ := time.LoadLocation("Local")
  4772. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4773. allergic_history := c.GetString("allergic_history")
  4774. if err != nil {
  4775. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4776. return
  4777. }
  4778. recordDateTime := theTime.Unix()
  4779. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  4780. if err != nil {
  4781. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4782. return
  4783. }
  4784. sickTimes := sickTime.Unix()
  4785. ctime := time.Now().Unix()
  4786. primary_disease := c.GetString("primary_disease")
  4787. confirm_failure_date := c.GetString("confirm_failure_date")
  4788. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  4789. drug_allergy_history := c.GetString("drug_allergy_history")
  4790. physical_examination := c.GetString("physical_examination")
  4791. special_inspection := c.GetString("special_inspection")
  4792. lab_apparatus := c.GetString("lab_apparatus")
  4793. caseHistory := models.HisPatientCaseHistory{
  4794. HisPatientId: his_patient_id,
  4795. PatientId: patient_id,
  4796. Temperature: temperature,
  4797. BloodSugar: bloodsugarfloat,
  4798. Pulse: pulsefloat,
  4799. Sbp: sbpfloat,
  4800. Dbp: dbpfloat,
  4801. Height: heightfloat,
  4802. BloodFat: bloodfatfloat,
  4803. SickType: sick_type,
  4804. Symptom: symptom,
  4805. SickDate: sickTimes,
  4806. IsInfect: is_infect,
  4807. HistoryOfPresentIllness: history_of_present_illness,
  4808. PastHistory: past_history,
  4809. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  4810. ChiefConplaint: chief_conplaint,
  4811. PersonalHistory: personal_history,
  4812. FamilyHistory: family_history,
  4813. Diagnostic: diagnostic,
  4814. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4815. Status: 1,
  4816. Ctime: ctime,
  4817. Mtime: ctime,
  4818. RecordDate: recordDateTime,
  4819. DeliveryWay: delivery_way,
  4820. Breathing: breathingfloat,
  4821. DoctorAdvice: doctor_advice,
  4822. Remark: remark,
  4823. Sick: sick,
  4824. Diagnose: diagnose,
  4825. AllergicHistory: allergic_history,
  4826. PrimaryDisease: primary_disease,
  4827. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  4828. DrugAllergyHistory: drug_allergy_history,
  4829. PhysicalExamination: physical_examination,
  4830. SpecialInspection: special_inspection,
  4831. LabApparatus: lab_apparatus,
  4832. }
  4833. //查询该患者是否有病历
  4834. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  4835. if errcodes == gorm.ErrRecordNotFound {
  4836. err = service.SaveHisPatientCaseHistory(&caseHistory)
  4837. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4838. if err != nil {
  4839. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4840. return
  4841. }
  4842. c.ServeSuccessJSON(map[string]interface{}{
  4843. "caseHistory": caseHistory,
  4844. "historyInfo": historyInfo,
  4845. })
  4846. return
  4847. } else if errcodes == nil {
  4848. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  4849. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  4850. if err != nil {
  4851. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4852. return
  4853. }
  4854. c.ServeSuccessJSON(map[string]interface{}{
  4855. "caseHistory": caseHistory,
  4856. "historyInfo": historyInfo,
  4857. })
  4858. }
  4859. //查询该患者是否有病历
  4860. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  4861. //if errcode == gorm.ErrRecordNotFound {
  4862. // err = service.SaveHisPatientCaseHistory(caseHistory)
  4863. // if err != nil {
  4864. // c.ServeSuccessJSON(map[string]interface{}{
  4865. // "msg": "保存成功",
  4866. // })
  4867. // }
  4868. //} else if errcode == nil {
  4869. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  4870. // return
  4871. //}
  4872. }
  4873. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  4874. patient_id, _ := c.GetInt64("patient_id", 0)
  4875. adminUser := c.GetAdminUserInfo()
  4876. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  4877. c.ServeSuccessJSON(map[string]interface{}{
  4878. "list": caseHistorys,
  4879. })
  4880. }
  4881. func (c *HisApiController) GetHisPatientCaseHistory() {
  4882. record_date, _ := c.GetInt64("record_date", 0)
  4883. patient_id, _ := c.GetInt64("patient_id", 0)
  4884. admin := c.GetAdminUserInfo()
  4885. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  4886. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  4887. c.ServeSuccessJSON(map[string]interface{}{
  4888. "info": info,
  4889. "case_history": case_history,
  4890. })
  4891. }
  4892. func (c *HisApiController) CreateCaseHistoryTemplate() {
  4893. template_name := c.GetString("template_name")
  4894. template_remark := c.GetString("template_remark")
  4895. doctor := c.GetAdminUserInfo().AdminUser.Id
  4896. diagnostic := c.GetString("diagnostic")
  4897. chief_conplaint := c.GetString("chief_conplain")
  4898. history_of_present_illness := c.GetString("history_of_present_illness")
  4899. past_history := c.GetString("past_history")
  4900. personal_history := c.GetString("personal_history")
  4901. family_history := c.GetString("family_history")
  4902. user_name := c.GetString("user_name")
  4903. doctor_advice := c.GetString("doctor_advice")
  4904. remark := c.GetString("remark")
  4905. //record_date := c.GetString("record_date")
  4906. //fmt.Println("record_date--------",record_date)
  4907. //timeLayout := "2006-01-02"
  4908. //loc, _ := time.LoadLocation("Local")
  4909. //
  4910. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4911. //if err != nil {
  4912. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4913. // return
  4914. //}
  4915. //recordDateTime := theTime.Unix()
  4916. ctime := time.Now().Unix()
  4917. template := models.HisCaseHistoryTemplate{
  4918. HistoryOfPresentIllness: history_of_present_illness,
  4919. PastHistory: past_history,
  4920. ChiefConplaint: chief_conplaint,
  4921. PersonalHistory: personal_history,
  4922. FamilyHistory: family_history,
  4923. Diagnostic: diagnostic,
  4924. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4925. Status: 1,
  4926. Ctime: ctime,
  4927. Mtime: ctime,
  4928. RecordDate: time.Now().Unix(),
  4929. TemplateName: template_name,
  4930. TemplateRemark: template_remark,
  4931. Creator: doctor,
  4932. Modifier: doctor,
  4933. UserName: user_name,
  4934. DoctorAdvice: doctor_advice,
  4935. Remark: remark,
  4936. }
  4937. err := service.SaveHisPatientCaseHistoryTemplate(template)
  4938. if err == nil {
  4939. c.ServeSuccessJSON(map[string]interface{}{
  4940. "msg": "保存成功",
  4941. })
  4942. } else {
  4943. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4944. return
  4945. }
  4946. }
  4947. func (c *HisApiController) GetCaseHistoryTemplate() {
  4948. timeLayout := "2006-01-02"
  4949. loc, _ := time.LoadLocation("Local")
  4950. keyword := c.GetString("keyword")
  4951. start_time := c.GetString("start_time")
  4952. end_time := c.GetString("end_time")
  4953. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4954. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4955. admin := c.GetAdminUserInfo()
  4956. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  4957. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  4958. c.ServeSuccessJSON(map[string]interface{}{
  4959. "template": template,
  4960. //"history": history,
  4961. })
  4962. }
  4963. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4964. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4965. utils.ErrorLog("drug_name")
  4966. return enums.ErrorCodeParamWrong
  4967. }
  4968. adviceName, _ := json["drug_name"].(string)
  4969. if len(adviceName) == 0 {
  4970. utils.ErrorLog("len(advice_name) == 0")
  4971. return enums.ErrorCodeParamWrong
  4972. }
  4973. advice.AdviceName = adviceName
  4974. adviceDesc, _ := json["advice_desc"].(string)
  4975. advice.AdviceDesc = adviceDesc
  4976. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4977. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4978. advice.DrugSpec = drugSpec
  4979. }
  4980. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4981. remark, _ := json["remark"].(string)
  4982. advice.Remark = remark
  4983. }
  4984. if json["id"] == nil {
  4985. advice.DrugId = 0
  4986. } else {
  4987. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4988. drug_id := int64(json["id"].(float64))
  4989. advice.DrugId = drug_id
  4990. }
  4991. }
  4992. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4993. advice_id := int64(json["advice_id"].(float64))
  4994. advice.ID = advice_id
  4995. if advice.ID > 0 {
  4996. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4997. if err == nil {
  4998. if hisAdvice.ID > 0 {
  4999. advice.ExecutionTime = hisAdvice.ExecutionTime
  5000. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5001. advice.ExecutionState = hisAdvice.ExecutionState
  5002. advice.CheckTime = hisAdvice.CheckTime
  5003. advice.Checker = hisAdvice.Checker
  5004. advice.CheckState = hisAdvice.CheckState
  5005. advice.StartTime = hisAdvice.StartTime
  5006. advice.FeedetlSn = hisAdvice.FeedetlSn
  5007. }
  5008. }
  5009. }
  5010. }
  5011. //
  5012. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5013. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5014. // advice.ExecutionTime = execution_time
  5015. //}
  5016. //
  5017. //
  5018. //
  5019. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5020. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5021. // advice.ExecutionStaff = execution_staff
  5022. //}
  5023. //
  5024. //
  5025. //
  5026. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5027. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5028. // advice.ExecutionState = execution_state
  5029. //}
  5030. //
  5031. //
  5032. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5033. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5034. // advice.CheckTime = check_time
  5035. //}
  5036. //
  5037. //
  5038. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5039. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5040. // advice.CheckState = check_state
  5041. //}
  5042. //
  5043. //
  5044. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5045. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5046. // advice.Checker = checker
  5047. //}
  5048. //
  5049. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5050. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5051. // advice.StartTime = start_time
  5052. //}
  5053. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5054. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5055. advice.IsSelfDrug = is_self_drug
  5056. }
  5057. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5058. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5059. drug_way_count, _ := json["drug_way_count"].(string)
  5060. advice.DrugWayCount = drug_way_count
  5061. }
  5062. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5063. drugSpecUnit, _ := json["min_unit"].(string)
  5064. advice.DrugSpecUnit = drugSpecUnit
  5065. }
  5066. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5067. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5068. advice.SingleDose = singleDose
  5069. }
  5070. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5071. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5072. advice.SingleDoseUnit = singleDoseUnit
  5073. }
  5074. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5075. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5076. advice.PrescribingNumber = prescribingNumber
  5077. }
  5078. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5079. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5080. advice.PrescribingNumberUnit = prescribingNumberUnit
  5081. }
  5082. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5083. deliveryWay, _ := json["delivery_way"].(string)
  5084. advice.DeliveryWay = deliveryWay
  5085. }
  5086. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5087. executionFrequency, _ := json["execution_frequency"].(string)
  5088. advice.ExecutionFrequency = executionFrequency
  5089. }
  5090. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5091. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5092. advice.Price = price
  5093. }
  5094. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5095. med_list_codg, _ := json["medical_insurance_number"].(string)
  5096. advice.MedListCodg = med_list_codg
  5097. }
  5098. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5099. day := int64(json["day"].(float64))
  5100. advice.Day = day
  5101. }
  5102. return 0
  5103. }
  5104. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5105. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5106. id := int64(json["id"].(float64))
  5107. project.ID = id
  5108. historyProject, _ := service.GetHisProjectByID(id)
  5109. project.FeedetlSn = historyProject.FeedetlSn
  5110. }
  5111. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5112. project_id := int64(json["project_id"].(float64))
  5113. project.ProjectId = project_id
  5114. }
  5115. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5116. // price := int64(json["price"].(float64))
  5117. // formatInt_price := strconv.FormatInt(price, 10)
  5118. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5119. // project.Price = float_price
  5120. // }
  5121. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5122. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5123. project.Price = price
  5124. }
  5125. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5126. total, _ := json["total"].(string)
  5127. project.Count = total
  5128. }
  5129. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5130. medical_code, _ := json["medical_code"].(string)
  5131. project.MedListCodg = medical_code
  5132. }
  5133. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5134. single_dose, _ := json["single_dose"].(string)
  5135. project.SingleDose = single_dose
  5136. }
  5137. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5138. delivery_way, _ := json["delivery_way"].(string)
  5139. project.DeliveryWay = delivery_way
  5140. }
  5141. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5142. execution_frequency, _ := json["execution_frequency"].(string)
  5143. project.ExecutionFrequency = execution_frequency
  5144. }
  5145. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5146. remark, _ := json["remark"].(string)
  5147. project.Remark = remark
  5148. }
  5149. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5150. day, _ := json["number_days"].(string)
  5151. project.Day = day
  5152. }
  5153. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5154. unit, _ := json["unit"].(string)
  5155. project.Unit = unit
  5156. }
  5157. return 0
  5158. }
  5159. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5160. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5161. id := int64(json["id"].(float64))
  5162. historyAddtions, _ := service.GetHisAdditionByID(id)
  5163. additionalCharge.ID = id
  5164. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5165. }
  5166. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5167. item_id := int64(json["item_id"].(float64))
  5168. additionalCharge.ItemId = item_id
  5169. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5170. if config.ID > 0 {
  5171. if len(config.Code) > 0 {
  5172. additionalCharge.MedListCodg = config.Code
  5173. }
  5174. }
  5175. }
  5176. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5177. // price := int64(json["price"].(float64))
  5178. // formatInt_price := strconv.FormatInt(price, 10)
  5179. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5180. // additionalCharge.Price = float_price
  5181. // }
  5182. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5183. // price := int64(json["price"].(float64))
  5184. // formatInt_price := strconv.FormatInt(price, 10)
  5185. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5186. // additionalCharge.Price = float_price
  5187. //}
  5188. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5189. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5190. additionalCharge.Price = price
  5191. }
  5192. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5193. count, _ := json["count"].(string)
  5194. counts, _ := strconv.ParseInt(count, 10, 64)
  5195. additionalCharge.Count = counts
  5196. }
  5197. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5198. item_name, _ := json["item_name"].(string)
  5199. additionalCharge.ItemName = item_name
  5200. }
  5201. return 0
  5202. }
  5203. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5204. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5205. utils.ErrorLog("drug_name")
  5206. return enums.ErrorCodeParamWrong
  5207. }
  5208. adviceName, _ := json["drug_name"].(string)
  5209. if len(adviceName) == 0 {
  5210. utils.ErrorLog("len(advice_name) == 0")
  5211. return enums.ErrorCodeParamWrong
  5212. }
  5213. advice.AdviceName = adviceName
  5214. adviceDesc, _ := json["advice_desc"].(string)
  5215. advice.AdviceDesc = adviceDesc
  5216. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5217. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5218. advice.DrugSpec = drugSpec
  5219. }
  5220. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5221. remark, _ := json["remark"].(string)
  5222. advice.Remark = remark
  5223. }
  5224. if json["id"] == nil {
  5225. advice.DrugId = 0
  5226. } else {
  5227. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5228. drug_id := int64(json["id"].(float64))
  5229. advice.DrugId = drug_id
  5230. }
  5231. }
  5232. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5233. groupno := int64(json["groupno"].(float64))
  5234. advice.Groupno = groupno
  5235. }
  5236. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5237. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5238. advice.IsSelfDrug = is_self_drug
  5239. }
  5240. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5241. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5242. drug_way_count, _ := json["drug_way_count"].(string)
  5243. advice.DrugWayCount = drug_way_count
  5244. }
  5245. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  5246. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  5247. advice.HospApprFlag = hosp_appr_flag
  5248. }
  5249. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5250. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5251. advice.PrescribingNumber = prescribingNumber
  5252. }
  5253. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5254. // frequency_type := int64(json["frequency_type"].(float64))
  5255. // advice.FrequencyType = frequency_type
  5256. //}
  5257. //
  5258. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5259. // day_count := int64(json["day_count"].(float64))
  5260. // advice.DayCount = day_count
  5261. //}
  5262. //
  5263. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5264. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5265. // week_day, _ := json["week_day"].(string)
  5266. // advice.WeekDay = week_day
  5267. //}
  5268. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5269. drugSpecUnit, _ := json["min_unit"].(string)
  5270. advice.DrugSpecUnit = drugSpecUnit
  5271. }
  5272. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5273. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5274. advice.SingleDose = singleDose
  5275. }
  5276. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5277. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5278. advice.SingleDoseUnit = singleDoseUnit
  5279. }
  5280. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5281. deliveryWay, _ := json["delivery_way"].(string)
  5282. advice.DeliveryWay = deliveryWay
  5283. }
  5284. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5285. executionFrequency, _ := json["execution_frequency"].(string)
  5286. advice.ExecutionFrequency = executionFrequency
  5287. }
  5288. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5289. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5290. advice.Price = price
  5291. }
  5292. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5293. med_list_codg, _ := json["medical_insurance_number"].(string)
  5294. advice.MedListCodg = med_list_codg
  5295. }
  5296. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5297. day := int64(json["day"].(float64))
  5298. advice.Day = day
  5299. }
  5300. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5301. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5302. advice.PrescribingNumberUnit = prescribingNumberUnit
  5303. }
  5304. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5305. advice_id := int64(json["advice_id"].(float64))
  5306. advice.ID = advice_id
  5307. if advice.ID > 0 {
  5308. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5309. if err == nil {
  5310. if hisAdvice.ID > 0 {
  5311. advice.ExecutionTime = hisAdvice.ExecutionTime
  5312. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5313. advice.ExecutionState = hisAdvice.ExecutionState
  5314. advice.CheckTime = hisAdvice.CheckTime
  5315. advice.Checker = hisAdvice.Checker
  5316. advice.CheckState = hisAdvice.CheckState
  5317. advice.StartTime = hisAdvice.StartTime
  5318. advice.HospApprFlag = hisAdvice.HospApprFlag
  5319. advice.IsMedicine = hisAdvice.IsMedicine
  5320. if hisAdvice.UserOrgId == 10028 {
  5321. 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 {
  5322. advice.ExecutionTime = 0
  5323. advice.ExecutionStaff = 0
  5324. advice.ExecutionState = 2
  5325. advice.CheckTime = 0
  5326. advice.Checker = 0
  5327. advice.CheckState = 2
  5328. }
  5329. } else {
  5330. 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 {
  5331. advice.ExecutionTime = 0
  5332. advice.ExecutionStaff = 0
  5333. advice.ExecutionState = 2
  5334. advice.CheckTime = 0
  5335. advice.Checker = 0
  5336. advice.CheckState = 2
  5337. }
  5338. }
  5339. //advice.Groupno = hisAdvice.Groupno
  5340. }
  5341. }
  5342. }
  5343. }
  5344. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  5345. //
  5346. //if drugStockConfig.IsOpen == 1 {
  5347. //
  5348. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5349. // if advice.ID == 0 { //医嘱不存在
  5350. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  5351. // drug.Total = drug.Total - advice.PrescribingNumber
  5352. // service.UpdateBaseDrugLib(&drug)
  5353. //
  5354. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  5355. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  5356. // drug.Total = drug.Total - num
  5357. // service.UpdateBaseDrugLib(&drug)
  5358. // }
  5359. //
  5360. // } else if advice.ID > 0 { //医嘱存在
  5361. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  5362. // var num float64
  5363. //
  5364. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  5365. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  5366. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  5367. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  5368. // drug.Total = drug.Total + num
  5369. // service.UpdateBaseDrugLib(&drug)
  5370. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  5371. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  5372. // drug.Total = drug.Total - num
  5373. // service.UpdateBaseDrugLib(&drug)
  5374. // }
  5375. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  5376. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5377. // if num2 > advice.PrescribingNumber {
  5378. // num = num2 - advice.PrescribingNumber
  5379. // drug.Total = drug.Total + num
  5380. // service.UpdateBaseDrugLib(&drug)
  5381. // } else if num2 < advice.PrescribingNumber {
  5382. // num = advice.PrescribingNumber - num2
  5383. // drug.Total = drug.Total - num
  5384. // service.UpdateBaseDrugLib(&drug)
  5385. // }
  5386. //
  5387. // }
  5388. //
  5389. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  5390. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  5391. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  5392. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5393. // if num1 > num2 {
  5394. // num = num1 - num2
  5395. // drug.Total = drug.Total + num
  5396. // service.UpdateBaseDrugLib(&drug)
  5397. // } else if num1 < num2 {
  5398. // num = num2 - num1
  5399. // drug.Total = drug.Total - num
  5400. // service.UpdateBaseDrugLib(&drug)
  5401. // }
  5402. //
  5403. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  5404. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  5405. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  5406. // if hisAdvice.PrescribingNumber > num2 {
  5407. // num = hisAdvice.PrescribingNumber - num2
  5408. // drug.Total = drug.Total + num
  5409. // service.UpdateBaseDrugLib(&drug)
  5410. // } else if num2 < advice.PrescribingNumber {
  5411. // num = num2 - hisAdvice.PrescribingNumber
  5412. // drug.Total = drug.Total - num
  5413. // service.UpdateBaseDrugLib(&drug)
  5414. // }
  5415. //
  5416. // }
  5417. // }
  5418. // }
  5419. //}
  5420. //
  5421. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5422. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5423. // advice.ExecutionTime = execution_time
  5424. //}
  5425. //
  5426. //
  5427. //
  5428. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5429. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5430. // advice.ExecutionStaff = execution_staff
  5431. //}
  5432. //
  5433. //
  5434. //
  5435. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5436. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5437. // advice.ExecutionState = execution_state
  5438. //}
  5439. //
  5440. //
  5441. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5442. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5443. // advice.CheckTime = check_time
  5444. //}
  5445. //
  5446. //
  5447. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5448. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5449. // advice.CheckState = check_state
  5450. //}
  5451. //
  5452. //
  5453. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5454. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5455. // advice.Checker = checker
  5456. //}
  5457. //
  5458. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5459. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5460. // advice.StartTime = start_time
  5461. //}
  5462. return 0
  5463. }
  5464. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5465. project.ExecutionStaff = 0
  5466. project.ExecutionState = 2
  5467. project.ExecutionTime = 0
  5468. project.Checker = 0
  5469. project.CheckState = 2
  5470. project.CheckTime = 0
  5471. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5472. id := int64(json["id"].(float64))
  5473. project.ID = id
  5474. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  5475. project.ExecutionStaff = temp_project.ExecutionStaff
  5476. project.ExecutionState = temp_project.ExecutionState
  5477. project.ExecutionTime = temp_project.ExecutionTime
  5478. project.Checker = temp_project.Checker
  5479. project.CheckState = temp_project.CheckState
  5480. project.CheckTime = temp_project.CheckTime
  5481. project.TeamId = temp_project.TeamId
  5482. }
  5483. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5484. types := int64(json["type"].(float64))
  5485. project.Type = types
  5486. }
  5487. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5488. project_id := int64(json["project_id"].(float64))
  5489. project.ProjectId = project_id
  5490. }
  5491. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  5492. team_id := int64(json["team_id"].(float64))
  5493. project.TeamId = team_id
  5494. }
  5495. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5496. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5497. project.Price = price
  5498. }
  5499. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5500. total, _ := json["total"].(string)
  5501. //totals, _ := strconv.ParseInt(total, 10, 64)
  5502. project.Count = total
  5503. }
  5504. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5505. medical_code, _ := json["medical_code"].(string)
  5506. project.MedListCodg = medical_code
  5507. }
  5508. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5509. single_dose, _ := json["single_dose"].(string)
  5510. project.SingleDose = single_dose
  5511. }
  5512. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5513. delivery_way, _ := json["delivery_way"].(string)
  5514. project.DeliveryWay = delivery_way
  5515. }
  5516. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5517. execution_frequency, _ := json["execution_frequency"].(string)
  5518. project.ExecutionFrequency = execution_frequency
  5519. }
  5520. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5521. remark, _ := json["remark"].(string)
  5522. project.Remark = remark
  5523. }
  5524. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5525. day, _ := json["number_days"].(string)
  5526. project.Day = day
  5527. }
  5528. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5529. unit, _ := json["unit"].(string)
  5530. project.Unit = unit
  5531. }
  5532. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  5533. // frequency_type := int64(json["frequency_type"].(float64))
  5534. // project.FrequencyType = frequency_type
  5535. //}
  5536. //
  5537. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  5538. // day_count := int64(json["day_count"].(float64))
  5539. // project.DayCount = day_count
  5540. //}
  5541. //
  5542. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  5543. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  5544. // week_day, _ := json["week_day"].(string)
  5545. // project.WeekDay = week_day
  5546. //}
  5547. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  5548. //
  5549. //if project.ID == 0 {
  5550. // if stockConfig.IsOpen == 1 {
  5551. // if project.Type == 3 {
  5552. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5553. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  5554. // good.Total = good.Total - f_count
  5555. // service.UpdateGoodInfo(&good)
  5556. // }
  5557. // }
  5558. //
  5559. //} else {
  5560. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  5561. //
  5562. // if stockConfig.IsOpen == 1 {
  5563. // if project.Type == 3 {
  5564. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5565. // if project.Count < temp_project.Count {
  5566. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5567. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5568. //
  5569. // other_count := f_count_two - f_count_one
  5570. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5571. // good.Total = good.Total + other_count_two
  5572. // service.UpdateGoodInfo(&good)
  5573. // } else if project.Count > temp_project.Count {
  5574. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  5575. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  5576. //
  5577. // other_count := f_count_one - f_count_two
  5578. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  5579. // good.Total = good.Total - other_count_two
  5580. // service.UpdateGoodInfo(&good)
  5581. // }
  5582. //
  5583. // }
  5584. // }
  5585. //
  5586. //}
  5587. return 0
  5588. }
  5589. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5590. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5591. id := int64(json["id"].(float64))
  5592. additionalCharge.ID = id
  5593. }
  5594. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5595. item_id := int64(json["item_id"].(float64))
  5596. additionalCharge.ItemId = item_id
  5597. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5598. if config.ID > 0 {
  5599. if len(config.Code) > 0 {
  5600. additionalCharge.MedListCodg = config.Code
  5601. }
  5602. }
  5603. }
  5604. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5605. // price := int64(json["price"].(float64))
  5606. // formatInt_price := strconv.FormatInt(price, 10)
  5607. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5608. // additionalCharge.Price = float_price
  5609. // }
  5610. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5611. // price := int64(json["price"].(float64))
  5612. // formatInt_price := strconv.FormatInt(price, 10)
  5613. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5614. // additionalCharge.Price = float_price
  5615. //}
  5616. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5617. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5618. additionalCharge.Price = price
  5619. }
  5620. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5621. count, _ := json["count"].(string)
  5622. counts, _ := strconv.ParseInt(count, 10, 64)
  5623. additionalCharge.Count = counts
  5624. }
  5625. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5626. item_name, _ := json["item_name"].(string)
  5627. additionalCharge.ItemName = item_name
  5628. }
  5629. return 0
  5630. }
  5631. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  5632. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5633. utils.ErrorLog("drug_name")
  5634. return enums.ErrorCodeParamWrong
  5635. }
  5636. adviceName, _ := json["drug_name"].(string)
  5637. if len(adviceName) == 0 {
  5638. utils.ErrorLog("len(advice_name) == 0")
  5639. return enums.ErrorCodeParamWrong
  5640. }
  5641. advice.AdviceName = adviceName
  5642. adviceDesc, _ := json["advice_desc"].(string)
  5643. advice.AdviceDesc = adviceDesc
  5644. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5645. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5646. advice.DrugSpec = drugSpec
  5647. }
  5648. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5649. remark, _ := json["remark"].(string)
  5650. advice.Remark = remark
  5651. }
  5652. if json["id"] == nil {
  5653. advice.DrugId = 0
  5654. } else {
  5655. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5656. drug_id := int64(json["id"].(float64))
  5657. advice.DrugId = drug_id
  5658. }
  5659. }
  5660. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  5661. groupno := int64(json["groupno"].(float64))
  5662. advice.Groupno = groupno
  5663. }
  5664. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5665. drugSpecUnit, _ := json["min_unit"].(string)
  5666. advice.DrugSpecUnit = drugSpecUnit
  5667. }
  5668. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5669. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5670. advice.SingleDose = singleDose
  5671. }
  5672. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5673. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5674. advice.SingleDoseUnit = singleDoseUnit
  5675. }
  5676. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5677. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5678. advice.PrescribingNumber = prescribingNumber
  5679. }
  5680. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5681. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5682. advice.PrescribingNumberUnit = prescribingNumberUnit
  5683. }
  5684. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5685. deliveryWay, _ := json["delivery_way"].(string)
  5686. advice.DeliveryWay = deliveryWay
  5687. }
  5688. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5689. executionFrequency, _ := json["execution_frequency"].(string)
  5690. advice.ExecutionFrequency = executionFrequency
  5691. }
  5692. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5693. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5694. advice.Price = price
  5695. }
  5696. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5697. med_list_codg, _ := json["medical_insurance_number"].(string)
  5698. advice.MedListCodg = med_list_codg
  5699. }
  5700. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5701. day := int64(json["day"].(float64))
  5702. advice.Day = day
  5703. }
  5704. advice.FrequencyType = 1
  5705. return 0
  5706. }
  5707. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  5708. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  5709. types := int64(json["type"].(float64))
  5710. project.Type = types
  5711. }
  5712. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5713. project_id := int64(json["project_id"].(float64))
  5714. project.ProjectId = project_id
  5715. }
  5716. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5717. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5718. project.Price = price
  5719. }
  5720. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5721. total, _ := json["total"].(string)
  5722. //totals, _ := strconv.ParseInt(total, 10, 64)
  5723. project.Count = total
  5724. }
  5725. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5726. medical_code, _ := json["medical_code"].(string)
  5727. project.MedListCodg = medical_code
  5728. }
  5729. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5730. single_dose, _ := json["single_dose"].(string)
  5731. project.SingleDose = single_dose
  5732. }
  5733. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5734. delivery_way, _ := json["delivery_way"].(string)
  5735. project.DeliveryWay = delivery_way
  5736. }
  5737. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5738. execution_frequency, _ := json["execution_frequency"].(string)
  5739. project.ExecutionFrequency = execution_frequency
  5740. }
  5741. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5742. remark, _ := json["remark"].(string)
  5743. project.Remark = remark
  5744. }
  5745. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5746. day, _ := json["number_days"].(string)
  5747. project.Day = day
  5748. }
  5749. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5750. unit, _ := json["unit"].(string)
  5751. project.Unit = unit
  5752. }
  5753. project.FrequencyType = 1
  5754. return 0
  5755. }
  5756. func (c *HisApiController) GetHisOrderList() {
  5757. page, _ := c.GetInt64("page", -1)
  5758. limit, _ := c.GetInt64("limit", -1)
  5759. start_time := c.GetString("start_time")
  5760. end_time := c.GetString("end_time")
  5761. types, _ := c.GetInt64("type", 0)
  5762. keywords := c.GetString("keywords")
  5763. p_type, _ := c.GetInt64("p_type", 0)
  5764. sort_type, _ := c.GetInt64("sort_type", 0)
  5765. charge_type, _ := c.GetInt64("charge_type", 0)
  5766. sch_type, _ := c.GetInt64("sch_type", 0)
  5767. zone_type, _ := c.GetInt64("zone_type", 0)
  5768. med_type, _ := c.GetInt64("med_type", 0)
  5769. timeLayout := "2006-01-02"
  5770. loc, _ := time.LoadLocation("Local")
  5771. var startTime int64
  5772. if len(start_time) > 0 {
  5773. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5774. if err != nil {
  5775. //fmt.Println(err)
  5776. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5777. return
  5778. }
  5779. startTime = theTime.Unix()
  5780. }
  5781. var endTime int64
  5782. if len(end_time) > 0 {
  5783. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5784. if err != nil {
  5785. utils.ErrorLog(err.Error())
  5786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5787. return
  5788. }
  5789. endTime = theTime.Unix()
  5790. }
  5791. adminUser := c.GetAdminUserInfo()
  5792. org_id := adminUser.CurrentOrgId
  5793. 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)
  5794. order2, _ := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  5795. for _, item := range order {
  5796. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  5797. item.DoctorName = info.Doctor
  5798. item.DepartmentName = info.XtHisDepartment.Name
  5799. }
  5800. if err == nil {
  5801. c.ServeSuccessJSON(map[string]interface{}{
  5802. "order": order,
  5803. "order2": order2,
  5804. "total": total,
  5805. })
  5806. } else {
  5807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5808. return
  5809. }
  5810. }
  5811. func (c *HisApiController) GetHisOrder() {
  5812. patient_id, _ := c.GetInt64("patient_id", 0)
  5813. number := c.GetString("number")
  5814. adminInfo := c.GetAdminUserInfo()
  5815. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  5816. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  5817. if err == nil {
  5818. c.ServeSuccessJSON(map[string]interface{}{
  5819. "order": order,
  5820. "prescription": prescriptions,
  5821. })
  5822. } else {
  5823. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5824. return
  5825. }
  5826. }
  5827. func (c *HisApiController) GetHisPrescriptionList() {
  5828. record_date := c.GetString("record_date")
  5829. keywords := c.GetString("keywords")
  5830. page, _ := c.GetInt64("page")
  5831. limit, _ := c.GetInt64("limit")
  5832. sch_type, _ := c.GetInt64("sch_type")
  5833. timeLayout := "2006-01-02"
  5834. loc, _ := time.LoadLocation("Local")
  5835. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5836. if err != nil {
  5837. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5838. return
  5839. }
  5840. recordDateTime := theTime.Unix()
  5841. adminInfo := c.GetAdminUserInfo()
  5842. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  5843. //adminInfo := c.GetAdminUserInfo()
  5844. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  5845. //fmt.Println(prescriptionOrder)
  5846. if err == nil {
  5847. c.ServeSuccessJSON(map[string]interface{}{
  5848. "order": prescriptionOrder,
  5849. "total": total,
  5850. })
  5851. } else {
  5852. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5853. return
  5854. }
  5855. }
  5856. func (c *HisApiController) GetHisPrescriptionInfo() {
  5857. id, _ := c.GetInt64("id")
  5858. adminInfo := c.GetAdminUserInfo()
  5859. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  5860. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  5861. if err == nil {
  5862. c.ServeSuccessJSON(map[string]interface{}{
  5863. "order": prescriptionOrder,
  5864. "prescription": prescription,
  5865. })
  5866. } else {
  5867. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5868. return
  5869. }
  5870. }
  5871. func (c *HisApiController) GetMedicalInsuranceConfig() {
  5872. adminUser := c.GetAdminUserInfo()
  5873. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  5874. c.ServeSuccessJSON(map[string]interface{}{
  5875. "config": config,
  5876. })
  5877. }
  5878. type ResultTwo struct {
  5879. ErrMsg interface{} `json:"err_msg"`
  5880. InfRefmsgid string `json:"inf_refmsgid"`
  5881. Infcode int64 `json:"infcode"`
  5882. Output struct {
  5883. Baseinfo struct {
  5884. Age float64 `json:"age"`
  5885. Brdy string `json:"brdy"`
  5886. Certno string `json:"certno"`
  5887. Gend string `json:"gend"`
  5888. Naty string `json:"naty"`
  5889. PsnCertType string `json:"psn_cert_type"`
  5890. PsnName string `json:"psn_name"`
  5891. PsnNo string `json:"psn_no"`
  5892. } `json:"baseinfo"`
  5893. Idetinfo []interface{} `json:"idetinfo"`
  5894. Iinfo []struct {
  5895. Balc float64 `json:"balc"`
  5896. CvlservFlag string `json:"cvlserv_flag"`
  5897. EmpName string `json:"emp_name"`
  5898. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  5899. Insutype string `json:"insutype"`
  5900. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  5901. PausInsuDate interface{} `json:"paus_insu_date"`
  5902. PsnInsuDate string `json:"psn_insu_date"`
  5903. PsnInsuStas string `json:"psn_insu_stas"`
  5904. PsnType string `json:"psn_type"`
  5905. } `json:"insuinfo"`
  5906. } `json:"output"`
  5907. RefmsgTime string `json:"refmsg_time"`
  5908. RespondTime string `json:"respond_time"`
  5909. Signtype interface{} `json:"signtype"`
  5910. WarnInfo interface{} `json:"warn_info"`
  5911. }
  5912. type ResultThree struct {
  5913. Cainfo interface{} `json:"cainfo"`
  5914. ErrMsg interface{} `json:"err_msg"`
  5915. InfRefmsgid string `json:"inf_refmsgid"`
  5916. Infcode int64 `json:"infcode"`
  5917. Output struct {
  5918. Data struct {
  5919. IptOtpNo string `json:"ipt_otp_no"`
  5920. MdtrtID string `json:"mdtrt_id"`
  5921. PsnNo string `json:"psn_no"`
  5922. } `json:"data"`
  5923. } `json:"output"`
  5924. RefmsgTime string `json:"refmsg_time"`
  5925. RespondTime string `json:"respond_time"`
  5926. Signtype interface{} `json:"signtype"`
  5927. WarnMsg interface{} `json:"warn_msg"`
  5928. }
  5929. type ResultFour struct {
  5930. Cainfo string `json:"cainfo"`
  5931. ErrMsg string `json:"err_msg"`
  5932. InfRefmsgid string `json:"inf_refmsgid"`
  5933. Infcode int64 `json:"infcode"`
  5934. Output struct {
  5935. Result []struct {
  5936. BasMednFlag string `json:"bas_medn_flag"`
  5937. ChldMedcFlag string `json:"chld_medc_flag"`
  5938. ChrgitmLv string `json:"chrgitm_lv"`
  5939. Cnt float64 `json:"cnt"`
  5940. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  5941. DrtReimFlag string `json:"drt_reim_flag"`
  5942. FeedetlSn string `json:"feedetl_sn"`
  5943. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5944. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  5945. InscpScpAmt float64 `json:"inscp_scp_amt"`
  5946. ListSpItemFlag string `json:"list_sp_item_flag"`
  5947. LmtUsedFlag string `json:"lmt_used_flag"`
  5948. MedChrgitmType string `json:"med_chrgitm_type"`
  5949. Memo string `json:"memo"`
  5950. OverlmtAmt float64 `json:"overlmt_amt"`
  5951. PreselfpayAmt float64 `json:"preselfpay_amt"`
  5952. Pric float64 `json:"pric"`
  5953. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  5954. SelfpayProp float64 `json:"selfpay_prop"`
  5955. } `json:"result"`
  5956. } `json:"output"`
  5957. RefmsgTime string `json:"refmsg_time"`
  5958. RespondTime string `json:"respond_time"`
  5959. Signtype string `json:"signtype"`
  5960. WarnMsg string `json:"warn_msg"`
  5961. }
  5962. type ResultFive struct {
  5963. Insutype string `json:"insutype"`
  5964. }
  5965. type ResultSix struct {
  5966. Cainfo interface{} `json:"cainfo"`
  5967. ErrMsg interface{} `json:"err_msg"`
  5968. InfRefmsgid string `json:"inf_refmsgid"`
  5969. Infcode int64 `json:"infcode"`
  5970. Output struct {
  5971. } `json:"output"`
  5972. RefmsgTime string `json:"refmsg_time"`
  5973. RespondTime string `json:"respond_time"`
  5974. Signtype interface{} `json:"signtype"`
  5975. WarnMsg interface{} `json:"warn_msg"`
  5976. }
  5977. type ResultSeven struct {
  5978. Cainfo string `json:"cainfo"`
  5979. ErrMsg string `json:"err_msg"`
  5980. InfRefmsgid string `json:"inf_refmsgid"`
  5981. Infcode int64 `json:"infcode"`
  5982. Output struct {
  5983. Setldetail []interface{} `json:"setldetail"`
  5984. Setlinfo struct {
  5985. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  5986. AcctPay float64 `json:"acct_pay"`
  5987. ActPayDedc float64 `json:"act_pay_dedc"`
  5988. Age float64 `json:"age"`
  5989. Balc float64 `json:"balc"`
  5990. Brdy string `json:"brdy"`
  5991. Certno string `json:"certno"`
  5992. ClrOptins string `json:"clr_optins"`
  5993. ClrType string `json:"clr_type"`
  5994. ClrWay string `json:"clr_way"`
  5995. CvlservFlag string `json:"cvlserv_flag"`
  5996. CvlservPay float64 `json:"cvlserv_pay"`
  5997. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  5998. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  5999. Gend string `json:"gend"`
  6000. HifesPay float64 `json:"hifes_pay"`
  6001. HifmiPay float64 `json:"hifmi_pay"`
  6002. HifobPay float64 `json:"hifob_pay"`
  6003. HifpPay float64 `json:"hifp_pay"`
  6004. HospPartAmt float64 `json:"hosp_part_amt"`
  6005. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6006. Insutype string `json:"insutype"`
  6007. MafPay float64 `json:"maf_pay"`
  6008. MdtrtCertType string `json:"mdtrt_cert_type"`
  6009. MdtrtID string `json:"mdtrt_id"`
  6010. MedType string `json:"med_type"`
  6011. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6012. MedinsSetlID string `json:"medins_setl_id"`
  6013. Naty string `json:"naty"`
  6014. OthPay float64 `json:"oth_pay"`
  6015. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6016. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6017. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6018. PsnCashPay float64 `json:"psn_cash_pay"`
  6019. PsnCertType string `json:"psn_cert_type"`
  6020. PsnName string `json:"psn_name"`
  6021. PsnNo string `json:"psn_no"`
  6022. PsnPartAmt float64 `json:"psn_part_amt"`
  6023. PsnType string `json:"psn_type"`
  6024. SetlID string `json:"setl_id"`
  6025. SetlTime string `json:"setl_time"`
  6026. } `json:"setlinfo"`
  6027. } `json:"output"`
  6028. RefmsgTime string `json:"refmsg_time"`
  6029. RespondTime string `json:"respond_time"`
  6030. Signtype interface{} `json:"signtype"`
  6031. WarnMsg interface{} `json:"warn_msg"`
  6032. }
  6033. type ResultEight struct {
  6034. Cainfo string `json:"cainfo"`
  6035. ErrMsg string `json:"err_msg"`
  6036. InfRefmsgid string `json:"inf_refmsgid"`
  6037. Infcode int64 `json:"infcode"`
  6038. Output struct {
  6039. Stmtinfo struct {
  6040. SetlOptins string `json:"setl_optins"`
  6041. StmtRslt string `json:"stmt_rslt"`
  6042. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  6043. } `json:"stmtinfo"`
  6044. } `json:"output"`
  6045. RefmsgTime string `json:"refmsg_time"`
  6046. RespondTime string `json:"respond_time"`
  6047. Signtype interface{} `json:"signtype"`
  6048. WarnMsg interface{} `json:"warn_msg"`
  6049. }
  6050. type ResultNine struct {
  6051. Cainfo string `json:"cainfo"`
  6052. ErrMsg string `json:"err_msg"`
  6053. InfRefmsgid string `json:"inf_refmsgid"`
  6054. Infcode int64 `json:"infcode"`
  6055. Output struct {
  6056. FileQuryNo string `json:"file_qury_no"`
  6057. } `json:"output"`
  6058. RefmsgTime string `json:"refmsg_time"`
  6059. RespondTime string `json:"respond_time"`
  6060. Signtype interface{} `json:"signtype"`
  6061. WarnMsg interface{} `json:"warn_msg"`
  6062. }
  6063. type ResultTen struct {
  6064. Cainfo string `json:"cainfo"`
  6065. ErrMsg string `json:"err_msg"`
  6066. InfRefmsgid string `json:"inf_refmsgid"`
  6067. Infcode int64 `json:"infcode"`
  6068. Output struct {
  6069. DldEndtime string `json:"dld_endtime"`
  6070. FileQuryNo string `json:"file_qury_no"`
  6071. Filename string `json:"filename"`
  6072. } `json:"output"`
  6073. RefmsgTime string `json:"refmsg_time"`
  6074. RespondTime string `json:"respond_time"`
  6075. Signtype interface{} `json:"signtype"`
  6076. WarnMsg interface{} `json:"warn_msg"`
  6077. }
  6078. type ResultEleven struct {
  6079. Cainfo string `json:"cainfo"`
  6080. ErrMsg string `json:"err_msg"`
  6081. InfRefmsgid string `json:"inf_refmsgid"`
  6082. Infcode int64 `json:"infcode"`
  6083. Output struct {
  6084. Setlinfo struct {
  6085. FixmedinsName string `json:"fixmedins_name"`
  6086. FixmedinsCode string `json:"fixmedins_code"`
  6087. PsnNo string `json:"psn_no"`
  6088. PsnName string `json:"psn_name"`
  6089. HifobPay float64 `json:"hifob_pay"`
  6090. Gend string `json:"gend"`
  6091. Brdy string `json:"brdy"`
  6092. PsnCertType string `json:"psn_cert_type"`
  6093. PsnType string `json:"psn_type"`
  6094. EmpName string `json:"emp_name"`
  6095. Certno string `json:"certno"`
  6096. Insutype string `json:"insutype"`
  6097. MedfeeSumamt float64 `json:"medfee_sumamt"`
  6098. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  6099. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  6100. PreselfpayAmt float64 `json:"preselfpay_amt"`
  6101. InscpScpAmt float64 `json:"inscp_scp_amt"`
  6102. ActPayDedc float64 `json:"act_pay_dedc"`
  6103. HifpPay float64 `json:"hifp_pay"`
  6104. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  6105. CvlservPay float64 `json:"cvlserv_pay"`
  6106. HifesPay float64 `json:"hifes_pay"`
  6107. HifmiPay float64 `json:"hifmi_pay"`
  6108. MafPay float64 `json:"maf_pay"`
  6109. OthPay float64 `json:"oth_pay"`
  6110. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  6111. PsnPay float64 `json:"psn_pay"`
  6112. AcctPay float64 `json:"acct_pay"`
  6113. CashPayamt float64 `json:"cash_payamt"`
  6114. Balc float64 `json:"balc"`
  6115. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  6116. MedinsSetlId string `json:"medins_setl_id"`
  6117. RefdSetlFlag string `json:"refd_setl_flag"`
  6118. SetlTime string `json:"setl_time"`
  6119. MedType string `json:"med_type"`
  6120. } `json:"setlinfo"`
  6121. } `json:"output"`
  6122. RefmsgTime string `json:"refmsg_time"`
  6123. RespondTime string `json:"respond_time"`
  6124. Signtype interface{} `json:"signtype"`
  6125. WarnMsg interface{} `json:"warn_msg"`
  6126. }
  6127. type Custom struct {
  6128. DetItemFeeSumamt string
  6129. Cut string
  6130. FeedetlSn string
  6131. Price string
  6132. MedListCodg string
  6133. Type int64
  6134. AdviceId int64
  6135. ProjectId int64
  6136. ItemId int64
  6137. }
  6138. // 获取个人信息----挂号-----上传就诊信息
  6139. func (c *HisApiController) GetRegisterInfo() {
  6140. id, _ := c.GetInt64("id")
  6141. record_time := c.GetString("record_time")
  6142. settlementValue, _ := c.GetInt64("settlement_value")
  6143. medical_insurance_card := c.GetString("medical_insurance_card")
  6144. name := c.GetString("name")
  6145. id_card_type, _ := c.GetInt64("id_card_type")
  6146. certificates, _ := c.GetInt64("certificates")
  6147. medical_care, _ := c.GetInt64("medical_care")
  6148. birthday := c.GetString("birthday")
  6149. age, _ := c.GetInt64("age")
  6150. id_card := c.GetString("id_card")
  6151. register_type, _ := c.GetInt64("register")
  6152. doctor, _ := c.GetInt64("doctor")
  6153. department, _ := c.GetInt64("department")
  6154. gender, _ := c.GetInt64("sex")
  6155. phone := c.GetString("phone")
  6156. registration_fee, _ := c.GetFloat("registration_fee")
  6157. medical_expenses, _ := c.GetFloat("medical_expenses")
  6158. social_type, _ := c.GetInt64("social_type")
  6159. //diagnosis_id, _ := c.GetInt64("diagnosis")
  6160. diagnosis_ids := c.GetString("diagnosis")
  6161. sick_type, _ := c.GetInt64("sick_type")
  6162. reg_type := c.GetString("p_type")
  6163. timeLayout := "2006-01-02"
  6164. loc, _ := time.LoadLocation("Local")
  6165. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  6166. birthUnix := birthdays.Unix()
  6167. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6168. if err != nil {
  6169. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6170. return
  6171. }
  6172. recordDateTime := theTime.Unix()
  6173. adminInfo := c.GetAdminUserInfo()
  6174. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  6175. if tempPatient.ID == 0 {
  6176. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  6177. return
  6178. }
  6179. var patient service.Patients
  6180. if id == 0 {
  6181. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  6182. } else {
  6183. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  6184. }
  6185. if patient.ID == 0 {
  6186. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  6187. return
  6188. }
  6189. if len(patient.IdCardNo) == 0 {
  6190. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  6191. return
  6192. }
  6193. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6194. if len(his) >= 1 {
  6195. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  6196. if len(his) >= 1 && order.ID == 0 {
  6197. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  6198. return
  6199. }
  6200. }
  6201. timeStr := time.Now().Format("2006-01-02 15:04:05")
  6202. fmt.Println(timeStr)
  6203. timeArr := strings.Split(timeStr, " ")
  6204. fmt.Println(timeArr)
  6205. timeArrTwo := strings.Split(timeArr[0], "-")
  6206. timeArrThree := strings.Split(timeArr[1], ":")
  6207. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  6208. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  6209. if len(lists) == 0 {
  6210. var hisPatient models.XtHisPatient
  6211. hisPatient = models.XtHisPatient{
  6212. Name: name,
  6213. Age: age,
  6214. Gender: gender,
  6215. Birthday: birthUnix,
  6216. Phone: phone,
  6217. MedicalTreatmentType: medical_care,
  6218. IdType: certificates,
  6219. IdCardNo: id_card,
  6220. BalanceAccountsType: settlementValue,
  6221. SocialType: social_type,
  6222. MedicalInsuranceNumber: medical_insurance_card,
  6223. RegisterType: register_type,
  6224. RegisterCost: registration_fee,
  6225. TreatmentCost: medical_expenses,
  6226. AdminUserId: adminInfo.AdminUser.Id,
  6227. UserOrgId: adminInfo.CurrentOrgId,
  6228. Status: 1,
  6229. RecordDate: recordDateTime,
  6230. IsReturn: 1,
  6231. PatientId: patient.ID,
  6232. Ctime: time.Now().Unix(),
  6233. Mtime: time.Now().Unix(),
  6234. Number: str,
  6235. IdCardType: id_card_type,
  6236. Departments: department,
  6237. Doctor: doctor,
  6238. PType: reg_type,
  6239. Diagnosis: diagnosis_ids,
  6240. SickType: sick_type,
  6241. }
  6242. service.CreateHisPatient(&hisPatient)
  6243. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6244. c.ServeSuccessJSON(map[string]interface{}{
  6245. "his_info": hisPatient,
  6246. })
  6247. } else {
  6248. //chrgBchno := rand.Intn(1000000) + 10000
  6249. var hisPatient models.XtHisPatient
  6250. hisPatient = models.XtHisPatient{
  6251. Name: name,
  6252. Age: age,
  6253. Gender: gender,
  6254. Birthday: birthUnix,
  6255. Phone: phone,
  6256. MedicalTreatmentType: medical_care,
  6257. IdType: certificates,
  6258. IdCardNo: id_card,
  6259. BalanceAccountsType: settlementValue,
  6260. SocialType: social_type,
  6261. MedicalInsuranceNumber: medical_insurance_card,
  6262. RegisterType: register_type,
  6263. RegisterCost: registration_fee,
  6264. TreatmentCost: medical_expenses,
  6265. AdminUserId: adminInfo.AdminUser.Id,
  6266. UserOrgId: adminInfo.CurrentOrgId,
  6267. Status: 1,
  6268. RecordDate: recordDateTime,
  6269. IsReturn: 1,
  6270. PatientId: patient.ID,
  6271. Ctime: time.Now().Unix(),
  6272. Mtime: time.Now().Unix(),
  6273. Number: str,
  6274. IdCardType: id_card_type,
  6275. Departments: department,
  6276. Doctor: doctor,
  6277. PType: reg_type,
  6278. Diagnosis: diagnosis_ids,
  6279. SickType: sick_type,
  6280. }
  6281. service.CreateHisPatient(&hisPatient)
  6282. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  6283. c.ServeSuccessJSON(map[string]interface{}{
  6284. "his_info": hisPatient,
  6285. })
  6286. }
  6287. }
  6288. // 上传明细----结算
  6289. func (c *HisApiController) GetUploadInfo() {
  6290. id, _ := c.GetInt64("id")
  6291. record_time := c.GetString("record_time")
  6292. his_patient_id, _ := c.GetInt64("his_patient_id")
  6293. oth_desc := c.GetString("oth_desc")
  6294. pay_way, _ := c.GetInt64("pay_way")
  6295. pay_ways := c.GetString("pay_ways")
  6296. pay_price, _ := c.GetFloat("pay_price")
  6297. pay_card_no := c.GetString("pay_card_no")
  6298. discount_price, _ := c.GetFloat("discount_price")
  6299. preferential_price, _ := c.GetFloat("preferential_price")
  6300. reality_price, _ := c.GetFloat("reality_price")
  6301. found_price, _ := c.GetFloat("found_price")
  6302. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  6303. private_price, _ := c.GetFloat("private_price")
  6304. timeLayout := "2006-01-02"
  6305. loc, _ := time.LoadLocation("Local")
  6306. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6307. fapiao_code := c.GetString("fapiao_code")
  6308. fapiao_number := c.GetString("fapiao_number")
  6309. diagnosis_id := c.GetString("diagnosis")
  6310. sick_type, _ := c.GetInt64("sick_type")
  6311. reg_type, _ := c.GetInt64("p_type")
  6312. order_id, _ := c.GetInt64("order_id")
  6313. cash_pay := c.GetString("cash_pay")
  6314. wechat_pay := c.GetString("wechat_pay")
  6315. ali_pay := c.GetString("ali_pay")
  6316. jifen_pay := c.GetString("jifen_pay")
  6317. band_card_pay := c.GetString("band_card_pay")
  6318. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  6319. tmp_decimal := c.GetString("tmp_decimal")
  6320. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  6321. var decimal float64 //本次使用的押金
  6322. var errmsg error
  6323. tx := service.XTWriteDB().Begin() //开了事务
  6324. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  6325. defer func() {
  6326. if errmsg != nil {
  6327. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  6328. tx.Rollback()
  6329. } else {
  6330. tx.Commit()
  6331. }
  6332. }()
  6333. fmt.Println("dec_way", dec_way)
  6334. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  6335. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  6336. return
  6337. }
  6338. if len(tmp_decimal) > 0 {
  6339. if tmp_decimal[0] == 45 {
  6340. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  6341. return
  6342. }
  6343. }
  6344. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  6345. fmt.Println(errs)
  6346. decimal = tt
  6347. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  6348. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  6349. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6350. if err != nil {
  6351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6352. return
  6353. }
  6354. recordDateTime := theTime.Unix()
  6355. adminUser := c.GetAdminUserInfo()
  6356. var prescriptions []*models.HisPrescription
  6357. var prescriptionsOne []*models.HisPrescription
  6358. var start_time int64
  6359. var end_time int64
  6360. ids_str := c.GetString("ids")
  6361. ids_arr := strings.Split(ids_str, ",")
  6362. if tempOrder.ID == 0 {
  6363. if settle_accounts_type == 1 { //日结
  6364. fmt.Println(reg_type)
  6365. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6366. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  6367. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  6368. } else {
  6369. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6370. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6371. }
  6372. } else { //月结
  6373. start_time_str := c.GetString("start_time")
  6374. end_time_str := c.GetString("end_time")
  6375. timeLayout := "2006-01-02"
  6376. loc, _ := time.LoadLocation("Local")
  6377. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6378. if err != nil {
  6379. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6380. return
  6381. }
  6382. recordStartTime := theStartTime.Unix()
  6383. start_time = recordStartTime
  6384. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6385. if err != nil {
  6386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6387. return
  6388. }
  6389. recordEndTime := theEndTime.Unix()
  6390. end_time = recordEndTime
  6391. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  6392. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  6393. }
  6394. var goods []*models.DialysisBeforePrepareGoods
  6395. var newGoods []*models.NewDialysisBeforePrepareGoods
  6396. var oldGoods []*models.OldDialysisBeforePrepareGoods
  6397. var infos []*models.HisDoctorAdviceInfo
  6398. var infoList []*models.HisDoctorAdviceInfo
  6399. var hisAdvice []*models.HisDoctorAdviceInfo
  6400. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  6401. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  6402. //判断库存不足
  6403. //结算出库开关
  6404. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6405. if settConfig.IsOpen == 1 {
  6406. //判断库存的地方
  6407. for _, info := range prescriptions {
  6408. if info.Type == 1 {
  6409. infos = append(infos, info.HisDoctorAdviceInfo...)
  6410. }
  6411. if info.Type == 2 {
  6412. for _, sumItem := range info.HisPrescriptionProject {
  6413. if sumItem.Type == 3 {
  6414. var good models.DialysisBeforePrepareGoods
  6415. var newGood models.NewDialysisBeforePrepareGoods
  6416. good.GoodId = sumItem.GoodInfo.ID
  6417. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6418. count, _ := strconv.Atoi(sumItem.Count)
  6419. good.Count = int64(count)
  6420. good.StorehouseId = houseConfig.StorehouseOutInfo
  6421. good.ProjectId = sumItem.ID
  6422. goods = append(goods, &good)
  6423. newGood.GoodId = sumItem.GoodInfo.ID
  6424. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6425. count2, _ := strconv.Atoi(sumItem.Count)
  6426. newGood.Count = int64(count2)
  6427. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6428. newGood.ProjectId = sumItem.ID
  6429. newGoods = append(newGoods, &newGood)
  6430. }
  6431. }
  6432. }
  6433. }
  6434. for _, info := range prescriptionsOne {
  6435. if info.Type == 1 {
  6436. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  6437. }
  6438. if info.Type == 2 {
  6439. for _, sumItem := range info.HisPrescriptionProject {
  6440. if sumItem.Type == 3 {
  6441. var newGood models.NewDialysisBeforePrepareGoods
  6442. newGood.GoodId = sumItem.GoodInfo.ID
  6443. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6444. count2, _ := strconv.Atoi(sumItem.Count)
  6445. newGood.Count = int64(count2)
  6446. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6447. newGood.ProjectId = sumItem.ID
  6448. newGoodOne = append(newGoodOne, &newGood)
  6449. }
  6450. }
  6451. }
  6452. }
  6453. //判断
  6454. for _, itemOne := range infos {
  6455. for _, itemTwo := range hisAdvice {
  6456. if itemOne.DrugId == itemTwo.DrugId {
  6457. itemTwo.Child = append(itemTwo.Child, itemOne)
  6458. }
  6459. }
  6460. }
  6461. for _, itemTwo := range hisAdvice {
  6462. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  6463. var sum_out_count int64
  6464. for _, itemThree := range itemTwo.Child {
  6465. var prescribing_number int64
  6466. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  6467. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  6468. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  6469. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  6470. }
  6471. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  6472. prescribing_number = parseIntPrescribingNumber
  6473. }
  6474. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  6475. prescribing_number = parseIntPrescribingNumber
  6476. }
  6477. sum_out_count += prescribing_number
  6478. }
  6479. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  6480. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  6481. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  6482. if sum_out_count > drugStockOut.FlushCount {
  6483. c.ServeSuccessJSON(map[string]interface{}{
  6484. "msg": "2",
  6485. "drug": medical,
  6486. })
  6487. return
  6488. }
  6489. }
  6490. fmt.Println("newGoods99999988882os", newGoods)
  6491. for _, itemOne := range newGoods {
  6492. for _, item := range newGoodOne {
  6493. if itemOne.GoodId == item.GoodId {
  6494. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  6495. }
  6496. }
  6497. }
  6498. for _, item := range newGoodOne {
  6499. var sum_out_count_one int64
  6500. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  6501. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  6502. sum_out_count_one += itemOne.Count
  6503. }
  6504. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6505. fmt.Println("sum_out_count_one", sum_out_count_one)
  6506. fmt.Println("list.FlushCount", list.FlushCount)
  6507. if sum_out_count_one > list.FlushCount {
  6508. c.ServeSuccessJSON(map[string]interface{}{
  6509. "msg": "3",
  6510. "good": good,
  6511. })
  6512. return
  6513. }
  6514. }
  6515. }
  6516. timestamp := time.Now().Unix()
  6517. tempTime := time.Unix(timestamp, 0)
  6518. timeFormat := tempTime.Format("20060102150405")
  6519. chrgBchno := rand.Intn(100000) + 10000
  6520. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6521. strconv.FormatInt(his.PatientId, 10)
  6522. var ids []int64
  6523. for _, item := range prescriptions {
  6524. ids = append(ids, item.ID)
  6525. }
  6526. var total float64
  6527. for _, item := range prescriptions {
  6528. fmt.Println(item)
  6529. if item.Type == 1 { //药品
  6530. for _, subItem := range item.HisDoctorAdviceInfo {
  6531. total = total + (subItem.Price * subItem.PrescribingNumber)
  6532. }
  6533. }
  6534. if item.Type == 2 { //项目
  6535. for _, subItem := range item.HisPrescriptionProject {
  6536. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6537. total = total + (subItem.Price * cnt)
  6538. }
  6539. }
  6540. for _, subItem := range item.HisAdditionalCharge {
  6541. total = total + (subItem.Price * float64(subItem.Count))
  6542. }
  6543. }
  6544. if reg_type == 1111 || reg_type == 1112 {
  6545. reg_type = 11
  6546. }
  6547. tm := time.Unix(time.Now().Unix(), 0)
  6548. allTotal := fmt.Sprintf("%.4f", total)
  6549. totals, _ := strconv.ParseFloat(allTotal, 64)
  6550. order := &models.HisOrder{
  6551. UserOrgId: adminUser.CurrentOrgId,
  6552. HisPatientId: his.ID,
  6553. PatientId: id,
  6554. SettleAccountsDate: recordDateTime,
  6555. Ctime: time.Now().Unix(),
  6556. Mtime: time.Now().Unix(),
  6557. Status: 1,
  6558. OrderStatus: 2,
  6559. MdtrtId: his.Number,
  6560. Number: chrg_bchno,
  6561. MedfeeSumamt: totals,
  6562. PayWay: pay_way,
  6563. PayWays: pay_ways,
  6564. PayPrice: pay_price,
  6565. MedType: strconv.Itoa(int(reg_type)),
  6566. PayCardNo: pay_card_no,
  6567. DiscountPrice: discount_price,
  6568. PreferentialPrice: preferential_price,
  6569. RealityPrice: reality_price,
  6570. FoundPrice: found_price,
  6571. MedicalInsurancePrice: medical_insurance_price,
  6572. PrivatePrice: private_price,
  6573. SettleEndTime: end_time,
  6574. SettleStartTime: start_time,
  6575. PsnPartAmt: totals,
  6576. PsnCashPay: totals,
  6577. SettleType: settle_accounts_type,
  6578. FaPiaoCode: fapiao_code,
  6579. FaPiaoNumber: fapiao_number,
  6580. Diagnosis: diagnosis_id,
  6581. PType: 2,
  6582. SetlTime: tm.Format("2006-01-02 15:04:05"),
  6583. Decimal: decimal,
  6584. OthDesc: oth_desc,
  6585. CashPay: cash_pay,
  6586. WechatPay: wechat_pay,
  6587. AliPay: ali_pay,
  6588. JifenPay: jifen_pay,
  6589. BandCardPay: band_card_pay,
  6590. Creator: adminUser.AdminUser.Id,
  6591. }
  6592. err = service.CreateOrderTX(order, tx)
  6593. if err != nil {
  6594. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6595. return
  6596. }
  6597. var customs []*Custom
  6598. for _, item := range prescriptions {
  6599. if item.Type == 1 { //药品a
  6600. for _, subItem := range item.HisDoctorAdviceInfo {
  6601. cus := &Custom{
  6602. AdviceId: subItem.ID,
  6603. ProjectId: 0,
  6604. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  6605. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  6606. FeedetlSn: subItem.FeedetlSn,
  6607. Price: fmt.Sprintf("%.4f", subItem.Price),
  6608. MedListCodg: subItem.MedListCodg,
  6609. Type: 1,
  6610. }
  6611. customs = append(customs, cus)
  6612. }
  6613. }
  6614. if item.Type == 2 { //项目
  6615. for _, subItem := range item.HisPrescriptionProject {
  6616. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6617. cus := &Custom{
  6618. AdviceId: 0,
  6619. ProjectId: subItem.ID,
  6620. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  6621. Cut: fmt.Sprintf("%.4f", cnt),
  6622. FeedetlSn: subItem.FeedetlSn,
  6623. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  6624. MedListCodg: subItem.MedListCodg,
  6625. Type: 2,
  6626. }
  6627. customs = append(customs, cus)
  6628. }
  6629. }
  6630. for _, item := range item.HisAdditionalCharge {
  6631. cus := &Custom{
  6632. ItemId: item.ID,
  6633. AdviceId: 0,
  6634. ProjectId: 0,
  6635. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  6636. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  6637. FeedetlSn: item.FeedetlSn,
  6638. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  6639. MedListCodg: item.XtHisAddtionConfig.Code,
  6640. Type: 3,
  6641. }
  6642. customs = append(customs, cus)
  6643. }
  6644. }
  6645. for _, item := range customs {
  6646. var advice_id int64 = 0
  6647. var project_id int64 = 0
  6648. var item_id int64 = 0
  6649. var types int64 = 0
  6650. if item.Type == 1 {
  6651. advice_id = item.AdviceId
  6652. project_id = 0
  6653. item_id = 0
  6654. } else if item.Type == 2 {
  6655. advice_id = 0
  6656. item_id = 0
  6657. project_id = item.ProjectId
  6658. } else if item.Type == 3 {
  6659. advice_id = 0
  6660. item_id = item.ItemId
  6661. project_id = 0
  6662. }
  6663. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6664. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6665. pric, _ := strconv.ParseFloat(item.Price, 32)
  6666. info := &models.HisOrderInfo{
  6667. OrderNumber: order.Number,
  6668. UploadDate: time.Now().Unix(),
  6669. AdviceId: advice_id,
  6670. DetItemFeeSumamt: detItemFeeSumamt,
  6671. Cnt: cut,
  6672. Pric: pric,
  6673. PatientId: id,
  6674. Status: 1,
  6675. Mtime: time.Now().Unix(),
  6676. Ctime: time.Now().Unix(),
  6677. UserOrgId: adminUser.CurrentOrgId,
  6678. HisPatientId: his.ID,
  6679. OrderId: order.ID,
  6680. ProjectId: project_id,
  6681. Type: types,
  6682. ItemId: item_id,
  6683. }
  6684. service.CreateOrderInfoTX(info, tx)
  6685. }
  6686. his.Diagnosis = diagnosis_id
  6687. his.SickType = sick_type
  6688. his.RegisterType = reg_type
  6689. his.MedicalTreatmentType = reg_type
  6690. service.UpdataHisPateintTX(&his, tx)
  6691. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  6692. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  6693. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  6694. //判断是否使用了押金
  6695. if dec_way == "true" {
  6696. tmpstring := strconv.FormatInt(order.ID, 10)
  6697. //扣押金
  6698. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  6699. order.Decimal = decimal
  6700. service.UpDateOrderTwo(order, tx)
  6701. if errmsg != nil {
  6702. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  6703. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6704. return
  6705. }
  6706. }
  6707. if err == nil {
  6708. for _, info := range prescriptions {
  6709. if info.Type == 1 {
  6710. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  6711. }
  6712. if info.Type == 2 {
  6713. for _, sumItem := range info.HisPrescriptionProject {
  6714. if sumItem.Type == 3 {
  6715. var good models.DialysisBeforePrepareGoods
  6716. var newGood models.NewDialysisBeforePrepareGoods
  6717. var oldGood models.OldDialysisBeforePrepareGoods
  6718. good.GoodId = sumItem.GoodInfo.ID
  6719. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6720. count, _ := strconv.Atoi(sumItem.Count)
  6721. good.Count = int64(count)
  6722. good.StorehouseId = houseConfig.StorehouseOutInfo
  6723. good.ProjectId = sumItem.ID
  6724. good.PatientId = sumItem.PatientId
  6725. goods = append(goods, &good)
  6726. newGood.GoodId = sumItem.GoodInfo.ID
  6727. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6728. count2, _ := strconv.Atoi(sumItem.Count)
  6729. newGood.Count = int64(count2)
  6730. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6731. newGood.ProjectId = sumItem.ID
  6732. newGood.PatientId = sumItem.HisPatientId
  6733. newGoods = append(newGoods, &newGood)
  6734. oldGood.GoodId = sumItem.GoodInfo.ID
  6735. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  6736. count3, _ := strconv.Atoi(sumItem.Count)
  6737. oldGood.Count = int64(count3)
  6738. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  6739. oldGood.ProjectId = sumItem.ID
  6740. oldGood.RecordDate = sumItem.RecordDate
  6741. oldGood.PatientId = sumItem.HisPatientId
  6742. oldGoods = append(oldGoods, &oldGood)
  6743. }
  6744. }
  6745. }
  6746. }
  6747. if settConfig.IsOpen == 1 {
  6748. for _, item := range infoList {
  6749. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  6750. if medical.IsUse == 2 {
  6751. //药品出库
  6752. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  6753. //查询默认仓库
  6754. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  6755. //查询默认仓库剩余多少库存
  6756. var sum_count int64
  6757. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  6758. for _, its := range stockInfo {
  6759. if its.MaxUnit == medical.MaxUnit {
  6760. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  6761. }
  6762. sum_count += its.StockMaxNumber + its.StockMinNumber
  6763. }
  6764. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  6765. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  6766. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  6767. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  6768. }
  6769. }
  6770. orgId := c.GetAdminUserInfo().CurrentOrgId
  6771. if len(oldGoods) > 0 {
  6772. timeStr := time.Now().Format("2006-01-02")
  6773. timeArr := strings.Split(timeStr, "-")
  6774. total, _ := service.FindAllWarehouseOut(orgId)
  6775. total = total + 1
  6776. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  6777. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  6778. number = number + total
  6779. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  6780. operation_time := time.Now().Unix()
  6781. creater := c.GetAdminUserInfo().AdminUser.Id
  6782. //查询默认出库仓库库存
  6783. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  6784. recordDateStr := time.Now().Format("2006-01-02")
  6785. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  6786. nowtime := recordDate.Unix()
  6787. warehouseOut := models.WarehouseOut{
  6788. WarehouseOutOrderNumber: warehousing_out_order,
  6789. OperationTime: operation_time,
  6790. OrgId: orgId,
  6791. Creater: creater,
  6792. Ctime: time.Now().Unix(),
  6793. Status: 1,
  6794. WarehouseOutTime: nowtime,
  6795. Type: 1,
  6796. StorehouseId: storeConfig.StorehouseOutInfo,
  6797. IsCheck: 1,
  6798. OrderId: order.ID,
  6799. IsSys: 5,
  6800. }
  6801. //查询是否生成出库单
  6802. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6803. if out.ID == 0 {
  6804. service.AddSigleWarehouseOut(&warehouseOut)
  6805. }
  6806. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  6807. for _, item := range oldGoods {
  6808. dialyPrepareOne := models.DialysisBeforePrepare{
  6809. GoodTypeId: item.GoodTypeId,
  6810. GoodId: item.GoodId,
  6811. PatientId: his.PatientId,
  6812. RecordDate: item.RecordDate,
  6813. UserOrgId: adminUser.CurrentOrgId,
  6814. Count: item.Count,
  6815. Ctime: time.Now().Unix(),
  6816. Creater: adminUser.AdminUser.Id,
  6817. CommdityCode: item.CommdityCode,
  6818. Status: 1,
  6819. StorehouseId: houseConfig.StorehouseOutInfo,
  6820. }
  6821. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  6822. //非零用
  6823. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  6824. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6825. //查询剩余库存
  6826. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6827. var sum_count int64
  6828. for _, item := range goodList {
  6829. sum_count += item.StockCount
  6830. }
  6831. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6832. //耗材
  6833. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6834. }
  6835. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  6836. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  6837. //查询剩余库存
  6838. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  6839. var sum_count int64
  6840. for _, item := range goodList {
  6841. sum_count += item.StockCount
  6842. }
  6843. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  6844. //耗材
  6845. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  6846. }
  6847. }
  6848. }
  6849. }
  6850. c.ServeSuccessJSON(map[string]interface{}{
  6851. "msg": "结算成功",
  6852. })
  6853. }
  6854. }
  6855. }
  6856. // 退款
  6857. func (c *HisApiController) Refund() {
  6858. order_id, _ := c.GetInt64("order_id")
  6859. order, _ := service.GetHisOrderByID(order_id)
  6860. adminUser := c.GetAdminUserInfo()
  6861. orgid := c.GetAdminUserInfo().CurrentOrgId
  6862. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  6863. if err != nil {
  6864. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6865. return
  6866. }
  6867. tmp := strconv.FormatInt(order.ID, 10)
  6868. //当押金不为零时产生退费记录
  6869. if order.Decimal != 0 {
  6870. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  6871. if err != nil {
  6872. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6873. return
  6874. }
  6875. }
  6876. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  6877. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  6878. var goods []*models.DialysisBeforePrepareGoods
  6879. var newGoods []*models.NewDialysisBeforePrepareGoods
  6880. var infos []*models.HisDoctorAdviceInfo
  6881. for _, info := range orders {
  6882. if info.AdviceId > 0 && info.ProjectId == 0 {
  6883. infos = append(infos, &info.HisDoctorAdviceInfo)
  6884. }
  6885. if info.ProjectId > 0 && info.AdviceId == 0 {
  6886. if info.HisPrescriptionProject.Type == 3 {
  6887. var good models.DialysisBeforePrepareGoods
  6888. var newGood models.NewDialysisBeforePrepareGoods
  6889. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6890. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6891. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6892. good.Count = int64(count)
  6893. good.StorehouseId = houseConfig.StorehouseOutInfo
  6894. good.ProjectId = info.HisPrescriptionProject.ID
  6895. good.PatientId = info.PatientId
  6896. good.OrderId = order_id
  6897. goods = append(goods, &good)
  6898. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  6899. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  6900. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  6901. newGood.Count = int64(count2)
  6902. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  6903. newGood.ProjectId = info.HisPrescriptionProject.ID
  6904. newGood.RecordDate = order.SettleAccountsDate
  6905. newGood.UserOrgId = order.UserOrgId
  6906. newGood.PatientId = info.PatientId
  6907. newGood.OrderId = order_id
  6908. newGoods = append(newGoods, &newGood)
  6909. }
  6910. }
  6911. }
  6912. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  6913. if settConfig.IsOpen == 1 {
  6914. for _, item := range infos {
  6915. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6916. }
  6917. for _, item := range newGoods {
  6918. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  6919. }
  6920. }
  6921. c.ServeSuccessJSON(map[string]interface{}{
  6922. "msg": "退费成功",
  6923. })
  6924. }
  6925. func (c *HisApiController) RefundNumber() {
  6926. his_patient_id, _ := c.GetInt64("id")
  6927. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6928. info.Status = 0
  6929. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  6930. if count > 0 {
  6931. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  6932. return
  6933. }
  6934. err := service.SaveHisPatient(info)
  6935. if err == nil {
  6936. c.ServeSuccessJSON(map[string]interface{}{
  6937. "msg": "退号成功",
  6938. })
  6939. } else {
  6940. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6941. return
  6942. }
  6943. }
  6944. func (this *HisApiController) AdditionalCharge() {
  6945. dataBody := make(map[string]interface{}, 0)
  6946. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6947. fmt.Println(err)
  6948. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  6949. patient_id := int64(dataBody["patient_id"].(float64))
  6950. medicineData, _ := dataBody["medicineData"].([]interface{})
  6951. adminUserInfo := this.GetAdminUserInfo()
  6952. orgId := adminUserInfo.CurrentOrgId
  6953. admin_user_id := adminUserInfo.AdminUser.Id
  6954. timeStr := time.Now().Format("2006-01-02")
  6955. timeLayout := "2006-01-02 15:04:05"
  6956. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  6957. timenow := timeStringToTime.Unix()
  6958. var additionalCharges []*models.HisAdditionalCharge
  6959. for _, item := range medicineData {
  6960. var randNum int
  6961. randNum = rand.Intn(10000) + 1000
  6962. timestamp := time.Now().Unix()
  6963. tempTime := time.Unix(timestamp, 0)
  6964. timeFormat := tempTime.Format("20060102150405")
  6965. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  6966. items := item.(map[string]interface{})
  6967. money := items["price"].(string)
  6968. item_id_str := items["item_id"].(string)
  6969. name := items["name"].(string)
  6970. id_str := items["id"].(string)
  6971. moneys, _ := strconv.ParseInt(money, 10, 64)
  6972. monStr := strconv.FormatInt(moneys, 10)
  6973. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  6974. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  6975. id, _ := strconv.ParseInt(id_str, 10, 64)
  6976. additionalCharge := &models.HisAdditionalCharge{
  6977. ID: id,
  6978. HisPatientId: his_patient_id,
  6979. UserOrgId: orgId,
  6980. PatientId: patient_id,
  6981. RecordDate: timenow,
  6982. Price: monneyStr,
  6983. Status: 1,
  6984. ItemName: name,
  6985. ItemId: item_id,
  6986. AdminUserId: admin_user_id,
  6987. CreatedTime: time.Now().Unix(),
  6988. OrderStatus: 0,
  6989. PrescriptionNumber: "",
  6990. BatchNumber: "",
  6991. FeedetlSn: p_number,
  6992. }
  6993. service.CreateAdditionalCharge(additionalCharge)
  6994. additionalCharges = append(additionalCharges, additionalCharge)
  6995. }
  6996. this.ServeSuccessJSON(map[string]interface{}{
  6997. "msg": "添加成功",
  6998. "additional_charges": additionalCharges,
  6999. })
  7000. }
  7001. func (this *HisApiController) DeleteAddition() {
  7002. id, _ := this.GetInt64("id")
  7003. //TODO 需要判断是否已经结算
  7004. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  7005. if err == nil {
  7006. this.ServeSuccessJSON(map[string]interface{}{
  7007. "msg": "删除成功",
  7008. })
  7009. return
  7010. } else {
  7011. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7012. return
  7013. }
  7014. }
  7015. func (this *HisApiController) GetAdminUsers() {
  7016. adminUser := this.GetAdminUserInfo()
  7017. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  7018. this.ServeSuccessJSON(map[string]interface{}{
  7019. "doctors": doctors,
  7020. })
  7021. }
  7022. func (this *HisApiController) GetLastOrNextHisPrescription() {
  7023. change_type, _ := this.GetInt64("type", 0)
  7024. record_date := this.GetString("record_time")
  7025. patient_id, _ := this.GetInt64("patient_id", 0)
  7026. p_type, _ := this.GetInt64("p_type", 0)
  7027. timeLayout := "2006-01-02"
  7028. loc, _ := time.LoadLocation("Local")
  7029. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  7030. record_time := theAdviceRecordTime.Unix()
  7031. adminUserInfo := this.GetAdminUserInfo()
  7032. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  7033. if err == nil {
  7034. if len(prescriptions) == 0 {
  7035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  7036. return
  7037. } else {
  7038. this.ServeSuccessJSON(map[string]interface{}{
  7039. "prescriptions": prescriptions,
  7040. })
  7041. return
  7042. }
  7043. } else {
  7044. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7045. return
  7046. }
  7047. }
  7048. func (this *HisApiController) GetCallHisPrescription() {
  7049. patient_id, _ := this.GetInt64("patient_id", 0)
  7050. timeLayout := "2006-01-02"
  7051. loc, _ := time.LoadLocation("Local")
  7052. start_time := this.GetString("start_time")
  7053. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7054. end_time := this.GetString("end_time")
  7055. p_type, _ := this.GetInt64("p_type")
  7056. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7057. adminUserInfo := this.GetAdminUserInfo()
  7058. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  7059. if err == nil {
  7060. this.ServeSuccessJSON(map[string]interface{}{
  7061. "prescriptions": prescriptions,
  7062. })
  7063. return
  7064. } else {
  7065. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7066. return
  7067. }
  7068. }
  7069. func (this *HisApiController) GetHisDayPrescription() {
  7070. timeLayout := "2006-01-02"
  7071. loc, _ := time.LoadLocation("Local")
  7072. start_time := this.GetString("start_time")
  7073. patient_id, _ := this.GetInt64("patient_id", 0)
  7074. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7075. end_time := this.GetString("end_time")
  7076. p_type, _ := this.GetInt64("p_type")
  7077. order_status, _ := this.GetInt64("type")
  7078. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7079. adminUserInfo := this.GetAdminUserInfo()
  7080. var dayHisPrescription []*models.HisPrescription
  7081. var err error
  7082. if order_status == 1 || order_status == 0 {
  7083. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7084. } else if order_status == 2 {
  7085. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  7086. }
  7087. var settle_total float64
  7088. for _, item := range dayHisPrescription {
  7089. if len(item.HisPrescriptionProject) > 0 {
  7090. for _, subItem := range item.HisPrescriptionProject {
  7091. count, _ := strconv.ParseFloat(subItem.Count, 64)
  7092. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  7093. settle_total = settle_total + total
  7094. }
  7095. }
  7096. if len(item.HisDoctorAdviceInfo) > 0 {
  7097. for _, subItem := range item.HisDoctorAdviceInfo {
  7098. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  7099. settle_total = settle_total + total
  7100. }
  7101. }
  7102. }
  7103. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  7104. if err == nil {
  7105. this.ServeSuccessJSON(map[string]interface{}{
  7106. "day_prescription": dayHisPrescription,
  7107. "settle_total": settle_total,
  7108. })
  7109. return
  7110. } else {
  7111. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  7112. return
  7113. }
  7114. }
  7115. func (c *HisApiController) GetHisChargePatientList() {
  7116. record_date := c.GetString("record_date")
  7117. order_status, _ := c.GetInt64("type")
  7118. sch_type, _ := c.GetInt64("sch_type")
  7119. timeLayout := "2006-01-02"
  7120. loc, _ := time.LoadLocation("Local")
  7121. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7122. if err != nil {
  7123. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7124. return
  7125. }
  7126. recordDateTime := theTime.Unix()
  7127. adminInfo := c.GetAdminUserInfo()
  7128. var tempPatients []*service.NewTempPatients
  7129. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  7130. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  7131. if order_status != 2 {
  7132. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7133. } else {
  7134. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7135. }
  7136. } else {
  7137. if order_status != 2 {
  7138. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7139. } else {
  7140. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  7141. }
  7142. }
  7143. var patients []*service.NewTempPatients
  7144. var patients_two []*service.NewTempPatients
  7145. for _, item := range tempPatients {
  7146. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  7147. //过滤掉没挂号的和没开处方的
  7148. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  7149. patients = append(patients, item)
  7150. }
  7151. //过滤掉没挂号的
  7152. if len(item.HisPatient) > 0 {
  7153. patients_two = append(patients_two, item)
  7154. }
  7155. } else {
  7156. if len(item.HisPrescription) > 0 {
  7157. patients = append(patients, item)
  7158. }
  7159. }
  7160. }
  7161. c.ServeSuccessJSON(map[string]interface{}{
  7162. "list": patients,
  7163. "list_two": patients_two,
  7164. })
  7165. }
  7166. func (c *HisApiController) GetHisUnRegisterPatientList() {
  7167. record_date := c.GetString("record_date")
  7168. timeLayout := "2006-01-02"
  7169. loc, _ := time.LoadLocation("Local")
  7170. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7171. if err != nil {
  7172. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7173. return
  7174. }
  7175. recordDateTime := theTime.Unix()
  7176. adminUser := c.GetAdminUserInfo()
  7177. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  7178. var patients []*service.Patients
  7179. for _, item := range tempPatients {
  7180. if item.HisPatient.ID == 0 {
  7181. patients = append(patients, item)
  7182. }
  7183. }
  7184. c.ServeSuccessJSON(map[string]interface{}{
  7185. "list": patients,
  7186. //"list_two": patients_two,
  7187. })
  7188. }
  7189. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  7190. newArr = make([]*service.Patients, 0)
  7191. for i := 0; i < len(patient); i++ {
  7192. repeat := false
  7193. for j := i + 1; j < len(patient); j++ {
  7194. if patient[i].ID == patient[j].ID {
  7195. repeat = true
  7196. break
  7197. }
  7198. }
  7199. if !repeat {
  7200. newArr = append(newArr, patient[i])
  7201. }
  7202. }
  7203. return
  7204. }
  7205. func (c *HisApiController) GetHisChargePatientInfo() {
  7206. patient_id, _ := c.GetInt64("patient_id")
  7207. his_patient_id, _ := c.GetInt64("his_patient_id")
  7208. record_date := c.GetString("record_date")
  7209. //start_time := c.GetString("start_time")
  7210. //end_time := c.GetString("end_time")
  7211. order_status, _ := c.GetInt64("type", 0)
  7212. p_type, _ := c.GetInt64("p_type", 0)
  7213. order_id, _ := c.GetInt64("order_id", 0)
  7214. timeLayout := "2006-01-02"
  7215. loc, _ := time.LoadLocation("Local")
  7216. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7217. if err != nil {
  7218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7219. return
  7220. }
  7221. recordDateTime := theTime.Unix()
  7222. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7223. //if err != nil {
  7224. //
  7225. //}
  7226. //startRecordDateTime := startTime.Unix()
  7227. //
  7228. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7229. //if err != nil {
  7230. //
  7231. //}
  7232. //endRecordDateTime := endTime.Unix()
  7233. admin := c.GetAdminUserInfo()
  7234. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  7235. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  7236. var prescriptions []*models.HisPrescription
  7237. //var unChargeMonthPrescriptions []*models.HisPrescription
  7238. order, _ := service.GetHisOrderByID(order_id)
  7239. if order_status == 1 || order_status == 0 {
  7240. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  7241. } else if order_status == 2 {
  7242. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  7243. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  7244. }
  7245. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  7246. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  7247. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  7248. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  7249. //获取所有科室信息
  7250. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  7251. c.ServeSuccessJSON(map[string]interface{}{
  7252. "his_info": his_patient_info,
  7253. "xt_info": xt_patient_info,
  7254. "prescription": prescriptions,
  7255. "case_history": case_history,
  7256. "info": patientPrescriptionInfo,
  7257. "last_info": lastPatientPrescriptionInfo,
  7258. "order": order,
  7259. "doctors": doctors,
  7260. "department": department,
  7261. })
  7262. return
  7263. }
  7264. func (c *HisApiController) GetAllOrderDetail() {
  7265. order_id, _ := c.GetInt64("id", 0)
  7266. order, _ := service.GetHisOrderByID(order_id)
  7267. if order.ID == 0 {
  7268. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7269. return
  7270. }
  7271. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7272. org_id := c.GetAdminUserInfo().CurrentOrgId
  7273. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7274. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7275. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7276. c.ServeSuccessJSON(map[string]interface{}{
  7277. "order": order,
  7278. "order_info": order_info,
  7279. "patient": patient,
  7280. "admin_info": adminInfo,
  7281. "hospital_record": record,
  7282. })
  7283. return
  7284. }
  7285. func (c *HisApiController) GetAllOrderDetailCollect() {
  7286. order_id, _ := c.GetInt64("id", 0)
  7287. order, _ := service.GetHisOrderByID(order_id)
  7288. if order.ID == 0 {
  7289. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  7290. return
  7291. }
  7292. org_id := c.GetAdminUserInfo().CurrentOrgId
  7293. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  7294. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  7295. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  7296. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  7297. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  7298. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7299. var bedCostTotal float64 = 0 //床位总费
  7300. //var bedCostSelfTotal float64 = 0 //床位自费
  7301. var operationCostTotal float64 = 0 //手术费
  7302. //var operationCostSelfTotal float64 = 0 //手术费
  7303. var otherCostTotal float64 = 0 //其他费用
  7304. //var otherCostSelfTotal float64 = 0 //其他费用
  7305. var materialCostTotal float64 = 0 //材料费
  7306. //var materialCostSelfTotal float64 = 0 //材料费
  7307. var westernMedicineCostTotal float64 = 0 //西药费
  7308. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  7309. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7310. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7311. var checkCostTotal float64 = 0 //检查费
  7312. //var checkCostSelfTotal float64 = 0 //检查费
  7313. var laboratoryCostTotal float64 = 0 //化验费
  7314. //var laboratoryCostSelfTotal float64 = 0 //化验费
  7315. var treatCostTotal float64 = 0 //治疗费用
  7316. //var treatCostSelfTotal float64 = 0 //治疗费用
  7317. var zhenChaCostTotal float64 = 0 //其他费用
  7318. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7319. decimal.DivisionPrecision = 2
  7320. var BalanceAccountsType int64
  7321. if his.ID > 0 {
  7322. BalanceAccountsType = his.BalanceAccountsType
  7323. } else {
  7324. BalanceAccountsType = record.BalanceAccountsType
  7325. }
  7326. if BalanceAccountsType != 2 {
  7327. for _, item := range order_info {
  7328. if org_id == 10215 {
  7329. if item.MedChrgitmType == "01" { //床位费
  7330. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7331. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7332. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7333. }
  7334. if item.MedChrgitmType == "02" { //诊察费
  7335. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7336. //zhenChaCostSelfTotal = zhenChaCostTotal
  7337. }
  7338. if item.MedChrgitmType == "03" { //检查费
  7339. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7340. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7341. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7342. }
  7343. //if item.MedChrgitmType == "02" { //检查费
  7344. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7345. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7346. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7347. //}
  7348. if item.MedChrgitmType == "04" { //化验费
  7349. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7350. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7351. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7352. }
  7353. if item.MedChrgitmType == "05" { //治疗费
  7354. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7355. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7356. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7357. }
  7358. if item.MedChrgitmType == "06" { //手术费
  7359. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7360. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7361. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7362. }
  7363. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7364. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7365. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7366. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7367. }
  7368. if item.MedChrgitmType == "09" { //西药费
  7369. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7370. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7371. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7372. }
  7373. if item.MedChrgitmType == "11" { //中成费
  7374. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7375. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7376. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7377. }
  7378. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7379. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7380. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7381. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7382. }
  7383. } else if org_id == 10188 || org_id == 10217 {
  7384. if item.MedChrgitmType == "01" { //床位费
  7385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7386. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7387. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7388. }
  7389. if item.MedChrgitmType == "02" { //诊察费
  7390. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7391. //zhenChaCostSelfTotal = zhenChaCostTotal
  7392. }
  7393. if item.MedChrgitmType == "03" { //检查费
  7394. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7395. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7396. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7397. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7398. }
  7399. //if item.MedChrgitmType == "02" { //检查费
  7400. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7401. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7402. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7403. //}
  7404. if item.MedChrgitmType == "04" { //化验费
  7405. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7406. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7407. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7408. }
  7409. if item.MedChrgitmType == "05" { //治疗费
  7410. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7411. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7412. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7413. }
  7414. if item.MedChrgitmType == "06" { //手术费
  7415. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7416. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7417. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7418. }
  7419. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7420. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7421. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7422. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7423. }
  7424. if item.MedChrgitmType == "09" { //西药费
  7425. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7426. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7427. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7428. }
  7429. if item.MedChrgitmType == "11" { //中成费
  7430. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7431. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7432. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7433. }
  7434. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7435. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7436. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7437. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7438. }
  7439. } else {
  7440. if item.MedChrgitmType == "01" { //床位费
  7441. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7442. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7443. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7444. }
  7445. //if item.MedChrgitmType == "02" { //诊察费
  7446. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7447. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7448. //}
  7449. if item.MedChrgitmType == "03" { //检查费
  7450. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7451. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7452. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7453. }
  7454. //if item.MedChrgitmType == "02" { //检查费
  7455. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7456. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7457. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7458. //}
  7459. if item.MedChrgitmType == "04" { //化验费
  7460. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7461. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7462. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7463. }
  7464. if item.MedChrgitmType == "05" { //治疗费
  7465. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7466. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7467. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7468. }
  7469. if item.MedChrgitmType == "06" { //手术费
  7470. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7471. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7472. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7473. }
  7474. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7475. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7476. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7477. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7478. }
  7479. if item.MedChrgitmType == "09" { //西药费
  7480. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7481. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7482. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7483. }
  7484. if item.MedChrgitmType == "11" { //中成费
  7485. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7486. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7487. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7488. }
  7489. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7490. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7491. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7492. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7493. }
  7494. }
  7495. }
  7496. c.ServeSuccessJSON(map[string]interface{}{
  7497. "order": order,
  7498. "order_info": order_info,
  7499. "patient": patient,
  7500. "admin_info": adminInfo,
  7501. "his_hospital": record,
  7502. "bedCostTotal": bedCostTotal,
  7503. "operationCostTotal": operationCostTotal,
  7504. "otherCostTotal": otherCostTotal,
  7505. "materialCostTotal": materialCostTotal,
  7506. "westernMedicineCostTotal": westernMedicineCostTotal,
  7507. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7508. "checkCostTotal": checkCostTotal,
  7509. "zhenChaCostTotal": zhenChaCostTotal,
  7510. "laboratoryCostTotal": laboratoryCostTotal,
  7511. "treatCostTotal": treatCostTotal,
  7512. })
  7513. } else {
  7514. for _, item := range order_info {
  7515. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7516. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7517. item.MedChrgitmType = "09"
  7518. }
  7519. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7520. if item.HisPrescriptionProject.Type == 2 {
  7521. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7522. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7523. case 0:
  7524. item.MedChrgitmType = "0"
  7525. break
  7526. case 1:
  7527. item.MedChrgitmType = "14"
  7528. break
  7529. case 2:
  7530. item.MedChrgitmType = "05"
  7531. break
  7532. case 3:
  7533. item.MedChrgitmType = "03"
  7534. break
  7535. case 4:
  7536. item.MedChrgitmType = "03"
  7537. break
  7538. case 5:
  7539. item.MedChrgitmType = "08"
  7540. break
  7541. case 6:
  7542. item.MedChrgitmType = "14"
  7543. break
  7544. case 7:
  7545. item.MedChrgitmType = "14"
  7546. break
  7547. case 8:
  7548. item.MedChrgitmType = "03"
  7549. break
  7550. case 9:
  7551. item.MedChrgitmType = "14"
  7552. break
  7553. case 10:
  7554. item.MedChrgitmType = "14"
  7555. break
  7556. case 11:
  7557. item.MedChrgitmType = "06"
  7558. break
  7559. case 12:
  7560. item.MedChrgitmType = "12"
  7561. break
  7562. case 13:
  7563. item.MedChrgitmType = "01"
  7564. break
  7565. case 14:
  7566. item.MedChrgitmType = "04"
  7567. break
  7568. case 15:
  7569. item.MedChrgitmType = "14"
  7570. break
  7571. }
  7572. } else {
  7573. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7574. case 1:
  7575. item.MedChrgitmType = "14"
  7576. break
  7577. case 2:
  7578. item.MedChrgitmType = "05"
  7579. break
  7580. case 3:
  7581. item.MedChrgitmType = "04"
  7582. break
  7583. case 4:
  7584. item.MedChrgitmType = "14"
  7585. break
  7586. case 5:
  7587. item.MedChrgitmType = "08"
  7588. break
  7589. case 6:
  7590. item.MedChrgitmType = "14"
  7591. break
  7592. case 7:
  7593. item.MedChrgitmType = "14"
  7594. break
  7595. case 8:
  7596. item.MedChrgitmType = "03"
  7597. break
  7598. case 9:
  7599. item.MedChrgitmType = "14"
  7600. break
  7601. }
  7602. }
  7603. } else if item.HisPrescriptionProject.Type == 3 {
  7604. item.MedChrgitmType = "08"
  7605. }
  7606. }
  7607. }
  7608. for _, item := range order_info {
  7609. if org_id == 10215 {
  7610. if item.MedChrgitmType == "01" { //床位费
  7611. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7612. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7613. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7614. }
  7615. if item.MedChrgitmType == "02" { //诊察费
  7616. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7617. //zhenChaCostSelfTotal = zhenChaCostTotal
  7618. }
  7619. if item.MedChrgitmType == "03" { //检查费
  7620. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7621. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7622. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7623. }
  7624. //if item.MedChrgitmType == "02" { //检查费
  7625. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7626. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7627. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7628. //}
  7629. if item.MedChrgitmType == "04" { //化验费
  7630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7631. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7632. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7633. }
  7634. if item.MedChrgitmType == "05" { //治疗费
  7635. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7636. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7637. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7638. }
  7639. if item.MedChrgitmType == "06" { //手术费
  7640. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7641. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7642. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7643. }
  7644. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7645. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7646. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7647. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7648. }
  7649. if item.MedChrgitmType == "09" { //西药费
  7650. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7651. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7652. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7653. }
  7654. if item.MedChrgitmType == "11" { //中成费
  7655. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7656. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7657. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7658. }
  7659. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7660. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7661. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7662. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7663. }
  7664. } else {
  7665. if item.MedChrgitmType == "01" { //床位费
  7666. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7667. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7668. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7669. }
  7670. //if item.MedChrgitmType == "02" { //诊察费
  7671. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7672. // //zhenChaCostSelfTotal = zhenChaCostTotal
  7673. //}
  7674. if item.MedChrgitmType == "03" { //检查费
  7675. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7676. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7677. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7678. }
  7679. //if item.MedChrgitmType == "02" { //检查费
  7680. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7681. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7682. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7683. //}
  7684. if item.MedChrgitmType == "04" { //化验费
  7685. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7686. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7687. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7688. }
  7689. if item.MedChrgitmType == "05" { //治疗费
  7690. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7691. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7692. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7693. }
  7694. if item.MedChrgitmType == "06" { //手术费
  7695. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7696. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7697. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7698. }
  7699. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  7700. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7701. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7702. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7703. }
  7704. if item.MedChrgitmType == "09" { //西药费
  7705. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7706. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7707. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7708. }
  7709. if item.MedChrgitmType == "11" { //中成费
  7710. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7711. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7712. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7713. }
  7714. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7715. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7716. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7717. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7718. }
  7719. }
  7720. }
  7721. c.ServeSuccessJSON(map[string]interface{}{
  7722. "order": order,
  7723. "order_info": order_info,
  7724. "patient": patient,
  7725. "admin_info": adminInfo,
  7726. "his_hospital": record,
  7727. "bedCostTotal": bedCostTotal,
  7728. "operationCostTotal": operationCostTotal,
  7729. "otherCostTotal": otherCostTotal,
  7730. "materialCostTotal": materialCostTotal,
  7731. "westernMedicineCostTotal": westernMedicineCostTotal,
  7732. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7733. "checkCostTotal": checkCostTotal,
  7734. "zhenChaCostTotal": zhenChaCostTotal,
  7735. "laboratoryCostTotal": laboratoryCostTotal,
  7736. "treatCostTotal": treatCostTotal,
  7737. })
  7738. }
  7739. }
  7740. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  7741. page, _ := c.GetInt64("page")
  7742. limit, _ := c.GetInt64("limit")
  7743. keywords := c.GetString("keywords")
  7744. start_time := c.GetString("start_time")
  7745. end_time := c.GetString("end_time")
  7746. //clr_type := c.GetString("clr_type")
  7747. insutype := c.GetString("insutype")
  7748. timeLayout := "2006-01-02"
  7749. loc, _ := time.LoadLocation("Local")
  7750. var theStartTIme int64
  7751. if len(start_time) > 0 {
  7752. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7753. theStartTIme = theTime.Unix()
  7754. }
  7755. var theEndtTIme int64
  7756. if len(end_time) > 0 {
  7757. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7758. theEndtTIme = theTime.Unix()
  7759. }
  7760. if page <= 0 {
  7761. page = 1
  7762. }
  7763. if limit <= 0 {
  7764. limit = 10
  7765. }
  7766. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  7767. c.ServeSuccessJSON(map[string]interface{}{
  7768. "total": total,
  7769. "list": list,
  7770. })
  7771. return
  7772. }
  7773. func (c *HisApiController) GetPutOnRecordList() {
  7774. page, _ := c.GetInt64("page")
  7775. limit, _ := c.GetInt64("limit")
  7776. keywords := c.GetString("keywords")
  7777. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  7778. if page <= 0 {
  7779. page = 1
  7780. }
  7781. if limit <= 0 {
  7782. limit = 10
  7783. }
  7784. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  7785. c.ServeSuccessJSON(map[string]interface{}{
  7786. "total": total,
  7787. "list": list,
  7788. })
  7789. return
  7790. }
  7791. func (c *HisApiController) GetCompareData() {
  7792. start_time := c.GetString("start_time")
  7793. end_time := c.GetString("end_time")
  7794. insutype := c.GetString("insutype")
  7795. clr_type := c.GetString("clr_type")
  7796. timeLayout := "2006-01-02"
  7797. loc, _ := time.LoadLocation("Local")
  7798. var theStartTIme int64
  7799. if len(start_time) > 0 {
  7800. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7801. if err != nil {
  7802. theStartTIme = 0
  7803. }
  7804. theStartTIme = theTime.Unix()
  7805. }
  7806. var theEndtTIme int64
  7807. if len(end_time) > 0 {
  7808. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7809. if err != nil {
  7810. theEndtTIme = 0
  7811. }
  7812. theEndtTIme = theTime.Unix()
  7813. }
  7814. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  7815. fmt.Println(err)
  7816. if err == nil {
  7817. c.ServeSuccessJSON(map[string]interface{}{
  7818. "list": formData,
  7819. })
  7820. } else {
  7821. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7822. return
  7823. }
  7824. }
  7825. func (c *HisApiController) GetFaPiaoData() {
  7826. order_id, _ := c.GetInt64("order_id")
  7827. patient_id, _ := c.GetInt64("patient_id")
  7828. //number := c.GetString("number")
  7829. adminUser := c.GetAdminUserInfo()
  7830. order, _ := service.GetHisOrderByID(order_id)
  7831. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  7832. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  7833. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  7834. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  7835. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  7836. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  7837. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  7838. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  7839. var bedCostTotal float64 = 0 //床位总费
  7840. var bedCostSelfTotal float64 = 0 //床位自费
  7841. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  7842. var operationCostTotal float64 = 0 //手术费
  7843. var operationCostSelfTotal float64 = 0 //手术费
  7844. var operationCostPartSelfTotal float64 = 0 //手术费
  7845. var otherCostTotal float64 = 0 //其他费用
  7846. var otherCostSelfTotal float64 = 0 //其他费用
  7847. var otherCostPartSelfTotal float64 = 0 //其他费用
  7848. var materialCostTotal float64 = 0 //材料费
  7849. var materialCostSelfTotal float64 = 0 //材料费
  7850. var materialCostPartSelfTotal float64 = 0 //材料费
  7851. var westernMedicineCostTotal float64 = 0 //西药费
  7852. var westernMedicineCostSelfTotal float64 = 0 //西药费
  7853. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  7854. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  7855. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  7856. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  7857. var checkCostTotal float64 = 0 //检查费
  7858. var checkCostSelfTotal float64 = 0 //检查费
  7859. var checkCostPartSelfTotal float64 = 0 //检查费
  7860. var hiliCostTotal float64 = 0 //护理费
  7861. var hiliCostSelfTotal float64 = 0 //护理费
  7862. var hiliCostPartSelfTotal float64 = 0 //护理费
  7863. var laboratoryCostTotal float64 = 0 //化验费
  7864. var laboratoryCostSelfTotal float64 = 0 //化验费
  7865. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  7866. var treatCostTotal float64 = 0 //治疗费用
  7867. var treatCostSelfTotal float64 = 0 //治疗费用
  7868. var treatCostPartSelfTotal float64 = 0 //治疗费用
  7869. var zhenChaCostTotal float64 = 0 //其他费用
  7870. var zhenChaCostSelfTotal float64 = 0 //其他费用
  7871. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  7872. decimal.DivisionPrecision = 2
  7873. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7874. var balanceAccountsType int64
  7875. if his.ID > 0 {
  7876. balanceAccountsType = his.BalanceAccountsType
  7877. } else {
  7878. balanceAccountsType = his_hospital_record.BalanceAccountsType
  7879. }
  7880. if balanceAccountsType == 2 {
  7881. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  7882. for _, item := range orderInfos_two {
  7883. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  7884. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  7885. item.MedChrgitmType = "09"
  7886. }
  7887. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  7888. if item.HisPrescriptionProject.Type == 2 {
  7889. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  7890. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7891. case 0:
  7892. item.MedChrgitmType = "0"
  7893. break
  7894. case 1:
  7895. item.MedChrgitmType = "14"
  7896. break
  7897. case 2:
  7898. item.MedChrgitmType = "05"
  7899. break
  7900. case 3:
  7901. item.MedChrgitmType = "03"
  7902. break
  7903. case 4:
  7904. item.MedChrgitmType = "03"
  7905. break
  7906. case 5:
  7907. item.MedChrgitmType = "08"
  7908. break
  7909. case 6:
  7910. item.MedChrgitmType = "14"
  7911. break
  7912. case 7:
  7913. item.MedChrgitmType = "14"
  7914. break
  7915. case 8:
  7916. item.MedChrgitmType = "03"
  7917. break
  7918. case 9:
  7919. item.MedChrgitmType = "14"
  7920. break
  7921. case 10:
  7922. item.MedChrgitmType = "14"
  7923. break
  7924. case 11:
  7925. item.MedChrgitmType = "06"
  7926. break
  7927. case 12:
  7928. item.MedChrgitmType = "12"
  7929. break
  7930. case 13:
  7931. item.MedChrgitmType = "01"
  7932. break
  7933. case 14:
  7934. item.MedChrgitmType = "04"
  7935. break
  7936. case 15:
  7937. item.MedChrgitmType = "02"
  7938. break
  7939. }
  7940. } else {
  7941. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  7942. case 1:
  7943. item.MedChrgitmType = "14"
  7944. break
  7945. case 2:
  7946. item.MedChrgitmType = "05"
  7947. break
  7948. case 3:
  7949. item.MedChrgitmType = "03"
  7950. break
  7951. case 4:
  7952. item.MedChrgitmType = "03"
  7953. break
  7954. case 5:
  7955. item.MedChrgitmType = "08"
  7956. break
  7957. case 6:
  7958. item.MedChrgitmType = "14"
  7959. break
  7960. case 7:
  7961. item.MedChrgitmType = "14"
  7962. break
  7963. case 8:
  7964. item.MedChrgitmType = "03"
  7965. break
  7966. case 9:
  7967. item.MedChrgitmType = "14"
  7968. break
  7969. }
  7970. }
  7971. } else if item.HisPrescriptionProject.Type == 3 {
  7972. item.MedChrgitmType = "08"
  7973. }
  7974. }
  7975. }
  7976. for _, item := range orderInfos_two {
  7977. fmt.Println(item.MedChrgitmType)
  7978. if item.MedChrgitmType == "07" { //床位费
  7979. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7980. hiliCostSelfTotal = hiliCostTotal
  7981. }
  7982. if item.MedChrgitmType == "01" { //床位费
  7983. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7984. bedCostSelfTotal = bedCostTotal
  7985. }
  7986. if item.MedChrgitmType == "02" { //诊察费
  7987. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7988. zhenChaCostSelfTotal = zhenChaCostTotal
  7989. }
  7990. if item.MedChrgitmType == "03" { //检查费
  7991. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7992. checkCostSelfTotal = checkCostTotal
  7993. }
  7994. if item.MedChrgitmType == "04" { //化验费
  7995. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7996. laboratoryCostSelfTotal = laboratoryCostTotal
  7997. }
  7998. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  7999. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8000. treatCostSelfTotal = treatCostTotal
  8001. }
  8002. if item.MedChrgitmType == "06" { //手术费
  8003. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8004. operationCostSelfTotal = treatCostTotal
  8005. }
  8006. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8007. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8008. materialCostSelfTotal = materialCostTotal
  8009. }
  8010. if item.MedChrgitmType == "09" { //西药费
  8011. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8012. westernMedicineCostSelfTotal = westernMedicineCostTotal
  8013. }
  8014. if item.MedChrgitmType == "11" { //中成费
  8015. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8016. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8017. }
  8018. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8019. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8020. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8021. otherCostSelfTotal = otherCostTotal
  8022. }
  8023. } else {
  8024. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8025. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8026. otherCostSelfTotal = otherCostTotal
  8027. }
  8028. }
  8029. }
  8030. } else {
  8031. for _, item := range orderInfos {
  8032. if item.MedChrgitmType == "01" { //床位费
  8033. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8034. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8035. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8036. }
  8037. if item.MedChrgitmType == "02" { //诊察费
  8038. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8039. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8040. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8041. }
  8042. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8043. if item.MedChrgitmType == "03" { //检查费
  8044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8045. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8046. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8047. }
  8048. } else {
  8049. if item.MedChrgitmType == "03" { //检查费
  8050. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8051. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8052. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8053. }
  8054. }
  8055. if item.MedChrgitmType == "04" { //化验费
  8056. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8057. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8058. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8059. }
  8060. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8061. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8062. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8063. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8064. }
  8065. if item.MedChrgitmType == "06" { //手术费
  8066. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8067. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8068. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8069. }
  8070. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //材料费
  8071. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8072. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8073. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8074. }
  8075. if item.MedChrgitmType == "07" { //西药费
  8076. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8077. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8078. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8079. }
  8080. if item.MedChrgitmType == "09" { //西药费
  8081. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8082. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8083. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8084. }
  8085. if item.MedChrgitmType == "11" { //中成费
  8086. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8087. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8088. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8089. }
  8090. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8091. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8092. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8093. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8094. }
  8095. }
  8096. }
  8097. timeLayout := "2006-01-02"
  8098. loc, _ := time.LoadLocation("Local")
  8099. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8100. if err != nil {
  8101. }
  8102. startRecordDateTime := startTime.Unix()
  8103. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8104. if err != nil {
  8105. }
  8106. endRecordDateTime := endTime.Unix()
  8107. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8108. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8109. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8110. c.ServeSuccessJSON(map[string]interface{}{
  8111. "order_number": order.Number, //业务流水号
  8112. "id_card_no": his.IdCardNo, //社会保障号
  8113. "patient": patient,
  8114. "department_name": department.Name, //科室
  8115. "number": his.Number, //门诊号
  8116. "date": order.SettleAccountsDate, //结算日期
  8117. "name": order.PsnName, //姓名
  8118. "gender": patient.Gender, //性别
  8119. "psn_cash_money": order.PsnCashPay, //个人支付
  8120. "pay_way": "门诊", //结算方式
  8121. "medfee_sumamt": order.MedfeeSumamt, //总费用
  8122. "admin_user_name": admin.UserName, //收款员
  8123. "order": order,
  8124. "order_info": orderInfos_two,
  8125. "his": his,
  8126. "bedCostTotal": bedCostTotal,
  8127. "bedCostSelfTotal": bedCostSelfTotal,
  8128. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8129. "operationCostTotal": operationCostTotal,
  8130. "operationCostSelfTotal": operationCostSelfTotal,
  8131. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8132. "otherCostTotal": otherCostTotal,
  8133. "otherCostSelfTotal": otherCostSelfTotal,
  8134. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8135. "materialCostTotal": materialCostTotal,
  8136. "materialCostSelfTotal": materialCostSelfTotal,
  8137. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8138. "westernMedicineCostTotal": westernMedicineCostTotal,
  8139. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8140. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8141. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8142. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8143. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8144. "checkCostTotal": checkCostTotal,
  8145. "checkCostSelfTotal": checkCostSelfTotal,
  8146. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8147. "laboratoryCostTotal": laboratoryCostTotal,
  8148. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8149. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8150. "treatCostTotal": treatCostTotal,
  8151. "treatCostSelfTotal": treatCostSelfTotal,
  8152. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8153. "zhenChaCostTotal": zhenChaCostTotal,
  8154. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8155. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8156. "his_hospital_record": his_hospital_record,
  8157. "pre_pay_money": pre_pay_money,
  8158. "refund_sum": sum,
  8159. "doctor_info": doctor_info,
  8160. "hiliCostTotal": hiliCostTotal,
  8161. "hiliCostSelfTotal": hiliCostSelfTotal,
  8162. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  8163. })
  8164. }
  8165. //func (c *HisApiController) GetFaPiaoDatas() {
  8166. // order_ids := c.GetString("order_ids")
  8167. // patient_id, _ := c.GetInt64("patient_id")
  8168. // adminUser := c.GetAdminUserInfo()
  8169. //
  8170. // orders := strings.Split(order_ids, ",")
  8171. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  8172. //
  8173. // for _, item := range orders {
  8174. // order_id, _ := strconv.ParseInt(item, 10, 64)
  8175. // order, _ := service.GetHisOrderByID(order_id)
  8176. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  8177. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  8178. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  8179. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  8180. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8181. //
  8182. // }
  8183. //
  8184. // var bedCostTotal float64 = 0 //床位总费
  8185. // var bedCostSelfTotal float64 = 0 //床位自费
  8186. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  8187. //
  8188. // var operationCostTotal float64 = 0 //手术费
  8189. // var operationCostSelfTotal float64 = 0 //手术费
  8190. // var operationCostPartSelfTotal float64 = 0 //手术费
  8191. //
  8192. // var otherCostTotal float64 = 0 //其他费用
  8193. // var otherCostSelfTotal float64 = 0 //其他费用
  8194. // var otherCostPartSelfTotal float64 = 0 //其他费用
  8195. //
  8196. // var materialCostTotal float64 = 0 //材料费
  8197. // var materialCostSelfTotal float64 = 0 //材料费
  8198. // var materialCostPartSelfTotal float64 = 0 //材料费
  8199. //
  8200. // var westernMedicineCostTotal float64 = 0 //西药费
  8201. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  8202. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  8203. //
  8204. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8205. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8206. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  8207. //
  8208. // var checkCostTotal float64 = 0 //检查费
  8209. // var checkCostSelfTotal float64 = 0 //检查费
  8210. // var checkCostPartSelfTotal float64 = 0 //检查费
  8211. //
  8212. // var laboratoryCostTotal float64 = 0 //化验费
  8213. // var laboratoryCostSelfTotal float64 = 0 //化验费
  8214. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  8215. //
  8216. // var treatCostTotal float64 = 0 //治疗费用
  8217. // var treatCostSelfTotal float64 = 0 //治疗费用
  8218. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  8219. //
  8220. // var zhenChaCostTotal float64 = 0 //其他费用
  8221. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  8222. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8223. //
  8224. // decimal.DivisionPrecision = 2
  8225. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8226. //
  8227. // var balanceAccountsType int64
  8228. // if his.ID > 0 {
  8229. // balanceAccountsType = his.BalanceAccountsType
  8230. // } else {
  8231. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  8232. // }
  8233. // if balanceAccountsType == 2 {
  8234. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  8235. // for _, item := range orderInfos_two {
  8236. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8237. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8238. // item.MedChrgitmType = "09"
  8239. // }
  8240. //
  8241. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8242. // if item.HisPrescriptionProject.Type == 2 {
  8243. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8244. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8245. // case 0:
  8246. // item.MedChrgitmType = "0"
  8247. // break
  8248. // case 1:
  8249. // item.MedChrgitmType = "14"
  8250. // break
  8251. // case 2:
  8252. // item.MedChrgitmType = "05"
  8253. //
  8254. // break
  8255. // case 3:
  8256. // item.MedChrgitmType = "03"
  8257. //
  8258. // break
  8259. // case 4:
  8260. // item.MedChrgitmType = "03"
  8261. //
  8262. // break
  8263. // case 5:
  8264. // item.MedChrgitmType = "08"
  8265. //
  8266. // break
  8267. // case 6:
  8268. // item.MedChrgitmType = "14"
  8269. //
  8270. // break
  8271. // case 7:
  8272. // item.MedChrgitmType = "14"
  8273. //
  8274. // break
  8275. // case 8:
  8276. // item.MedChrgitmType = "03"
  8277. // break
  8278. // case 9:
  8279. // item.MedChrgitmType = "14"
  8280. // break
  8281. // case 10:
  8282. // item.MedChrgitmType = "14"
  8283. // break
  8284. // case 11:
  8285. // item.MedChrgitmType = "06"
  8286. // break
  8287. // case 12:
  8288. // item.MedChrgitmType = "12"
  8289. // break
  8290. // case 13:
  8291. // item.MedChrgitmType = "01"
  8292. // break
  8293. // case 14:
  8294. // item.MedChrgitmType = "04"
  8295. // break
  8296. // case 15:
  8297. // item.MedChrgitmType = "02"
  8298. // break
  8299. //
  8300. // }
  8301. //
  8302. // } else {
  8303. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8304. //
  8305. // case 1:
  8306. // item.MedChrgitmType = "14"
  8307. // break
  8308. // case 2:
  8309. // item.MedChrgitmType = "05"
  8310. //
  8311. // break
  8312. // case 3:
  8313. // item.MedChrgitmType = "03"
  8314. //
  8315. // break
  8316. // case 4:
  8317. // item.MedChrgitmType = "03"
  8318. //
  8319. // break
  8320. // case 5:
  8321. // item.MedChrgitmType = "08"
  8322. //
  8323. // break
  8324. // case 6:
  8325. // item.MedChrgitmType = "14"
  8326. //
  8327. // break
  8328. // case 7:
  8329. // item.MedChrgitmType = "14"
  8330. //
  8331. // break
  8332. // case 8:
  8333. // item.MedChrgitmType = "03"
  8334. // break
  8335. // case 9:
  8336. // item.MedChrgitmType = "14"
  8337. // break
  8338. //
  8339. // }
  8340. //
  8341. // }
  8342. //
  8343. // } else if item.HisPrescriptionProject.Type == 3 {
  8344. // item.MedChrgitmType = "08"
  8345. // }
  8346. // }
  8347. // }
  8348. //
  8349. // for _, item := range orderInfos_two {
  8350. // fmt.Println(item.MedChrgitmType)
  8351. // if item.MedChrgitmType == "01" { //床位费
  8352. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8353. // bedCostSelfTotal = bedCostTotal
  8354. // }
  8355. //
  8356. // if item.MedChrgitmType == "02" { //诊察费
  8357. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8358. // zhenChaCostSelfTotal = zhenChaCostTotal
  8359. // }
  8360. //
  8361. // if item.MedChrgitmType == "03" { //检查费
  8362. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8363. // checkCostSelfTotal = checkCostTotal
  8364. // }
  8365. //
  8366. // if item.MedChrgitmType == "04" { //化验费
  8367. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8368. // laboratoryCostSelfTotal = laboratoryCostTotal
  8369. // }
  8370. //
  8371. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  8372. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8373. // treatCostSelfTotal = treatCostTotal
  8374. // }
  8375. //
  8376. // if item.MedChrgitmType == "06" { //手术费
  8377. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8378. // operationCostSelfTotal = treatCostTotal
  8379. // }
  8380. //
  8381. // if item.MedChrgitmType == "08" { //材料费
  8382. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8383. // materialCostSelfTotal = materialCostTotal
  8384. // }
  8385. //
  8386. // if item.MedChrgitmType == "09" { //西药费
  8387. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8388. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  8389. // }
  8390. //
  8391. // if item.MedChrgitmType == "11" { //中成费
  8392. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8393. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  8394. // }
  8395. //
  8396. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  8397. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8398. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8399. // otherCostSelfTotal = otherCostTotal
  8400. // }
  8401. // } else {
  8402. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8403. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8404. // otherCostSelfTotal = otherCostTotal
  8405. // }
  8406. //
  8407. // }
  8408. //
  8409. // }
  8410. //
  8411. // } else {
  8412. // for _, item := range orderInfos {
  8413. // if item.MedChrgitmType == "01" { //床位费
  8414. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8415. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8416. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8417. // }
  8418. //
  8419. // if item.MedChrgitmType == "02" { //诊察费
  8420. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8421. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8422. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8423. // }
  8424. //
  8425. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  8426. // if item.MedChrgitmType == "03" { //检查费
  8427. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8428. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8429. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8430. //
  8431. // }
  8432. // } else {
  8433. // if item.MedChrgitmType == "03" { //检查费
  8434. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8435. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8436. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8437. // }
  8438. //
  8439. // }
  8440. //
  8441. // if item.MedChrgitmType == "04" { //化验费
  8442. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8443. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8444. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8445. //
  8446. // }
  8447. //
  8448. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  8449. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8450. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8451. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8452. //
  8453. // }
  8454. //
  8455. // if item.MedChrgitmType == "06" { //手术费
  8456. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8457. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8458. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8459. // }
  8460. //
  8461. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  8462. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8463. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8464. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8465. // }
  8466. //
  8467. // if item.MedChrgitmType == "09" { //西药费
  8468. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8469. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8470. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8471. // }
  8472. //
  8473. // if item.MedChrgitmType == "11" { //中成费
  8474. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8475. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8476. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8477. // }
  8478. //
  8479. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8480. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8481. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8482. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8483. // }
  8484. //
  8485. // }
  8486. // }
  8487. // timeLayout := "2006-01-02"
  8488. // loc, _ := time.LoadLocation("Local")
  8489. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  8490. // if err != nil {
  8491. // }
  8492. // startRecordDateTime := startTime.Unix()
  8493. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  8494. // if err != nil {
  8495. // }
  8496. // endRecordDateTime := endTime.Unix()
  8497. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  8498. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  8499. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  8500. //
  8501. // c.ServeSuccessJSON(map[string]interface{}{
  8502. // "order_number": order.Number, //业务流水号
  8503. // "id_card_no": his.IdCardNo, //社会保障号
  8504. // "department_name": department.Name, //科室
  8505. // "number": his.Number, //门诊号
  8506. // "date": order.SettleAccountsDate, //结算日期
  8507. // "name": order.PsnName, //姓名
  8508. // "gender": patient.Gender, //性别
  8509. // "psn_cash_money": order.PsnCashPay, //个人支付
  8510. // "pay_way": "门诊", //结算方式
  8511. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  8512. // "admin_user_name": admin.UserName, //收款员
  8513. // "order": order,
  8514. // "order_info": orderInfos_two,
  8515. // "his": his,
  8516. // "bedCostTotal": bedCostTotal,
  8517. // "bedCostSelfTotal": bedCostSelfTotal,
  8518. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  8519. // "operationCostTotal": operationCostTotal,
  8520. // "operationCostSelfTotal": operationCostSelfTotal,
  8521. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  8522. // "otherCostTotal": otherCostTotal,
  8523. // "otherCostSelfTotal": otherCostSelfTotal,
  8524. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  8525. // "materialCostTotal": materialCostTotal,
  8526. // "materialCostSelfTotal": materialCostSelfTotal,
  8527. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  8528. // "westernMedicineCostTotal": westernMedicineCostTotal,
  8529. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  8530. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  8531. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8532. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  8533. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  8534. // "checkCostTotal": checkCostTotal,
  8535. // "checkCostSelfTotal": checkCostSelfTotal,
  8536. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  8537. // "laboratoryCostTotal": laboratoryCostTotal,
  8538. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  8539. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  8540. // "treatCostTotal": treatCostTotal,
  8541. // "treatCostSelfTotal": treatCostSelfTotal,
  8542. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  8543. // "zhenChaCostTotal": zhenChaCostTotal,
  8544. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  8545. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  8546. // "his_hospital_record": his_hospital_record,
  8547. // "pre_pay_money": pre_pay_money,
  8548. // "refund_sum": sum,
  8549. // })
  8550. //
  8551. //}
  8552. func (this *HisApiController) GetIncomeStatisticsData() {
  8553. start_time := this.GetString("start_time")
  8554. end_time := this.GetString("end_time")
  8555. key_words := this.GetString("key_words")
  8556. limit, _ := this.GetInt64("limit")
  8557. page, _ := this.GetInt64("page")
  8558. if page <= 0 {
  8559. page = 1
  8560. }
  8561. if limit <= 0 {
  8562. limit = 10
  8563. }
  8564. statistics_type, _ := this.GetInt64("statistics_type")
  8565. admin := this.GetAdminUserInfo()
  8566. timeLayout := "2006-01-02"
  8567. loc, _ := time.LoadLocation("Local")
  8568. var theStartTIme int64
  8569. if len(start_time) > 0 {
  8570. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8571. if err != nil {
  8572. theStartTIme = 0
  8573. }
  8574. theStartTIme = theTime.Unix()
  8575. }
  8576. var theEndtTIme int64
  8577. if len(end_time) > 0 {
  8578. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8579. if err != nil {
  8580. theEndtTIme = 0
  8581. }
  8582. theEndtTIme = theTime.Unix()
  8583. }
  8584. if statistics_type == 1 {
  8585. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8586. this.ServeSuccessJSON(map[string]interface{}{
  8587. "list": list,
  8588. "total": total,
  8589. })
  8590. } else {
  8591. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  8592. this.ServeSuccessJSON(map[string]interface{}{
  8593. "list": list,
  8594. "total": total,
  8595. })
  8596. }
  8597. }
  8598. func (c *HisApiController) PostProjectInformation() {
  8599. adminUser := c.GetAdminUserInfo()
  8600. orgId := adminUser.CurrentOrgId
  8601. dataBody := make(map[string]interface{}, 0)
  8602. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  8603. if err != nil {
  8604. utils.ErrorLog(err.Error())
  8605. return
  8606. }
  8607. utils.ErrorLog("%v", dataBody)
  8608. var projectList []*models.HisProject
  8609. var total_goods []interface{}
  8610. tempProjects := dataBody["projects"].([]interface{})
  8611. total_goods = tempProjects
  8612. for index, projectMap := range tempProjects {
  8613. projectM := projectMap.(map[string]interface{})
  8614. var project models.HisProject
  8615. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  8616. utils.ErrorLog("project_name")
  8617. return
  8618. }
  8619. project_name, _ := projectM["project_name"].(string)
  8620. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  8621. err_log := models.ExportErrLog{
  8622. LogType: 6,
  8623. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8624. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  8625. Status: 1,
  8626. CreateTime: time.Now().Unix(),
  8627. UpdateTime: time.Now().Unix(),
  8628. ExportTime: time.Now().Unix(),
  8629. }
  8630. service.CreateExportErrLog(&err_log)
  8631. continue
  8632. }
  8633. project.ProjectName = project_name
  8634. prices := projectM["price"].(string)
  8635. price, _ := strconv.ParseFloat(prices, 64)
  8636. if price <= 0 { //名字为空则生成一条导入错误日志
  8637. err_log := models.ExportErrLog{
  8638. LogType: 6,
  8639. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8640. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  8641. Status: 1,
  8642. CreateTime: time.Now().Unix(),
  8643. UpdateTime: time.Now().Unix(),
  8644. ExportTime: time.Now().Unix(),
  8645. }
  8646. service.CreateExportErrLog(&err_log)
  8647. continue
  8648. }
  8649. project.Price = price
  8650. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  8651. utils.ErrorLog("unit_id")
  8652. return
  8653. }
  8654. unit := projectM["unit"].(string)
  8655. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  8656. err_log := models.ExportErrLog{
  8657. LogType: 6,
  8658. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8659. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  8660. Status: 1,
  8661. CreateTime: time.Now().Unix(),
  8662. UpdateTime: time.Now().Unix(),
  8663. ExportTime: time.Now().Unix(),
  8664. }
  8665. service.CreateExportErrLog(&err_log)
  8666. continue
  8667. }
  8668. project.Unit = unit
  8669. cost_classify := projectM["cost_classify"].(string)
  8670. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  8671. err_log := models.ExportErrLog{
  8672. LogType: 6,
  8673. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8674. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8675. Status: 1,
  8676. CreateTime: time.Now().Unix(),
  8677. UpdateTime: time.Now().Unix(),
  8678. ExportTime: time.Now().Unix(),
  8679. }
  8680. service.CreateExportErrLog(&err_log)
  8681. continue
  8682. }
  8683. var costClassify = "费用类别"
  8684. var cost_classify_id int64
  8685. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  8686. if len(cost_classify) != 0 {
  8687. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  8688. if errcode == gorm.ErrRecordNotFound {
  8689. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  8690. dataconfig := models.DictDataconfig{
  8691. ParentId: costClassifyConfig.ID,
  8692. Module: "system",
  8693. OrgId: orgId,
  8694. Name: cost_classify,
  8695. FieldName: "",
  8696. Value: costConfig.Value + 1,
  8697. CreatedTime: "",
  8698. UpdatedTime: "",
  8699. CreateUserId: adminUser.AdminUser.Id,
  8700. Status: 1,
  8701. Remark: "",
  8702. DeleteIdSystem: 0,
  8703. Title: "",
  8704. Content: "",
  8705. Order: 0,
  8706. Code: "",
  8707. }
  8708. service.CreatedDicConfig(&dataconfig)
  8709. }
  8710. }
  8711. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  8712. for _, it := range costClassList {
  8713. if cost_classify == it.Name {
  8714. cost_classify_id = int64(it.Value)
  8715. }
  8716. }
  8717. project.CostClassify = cost_classify_id
  8718. executive_section := projectM["executive_section"].(string)
  8719. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  8720. err_log := models.ExportErrLog{
  8721. LogType: 6,
  8722. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8723. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  8724. Status: 1,
  8725. CreateTime: time.Now().Unix(),
  8726. UpdateTime: time.Now().Unix(),
  8727. ExportTime: time.Now().Unix(),
  8728. }
  8729. service.CreateExportErrLog(&err_log)
  8730. continue
  8731. }
  8732. if len(executive_section) != 0 {
  8733. //查找科室是否有内容
  8734. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  8735. if errcodedepart == gorm.ErrRecordNotFound {
  8736. department := models.XtHisDepartment{
  8737. Name: executive_section,
  8738. Status: 1,
  8739. UserOrgId: adminUser.CurrentOrgId,
  8740. CreatedTime: time.Now().Unix(),
  8741. }
  8742. service.CreateDePartment(&department)
  8743. }
  8744. }
  8745. var executive_section_id int64
  8746. departMentList, _ := service.GetAllDepartMent(orgId)
  8747. for _, it := range departMentList {
  8748. if executive_section == it.Name {
  8749. executive_section_id = it.ID
  8750. }
  8751. }
  8752. project.ExecutiveSection = executive_section_id
  8753. medical_coverage := projectM["medical_coverage"].(string)
  8754. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  8755. err_log := models.ExportErrLog{
  8756. LogType: 6,
  8757. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8758. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  8759. Status: 1,
  8760. CreateTime: time.Now().Unix(),
  8761. UpdateTime: time.Now().Unix(),
  8762. ExportTime: time.Now().Unix(),
  8763. }
  8764. service.CreateExportErrLog(&err_log)
  8765. continue
  8766. }
  8767. var medicalCoverage = "医保等级"
  8768. var medical_coverage_id int64
  8769. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  8770. if len(medical_coverage) != 0 {
  8771. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  8772. if errormedicalcoverage == gorm.ErrRecordNotFound {
  8773. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  8774. dataconfig := models.DictDataconfig{
  8775. ParentId: medicalCoverageConfig.ID,
  8776. Module: "system",
  8777. OrgId: orgId,
  8778. Name: medical_coverage,
  8779. FieldName: "",
  8780. Value: medicalCoverageConfig.Value + 1,
  8781. CreatedTime: "",
  8782. UpdatedTime: "",
  8783. CreateUserId: adminUser.AdminUser.Id,
  8784. Status: 1,
  8785. Remark: "",
  8786. DeleteIdSystem: 0,
  8787. Title: "",
  8788. Content: "",
  8789. Order: 0,
  8790. Code: "",
  8791. }
  8792. service.CreatedDicConfig(&dataconfig)
  8793. }
  8794. }
  8795. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  8796. for _, it := range medicalCoverageList {
  8797. if medical_coverage == it.Name {
  8798. medical_coverage_id = int64(it.Value)
  8799. }
  8800. }
  8801. project.MedicalCoverage = medical_coverage_id
  8802. pinyin := projectM["pinyin"].(string)
  8803. project.Pinyin = pinyin
  8804. wubi := projectM["wubi"].(string)
  8805. project.Wubi = wubi
  8806. statistical_classification := projectM["statistical_classification"].(string)
  8807. var statisticalClassification = "统计分类"
  8808. var statistical_classification_id int64
  8809. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  8810. if len(statistical_classification) != 0 {
  8811. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  8812. if classificationerrcodes == gorm.ErrRecordNotFound {
  8813. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  8814. dataconfig := models.DictDataconfig{
  8815. ParentId: classiFication.ID,
  8816. Module: "system",
  8817. OrgId: orgId,
  8818. Name: statistical_classification,
  8819. FieldName: "",
  8820. Value: classiFicationConfig.Value + 1,
  8821. CreatedTime: "",
  8822. UpdatedTime: "",
  8823. CreateUserId: adminUser.AdminUser.Id,
  8824. Status: 1,
  8825. Remark: "",
  8826. DeleteIdSystem: 0,
  8827. Title: "",
  8828. Content: "",
  8829. Order: 0,
  8830. Code: "",
  8831. }
  8832. service.CreatedDicConfig(&dataconfig)
  8833. }
  8834. }
  8835. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  8836. for _, it := range classiFicationList {
  8837. if statistical_classification == it.Name {
  8838. statistical_classification_id = int64(it.Value)
  8839. }
  8840. }
  8841. project.StatisticalClassification = statistical_classification_id
  8842. disease_directory := int64(projectM["disease_directory"].(float64))
  8843. project.DiseaseDirectory = disease_directory
  8844. is_record := int64(projectM["is_record"].(float64))
  8845. project.IsRecord = is_record
  8846. medical_code := projectM["medical_code"].(string)
  8847. project.MedicalCode = medical_code
  8848. tube_color := projectM["tube_color"].(string)
  8849. var tubeColor = "试管颜色"
  8850. var tube_color_id int64
  8851. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  8852. if len(tube_color) != 0 {
  8853. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  8854. if errcodetube == gorm.ErrRecordNotFound {
  8855. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  8856. dataconfig := models.DictDataconfig{
  8857. ParentId: tubeColorConfig.ID,
  8858. Module: "system",
  8859. OrgId: orgId,
  8860. Name: tube_color,
  8861. FieldName: "",
  8862. Value: tubeConfig.Value + 1,
  8863. CreatedTime: "",
  8864. UpdatedTime: "",
  8865. CreateUserId: adminUser.AdminUser.Id,
  8866. Status: 1,
  8867. Remark: "",
  8868. DeleteIdSystem: 0,
  8869. Title: "",
  8870. Content: "",
  8871. Order: 0,
  8872. Code: "",
  8873. }
  8874. service.CreatedDicConfig(&dataconfig)
  8875. }
  8876. }
  8877. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  8878. for _, it := range tubeColorList {
  8879. if tube_color == it.Name {
  8880. tube_color_id = int64(it.Value)
  8881. }
  8882. }
  8883. project.TubeColor = tube_color_id
  8884. single_dose := projectM["single_dose"].(string)
  8885. project.SingleDose = single_dose
  8886. execution_frequency := projectM["execution_frequency"].(string)
  8887. project.ExecutionFrequency = execution_frequency
  8888. delivery_way := projectM["delivery_way"].(string)
  8889. project.DeliveryWay = delivery_way
  8890. number_days := projectM["number_days"].(string)
  8891. project.NumberDays = number_days
  8892. total := projectM["total"].(string)
  8893. project.Total = total
  8894. medical_status := int64(projectM["medical_status"].(float64))
  8895. project.MedicalStatus = medical_status
  8896. category := int64(projectM["category"].(float64))
  8897. project.Category = category
  8898. specail_project := int64(projectM["specail_project"].(float64))
  8899. project.SpecailProject = specail_project
  8900. social_security_directory_code := projectM["social_security_directory_code"].(string)
  8901. project.SocialSecurityDirectoryCode = social_security_directory_code
  8902. remark := projectM["remark"].(string)
  8903. project.Remark = remark
  8904. record_date := projectM["record_date"].(string)
  8905. timeLayout := "2006-01-02"
  8906. loc, _ := time.LoadLocation("Local")
  8907. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8908. project.RecordDate = theTime.Unix()
  8909. projectList = append(projectList, &project)
  8910. }
  8911. export_time := time.Now().Unix()
  8912. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  8913. if len(projectList) > 0 {
  8914. for _, item := range projectList {
  8915. project := models.HisProject{
  8916. ProjectName: item.ProjectName,
  8917. Price: item.Price,
  8918. Unit: item.Unit,
  8919. CostClassify: item.CostClassify,
  8920. ExecutiveSection: item.ExecutiveSection,
  8921. MedicalCoverage: item.MedicalCoverage,
  8922. UserOrgId: orgId,
  8923. Status: 1,
  8924. CreatedTime: time.Now().Unix(),
  8925. Pinyin: item.Pinyin,
  8926. Wubi: item.Wubi,
  8927. StatisticalClassification: item.StatisticalClassification,
  8928. DiseaseDirectory: item.DiseaseDirectory,
  8929. IsRecord: item.IsRecord,
  8930. MedicalCode: item.MedicalCode,
  8931. TubeColor: item.TubeColor,
  8932. SingleDose: item.SingleDose,
  8933. DeliveryWay: item.DeliveryWay,
  8934. NumberDays: item.NumberDays,
  8935. Total: item.Total,
  8936. Category: item.Category,
  8937. MedicalStatus: item.MedicalStatus,
  8938. SpecailProject: item.SpecailProject,
  8939. RecordDate: item.RecordDate,
  8940. Remark: item.Remark,
  8941. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  8942. ExecutionFrequency: item.ExecutionFrequency,
  8943. }
  8944. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  8945. if errcodeproject == gorm.ErrRecordNotFound {
  8946. service.CreateProjectInfomation(&project)
  8947. } else if errcodeproject == nil {
  8948. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  8949. }
  8950. log := models.ExportLog{
  8951. LogType: 6,
  8952. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8953. TotalNum: int64(len(total_goods)),
  8954. FailNum: int64(len(errLogs)),
  8955. SuccessNum: int64(len(projectList)),
  8956. CreateTime: time.Now().Unix(),
  8957. UpdateTime: time.Now().Unix(),
  8958. ExportTime: export_time,
  8959. Status: 1,
  8960. }
  8961. service.CreateExportLog(&log)
  8962. c.ServeSuccessJSON(map[string]interface{}{
  8963. "msg": "导入成功",
  8964. "total_num": len(total_goods),
  8965. "success_num": len(projectList),
  8966. "fail_num": int64(len(errLogs)),
  8967. })
  8968. }
  8969. } else {
  8970. log := models.ExportLog{
  8971. LogType: 6,
  8972. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  8973. TotalNum: int64(len(total_goods)),
  8974. FailNum: int64(len(errLogs)),
  8975. SuccessNum: int64(len(projectList)),
  8976. CreateTime: time.Now().Unix(),
  8977. UpdateTime: time.Now().Unix(),
  8978. ExportTime: export_time,
  8979. Status: 1,
  8980. }
  8981. service.CreateExportLog(&log)
  8982. c.ServeSuccessJSON(map[string]interface{}{
  8983. "msg": "导入成功",
  8984. "total_num": len(total_goods),
  8985. "success_num": len(projectList),
  8986. "fail_num": int64(len(errLogs)),
  8987. })
  8988. }
  8989. }
  8990. //func (this *HisApiController) EditProjectInformation(){
  8991. //
  8992. // id, _ := this.GetInt64("id")
  8993. // project_team := this.GetString("project_team")
  8994. // price := this.GetString("price")
  8995. // price_float, _ := strconv.ParseFloat(price, 64)
  8996. // pinyin := this.GetString("pinyin")
  8997. // wubi := this.GetString("wubi")
  8998. // tube_color, _ := this.GetInt64("tube_color")
  8999. // team_type, _ := this.GetInt64("team_type")
  9000. // remark := this.GetString("remark")
  9001. // ids := this.GetString("ids")
  9002. // item_id := this.GetString("item_id")
  9003. // projectTeam := models.XtHisProjectTeam{
  9004. // ProjectTeam: project_team,
  9005. // Price: price_float,
  9006. // Pinyin: pinyin,
  9007. // Wubi: wubi,
  9008. // TubeColor: tube_color,
  9009. // TeamType: team_type,
  9010. // Remark: remark,
  9011. // ProjectId: ids,
  9012. // ItemId: item_id,
  9013. // }
  9014. //
  9015. //
  9016. // dataBody := make(map[string]interface{}, 0)
  9017. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  9018. // if err != nil {
  9019. // utils.ErrorLog(err.Error())
  9020. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9021. // return
  9022. // }
  9023. //
  9024. // err = service.UpdatedProjectTeam(id, &projectTeam)
  9025. //
  9026. //
  9027. // if err != nil {
  9028. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  9029. // return
  9030. // }
  9031. //
  9032. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  9033. // infos, _ := dataBody["info"].([]interface{})
  9034. // if len(infos) > 0 {
  9035. // var ids []string
  9036. //
  9037. // for _, item := range infos {
  9038. // items := item.(map[string]interface{})
  9039. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  9040. // utils.ErrorLog("id")
  9041. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9042. // return
  9043. // }
  9044. // id := int64(items["id"].(float64))
  9045. //
  9046. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9047. // utils.ErrorLog("type")
  9048. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9049. // return
  9050. // }
  9051. // types := int64(items["type"].(float64))
  9052. //
  9053. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  9054. // utils.ErrorLog("number")
  9055. // }
  9056. //
  9057. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  9058. //
  9059. // projectList := models.XtHisProjectList{
  9060. // Number: number,
  9061. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  9062. // ProjectId: id,
  9063. // Status: 1,
  9064. // CreatedTime: time.Now().Unix(),
  9065. // UpdatedTime: time.Now().Unix(),
  9066. // TeamId: projectTeam.ID,
  9067. // Type: types,
  9068. // }
  9069. // list := projectList
  9070. //
  9071. // service.CreateProjectList(&list)
  9072. //
  9073. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  9074. //
  9075. // }
  9076. // ids_str := strings.Join(ids, ",")
  9077. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  9078. // service.SaveProjectTeam(&projectTeam)
  9079. // this.ServeSuccessJSON(map[string]interface{}{
  9080. // "projectTeam": projectTeam,
  9081. // })
  9082. // }
  9083. // }
  9084. //}
  9085. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  9086. name := c.GetString("name")
  9087. mode_id, _ := c.GetInt64("mode", 0)
  9088. types, _ := c.GetInt64("type", 0)
  9089. patient_id, _ := c.GetInt64("patient_id", 0)
  9090. types = 1
  9091. adminInfo := c.GetAdminUserInfo()
  9092. template := &models.HisPrescriptionTemplate{
  9093. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9094. PatientId: patient_id,
  9095. Type: types,
  9096. Status: 1,
  9097. Ctime: time.Now().Unix(),
  9098. Mtime: time.Now().Unix(),
  9099. Name: name,
  9100. Mode: mode_id,
  9101. }
  9102. dataBody := make(map[string]interface{}, 0)
  9103. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9104. if err != nil {
  9105. utils.ErrorLog(err.Error())
  9106. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9107. return
  9108. }
  9109. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  9110. //如果已经存在记录则删除处方
  9111. if template_one.ID > 0 {
  9112. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  9113. var ids []int64
  9114. var org_id int64
  9115. for _, item := range ps {
  9116. org_id = c.GetAdminUserInfo().CurrentOrgId
  9117. ids = append(ids, item.ID)
  9118. }
  9119. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  9120. if err2 == nil {
  9121. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9122. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9123. if len(prescriptions) > 0 {
  9124. for _, item := range prescriptions {
  9125. items := item.(map[string]interface{})
  9126. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9127. utils.ErrorLog("type")
  9128. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9129. return
  9130. }
  9131. types := int64(items["type"].(float64))
  9132. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9133. utils.ErrorLog("med_type")
  9134. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9135. return
  9136. }
  9137. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9138. ctime := time.Now().Unix()
  9139. prescription := &models.HisPrescriptionInfoTemplate{
  9140. PatientId: patient_id,
  9141. UserOrgId: adminInfo.CurrentOrgId,
  9142. Ctime: ctime,
  9143. Mtime: ctime,
  9144. Type: types,
  9145. Modifier: adminInfo.AdminUser.Id,
  9146. Creator: adminInfo.AdminUser.Id,
  9147. Status: 1,
  9148. PTemplateId: template_one.ID,
  9149. MedType: med_type,
  9150. }
  9151. service.CreateHisPrescriptionInfoTemplate(prescription)
  9152. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9153. advices := items["advices"].([]interface{})
  9154. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9155. ctime := time.Now().Unix()
  9156. mtime := ctime
  9157. if len(advices) > 0 {
  9158. for _, advice := range advices {
  9159. var s models.HisPrescriptionAdviceTemplate
  9160. s.PrescriptionId = prescription.ID
  9161. s.AdviceType = 2
  9162. s.StopState = 2
  9163. s.ExecutionState = 2
  9164. s.Status = 1
  9165. s.UserOrgId = adminInfo.CurrentOrgId
  9166. s.CreatedTime = ctime
  9167. s.UpdatedTime = mtime
  9168. s.PatientId = patient_id
  9169. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9170. if errcode > 0 {
  9171. c.ServeFailJSONWithSGJErrorCode(errcode)
  9172. return
  9173. }
  9174. service.CreateHisPrescriptionAdviceTemplate(&s)
  9175. }
  9176. }
  9177. }
  9178. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9179. projects := items["project"].([]interface{})
  9180. if len(projects) > 0 {
  9181. for _, project := range projects {
  9182. var p models.HisPrescriptionProjectTemplate
  9183. p.PrescriptionId = prescription.ID
  9184. p.Ctime = time.Now().Unix()
  9185. p.Mtime = time.Now().Unix()
  9186. p.PatientId = patient_id
  9187. p.UserOrgId = adminInfo.CurrentOrgId
  9188. p.Status = 1
  9189. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9190. if errcode > 0 {
  9191. c.ServeFailJSONWithSGJErrorCode(errcode)
  9192. return
  9193. }
  9194. service.CreateHisPrescriptionProjectTemplate(&p)
  9195. }
  9196. }
  9197. }
  9198. }
  9199. c.ServeSuccessJSON(map[string]interface{}{
  9200. "msg": "创建成功",
  9201. })
  9202. }
  9203. }
  9204. } else {
  9205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9206. return
  9207. }
  9208. } else {
  9209. err3 := service.CreateHisPrescriptionTemplate(template)
  9210. if err3 == nil {
  9211. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  9212. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  9213. if len(prescriptions) > 0 {
  9214. for _, item := range prescriptions {
  9215. items := item.(map[string]interface{})
  9216. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  9217. utils.ErrorLog("type")
  9218. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9219. return
  9220. }
  9221. types := int64(items["type"].(float64))
  9222. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  9223. utils.ErrorLog("med_type")
  9224. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9225. return
  9226. }
  9227. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  9228. ctime := time.Now().Unix()
  9229. prescription := &models.HisPrescriptionInfoTemplate{
  9230. PatientId: patient_id,
  9231. UserOrgId: adminInfo.CurrentOrgId,
  9232. Ctime: ctime,
  9233. Mtime: ctime,
  9234. Type: types,
  9235. Modifier: adminInfo.AdminUser.Id,
  9236. Creator: adminInfo.AdminUser.Id,
  9237. Status: 1,
  9238. PTemplateId: template.ID,
  9239. MedType: med_type,
  9240. }
  9241. service.CreateHisPrescriptionInfoTemplate(prescription)
  9242. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  9243. advices := items["advices"].([]interface{})
  9244. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  9245. ctime := time.Now().Unix()
  9246. mtime := ctime
  9247. if len(advices) > 0 {
  9248. for _, advice := range advices {
  9249. var s models.HisPrescriptionAdviceTemplate
  9250. s.PrescriptionId = prescription.ID
  9251. s.AdviceType = 2
  9252. s.StopState = 2
  9253. s.ExecutionState = 2
  9254. s.Status = 1
  9255. s.UserOrgId = adminInfo.CurrentOrgId
  9256. s.CreatedTime = ctime
  9257. s.UpdatedTime = mtime
  9258. s.PatientId = patient_id
  9259. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  9260. if errcode > 0 {
  9261. c.ServeFailJSONWithSGJErrorCode(errcode)
  9262. return
  9263. }
  9264. service.CreateHisPrescriptionAdviceTemplate(&s)
  9265. }
  9266. }
  9267. }
  9268. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  9269. projects := items["project"].([]interface{})
  9270. if len(projects) > 0 {
  9271. for _, project := range projects {
  9272. var p models.HisPrescriptionProjectTemplate
  9273. p.PrescriptionId = prescription.ID
  9274. p.Ctime = time.Now().Unix()
  9275. p.Mtime = time.Now().Unix()
  9276. p.PatientId = patient_id
  9277. p.UserOrgId = adminInfo.CurrentOrgId
  9278. p.Status = 1
  9279. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  9280. if errcode > 0 {
  9281. c.ServeFailJSONWithSGJErrorCode(errcode)
  9282. return
  9283. }
  9284. service.CreateHisPrescriptionProjectTemplate(&p)
  9285. }
  9286. }
  9287. }
  9288. }
  9289. c.ServeSuccessJSON(map[string]interface{}{
  9290. "msg": "创建成功",
  9291. })
  9292. }
  9293. }
  9294. } else {
  9295. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9296. return
  9297. }
  9298. }
  9299. }
  9300. func (c *HisApiController) PreSettle() {
  9301. id, _ := c.GetInt64("id")
  9302. record_time := c.GetString("record_time")
  9303. his_patient_id, _ := c.GetInt64("his_patient_id")
  9304. timeLayout := "2006-01-02"
  9305. loc, _ := time.LoadLocation("Local")
  9306. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  9307. diagnosis_id := c.GetString("diagnosis")
  9308. sick_type, _ := c.GetInt64("sick_type")
  9309. reg_type, _ := c.GetInt64("p_type")
  9310. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9311. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  9312. if err != nil {
  9313. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9314. return
  9315. }
  9316. recordDateTime := theTime.Unix()
  9317. adminUser := c.GetAdminUserInfo()
  9318. var prescriptions []*models.HisPrescription
  9319. var start_time int64
  9320. var end_time int64
  9321. ids_str := c.GetString("ids")
  9322. ids_arr := strings.Split(ids_str, ",")
  9323. fmt.Println(reg_type)
  9324. if settle_accounts_type == 1 { //日结
  9325. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  9326. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  9327. } else {
  9328. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  9329. }
  9330. fmt.Println(prescriptions)
  9331. } else { //月结
  9332. start_time_str := c.GetString("start_time")
  9333. end_time_str := c.GetString("end_time")
  9334. timeLayout := "2006-01-02"
  9335. loc, _ := time.LoadLocation("Local")
  9336. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  9337. if err != nil {
  9338. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9339. return
  9340. }
  9341. recordStartTime := theStartTime.Unix()
  9342. start_time = recordStartTime
  9343. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  9344. if err != nil {
  9345. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9346. return
  9347. }
  9348. recordEndTime := theEndTime.Unix()
  9349. end_time = recordEndTime
  9350. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  9351. }
  9352. if reg_type == 1111 || reg_type == 1112 {
  9353. reg_type = 11
  9354. }
  9355. timestamp := time.Now().Unix()
  9356. tempTime := time.Unix(timestamp, 0)
  9357. timeFormat := tempTime.Format("20060102150405")
  9358. chrgBchno := rand.Intn(100000) + 10000
  9359. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  9360. strconv.FormatInt(his.PatientId, 10)
  9361. var ids []int64
  9362. for _, item := range prescriptions {
  9363. ids = append(ids, item.ID)
  9364. }
  9365. fmt.Println(ids)
  9366. var total float64
  9367. for _, item := range prescriptions {
  9368. fmt.Println(item)
  9369. if item.Type == 1 { //药品
  9370. for _, subItem := range item.HisDoctorAdviceInfo {
  9371. total = total + (subItem.Price * subItem.PrescribingNumber)
  9372. }
  9373. }
  9374. if item.Type == 2 { //项目
  9375. for _, subItem := range item.HisPrescriptionProject {
  9376. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9377. total = total + (subItem.Price * cnt)
  9378. }
  9379. }
  9380. for _, subItem := range item.HisAdditionalCharge {
  9381. total = total + (subItem.Price * float64(subItem.Count))
  9382. }
  9383. }
  9384. allTotal := fmt.Sprintf("%.2f", total)
  9385. totals, _ := strconv.ParseFloat(allTotal, 64)
  9386. order := &models.HisOrder{
  9387. UserOrgId: adminUser.CurrentOrgId,
  9388. HisPatientId: his.ID,
  9389. PatientId: id,
  9390. SettleAccountsDate: recordDateTime,
  9391. Ctime: time.Now().Unix(),
  9392. Mtime: time.Now().Unix(),
  9393. Status: 1,
  9394. OrderStatus: 1,
  9395. MdtrtId: his.Number,
  9396. Number: chrg_bchno,
  9397. MedfeeSumamt: totals,
  9398. SettleEndTime: end_time,
  9399. SettleStartTime: start_time,
  9400. SettleType: settle_accounts_type,
  9401. PsnPartAmt: totals,
  9402. PsnCashPay: totals,
  9403. PType: 2,
  9404. IsPre: 1,
  9405. MedType: strconv.Itoa(int(reg_type)),
  9406. Diagnosis: diagnosis_id,
  9407. }
  9408. err = service.CreateOrder(order)
  9409. if err != nil {
  9410. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  9411. return
  9412. }
  9413. var customs []*Custom
  9414. for _, item := range prescriptions {
  9415. fmt.Println(item.Type)
  9416. if item.Type == 1 { //药品
  9417. for _, subItem := range item.HisDoctorAdviceInfo {
  9418. cus := &Custom{
  9419. AdviceId: subItem.ID,
  9420. ProjectId: 0,
  9421. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  9422. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  9423. FeedetlSn: subItem.FeedetlSn,
  9424. Price: fmt.Sprintf("%.2f", subItem.Price),
  9425. MedListCodg: subItem.MedListCodg,
  9426. Type: 1,
  9427. }
  9428. customs = append(customs, cus)
  9429. }
  9430. }
  9431. if item.Type == 2 { //项目
  9432. for _, subItem := range item.HisPrescriptionProject {
  9433. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  9434. cus := &Custom{
  9435. AdviceId: 0,
  9436. ProjectId: subItem.ID,
  9437. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  9438. Cut: fmt.Sprintf("%.2f", cnt),
  9439. FeedetlSn: subItem.FeedetlSn,
  9440. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  9441. MedListCodg: subItem.MedListCodg,
  9442. Type: 2,
  9443. }
  9444. customs = append(customs, cus)
  9445. }
  9446. }
  9447. for _, item := range item.HisAdditionalCharge {
  9448. cus := &Custom{
  9449. ItemId: item.ID,
  9450. AdviceId: 0,
  9451. ProjectId: 0,
  9452. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  9453. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  9454. FeedetlSn: item.FeedetlSn,
  9455. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  9456. MedListCodg: item.XtHisAddtionConfig.Code,
  9457. Type: 3,
  9458. }
  9459. customs = append(customs, cus)
  9460. }
  9461. }
  9462. fmt.Println(customs)
  9463. for _, item := range customs {
  9464. var advice_id int64 = 0
  9465. var project_id int64 = 0
  9466. var item_id int64 = 0
  9467. var types int64 = 0
  9468. if item.Type == 1 {
  9469. advice_id = item.AdviceId
  9470. project_id = 0
  9471. item_id = 0
  9472. } else if item.Type == 2 {
  9473. advice_id = 0
  9474. item_id = 0
  9475. project_id = item.ProjectId
  9476. } else if item.Type == 3 {
  9477. advice_id = 0
  9478. item_id = item.ItemId
  9479. project_id = 0
  9480. }
  9481. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  9482. cut, _ := strconv.ParseFloat(item.Cut, 32)
  9483. pric, _ := strconv.ParseFloat(item.Price, 32)
  9484. info := &models.HisOrderInfo{
  9485. OrderNumber: order.Number,
  9486. UploadDate: time.Now().Unix(),
  9487. AdviceId: advice_id,
  9488. DetItemFeeSumamt: detItemFeeSumamt,
  9489. Cnt: cut,
  9490. Pric: pric,
  9491. PatientId: id,
  9492. Status: 1,
  9493. Mtime: time.Now().Unix(),
  9494. Ctime: time.Now().Unix(),
  9495. UserOrgId: adminUser.CurrentOrgId,
  9496. HisPatientId: his.ID,
  9497. OrderId: order.ID,
  9498. ProjectId: project_id,
  9499. Type: types,
  9500. ItemId: item_id,
  9501. }
  9502. service.CreateOrderInfo(info)
  9503. }
  9504. his.SickType = sick_type
  9505. service.UpdataHisPateint(&his)
  9506. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  9507. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  9508. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  9509. if err == nil {
  9510. c.ServeSuccessJSON(map[string]interface{}{
  9511. "msg": "结算成功",
  9512. })
  9513. }
  9514. }
  9515. type CustomOrderInfo struct {
  9516. Name string
  9517. Spec string
  9518. Unit string
  9519. Count float64
  9520. Price float64
  9521. Total float64
  9522. }
  9523. func (c *HisApiController) GetPrivateExpensesInfo() {
  9524. order_id, _ := c.GetInt64("id", 0)
  9525. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  9526. order, _ := service.GetHisOrderByID(order_id)
  9527. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  9528. if order.ID == 0 {
  9529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  9530. return
  9531. }
  9532. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  9533. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  9534. org_id := c.GetAdminUserInfo().CurrentOrgId
  9535. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  9536. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  9537. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  9538. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  9539. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  9540. //var orderInfos_four []*models.HisOrderInfoTwo
  9541. //for _, item := range orderInfos_three {
  9542. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  9543. // item.HisPrescriptionProject.IsCheckTeam = 1
  9544. // orderInfos_four = append(orderInfos_four, item)
  9545. //
  9546. // }
  9547. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  9548. // item.HisPrescriptionProject.IsCheckTeam = 2
  9549. // orderInfos_two = append(orderInfos_two, item)
  9550. // }
  9551. //}
  9552. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  9553. //var cus_slice []CustomOrderInfo
  9554. //for _, item := range new_order_info {
  9555. // var cus CustomOrderInfo
  9556. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  9557. // cus.Unit = ""
  9558. // cus.Spec = ""
  9559. // var total float64
  9560. // for _, subItem := range orderInfos_four {
  9561. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  9562. // total = total + subItem.DetItemFeeSumamt
  9563. // fmt.Println(subItem.DetItemFeeSumamt)
  9564. // }
  9565. // }
  9566. // cus.Count = 1
  9567. // cus.Total = total
  9568. // cus_slice = append(cus_slice, cus)
  9569. //}
  9570. orderInfos = append(orderInfos, orderInfos_two...)
  9571. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  9572. //orderInfos = append(orderInfos, orderInfos_three...)
  9573. //}/**/
  9574. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  9575. c.ServeSuccessJSON(map[string]interface{}{
  9576. "order": order,
  9577. "order_info": orderInfos,
  9578. "patient": patient,
  9579. "admin_info": adminInfo,
  9580. "his": his,
  9581. "current_admin": role,
  9582. "org_config": miConfig,
  9583. //"new_order_info": cus_slice,
  9584. })
  9585. }
  9586. func (this *HisApiController) ChangeMedType() {
  9587. med_type := this.GetString("med_type")
  9588. old_med_type := this.GetString("old_med_type")
  9589. ids := this.GetString("ids")
  9590. settle_type, _ := this.GetInt64("settle_type")
  9591. start_time := this.GetString("start_time")
  9592. end_time := this.GetString("end_time")
  9593. ids_arr := strings.Split(ids, ",")
  9594. if settle_type == 1 { //日结
  9595. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  9596. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  9597. prescription.MedType = med_type
  9598. err := service.SaveHisPrescription(&prescription)
  9599. if err == nil {
  9600. this.ServeSuccessJSON(map[string]interface{}{
  9601. "msg": "修改成功",
  9602. })
  9603. } else {
  9604. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9605. return
  9606. }
  9607. } else if settle_type == 2 {
  9608. timeLayout := "2006-01-02"
  9609. loc, _ := time.LoadLocation("Local")
  9610. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9611. if err != nil {
  9612. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9613. return
  9614. }
  9615. recordStartTime := theStartTime.Unix()
  9616. start_time_timestamp := recordStartTime
  9617. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  9618. if err != nil {
  9619. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9620. return
  9621. }
  9622. recordEndTime := theEndTime.Unix()
  9623. end_time_timestamp := recordEndTime
  9624. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  9625. if updateErr == nil {
  9626. this.ServeSuccessJSON(map[string]interface{}{
  9627. "msg": "修改成功",
  9628. })
  9629. } else {
  9630. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  9631. return
  9632. }
  9633. }
  9634. }
  9635. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  9636. patient_id, _ := c.GetInt64("patient_id")
  9637. his_patient_id, _ := c.GetInt64("his_patient_id")
  9638. record_date := c.GetString("record_date")
  9639. start_time := c.GetString("start_time")
  9640. end_time := c.GetString("end_time")
  9641. order_status, _ := c.GetInt64("type", 0)
  9642. p_type, _ := c.GetInt64("p_type", 0)
  9643. order_id, _ := c.GetInt64("order_id", 0)
  9644. timeLayout := "2006-01-02"
  9645. loc, _ := time.LoadLocation("Local")
  9646. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9647. if err != nil {
  9648. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9649. return
  9650. }
  9651. recordDateTime := theTime.Unix()
  9652. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9653. if err != nil {
  9654. }
  9655. startRecordDateTime := startTime.Unix()
  9656. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9657. if err != nil {
  9658. }
  9659. endRecordDateTime := endTime.Unix()
  9660. admin := c.GetAdminUserInfo()
  9661. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  9662. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9663. order, _ := service.GetHisOrderByID(order_id)
  9664. var monthPrescriptions []*models.HisPrescription
  9665. if order_status == 1 || order_status == 0 {
  9666. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9667. } else if order_status == 2 {
  9668. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  9669. }
  9670. var settle_total float64
  9671. for _, item := range monthPrescriptions {
  9672. if len(item.HisPrescriptionProject) > 0 {
  9673. for _, subItem := range item.HisPrescriptionProject {
  9674. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9675. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9676. settle_total = settle_total + total
  9677. }
  9678. }
  9679. if len(item.HisDoctorAdviceInfo) > 0 {
  9680. for _, subItem := range item.HisDoctorAdviceInfo {
  9681. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9682. settle_total = settle_total + total
  9683. }
  9684. }
  9685. }
  9686. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9687. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9688. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9689. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9690. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9691. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9692. //获取所有科室信息
  9693. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9694. var dia string
  9695. for _, item := range month_p_info {
  9696. if len(dia) == 0 {
  9697. dia = item.Diagnosis
  9698. } else {
  9699. dia = dia + "," + item.Diagnosis
  9700. }
  9701. }
  9702. dia_arr := removeDuplicates(strings.Split(dia, ","))
  9703. dia_arr = removeEmptyStrings(dia_arr)
  9704. c.ServeSuccessJSON(map[string]interface{}{
  9705. "his_info": his_patient_info,
  9706. "xt_info": xt_patient_info,
  9707. "case_history": case_history,
  9708. "info": patientPrescriptionInfo,
  9709. "last_info": lastPatientPrescriptionInfo,
  9710. "month_prescriptions": monthPrescriptions,
  9711. "order": order,
  9712. "doctors": doctors,
  9713. "department": department,
  9714. "settle_total": settle_total,
  9715. "dia_arr": dia_arr,
  9716. })
  9717. return
  9718. }
  9719. func removeEmptyStrings(input []string) []string {
  9720. var output []string
  9721. for _, s := range input {
  9722. if s != "" {
  9723. output = append(output, s)
  9724. }
  9725. }
  9726. return output
  9727. }
  9728. func removeDuplicates(input []string) []string {
  9729. seen := make(map[string]bool)
  9730. output := []string{}
  9731. for _, s := range input {
  9732. if _, exists := seen[s]; !exists {
  9733. seen[s] = true
  9734. output = append(output, s)
  9735. }
  9736. }
  9737. return output
  9738. }
  9739. func (c *HisApiController) GetHisMonthPatientInfo() {
  9740. patient_id, _ := c.GetInt64("patient_id")
  9741. his_patient_id, _ := c.GetInt64("his_patient_id")
  9742. record_date := c.GetString("record_date")
  9743. number := c.GetString("number")
  9744. start_time := c.GetString("start_time")
  9745. end_time := c.GetString("end_time")
  9746. p_type, _ := c.GetInt64("p_type")
  9747. timeLayout := "2006-01-02"
  9748. loc, _ := time.LoadLocation("Local")
  9749. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  9750. if err != nil {
  9751. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  9752. return
  9753. }
  9754. recordDateTime := theTime.Unix()
  9755. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9756. if err != nil {
  9757. }
  9758. startRecordDateTime := startTime.Unix()
  9759. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9760. if err != nil {
  9761. }
  9762. endRecordDateTime := endTime.Unix()
  9763. admin := c.GetAdminUserInfo()
  9764. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  9765. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  9766. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  9767. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  9768. var settle_total float64
  9769. for _, item := range monthPrescriptions {
  9770. if len(item.HisPrescriptionProject) > 0 {
  9771. for _, subItem := range item.HisPrescriptionProject {
  9772. count, _ := strconv.ParseFloat(subItem.Count, 64)
  9773. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  9774. settle_total = settle_total + total
  9775. }
  9776. }
  9777. if len(item.HisDoctorAdviceInfo) > 0 {
  9778. for _, subItem := range item.HisDoctorAdviceInfo {
  9779. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  9780. settle_total = settle_total + total
  9781. }
  9782. }
  9783. }
  9784. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  9785. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  9786. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  9787. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  9788. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  9789. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  9790. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  9791. //获取所有科室信息
  9792. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  9793. c.ServeSuccessJSON(map[string]interface{}{
  9794. "his_info": his_patient_info,
  9795. "xt_info": xt_patient_info,
  9796. "case_history": case_history,
  9797. "info": patientPrescriptionInfo,
  9798. "month_prescriptions": monthPrescriptions,
  9799. "order": order,
  9800. "doctors": doctors,
  9801. "department": department,
  9802. "count": count,
  9803. "drugStockConfig": drugStockConfig,
  9804. "last_info": lastPatientPrescriptionInfo,
  9805. "settle_total": settle_total,
  9806. })
  9807. return
  9808. }
  9809. func (c *HisApiController) GetAllOrder() {
  9810. org_id := c.GetAdminUserInfo().CurrentOrgId
  9811. orders, _ := service.GetNewHisOrderList(org_id)
  9812. c.ServeSuccessJSON(map[string]interface{}{
  9813. "order": orders,
  9814. })
  9815. return
  9816. }
  9817. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  9818. newArr = make([]*models.HisOrderInfoTwo, 0)
  9819. for i := 0; i < len(arr); i++ {
  9820. repeat := false
  9821. for j := i + 1; j < len(arr); j++ {
  9822. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  9823. repeat = true
  9824. break
  9825. }
  9826. }
  9827. if !repeat {
  9828. newArr = append(newArr, arr[i])
  9829. }
  9830. }
  9831. return
  9832. }
  9833. // 修改处方退库操作 参数传修改之前的处方数据
  9834. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  9835. if advice.ExecutionState == 1 {
  9836. //查询该病人该药品是否有库存记录
  9837. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  9838. if errcode == gorm.ErrRecordNotFound {
  9839. } else {
  9840. //退库
  9841. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  9842. if advice.PrescribingNumberUnit == drug.MinUnit {
  9843. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9844. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9845. //退库
  9846. warehouseInfo := models.DrugWarehouseInfo{
  9847. StockMinNumber: prescribingNumber,
  9848. }
  9849. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  9850. operation_time := time.Now().Unix()
  9851. creater := advice.AdviceDoctor
  9852. ctime := time.Now().Unix()
  9853. timeStr := time.Now().Format("2006-01-02")
  9854. timeArr := strings.Split(timeStr, "-")
  9855. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9856. total = total + 1
  9857. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9858. cancelStock := models.DrugCancelStock{
  9859. OrderNumber: orderNumber,
  9860. OperaTime: operation_time,
  9861. OrgId: advice.UserOrgId,
  9862. Creater: creater,
  9863. Ctime: ctime,
  9864. Status: 1,
  9865. ReturnTime: advice.AdviceDate,
  9866. Dealer: info.Dealer,
  9867. Manufacturer: info.Manufacturer,
  9868. Type: 1,
  9869. }
  9870. service.AddSigleDrugCancelStock(&cancelStock)
  9871. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9872. dealer, _ := service.GetDealerById(info.Dealer)
  9873. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9874. cancelStockInfo := models.DrugCancelStockInfo{
  9875. OrderNumber: cancelInfo.OrderNumber,
  9876. CancelStockId: cancelInfo.ID,
  9877. DrugId: info.DrugId,
  9878. Count: info.Count,
  9879. Status: 1,
  9880. Ctime: ctime,
  9881. OrgId: advice.UserOrgId,
  9882. Type: 1,
  9883. Manufacturer: manufactureName.ManufacturerName,
  9884. Dealer: dealer.DealerName,
  9885. Total: 0,
  9886. RetailPrice: info.RetailPrice,
  9887. RetailTotalPrice: info.RetailTotalPrice,
  9888. Price: info.Price,
  9889. RegisterAccount: "",
  9890. Remark: info.Remark,
  9891. BatchNumber: info.BatchNumber,
  9892. MaxUnit: info.CountUnit,
  9893. ProductDate: info.ProductDate,
  9894. ExpiryDate: info.ExpiryDate,
  9895. BatchNumberId: info.WarehouseInfoId,
  9896. }
  9897. flow := models.DrugFlow{
  9898. WarehousingId: 0,
  9899. DrugId: info.DrugId,
  9900. Number: "",
  9901. BatchNumber: info.BatchNumber,
  9902. Count: info.Count,
  9903. UserOrgId: advice.UserOrgId,
  9904. PatientId: 0,
  9905. SystemTime: ctime,
  9906. ConsumableType: 4,
  9907. IsSys: 0,
  9908. WarehousingOrder: "",
  9909. WarehouseOutId: 0,
  9910. WarehouseOutOrderNumber: "",
  9911. IsEdit: 0,
  9912. CancelStockId: cancelStock.ID,
  9913. CancelOrderNumber: cancelStock.OrderNumber,
  9914. Manufacturer: info.Manufacturer,
  9915. Dealer: info.Dealer,
  9916. Creator: advice.UserOrgId,
  9917. UpdateCreator: 0,
  9918. Status: 1,
  9919. Ctime: time.Now().Unix(),
  9920. Mtime: 0,
  9921. Price: info.Price,
  9922. WarehousingDetailId: 0,
  9923. WarehouseOutDetailId: 0,
  9924. CancelOutDetailId: 0,
  9925. ExpireDate: info.ExpiryDate,
  9926. ProductDate: info.ProductDate,
  9927. MaxUnit: info.CountUnit,
  9928. MinUnit: "",
  9929. }
  9930. service.CreatedCancelStock(cancelStockInfo)
  9931. service.CreateDrugFlowOne(flow)
  9932. } else {
  9933. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  9934. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  9935. if advice.PrescribingNumberUnit == drug.MaxUnit {
  9936. warehouseInfo := models.DrugWarehouseInfo{
  9937. StockMinNumber: prescribingNumber,
  9938. }
  9939. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  9940. }
  9941. operation_time := time.Now().Unix()
  9942. creater := advice.AdviceDoctor
  9943. ctime := time.Now().Unix()
  9944. timeStr := time.Now().Format("2006-01-02")
  9945. timeArr := strings.Split(timeStr, "-")
  9946. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  9947. total = total + 1
  9948. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  9949. cancelStock := models.DrugCancelStock{
  9950. OrderNumber: orderNumber,
  9951. OperaTime: operation_time,
  9952. OrgId: advice.UserOrgId,
  9953. Creater: creater,
  9954. Ctime: ctime,
  9955. Status: 1,
  9956. ReturnTime: advice.AdviceDate,
  9957. Dealer: info.Dealer,
  9958. Manufacturer: info.Manufacturer,
  9959. Type: 1,
  9960. }
  9961. service.AddSigleDrugCancelStock(&cancelStock)
  9962. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  9963. dealer, _ := service.GetDealerById(info.Dealer)
  9964. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  9965. cancelStockInfo := models.DrugCancelStockInfo{
  9966. OrderNumber: cancelInfo.OrderNumber,
  9967. CancelStockId: cancelInfo.ID,
  9968. DrugId: info.DrugId,
  9969. Count: info.Count,
  9970. Status: 1,
  9971. Ctime: ctime,
  9972. OrgId: advice.UserOrgId,
  9973. Type: 1,
  9974. Manufacturer: manufactureName.ManufacturerName,
  9975. Dealer: dealer.DealerName,
  9976. Total: 0,
  9977. RetailPrice: info.RetailPrice,
  9978. RetailTotalPrice: info.RetailTotalPrice,
  9979. Price: info.Price,
  9980. RegisterAccount: "",
  9981. Remark: info.Remark,
  9982. BatchNumber: info.BatchNumber,
  9983. MaxUnit: info.CountUnit,
  9984. ProductDate: info.ProductDate,
  9985. ExpiryDate: info.ExpiryDate,
  9986. BatchNumberId: info.WarehouseInfoId,
  9987. }
  9988. flow := models.DrugFlow{
  9989. WarehousingId: 0,
  9990. DrugId: info.DrugId,
  9991. Number: "",
  9992. BatchNumber: info.BatchNumber,
  9993. Count: info.Count,
  9994. UserOrgId: advice.UserOrgId,
  9995. PatientId: 0,
  9996. SystemTime: ctime,
  9997. ConsumableType: 4,
  9998. IsSys: 0,
  9999. WarehousingOrder: "",
  10000. WarehouseOutId: 0,
  10001. WarehouseOutOrderNumber: "",
  10002. IsEdit: 0,
  10003. CancelStockId: cancelStock.ID,
  10004. CancelOrderNumber: cancelStock.OrderNumber,
  10005. Manufacturer: info.Manufacturer,
  10006. Dealer: info.Dealer,
  10007. Creator: advice.AdviceDoctor,
  10008. UpdateCreator: 0,
  10009. Status: 1,
  10010. Ctime: time.Now().Unix(),
  10011. Mtime: 0,
  10012. Price: info.Price,
  10013. WarehousingDetailId: 0,
  10014. WarehouseOutDetailId: 0,
  10015. CancelOutDetailId: 0,
  10016. ExpireDate: info.ExpiryDate,
  10017. ProductDate: info.ProductDate,
  10018. MaxUnit: info.CountUnit,
  10019. MinUnit: "",
  10020. }
  10021. service.CreatedCancelStock(cancelStockInfo)
  10022. service.CreateDrugFlowOne(flow)
  10023. }
  10024. }
  10025. }
  10026. return err
  10027. }
  10028. func (this *HisApiController) DeleteNCDS() {
  10029. id, _ := this.GetInt64("id", 0)
  10030. if id > 0 {
  10031. service.DeletePsnNCDSRecordById(id)
  10032. this.ServeSuccessJSON(map[string]interface{}{
  10033. "msg": "删除成功",
  10034. })
  10035. } else {
  10036. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  10037. return
  10038. }
  10039. }
  10040. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  10041. id, _ := c.GetInt64("id")
  10042. advice, _ := service.GetHisDoctorAdviceInfo(id)
  10043. c.ServeSuccessJSON(map[string]interface{}{
  10044. "advice": advice,
  10045. })
  10046. return
  10047. }
  10048. func (c *HisApiController) GetHisMonthChargePatientList() {
  10049. record_date := c.GetString("record_date")
  10050. start_time := c.GetString("start_time")
  10051. end_time := c.GetString("end_time")
  10052. timeLayout := "2006-01-02"
  10053. loc, _ := time.LoadLocation("Local")
  10054. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10055. if err != nil {
  10056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10057. return
  10058. }
  10059. if err != nil {
  10060. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10061. return
  10062. }
  10063. recordDateTime := theTime.Unix()
  10064. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10065. if err != nil {
  10066. }
  10067. startRecordDateTime := startTime.Unix()
  10068. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10069. if err != nil {
  10070. }
  10071. endRecordDateTime := endTime.Unix()
  10072. adminInfo := c.GetAdminUserInfo()
  10073. var tempMonthChargePatients []*service.MonthChargePatients
  10074. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  10075. for _, item := range tempPatients {
  10076. //过滤没有处方的
  10077. if len(item.HisPrescription) == 0 {
  10078. tempMonthChargePatients = append(tempMonthChargePatients, item)
  10079. }
  10080. }
  10081. c.ServeSuccessJSON(map[string]interface{}{
  10082. "list": tempMonthChargePatients,
  10083. })
  10084. }