his_api_controller.go 367KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664
  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. }
  83. func (c *PublicApiController) GetBaiLinExportData() {
  84. data := service.GetBaiLinOrderData()
  85. fmt.Println(len(data))
  86. var new_data []*models.NewCustomHisOrder
  87. for _, item := range data {
  88. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  89. new_data = append(new_data, item)
  90. }
  91. }
  92. fmt.Println(len(new_data))
  93. c.ServeSuccessJSON(map[string]interface{}{
  94. "list": new_data,
  95. })
  96. }
  97. func (c *HisApiController) GetHisUnChargePatientList() {
  98. record_date := c.GetString("record_date")
  99. timeLayout := "2006-01-02"
  100. loc, _ := time.LoadLocation("Local")
  101. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  102. if err != nil {
  103. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  104. return
  105. }
  106. recordDateTime := theTime.Unix()
  107. adminInfo := c.GetAdminUserInfo()
  108. var tempPatients []*service.NewTempPatients
  109. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  111. var patients []*service.NewTempPatients
  112. var patients_two []*service.NewTempPatients
  113. for _, item := range tempPatients {
  114. //过滤掉没挂号的和没开处方的
  115. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  116. patients = append(patients, item)
  117. }
  118. //过滤掉没挂号的
  119. if len(item.HisPatient) > 0 {
  120. patients_two = append(patients_two, item)
  121. }
  122. }
  123. c.ServeSuccessJSON(map[string]interface{}{
  124. "list": patients,
  125. "list_two": patients_two,
  126. })
  127. }
  128. func (c *HisApiController) GetPrivateExpensesOrder() {
  129. //id, _ := c.GetInt64("id")
  130. //record_time := c.GetString("record_time")
  131. order_id, _ := c.GetInt64("order_id")
  132. admin_user_id, _ := c.GetInt64("admin_user_id")
  133. //timeLayout := "2006-01-02"
  134. //loc, _ := time.LoadLocation("Local")
  135. //
  136. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  137. //if err != nil {
  138. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  139. // return
  140. //}
  141. //recordDateTime := theTime.Unix()
  142. adminUser := c.GetAdminUserInfo()
  143. order, _ := service.GetHisOrderByID(order_id)
  144. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  145. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  146. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  147. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  148. //var config []*models.HisXtDiagnoseConfig
  149. var name string
  150. if order.PType == 1 {
  151. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  152. for _, item := range diagnosis_ids {
  153. id, _ := strconv.ParseInt(item, 10, 64)
  154. diagnosisConfig, _ := service.FindDiagnoseById(id)
  155. if len(name) == 0 {
  156. name = diagnosisConfig.ClassName
  157. } else {
  158. name = name + "," + diagnosisConfig.ClassName
  159. }
  160. }
  161. } else {
  162. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  163. for _, item := range diagnosis_ids {
  164. id, _ := strconv.ParseInt(item, 10, 64)
  165. diagnosisConfig, _ := service.FindDiagnoseById(id)
  166. if len(name) == 0 {
  167. name = diagnosisConfig.ClassName
  168. } else {
  169. name = name + "," + diagnosisConfig.ClassName
  170. }
  171. }
  172. }
  173. var bedCostTotal float64 = 0 //床位总费
  174. //var bedCostSelfTotal float64 = 0 //床位自费
  175. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  176. var operationCostTotal float64 = 0 //手术费
  177. //var operationCostSelfTotal float64 = 0 //手术费
  178. var operationCostPartSelfTotal float64 = 0 //手术费
  179. var otherCostTotal float64 = 0 //其他费用
  180. //var otherCostSelfTotal float64 = 0 //其他费用
  181. var otherCostPartSelfTotal float64 = 0 //其他费用
  182. var materialCostTotal float64 = 0 //材料费
  183. //var materialCostSelfTotal float64 = 0 //材料费
  184. var materialCostPartSelfTotal float64 = 0 //材料费
  185. var westernMedicineCostTotal float64 = 0 //西药费
  186. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  187. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  188. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  189. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  190. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  191. var checkCostTotal float64 = 0 //检查费
  192. //var checkCostSelfTotal float64 = 0 //检查费
  193. var checkCostPartSelfTotal float64 = 0 //检查费
  194. var laboratoryCostTotal float64 = 0 //化验费
  195. //var laboratoryCostSelfTotal float64 = 0 //化验费
  196. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  197. var treatCostTotal float64 = 0 //治疗费用
  198. //var treatCostSelfTotal float64 = 0 //治疗费用
  199. var treatCostPartSelfTotal float64 = 0 //治疗费用
  200. var zhenChaCostTotal float64 = 0 //其他费用
  201. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  202. decimal.DivisionPrecision = 2
  203. for _, item := range orderInfos {
  204. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  205. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  206. item.MedChrgitmType = "09"
  207. }
  208. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  209. if item.HisPrescriptionProject.Type == 2 {
  210. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  211. fmt.Println("CostClassify")
  212. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  213. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  214. case 0:
  215. item.MedChrgitmType = "0"
  216. break
  217. case 1:
  218. item.MedChrgitmType = "14"
  219. break
  220. case 2:
  221. item.MedChrgitmType = "05"
  222. break
  223. case 3:
  224. item.MedChrgitmType = "03"
  225. break
  226. case 4:
  227. item.MedChrgitmType = "03"
  228. break
  229. case 5:
  230. item.MedChrgitmType = "08"
  231. break
  232. case 6:
  233. item.MedChrgitmType = "14"
  234. break
  235. case 7:
  236. item.MedChrgitmType = "14"
  237. break
  238. case 8:
  239. item.MedChrgitmType = "03"
  240. break
  241. case 9:
  242. item.MedChrgitmType = "14"
  243. break
  244. case 10:
  245. item.MedChrgitmType = "14"
  246. break
  247. case 11:
  248. item.MedChrgitmType = "06"
  249. break
  250. case 12:
  251. item.MedChrgitmType = "12"
  252. break
  253. case 13:
  254. item.MedChrgitmType = "01"
  255. break
  256. case 14:
  257. item.MedChrgitmType = "04"
  258. break
  259. case 15:
  260. item.MedChrgitmType = "14"
  261. break
  262. }
  263. } else {
  264. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  265. case 1:
  266. item.MedChrgitmType = "14"
  267. break
  268. case 2:
  269. item.MedChrgitmType = "05"
  270. break
  271. case 3:
  272. item.MedChrgitmType = "04"
  273. break
  274. case 4:
  275. item.MedChrgitmType = "14"
  276. break
  277. case 5:
  278. item.MedChrgitmType = "08"
  279. break
  280. case 6:
  281. item.MedChrgitmType = "14"
  282. break
  283. case 7:
  284. item.MedChrgitmType = "14"
  285. break
  286. case 8:
  287. item.MedChrgitmType = "03"
  288. break
  289. case 9:
  290. item.MedChrgitmType = "14"
  291. break
  292. }
  293. }
  294. } else if item.HisPrescriptionProject.Type == 3 {
  295. item.MedChrgitmType = "08"
  296. }
  297. }
  298. }
  299. order.PsnCashPay = order.MedfeeSumamt
  300. for _, item := range orderInfos {
  301. if item.MedChrgitmType == "01" { //床位费
  302. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  303. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  304. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  305. }
  306. if item.MedChrgitmType == "02" { //诊察费
  307. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  308. //zhenChaCostSelfTotal = zhenChaCostTotal
  309. }
  310. if item.MedChrgitmType == "03" { //检查费
  311. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  312. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  313. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  314. }
  315. if item.MedChrgitmType == "02" { //检查费
  316. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  317. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  318. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  319. }
  320. if item.MedChrgitmType == "04" { //化验费
  321. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  322. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  323. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  324. }
  325. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  326. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  327. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  328. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  329. }
  330. if item.MedChrgitmType == "06" { //手术费
  331. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  332. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  333. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  334. }
  335. if item.MedChrgitmType == "08" { //材料费
  336. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  337. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  338. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  339. }
  340. if item.MedChrgitmType == "09" { //西药费
  341. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  342. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  343. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  344. }
  345. if item.MedChrgitmType == "11" { //中成费
  346. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  347. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  348. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  349. }
  350. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  351. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  352. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  353. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  354. }
  355. }
  356. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  357. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  358. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  359. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  360. c.ServeSuccessJSON(map[string]interface{}{
  361. "patient": patient,
  362. "order_infos": orderInfos,
  363. "diagnosis": name,
  364. "bedCostTotal": bedCostTotal,
  365. "bedCostSelfTotal": bedCostTotal,
  366. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  367. "operationCostTotal": operationCostTotal,
  368. "operationCostSelfTotal": operationCostTotal,
  369. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  370. "otherCostTotal": otherCostTotal,
  371. "otherCostSelfTotal": otherCostTotal,
  372. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  373. "materialCostTotal": materialCostTotal,
  374. "materialCostSelfTotal": materialCostTotal,
  375. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  376. "westernMedicineCostTotal": westernMedicineCostTotal,
  377. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  378. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  379. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  380. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  381. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  382. "checkCostTotal": checkCostTotal,
  383. "checkCostSelfTotal": checkCostTotal,
  384. "zhenChaCostTotal": zhenChaCostTotal,
  385. "zhenChaCostSelfTotal": zhenChaCostTotal,
  386. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  387. "laboratoryCostTotal": laboratoryCostTotal,
  388. "laboratoryCostSelfTotal": laboratoryCostTotal,
  389. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  390. "treatCostTotal": treatCostTotal,
  391. "treatCostSelfTotal": treatCostTotal,
  392. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  393. "charge_admin": charge_admin,
  394. "printor_admin": printor_admin,
  395. "org_name": org.OrgName,
  396. "org_code": miConfig.Code,
  397. "name": patient.Name,
  398. "number": order.MdtrtId,
  399. "date": order.SettleAccountsDate,
  400. "info": order,
  401. "his_hospital": his_hospital,
  402. "his": his,
  403. })
  404. }
  405. func (c *HisApiController) RefudDetail() {
  406. order_id, _ := c.GetInt64("order_id")
  407. order, _ := service.GetHisOrderByID(order_id)
  408. adminUser := c.GetAdminUserInfo()
  409. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  410. c.ServeSuccessJSON(map[string]interface{}{
  411. "msg": "撤销成功",
  412. })
  413. }
  414. func (c *HisApiController) Sscard() {
  415. //r := CardInit()
  416. //if r == 0 {
  417. // GetBaseInfo()
  418. //}
  419. //c.ServeSuccessJSON(map[string]interface{}{
  420. // "list": "11",
  421. //})
  422. }
  423. func GetBaseInfo() error {
  424. //handle := syscall.MustLoadDLL("SSCard.dll")
  425. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  426. //
  427. //str := make([]byte, 256)
  428. //str1 := make([]byte, 256)
  429. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  430. //if ferr != nil {
  431. // fmt.Println("ReadCardBas 报错", ferr.Error())
  432. // return ferr
  433. //}
  434. //
  435. //fmt.Println(string(str))
  436. //
  437. //fmt.Println(r)
  438. return nil
  439. }
  440. func CardInit() int {
  441. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  442. //add := DllTestDef.MustFindProc("Init")
  443. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  444. //if err != nil {
  445. // fmt.Println("SSCard的运算结果为:", ret)
  446. //}
  447. //result := int(ret)
  448. return 0
  449. }
  450. func IntPtr(n int) uintptr {
  451. return uintptr(n)
  452. }
  453. func StrPtr(s string) uintptr {
  454. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  455. }
  456. func (c *HisApiController) GetHisPatientList() {
  457. //types, _ := c.GetInt64("type", 0)
  458. record_date := c.GetString("record_date")
  459. sch_type, _ := c.GetInt64("sch_type")
  460. timeLayout := "2006-01-02"
  461. loc, _ := time.LoadLocation("Local")
  462. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  463. if err != nil {
  464. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  465. return
  466. }
  467. recordDateTime := theTime.Unix()
  468. adminInfo := c.GetAdminUserInfo()
  469. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  470. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  471. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  472. //获取当前用户的信息
  473. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  474. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  475. //获取所有科室信息
  476. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  477. c.ServeSuccessJSON(map[string]interface{}{
  478. "list": patients,
  479. "list_two": patients_two,
  480. "info": adminUserInfo,
  481. "doctors": doctors,
  482. "department": department,
  483. })
  484. }
  485. type CustomTemplate struct {
  486. ID int64 `gorm:"column:id" json:"id" form:"id"`
  487. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  488. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  489. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  490. Status int64 `gorm:"column:status" json:"status" form:"status"`
  491. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  492. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  493. Type int64 `gorm:"column:type" json:"type" form:"type"`
  494. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  495. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  496. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  497. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  498. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  499. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  500. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  501. }
  502. func (c *HisApiController) GetHisPatientInfo() {
  503. patient_id, _ := c.GetInt64("patient_id")
  504. his_patient_id, _ := c.GetInt64("his_patient_id")
  505. record_date := c.GetString("record_date")
  506. number := c.GetString("number")
  507. //start_time := c.GetString("start_time")
  508. //end_time := c.GetString("end_time")
  509. p_type, _ := c.GetInt64("p_type")
  510. timeLayout := "2006-01-02"
  511. loc, _ := time.LoadLocation("Local")
  512. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  513. if err != nil {
  514. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  515. return
  516. }
  517. recordDateTime := theTime.Unix()
  518. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  519. //if err != nil {
  520. //
  521. //}
  522. //startRecordDateTime := startTime.Unix()
  523. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  524. //if err != nil {
  525. //
  526. //}
  527. //endRecordDateTime := endTime.Unix()
  528. admin := c.GetAdminUserInfo()
  529. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  530. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  531. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  532. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  533. var prescriptions []*models.HisPrescription
  534. var last_prescriptions []*models.HisPrescription
  535. var sch_prescriptions []CustomTemplate
  536. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  537. if p_type == 1 { //住院
  538. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  539. for _, item := range prescriptions {
  540. for _, subItem := range item.HisDoctorAdviceInfo {
  541. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  542. if info.RetailPrice > 0 {
  543. subItem.Drug.MinPrice = info.RetailPrice
  544. }
  545. }
  546. }
  547. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  548. } else { //门诊
  549. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  550. for _, item := range prescriptions {
  551. for _, subItem := range item.HisDoctorAdviceInfo {
  552. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  553. if info.RetailPrice > 0 {
  554. subItem.Drug.MinPrice = info.RetailPrice
  555. }
  556. }
  557. }
  558. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  559. }
  560. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  561. if sch.ID > 0 {
  562. var week string
  563. t := time.Now()
  564. switch t.Weekday().String() {
  565. case "Monday":
  566. week = "周一"
  567. break
  568. case "Tuesday":
  569. week = "周二"
  570. break
  571. case "Wednesday":
  572. week = "周三"
  573. break
  574. case "Thursday":
  575. week = "周四"
  576. break
  577. case "Friday":
  578. week = "周五"
  579. break
  580. case "Saturday":
  581. week = "周六"
  582. break
  583. case "Sunday":
  584. week = "周日"
  585. break
  586. }
  587. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  588. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  589. //根据推送频率组装新的数组
  590. for _, item := range temp_sch_prescriptions {
  591. var cus CustomTemplate
  592. cus.ID = item.ID
  593. cus.UserOrgId = item.UserOrgId
  594. cus.PatientId = item.PatientId
  595. cus.MedType = item.MedType
  596. cus.RecordDate = item.RecordDate
  597. cus.Type = item.Type
  598. cus.PType = item.PType
  599. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  600. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  601. if subItem.FrequencyType == 1 { //每次必推
  602. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  603. }
  604. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  605. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  606. }
  607. if subItem.FrequencyType == 2 { //按照天数频率
  608. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  609. now := p.Unix()
  610. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  611. dayStr2 := "-" + dayStr
  612. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  613. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  614. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  615. if len(advices) == 0 {
  616. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  617. }
  618. }
  619. }
  620. }
  621. for _, subItem := range item.HisPrescriptionProjectTemplate {
  622. if subItem.Type == 2 {
  623. if subItem.XtHisProject.MedicalStatus != 1 {
  624. if subItem.FrequencyType == 1 {
  625. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  626. }
  627. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  628. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  629. }
  630. if subItem.FrequencyType == 2 {
  631. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  632. now := p.Unix()
  633. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  634. dayStr2 := "-" + dayStr
  635. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  636. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  637. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  638. if len(projects) == 0 {
  639. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  640. }
  641. }
  642. }
  643. } else if subItem.Type == 3 {
  644. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  645. if subItem.FrequencyType == 1 {
  646. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  647. }
  648. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  649. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  650. }
  651. if subItem.FrequencyType == 2 {
  652. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  653. now := p.Unix()
  654. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  655. dayStr2 := "-" + dayStr
  656. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  657. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  658. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  659. if len(projects) == 0 {
  660. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  661. }
  662. }
  663. }
  664. }
  665. }
  666. sch_prescriptions = append(sch_prescriptions, cus)
  667. }
  668. for _, item := range sch_prescriptions {
  669. if len(item.HisPrescriptionProjectTemplate) == 0 {
  670. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  671. }
  672. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  673. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  674. }
  675. }
  676. }
  677. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  678. if config.ID > 0 && config.IsOpen == 1 {
  679. for _, item := range sch_prescriptions {
  680. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  681. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  682. if info.RetailPrice > 0 {
  683. subItem.Drug.MinPrice = info.RetailPrice
  684. }
  685. }
  686. }
  687. }
  688. if config.ID > 0 && config.IsOpen == 1 {
  689. for _, item := range sch_prescriptions {
  690. for _, subItem := range item.HisPrescriptionProjectTemplate {
  691. if subItem.Type == 3 {
  692. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  693. if info.Price > 0 {
  694. subItem.GoodInfo.PackingPrice = info.Price
  695. }
  696. }
  697. }
  698. }
  699. }
  700. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  701. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  702. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  703. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  704. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  705. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  706. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  707. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  708. //获取所有科室信息
  709. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  710. c.ServeSuccessJSON(map[string]interface{}{
  711. "his_info": his_patient_info,
  712. "xt_info": xt_patient_info,
  713. "prescription": prescriptions,
  714. "case_history": case_history,
  715. "info": patientPrescriptionInfo,
  716. //"month_prescriptions": monthPrescriptions,
  717. "order": order,
  718. "doctors": doctors,
  719. "department": department,
  720. "sch_prescriptions": sch_prescriptions,
  721. "last_prescriptions": last_prescriptions,
  722. "schedule": sch,
  723. "count": count,
  724. "drugStockConfig": drugStockConfig,
  725. "last_info": lastPatientPrescriptionInfo,
  726. })
  727. return
  728. }
  729. func (c *HisApiController) GetHisPrescriptionConfig() {
  730. adminInfo := c.GetAdminUserInfo()
  731. //获取医嘱模版
  732. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  733. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  734. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  735. //获取所有基础药
  736. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  737. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  738. if config.ID > 0 && config.IsOpen == 1 {
  739. for _, item := range drugs {
  740. var index = 0
  741. for _, subItem := range item.OtherDrugWarehouseInfo {
  742. if index == 0 {
  743. index = index + 1
  744. if subItem.RetailPrice > 0 {
  745. item.MinPrice = subItem.RetailPrice
  746. }
  747. }
  748. }
  749. }
  750. }
  751. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  752. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  753. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  754. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  755. //获取所有科室信息
  756. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  757. //获取诊断信息
  758. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  759. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  760. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  761. //获取是否开启保存耗材出库的开关
  762. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  763. c.ServeSuccessJSON(map[string]interface{}{
  764. "drugs": drugs,
  765. "advices_template": advices,
  766. "drugways": drugways,
  767. "efs": efs,
  768. "doctors": doctors,
  769. "department": department,
  770. "sick": sick,
  771. "additions": additions,
  772. "diagnose": diagnose,
  773. "manufacturers": manufacturers,
  774. "goodOutOpen": goodOutOpen,
  775. })
  776. }
  777. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  778. //获取所有基础药
  779. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  780. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  781. if config.ID > 0 && config.IsOpen == 1 {
  782. for _, item := range drugs {
  783. var index = 0
  784. for _, subItem := range item.OtherDrugWarehouseInfo {
  785. if index == 0 {
  786. index = index + 1
  787. if subItem.RetailPrice > 0 {
  788. item.MinPrice = subItem.RetailPrice
  789. }
  790. }
  791. }
  792. }
  793. }
  794. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  795. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  796. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  797. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  798. //获取所有科室信息
  799. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  800. //获取诊断信息
  801. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  802. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  803. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  804. //获取是否开启保存耗材出库的开关
  805. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  806. c.ServeSuccessJSON(map[string]interface{}{
  807. "drugs": drugs,
  808. "advices_template": advices,
  809. "drugways": drugways,
  810. "efs": efs,
  811. "doctors": doctors,
  812. "department": department,
  813. "sick": sick,
  814. "additions": additions,
  815. "diagnose": diagnose,
  816. "manufacturers": manufacturers,
  817. "goodOutOpen": goodOutOpen,
  818. })
  819. }
  820. }
  821. func (c *HisApiController) CreateHisPrescription() {
  822. record_date := c.GetString("record_date")
  823. patient_id, _ := c.GetInt64("patient_id")
  824. reg_type, _ := c.GetInt64("reg_type")
  825. diagnose := c.GetString("diagnose")
  826. sick_type, _ := c.GetInt64("sick_type")
  827. sick_history := c.GetString("sick_history")
  828. doctor_id, _ := c.GetInt64("doctor", 0)
  829. department, _ := c.GetInt64("department", 0)
  830. his_patient_id, _ := c.GetInt64("his_patient_id")
  831. p_type, _ := c.GetInt64("p_type")
  832. dataBody := make(map[string]interface{}, 0)
  833. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  834. if err != nil {
  835. utils.ErrorLog(err.Error())
  836. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  837. return
  838. }
  839. timeLayout := "2006-01-02"
  840. loc, _ := time.LoadLocation("Local")
  841. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  842. if err != nil {
  843. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  844. return
  845. }
  846. adminInfo := c.GetAdminUserInfo()
  847. recordDateTime := theTime.Unix()
  848. //查询默认出库仓库库存
  849. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  850. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  851. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  852. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  853. if len(lists) == 1 {
  854. his_patient_id = lists[0].ID
  855. }
  856. }
  857. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  858. //保存处方出库
  859. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  860. //自动出库
  861. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  862. //耗材保存处方出库
  863. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  864. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  865. //已发药和已收费限制逻辑
  866. isMidicine := false
  867. isCharge := false
  868. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  869. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  870. if len(prescriptions) > 0 {
  871. for _, item := range prescriptions {
  872. items := item.(map[string]interface{})
  873. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  874. utils.ErrorLog("id")
  875. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  876. return
  877. }
  878. id := int64(items["id"].(float64))
  879. if id > 0 {
  880. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  881. if err != nil {
  882. if new_prescription.OrderStatus == 4 {
  883. isCharge = true
  884. }
  885. }
  886. }
  887. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  888. advices := items["advices"].([]interface{})
  889. if len(advices) > 0 {
  890. for _, advice := range advices {
  891. var adviceId int64
  892. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  893. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  894. }
  895. if adviceId > 0 {
  896. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  897. if err == nil {
  898. if his_advice_info.IsMedicine == 1 {
  899. isMidicine = true
  900. }
  901. }
  902. }
  903. }
  904. }
  905. }
  906. }
  907. }
  908. }
  909. if isMidicine == true {
  910. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  911. return
  912. }
  913. if isCharge == true {
  914. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  915. return
  916. }
  917. //已发药和已收费限制逻辑
  918. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  919. //校验库存总量
  920. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  921. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  922. if len(prescriptions) > 0 {
  923. for _, item := range prescriptions {
  924. items := item.(map[string]interface{})
  925. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  926. advices := items["advices"].([]interface{})
  927. if len(advices) > 0 {
  928. for _, advice := range advices {
  929. var drug_id int64
  930. var prescribing_number float64
  931. var prescribingNumberUnit string
  932. var adviceId int64
  933. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  934. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  935. }
  936. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  937. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  938. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  939. }
  940. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  941. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  942. }
  943. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  944. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  945. }
  946. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  947. if drug.ID == 0 {
  948. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  949. return
  950. }
  951. //查询药品的所有库存
  952. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  953. var total_count int64
  954. for _, it := range list {
  955. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  956. }
  957. totals := strconv.FormatInt(total_count, 10)
  958. //查询该药品是否存在开药记录
  959. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  960. //查询最新批次库存
  961. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  962. var batch_number_count int64
  963. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  964. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  965. //新增处方
  966. if advicelist.ID == 0 {
  967. all_count, _ := strconv.ParseFloat(totals, 64)
  968. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  969. if prescribingNumberUnit == drug.MinUnit {
  970. if drug.IsUse != 1 {
  971. if prescribing_number > all_count {
  972. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  973. return
  974. }
  975. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  976. if prescribing_number > batch_number_all_count {
  977. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  978. return
  979. }
  980. }
  981. }
  982. }
  983. if prescribingNumberUnit == drug.MaxUnit {
  984. num := prescribing_number * float64(drug.MinNumber)
  985. if drug.IsUse != 1 {
  986. if num > all_count {
  987. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  988. return
  989. }
  990. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  991. if num > batch_number_all_count {
  992. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  993. return
  994. }
  995. }
  996. }
  997. }
  998. }
  999. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1000. if drugOutConfig.IsOpen != 1 {
  1001. //修改处方
  1002. for _, advice := range advices {
  1003. var drug_id int64
  1004. var prescribing_number float64
  1005. var prescribingNumberUnit string
  1006. var prescribingNumber string
  1007. var adviceId int64
  1008. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1009. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1010. }
  1011. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1012. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1013. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1014. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1015. }
  1016. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1017. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1018. }
  1019. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1020. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1021. }
  1022. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1023. if drug.ID == 0 {
  1024. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1025. return
  1026. }
  1027. //查询药品的所有库存
  1028. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1029. var total_count int64
  1030. for _, it := range list {
  1031. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1032. }
  1033. totals := strconv.FormatInt(total_count, 10)
  1034. //查询该药品是否存在开药记录
  1035. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1036. //新增处方
  1037. if advicelist.ID == 0 {
  1038. //查询最新批次库存
  1039. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1040. var batch_number_count int64
  1041. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1042. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1043. all_count, _ := strconv.ParseFloat(totals, 64)
  1044. if prescribingNumberUnit == drug.MinUnit {
  1045. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1046. if drug.IsUse != 1 {
  1047. if prescribing_number > all_count {
  1048. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1049. return
  1050. }
  1051. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1052. if prescribing_number > batch_number_all_count {
  1053. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1054. return
  1055. }
  1056. }
  1057. }
  1058. } else {
  1059. if prescribingNumberUnit == drug.MaxUnit {
  1060. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1061. num := prescribing_number * float64(drug.MinNumber)
  1062. if drug.IsUse != 1 {
  1063. if num > all_count {
  1064. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1065. return
  1066. }
  1067. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1068. if prescribing_number > batch_number_all_count {
  1069. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1070. return
  1071. }
  1072. }
  1073. }
  1074. }
  1075. }
  1076. }
  1077. //修改处方
  1078. if advicelist.ID > 0 {
  1079. //查询最新批次库存
  1080. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1081. var batch_number_count int64
  1082. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1083. var device_number int64
  1084. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1085. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1086. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1087. device_number = prescribingNumberInt * drug.MinNumber
  1088. }
  1089. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1090. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1091. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1092. device_number = prescribingNumberInt
  1093. }
  1094. var number_count int64
  1095. if prescribingNumberUnit == drug.MaxUnit {
  1096. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1097. number_count = prescribingNumberInt * drug.MinNumber
  1098. }
  1099. if prescribingNumberUnit == drug.MinUnit {
  1100. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1101. number_count = prescribingNumberInt
  1102. }
  1103. //如果修改的数量大于之前修改的数量
  1104. if (number_count - device_number) > 0 {
  1105. //如果修改的差数量 大于库存数量
  1106. if drug.IsUse != 1 {
  1107. if (number_count - device_number) > total_count {
  1108. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1109. return
  1110. }
  1111. if (number_count - device_number) > batch_number_count {
  1112. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1113. return
  1114. }
  1115. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 || adminInfo.CurrentOrgId == 9671 {
  1116. // 查询该药品最后一次出库记录
  1117. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1118. var out_count int64
  1119. var in_count int64
  1120. var stock_max_number int64
  1121. var stock_min_number int64
  1122. for _, it := range outInfo {
  1123. if it.CountUnit == drug.MaxUnit {
  1124. it.Count = it.Count * drug.MinNumber
  1125. }
  1126. out_count += it.Count
  1127. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1128. stock_max_number = warehouseInfoList.StockMaxNumber
  1129. stock_min_number = warehouseInfoList.StockMinNumber
  1130. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1131. }
  1132. if out_count > 0 {
  1133. if (number_count - device_number) > in_count {
  1134. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1135. return
  1136. }
  1137. }
  1138. // 未出库
  1139. if out_count == 0 {
  1140. var sum_in_count int64
  1141. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1142. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1143. fmt.Println("sum_in_count", sum_in_count)
  1144. //如果修改的数量大于有库存的第一个批次
  1145. if number_count > sum_in_count {
  1146. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1147. return
  1148. }
  1149. }
  1150. }
  1151. }
  1152. }
  1153. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1154. fmt.Println("device_number2333233232323222323232323323322332", device_number)
  1155. fmt.Println("number_count99999999999999999999999999999999999", number_count)
  1156. if pharmacyConfig.IsOpen != 1 {
  1157. if device_number != number_count {
  1158. // 查询该药品最后一次出库记录
  1159. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1160. //回退库存
  1161. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1162. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1163. }
  1164. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1165. var stock_max_number int64
  1166. var stock_min_number int64
  1167. if number_count >= drug.MinNumber {
  1168. stock_max_number = device_number / drug.MinNumber
  1169. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1170. stock_min_number = device_number % drug.MinNumber
  1171. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1172. } else {
  1173. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1174. }
  1175. }
  1176. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1177. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1178. }
  1179. //删除记录
  1180. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1181. //查询默认仓库剩余多少库存
  1182. var sum_count int64
  1183. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1184. for _, its := range stockInfo {
  1185. if its.MaxUnit == drug.MaxUnit {
  1186. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  1187. }
  1188. sum_count += its.StockMaxNumber + its.StockMinNumber
  1189. }
  1190. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1191. }
  1192. }
  1193. }
  1194. }
  1195. }
  1196. //保存处方开药
  1197. if drugOutConfig.IsOpen == 1 {
  1198. //修改处方
  1199. for _, advice := range advices {
  1200. var drug_id int64
  1201. var prescribing_number float64
  1202. var prescribingNumberUnit string
  1203. var prescribingNumber string
  1204. var adviceId int64
  1205. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1206. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1207. }
  1208. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1209. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1210. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1211. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1212. }
  1213. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1214. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1215. }
  1216. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1217. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1218. }
  1219. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1220. if drug.ID == 0 {
  1221. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1222. return
  1223. }
  1224. //查询药品的所有库存
  1225. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1226. var total_count int64
  1227. for _, it := range list {
  1228. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1229. }
  1230. totals := strconv.FormatInt(total_count, 10)
  1231. //查询该药品是否存在开药记录
  1232. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1233. //新增处方
  1234. if advicelist.ID == 0 {
  1235. //查询最新批次库存
  1236. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1237. var batch_number_count int64
  1238. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1239. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1240. all_count, _ := strconv.ParseFloat(totals, 64)
  1241. if prescribingNumberUnit == drug.MinUnit {
  1242. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1243. if drug.IsUse != 1 {
  1244. if prescribing_number > all_count {
  1245. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1246. return
  1247. }
  1248. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1249. if prescribing_number > batch_number_all_count {
  1250. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1251. return
  1252. }
  1253. }
  1254. }
  1255. } else {
  1256. if prescribingNumberUnit == drug.MaxUnit {
  1257. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1258. num := prescribing_number * float64(drug.MinNumber)
  1259. if drug.IsUse != 1 {
  1260. if num > all_count {
  1261. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1262. return
  1263. }
  1264. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1265. if prescribing_number > batch_number_all_count {
  1266. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1267. return
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. }
  1274. //修改处方
  1275. if advicelist.ID > 0 {
  1276. //查询最新批次库存
  1277. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1278. var batch_number_count int64
  1279. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1280. var device_number int64
  1281. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1282. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1283. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1284. device_number = prescribingNumberInt * drug.MinNumber
  1285. }
  1286. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1287. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1288. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1289. device_number = prescribingNumberInt
  1290. }
  1291. var number_count int64
  1292. if prescribingNumberUnit == drug.MaxUnit {
  1293. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1294. number_count = prescribingNumberInt * drug.MinNumber
  1295. }
  1296. if prescribingNumberUnit == drug.MinUnit {
  1297. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1298. number_count = prescribingNumberInt
  1299. }
  1300. //如果修改的数量大于之前修改的数量
  1301. if (number_count - device_number) > 0 {
  1302. //如果修改的差数量 大于库存数量
  1303. if drug.IsUse != 1 {
  1304. if (number_count - device_number) > total_count {
  1305. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1306. return
  1307. }
  1308. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1309. if (number_count - device_number) > batch_number_count {
  1310. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1311. return
  1312. }
  1313. }
  1314. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1315. //查询历史出库数据总批次
  1316. // 查询该药品最后一次出库记录
  1317. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1318. var out_count int64
  1319. var in_count int64
  1320. var stock_max_number int64
  1321. var stock_min_number int64
  1322. for _, it := range outInfo {
  1323. if it.CountUnit == drug.MaxUnit {
  1324. it.Count = it.Count * drug.MinNumber
  1325. }
  1326. out_count += it.Count
  1327. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1328. stock_max_number = warehouseInfoList.StockMaxNumber
  1329. stock_min_number = warehouseInfoList.StockMinNumber
  1330. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1331. }
  1332. if out_count > 0 {
  1333. if (number_count - device_number) > in_count {
  1334. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1335. return
  1336. }
  1337. }
  1338. // 未出库
  1339. if out_count == 0 {
  1340. var sum_in_count int64
  1341. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1342. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1343. //如果修改的数量大于有库存的第一个批次
  1344. if number_count > sum_in_count {
  1345. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1346. return
  1347. }
  1348. }
  1349. }
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. }
  1356. }
  1357. }
  1358. }
  1359. }
  1360. }
  1361. }
  1362. //校验耗材库存
  1363. if goodOutConfig.IsOpen == 1 {
  1364. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1365. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1366. if len(prescriptions) > 0 {
  1367. for _, item := range prescriptions {
  1368. items := item.(map[string]interface{})
  1369. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1370. projects := items["project"].([]interface{})
  1371. if len(projects) > 0 {
  1372. for _, project := range projects {
  1373. var project_id int64
  1374. var project_type int64
  1375. var totals float64
  1376. var project_name string
  1377. var parsetotal int64
  1378. var id int64
  1379. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1380. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1381. }
  1382. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1383. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1384. }
  1385. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1386. total, _ := project.(map[string]interface{})["total"].(string)
  1387. totals, _ = strconv.ParseFloat(total, 64)
  1388. }
  1389. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1390. project_name = project.(map[string]interface{})["project_name"].(string)
  1391. }
  1392. if project_type == 3 {
  1393. //查找该耗材的出库记录
  1394. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1395. if len(goodWarehouseInfo) == 0 {
  1396. //查询耗材库存
  1397. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1398. var stock_count int64
  1399. for _, it := range list {
  1400. stock_count += it.StockCount
  1401. }
  1402. stock_counts := strconv.FormatInt(stock_count, 10)
  1403. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1404. if totals > stock_total_count {
  1405. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1406. return
  1407. }
  1408. }
  1409. if len(goodWarehouseInfo) > 0 {
  1410. //查询该患者耗材的历史数据
  1411. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1412. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1413. //数量发生改变
  1414. if parsetotal != count {
  1415. //如果现在的数量大于历史数量,就要看库存是否足够
  1416. if parsetotal > count {
  1417. //查询耗材所有库存
  1418. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  1419. var stock_count int64
  1420. for _, it := range list {
  1421. stock_count += it.StockCount
  1422. }
  1423. //库存不足
  1424. if (parsetotal - count) > stock_count {
  1425. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1426. return
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. }
  1439. //不使用耗材保存处方出库
  1440. if goodOutConfig.IsOpen != 1 {
  1441. if stockConfig.IsOpen == 1 {
  1442. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1443. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1444. if len(prescriptions) > 0 {
  1445. for _, item := range prescriptions {
  1446. items := item.(map[string]interface{})
  1447. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1448. projects := items["project"].([]interface{})
  1449. if len(projects) > 0 {
  1450. for _, project := range projects {
  1451. var project_id int64
  1452. var project_type int64
  1453. var totals float64
  1454. var project_name string
  1455. var parsetotal int64
  1456. var id int64
  1457. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1458. id = int64(project.(map[string]interface{})["id"].(float64))
  1459. }
  1460. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1461. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1462. }
  1463. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1464. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1465. }
  1466. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1467. total, _ := project.(map[string]interface{})["total"].(string)
  1468. totals, _ = strconv.ParseFloat(total, 64)
  1469. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1470. }
  1471. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1472. project_name = project.(map[string]interface{})["project_name"].(string)
  1473. }
  1474. if project_type == 3 {
  1475. //查找该耗材的出库记录
  1476. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1477. //没有出库记录
  1478. if len(goodWarehouseInfo) == 0 {
  1479. //查询耗材库存
  1480. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1481. var stock_count int64
  1482. for _, it := range list {
  1483. stock_count += it.StockCount
  1484. }
  1485. stock_counts := strconv.FormatInt(stock_count, 10)
  1486. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1487. if totals > stock_total_count {
  1488. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1489. return
  1490. }
  1491. //查找今日该患者已经出库的所有耗材
  1492. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1493. for _, item := range goodList {
  1494. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1495. var flush_count int64
  1496. for _, it := range goodListSix {
  1497. flush_count += it.StockCount
  1498. }
  1499. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1500. creater := adminInfo.AdminUser.Id
  1501. if errs != nil {
  1502. goodErrcode := models.XtGoodErrcode{
  1503. UserOrgId: item.OrgId,
  1504. Errcode: "手动出库更新剩余出库失败",
  1505. GoodId: item.GoodId,
  1506. Status: 1,
  1507. Ctime: time.Now().Unix(),
  1508. Mtime: 0,
  1509. Count: 0,
  1510. StockCount: 0,
  1511. Creater: creater,
  1512. BatchNumberId: 0,
  1513. WarehouseOutId: 0,
  1514. }
  1515. service.CreateGoodErrcode(goodErrcode)
  1516. }
  1517. }
  1518. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1519. }
  1520. //有出库记录
  1521. if len(goodWarehouseInfo) > 0 {
  1522. //查询该患者耗材的历史数据
  1523. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1524. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1525. //数量发生改变
  1526. if parsetotal != count {
  1527. //查找今日该患者已经出库的所有耗材
  1528. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1529. for _, item := range goodList {
  1530. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  1531. var flush_count int64
  1532. for _, it := range goodListSix {
  1533. flush_count += it.StockCount
  1534. }
  1535. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  1536. //减少出库数量
  1537. creater := adminInfo.AdminUser.Id
  1538. if errs != nil {
  1539. goodErrcode := models.XtGoodErrcode{
  1540. UserOrgId: item.OrgId,
  1541. Errcode: "手动出库更新剩余出库失败",
  1542. GoodId: item.GoodId,
  1543. Status: 1,
  1544. Ctime: time.Now().Unix(),
  1545. Mtime: 0,
  1546. Count: 0,
  1547. StockCount: 0,
  1548. Creater: creater,
  1549. BatchNumberId: 0,
  1550. WarehouseOutId: 0,
  1551. }
  1552. service.CreateGoodErrcode(goodErrcode)
  1553. }
  1554. //查询默认仓库
  1555. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1556. var total_count int64
  1557. for _, it := range stockList {
  1558. total_count += it.StockCount
  1559. }
  1560. //基础库插入数据
  1561. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1562. }
  1563. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1564. }
  1565. }
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. }
  1575. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1576. var hpInfo models.HisPrescriptionInfo
  1577. if info.ID == 0 {
  1578. var randNum int
  1579. randNum = rand.Intn(10000) + 1000
  1580. timestamp := time.Now().Unix()
  1581. tempTime := time.Unix(timestamp, 0)
  1582. timeFormat := tempTime.Format("20060102150405")
  1583. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1584. hpInfo = models.HisPrescriptionInfo{
  1585. HisPatientId: his_patient_id,
  1586. UserOrgId: adminInfo.CurrentOrgId,
  1587. RecordDate: theTime.Unix(),
  1588. PatientId: patient_id,
  1589. Status: 1,
  1590. Ctime: time.Now().Unix(),
  1591. Mtime: time.Now().Unix(),
  1592. Creator: adminInfo.AdminUser.Id,
  1593. Modifier: adminInfo.AdminUser.Id,
  1594. Diagnosis: diagnose,
  1595. SickHistory: sick_history,
  1596. Departments: department,
  1597. RegisterType: reg_type,
  1598. PrescriptionNumber: p_number,
  1599. PrescriptionStatus: 1,
  1600. Doctor: role.UserName,
  1601. DoctorId: doctor_id,
  1602. SickType: sick_type,
  1603. PType: p_type,
  1604. }
  1605. service.SavePatientPrescriptionInfo(hpInfo)
  1606. redis := service.RedisClient()
  1607. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1608. redis.Set(key, "", time.Second)
  1609. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1610. redis.Set(keyOne, "", time.Second)
  1611. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1612. redis.Set(keySeven, "", time.Second)
  1613. defer redis.Close()
  1614. } else {
  1615. hpInfo = models.HisPrescriptionInfo{
  1616. ID: info.ID,
  1617. UserOrgId: adminInfo.CurrentOrgId,
  1618. RecordDate: info.RecordDate,
  1619. PatientId: info.PatientId,
  1620. Status: 1,
  1621. Ctime: info.Ctime,
  1622. Mtime: time.Now().Unix(),
  1623. Creator: info.Creator,
  1624. Modifier: adminInfo.AdminUser.Id,
  1625. Diagnosis: diagnose,
  1626. SickHistory: sick_history,
  1627. Departments: department,
  1628. RegisterType: reg_type,
  1629. PrescriptionNumber: info.PrescriptionNumber,
  1630. Doctor: role.UserName,
  1631. PrescriptionStatus: info.PrescriptionStatus,
  1632. DoctorId: doctor_id,
  1633. SickType: sick_type,
  1634. PType: info.PType,
  1635. HisPatientId: info.HisPatientId,
  1636. }
  1637. service.SavePatientPrescriptionInfo(hpInfo)
  1638. redis := service.RedisClient()
  1639. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1640. redis.Set(key, "", time.Second)
  1641. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1642. redis.Set(keyOne, "", time.Second)
  1643. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1644. redis.Set(keySeven, "", time.Second)
  1645. defer redis.Close()
  1646. }
  1647. //定义切片
  1648. var adviceList []models.HisDoctorAdviceInfo
  1649. var projectList []models.HisPrescriptionProject
  1650. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1651. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1652. var tempPrescription *models.HisPrescription
  1653. if len(prescriptions) > 0 {
  1654. for _, item := range prescriptions {
  1655. items := item.(map[string]interface{})
  1656. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1657. utils.ErrorLog("id")
  1658. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1659. return
  1660. }
  1661. id := int64(items["id"].(float64))
  1662. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1663. tempPrescription = &new_prescription
  1664. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1665. utils.ErrorLog("type")
  1666. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1667. return
  1668. }
  1669. types := int64(items["type"].(float64))
  1670. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1671. utils.ErrorLog("med_type")
  1672. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1673. return
  1674. }
  1675. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1676. if med_type == "0" {
  1677. med_type = "14"
  1678. }
  1679. //if order_status == 0 {
  1680. // order_status = 1
  1681. //}
  1682. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1683. utils.ErrorLog("pre_time")
  1684. }
  1685. preTime, _ := items["pre_time"].(string)
  1686. timeLayout := "2006-01-02"
  1687. loc, _ := time.LoadLocation("Local")
  1688. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1689. if err != nil {
  1690. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1691. return
  1692. }
  1693. pTime := theTime2.Unix()
  1694. ctime := time.Now().Unix()
  1695. if tempPrescription.ID == 0 {
  1696. prescription := &models.HisPrescription{
  1697. ID: 0,
  1698. PatientId: patient_id,
  1699. UserOrgId: adminInfo.CurrentOrgId,
  1700. RecordDate: recordDateTime,
  1701. Ctime: ctime,
  1702. Mtime: ctime,
  1703. Type: types,
  1704. Modifier: adminInfo.AdminUser.Id,
  1705. Creator: adminInfo.AdminUser.Id,
  1706. Status: 1,
  1707. Doctor: role.UserName,
  1708. HisPatientId: his_patient_id,
  1709. OrderStatus: 1,
  1710. BatchNumber: "",
  1711. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1712. PreTime: pTime,
  1713. PType: p_type,
  1714. MedType: med_type,
  1715. }
  1716. tempPrescription = prescription
  1717. service.SaveHisPrescription(tempPrescription)
  1718. redis := service.RedisClient()
  1719. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1720. redis.Set(key, "", time.Second)
  1721. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1722. redis.Set(keyOne, "", time.Second)
  1723. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1724. redis.Set(keySeven, "", time.Second)
  1725. defer redis.Close()
  1726. } else {
  1727. tempPrescription.ID = id
  1728. tempPrescription.Type = types
  1729. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1730. tempPrescription.Mtime = time.Now().Unix()
  1731. tempPrescription.Doctor = role.UserName
  1732. //tempPrescription.OrderStatus = order_status
  1733. tempPrescription.PreTime = pTime
  1734. tempPrescription.MedType = med_type
  1735. service.SaveHisPrescription(tempPrescription)
  1736. redis := service.RedisClient()
  1737. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1738. redis.Set(key, "", time.Second)
  1739. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1740. redis.Set(keyOne, "", time.Second)
  1741. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1742. redis.Set(keySeven, "", time.Second)
  1743. defer redis.Close()
  1744. }
  1745. //service.SaveHisPrescription(prescription)
  1746. //更改患者挂号状态
  1747. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1748. fmt.Println("更改失败", err2)
  1749. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1750. advices := items["advices"].([]interface{})
  1751. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1752. groupNo := int64(0)
  1753. ctime := time.Now().Unix()
  1754. mtime := ctime
  1755. if len(advices) > 0 {
  1756. for _, advice := range advices {
  1757. var s models.HisDoctorAdviceInfo
  1758. s.PrescriptionId = tempPrescription.ID
  1759. s.AdviceType = 2
  1760. s.AdviceDoctor = doctor_id
  1761. s.StopState = 2
  1762. s.ExecutionState = 2
  1763. s.AdviceDate = recordDateTime
  1764. s.Status = 1
  1765. s.UserOrgId = adminInfo.CurrentOrgId
  1766. s.RecordDate = recordDateTime
  1767. s.StartTime = tempPrescription.PreTime
  1768. s.Groupno = groupNo
  1769. s.CreatedTime = ctime
  1770. s.UpdatedTime = mtime
  1771. s.PatientId = patient_id
  1772. s.HisPatientId = his_patient_id
  1773. s.StartTime = pTime
  1774. s.IsSettle = 2
  1775. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1776. if errcode > 0 {
  1777. c.ServeFailJSONWithSGJErrorCode(errcode)
  1778. return
  1779. }
  1780. s.StartTime = pTime
  1781. var total_count int64 //处方总库存
  1782. //查询改药品信息
  1783. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  1784. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  1785. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  1786. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1787. total_count += prescribingNumberSeven * medical.MinNumber
  1788. }
  1789. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1790. total_count += prescribingNumberSeven
  1791. }
  1792. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1793. total_count += prescribingNumberSeven
  1794. }
  1795. service.CreateHisDoctorAdvice(&s)
  1796. //存储切片中
  1797. adviceList = append(adviceList, s)
  1798. redis := service.RedisClient()
  1799. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1800. redis.Set(key, "", time.Second)
  1801. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1802. redis.Set(keyOne, "", time.Second)
  1803. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1804. redis.Set(keySeven, "", time.Second)
  1805. var randNum int
  1806. randNum = rand.Intn(10000) + 1000
  1807. timestamp := time.Now().Unix()
  1808. tempTime := time.Unix(timestamp, 0)
  1809. timeFormat := tempTime.Format("20060102150405")
  1810. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1811. service.CreateHisDoctorAdvice(&s)
  1812. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1813. redis.Set(keySix, "", time.Second)
  1814. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1815. redis.Set(keyFive, "", time.Second)
  1816. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1817. redis.Set(keyEight, "", time.Second)
  1818. defer redis.Close()
  1819. }
  1820. }
  1821. }
  1822. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1823. projects := items["project"].([]interface{})
  1824. if len(projects) > 0 {
  1825. for _, project := range projects {
  1826. var p models.HisPrescriptionProject
  1827. p.PrescriptionId = tempPrescription.ID
  1828. p.Ctime = time.Now().Unix()
  1829. p.Mtime = time.Now().Unix()
  1830. p.PatientId = patient_id
  1831. p.RecordDate = recordDateTime
  1832. p.Doctor = doctor_id
  1833. p.UserOrgId = adminInfo.CurrentOrgId
  1834. p.HisPatientId = his_patient_id
  1835. p.Status = 1
  1836. p.StartTime = pTime
  1837. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1838. if errcode > 0 {
  1839. c.ServeFailJSONWithSGJErrorCode(errcode)
  1840. return
  1841. }
  1842. if p.ID == 0 {
  1843. p.IsOut = 2
  1844. }
  1845. if p.ID > 0 {
  1846. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  1847. p.IsOut = projectDetail.IsOut
  1848. }
  1849. service.CreateHisProjectTwo(&p)
  1850. projectList = append(projectList, p)
  1851. var randNum int
  1852. randNum = rand.Intn(10000) + 1000
  1853. timestamp := time.Now().Unix()
  1854. tempTime := time.Unix(timestamp, 0)
  1855. timeFormat := tempTime.Format("20060102150405")
  1856. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1857. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1858. //新增或者编辑项目,修改对应的标签数据
  1859. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1860. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1861. var label models.HisLabelPrintInfo
  1862. project, _ := service.GetProjectDetail(p.ProjectId)
  1863. if project.CostClassify == 3 { //类别为检验检查
  1864. if p.TeamId > 0 { //检验检查组套
  1865. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1866. if tempLabel.ID == 0 {
  1867. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1868. label.Number = tempPrescription.PrescriptionNumber
  1869. label.ProjectId = project.ID
  1870. label.Status = 1
  1871. label.IsPrint = 2
  1872. label.DoctorId = info.DoctorId
  1873. label.UserOrgId = p.UserOrgId
  1874. label.PatientId = patient_id
  1875. label.RecordDate = recordDateTime
  1876. label.Ctime = time.Now().Unix()
  1877. label.Mtime = time.Now().Unix()
  1878. label.ItemId = p.TeamId
  1879. label.FeedetlSn = p.FeedetlSn
  1880. label.PProjectId = p.ID
  1881. label.ProjectName = team.ProjectTeam
  1882. label.PatientName = patient.Name
  1883. service.CreateHisLabelRecord(&label)
  1884. }
  1885. } else { //单条检验检查项目
  1886. label.Number = tempPrescription.PrescriptionNumber
  1887. label.ProjectId = project.ID
  1888. label.Status = 1
  1889. label.DoctorId = info.DoctorId
  1890. label.UserOrgId = p.UserOrgId
  1891. label.PatientId = patient_id
  1892. label.RecordDate = recordDateTime
  1893. label.IsPrint = 2
  1894. label.Ctime = time.Now().Unix()
  1895. label.Mtime = time.Now().Unix()
  1896. label.FeedetlSn = p.FeedetlSn
  1897. label.PProjectId = p.ID
  1898. label.ItemId = p.TeamId
  1899. label.ProjectName = project.ProjectName
  1900. label.PatientName = patient.Name
  1901. service.CreateHisLabelRecord(&label)
  1902. }
  1903. }
  1904. }
  1905. }
  1906. service.SaveHisProjectTwo(&p)
  1907. }
  1908. }
  1909. }
  1910. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1911. // addition := items["addition"].([]interface{})
  1912. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1913. // ctime := time.Now().Unix()
  1914. // mtime := ctime
  1915. // if len(addition) > 0 {
  1916. // for _, item := range addition {
  1917. // var s models.HisAdditionalCharge
  1918. // s.PrescriptionId = tempPrescription.ID
  1919. // s.Status = 1
  1920. // s.UserOrgId = adminInfo.CurrentOrgId
  1921. // s.RecordDate = recordDateTime
  1922. // s.CreatedTime = ctime
  1923. // s.UpdatedTime = mtime
  1924. // s.PatientId = patient_id
  1925. // s.HisPatientId = his_patient_id
  1926. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1927. // if errcode > 0 {
  1928. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1929. // return
  1930. // }
  1931. // service.CreateAdditionalCharge(&s)
  1932. // var randNum int
  1933. // randNum = rand.Intn(10000) + 1000
  1934. // timestamp := time.Now().Unix()
  1935. // tempTime := time.Unix(timestamp, 0)
  1936. // timeFormat := tempTime.Format("20060102150405")
  1937. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1938. // service.CreateAdditionalCharge(&s)
  1939. //
  1940. // }
  1941. // }
  1942. //}
  1943. }
  1944. }
  1945. //查询今日该患者开的药品处方
  1946. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1947. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1948. //药品出库
  1949. if drugOutConfig.IsOpen == 1 {
  1950. for _, item := range hisdoctorlist {
  1951. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  1952. // 查询该药品最后一次出库记录
  1953. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  1954. if len(druginfo) > 0 {
  1955. //回退库存
  1956. for _, it := range druginfo {
  1957. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1958. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1959. }
  1960. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1961. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1962. }
  1963. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  1964. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1965. }
  1966. }
  1967. }
  1968. //删除记录
  1969. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  1970. //查询最后一次数据
  1971. if drugOutConfig.IsOpen == 1 {
  1972. //出库
  1973. if drug.IsUse == 2 {
  1974. creater := adminInfo.AdminUser.Id
  1975. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  1976. }
  1977. //更新字典里面的库存
  1978. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1979. var sum_count int64
  1980. for _, its := range stockInfo {
  1981. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  1982. if its.MaxUnit == baseDrug.MaxUnit {
  1983. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  1984. }
  1985. sum_count += its.StockMaxNumber + its.StockMinNumber
  1986. }
  1987. //更新基础库存
  1988. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1989. //剩余库存
  1990. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  1991. }
  1992. }
  1993. }
  1994. //耗材保存处方出库
  1995. if goodOutConfig.IsOpen == 1 {
  1996. //查询今日耗材出库数量
  1997. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1998. for _, item := range hisgoodlist {
  1999. //查询历史出库数据
  2000. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2001. var out_count_five int64
  2002. for _, item := range flowGood {
  2003. out_count_five += item.Count
  2004. }
  2005. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  2006. if out_count_five != parseIntCount {
  2007. //查询耗材最后一次出库记录
  2008. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  2009. //查询默认出库仓库库存
  2010. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2011. if len(wareOut) > 0 {
  2012. for _, it := range wareOut {
  2013. //回退库存
  2014. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  2015. //删除出库记录
  2016. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  2017. }
  2018. }
  2019. timeStr := time.Now().Format("2006-01-02")
  2020. timeArr := strings.Split(timeStr, "-")
  2021. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2022. total = total + 1
  2023. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2024. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2025. number = number + total
  2026. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2027. operation_time := time.Now().Unix()
  2028. creater := c.GetAdminUserInfo().AdminUser.Id
  2029. recordDateStr := time.Now().Format("2006-01-02")
  2030. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  2031. nowtime := recordDate.Unix()
  2032. warehouseOut := models.WarehouseOut{
  2033. WarehouseOutOrderNumber: warehousing_out_order,
  2034. OperationTime: operation_time,
  2035. OrgId: adminInfo.CurrentOrgId,
  2036. Creater: creater,
  2037. Ctime: time.Now().Unix(),
  2038. Status: 1,
  2039. WarehouseOutTime: nowtime,
  2040. Type: 1,
  2041. StorehouseId: storeConfig.StorehouseOutInfo,
  2042. IsCheck: 1,
  2043. IsSys: 1,
  2044. }
  2045. //查询是否生成出库单
  2046. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2047. if out.ID == 0 {
  2048. service.AddSigleWarehouseOut(&warehouseOut)
  2049. }
  2050. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  2051. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2052. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  2053. dialyPrepareOne := models.DialysisBeforePrepare{
  2054. GoodTypeId: goodObj.GoodTypeId,
  2055. GoodId: item.ProjectId,
  2056. PatientId: item.PatientId,
  2057. RecordDate: item.RecordDate,
  2058. UserOrgId: adminInfo.CurrentOrgId,
  2059. Count: parseIntCount,
  2060. Ctime: time.Now().Unix(),
  2061. Creater: creater,
  2062. Status: 1,
  2063. StorehouseId: houseConfig.StorehouseOutInfo,
  2064. ProjectId: item.ID,
  2065. }
  2066. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  2067. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  2068. //查询历史出库数据
  2069. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2070. var out_count int64
  2071. for _, item := range flowGood {
  2072. out_count += item.Count
  2073. }
  2074. //如果历史数和当前数据不想等才进行退库出库
  2075. if out_count != parseIntCount {
  2076. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2077. fmt.Println("9999999----------------------------------------")
  2078. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2079. detail := models.AutomaticReduceDetail{
  2080. WarehouseOutId: 0,
  2081. WarehouseOutOrderNumber: "",
  2082. PatientId: item.PatientId,
  2083. Ctime: time.Now().Unix(),
  2084. Mtime: 0,
  2085. Status: 1,
  2086. RecordTime: item.RecordDate,
  2087. OrgId: item.UserOrgId,
  2088. GoodId: item.ProjectId,
  2089. GoodTypeId: 0,
  2090. Count: parseIntCount,
  2091. Type: 0,
  2092. ProjectId: item.ID,
  2093. StorehouseId: 0,
  2094. }
  2095. service.CreateAutoDetail(detail)
  2096. //查询剩余库存
  2097. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2098. var sum_count int64
  2099. for _, item := range goodList {
  2100. sum_count += item.StockCount
  2101. }
  2102. //更新剩余库存
  2103. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2104. //耗材
  2105. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2106. }
  2107. }
  2108. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  2109. //查询历史出库数据
  2110. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2111. var out_count int64
  2112. for _, item := range flowGood {
  2113. out_count += item.Count
  2114. }
  2115. //如果历史数和当前数据不想等才进行退库出库
  2116. if out_count != parseIntCount {
  2117. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  2118. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  2119. detail := models.AutomaticReduceDetail{
  2120. WarehouseOutId: 0,
  2121. WarehouseOutOrderNumber: "",
  2122. PatientId: item.PatientId,
  2123. Ctime: time.Now().Unix(),
  2124. Mtime: 0,
  2125. Status: 1,
  2126. RecordTime: item.RecordDate,
  2127. OrgId: item.UserOrgId,
  2128. GoodId: item.ProjectId,
  2129. GoodTypeId: 0,
  2130. Count: parseIntCount,
  2131. Type: 0,
  2132. ProjectId: item.ID,
  2133. StorehouseId: 0,
  2134. }
  2135. service.CreateAutoDetail(detail)
  2136. //查询剩余库存
  2137. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  2138. var sum_count int64
  2139. for _, item := range goodList {
  2140. sum_count += item.StockCount
  2141. }
  2142. //更新剩余库存
  2143. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  2144. //耗材
  2145. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  2146. }
  2147. }
  2148. }
  2149. }
  2150. }
  2151. }
  2152. //redisClient := service.RedisClient()
  2153. //defer redisClient.Close()
  2154. //
  2155. //list := models.HisList{
  2156. // Patient_id: patient_id,
  2157. // Advice_id:0,
  2158. // Record_date: 0,
  2159. // Advice: adviceList,
  2160. // Project: nil,
  2161. //}
  2162. //hisLis = append(hisLis, list)
  2163. //
  2164. //advice_json, _ := json.Marshal(&hisLis)
  2165. //redisClient.RPush("111", advice_json).Result()
  2166. //result, _ := redisClient.RPop("111").Result()
  2167. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  2168. //
  2169. //var dat []map[string]interface{}
  2170. //json.Unmarshal([]byte(result), &dat)
  2171. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  2172. //
  2173. //for k,v:=range dat{
  2174. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  2175. //}
  2176. //project_json, _ := json.Marshal(&projectList)
  2177. //redisClient.LPush("222", project_json).Result()
  2178. if err == nil {
  2179. c.ServeSuccessJSON(map[string]interface{}{
  2180. "msg": "保存成功",
  2181. })
  2182. return
  2183. } else {
  2184. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2185. return
  2186. }
  2187. }
  2188. func (c *HisApiController) EditHisPrescription() {
  2189. record_date := c.GetString("record_date")
  2190. patient_id, _ := c.GetInt64("patient_id")
  2191. reg_type, _ := c.GetInt64("reg_type")
  2192. //diagnose, _ := c.GetInt64("diagnose", 0)
  2193. diagnose := c.GetString("diagnose")
  2194. sick_type, _ := c.GetInt64("sick_type")
  2195. sick_history := c.GetString("sick_history")
  2196. doctor_id, _ := c.GetInt64("doctor", 0)
  2197. department, _ := c.GetInt64("department", 0)
  2198. his_patient_id, _ := c.GetInt64("his_patient_id")
  2199. p_type, _ := c.GetInt64("p_type")
  2200. dataBody := make(map[string]interface{}, 0)
  2201. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2202. if err != nil {
  2203. utils.ErrorLog(err.Error())
  2204. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2205. return
  2206. }
  2207. timeLayout := "2006-01-02"
  2208. loc, _ := time.LoadLocation("Local")
  2209. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2210. if err != nil {
  2211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2212. return
  2213. }
  2214. adminInfo := c.GetAdminUserInfo()
  2215. recordDateTime := theTime.Unix()
  2216. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  2217. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2218. var hpInfo models.HisPrescriptionInfo
  2219. if info.ID == 0 {
  2220. var randNum int
  2221. randNum = rand.Intn(10000) + 1000
  2222. timestamp := time.Now().Unix()
  2223. tempTime := time.Unix(timestamp, 0)
  2224. timeFormat := tempTime.Format("20060102150405")
  2225. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2226. hpInfo = models.HisPrescriptionInfo{
  2227. UserOrgId: adminInfo.CurrentOrgId,
  2228. RecordDate: theTime.Unix(),
  2229. PatientId: patient_id,
  2230. Status: 1,
  2231. Ctime: time.Now().Unix(),
  2232. Mtime: time.Now().Unix(),
  2233. Creator: adminInfo.AdminUser.Id,
  2234. Modifier: adminInfo.AdminUser.Id,
  2235. Diagnosis: diagnose,
  2236. SickHistory: sick_history,
  2237. Departments: department,
  2238. RegisterType: reg_type,
  2239. PrescriptionNumber: p_number,
  2240. PrescriptionStatus: 1,
  2241. Doctor: role.UserName,
  2242. DoctorId: doctor_id,
  2243. SickType: sick_type,
  2244. PType: p_type,
  2245. }
  2246. service.SavePatientPrescriptionInfo(hpInfo)
  2247. } else {
  2248. hpInfo = models.HisPrescriptionInfo{
  2249. ID: info.ID,
  2250. UserOrgId: adminInfo.CurrentOrgId,
  2251. RecordDate: info.RecordDate,
  2252. PatientId: info.PatientId,
  2253. Status: 1,
  2254. Ctime: info.Ctime,
  2255. Mtime: time.Now().Unix(),
  2256. Creator: info.Creator,
  2257. Modifier: adminInfo.AdminUser.Id,
  2258. Diagnosis: diagnose,
  2259. SickHistory: sick_history,
  2260. Departments: department,
  2261. RegisterType: reg_type,
  2262. PrescriptionNumber: info.PrescriptionNumber,
  2263. Doctor: role.UserName,
  2264. PrescriptionStatus: info.PrescriptionStatus,
  2265. DoctorId: doctor_id,
  2266. SickType: sick_type,
  2267. PType: info.PType,
  2268. }
  2269. service.SavePatientPrescriptionInfo(hpInfo)
  2270. }
  2271. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2272. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2273. if len(prescriptions) > 0 {
  2274. for _, item := range prescriptions {
  2275. items := item.(map[string]interface{})
  2276. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2277. utils.ErrorLog("id")
  2278. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2279. return
  2280. }
  2281. id := int64(items["id"].(float64))
  2282. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2283. utils.ErrorLog("type")
  2284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2285. return
  2286. }
  2287. types := int64(items["type"].(float64))
  2288. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2289. utils.ErrorLog("med_type")
  2290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2291. return
  2292. }
  2293. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2294. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  2295. ctime := time.Now().Unix()
  2296. prescription := &models.HisPrescription{
  2297. ID: id,
  2298. PatientId: patient_id,
  2299. UserOrgId: adminInfo.CurrentOrgId,
  2300. RecordDate: recordDateTime,
  2301. Ctime: ctime,
  2302. Mtime: ctime,
  2303. Type: types,
  2304. Modifier: adminInfo.AdminUser.Id,
  2305. Creator: adminInfo.AdminUser.Id,
  2306. Status: 1,
  2307. Doctor: role.UserName,
  2308. HisPatientId: his_patient_id,
  2309. OrderStatus: 1,
  2310. BatchNumber: "",
  2311. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2312. PType: hpInfo.PType,
  2313. MedType: med_type,
  2314. }
  2315. if historyPrescription.ID > 0 {
  2316. prescription.PreTime = historyPrescription.PreTime
  2317. }
  2318. service.SaveHisPrescription(prescription)
  2319. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2320. advices := items["advices"].([]interface{})
  2321. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2322. groupNo := int64(0)
  2323. ctime := time.Now().Unix()
  2324. mtime := ctime
  2325. if len(advices) > 0 {
  2326. for _, advice := range advices {
  2327. var s models.HisDoctorAdviceInfo
  2328. s.PrescriptionId = prescription.ID
  2329. s.AdviceType = 2
  2330. s.AdviceDoctor = adminInfo.AdminUser.Id
  2331. s.StopState = 2
  2332. s.ExecutionState = 2
  2333. s.AdviceDate = recordDateTime
  2334. s.Status = 1
  2335. s.UserOrgId = adminInfo.CurrentOrgId
  2336. s.RecordDate = recordDateTime
  2337. s.StartTime = prescription.PreTime
  2338. s.Groupno = groupNo
  2339. s.CreatedTime = ctime
  2340. s.UpdatedTime = mtime
  2341. s.PatientId = patient_id
  2342. s.HisPatientId = his_patient_id
  2343. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2344. if errcode > 0 {
  2345. c.ServeFailJSONWithSGJErrorCode(errcode)
  2346. return
  2347. }
  2348. service.CreateHisDoctorAdvice(&s)
  2349. redis := service.RedisClient()
  2350. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2351. redis.Set(key, "", time.Second)
  2352. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2353. fmt.Println("keyOne", keyOne)
  2354. redis.Set(keyOne, "", time.Second)
  2355. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2356. redis.Set(keySeven, "", time.Second)
  2357. redis.Close()
  2358. }
  2359. }
  2360. }
  2361. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2362. projects := items["project"].([]interface{})
  2363. if len(projects) > 0 {
  2364. for _, project := range projects {
  2365. var p models.HisPrescriptionProject
  2366. p.PrescriptionId = prescription.ID
  2367. p.Ctime = time.Now().Unix()
  2368. p.Mtime = time.Now().Unix()
  2369. p.PatientId = patient_id
  2370. p.RecordDate = recordDateTime
  2371. p.UserOrgId = adminInfo.CurrentOrgId
  2372. p.HisPatientId = his_patient_id
  2373. p.Status = 1
  2374. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2375. if errcode > 0 {
  2376. c.ServeFailJSONWithSGJErrorCode(errcode)
  2377. return
  2378. }
  2379. service.CreateHisProjectTwo(&p)
  2380. }
  2381. }
  2382. }
  2383. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2384. addition := items["addition"].([]interface{})
  2385. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2386. ctime := time.Now().Unix()
  2387. mtime := ctime
  2388. if len(addition) > 0 {
  2389. for _, item := range addition {
  2390. var s models.HisAdditionalCharge
  2391. s.PrescriptionId = prescription.ID
  2392. s.Status = 1
  2393. s.UserOrgId = adminInfo.CurrentOrgId
  2394. s.RecordDate = recordDateTime
  2395. s.CreatedTime = ctime
  2396. s.UpdatedTime = mtime
  2397. s.PatientId = patient_id
  2398. s.HisPatientId = his_patient_id
  2399. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2400. if errcode > 0 {
  2401. c.ServeFailJSONWithSGJErrorCode(errcode)
  2402. return
  2403. }
  2404. service.CreateAdditionalCharge(&s)
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. if err == nil {
  2412. c.ServeSuccessJSON(map[string]interface{}{
  2413. "msg": "保存成功",
  2414. })
  2415. return
  2416. } else {
  2417. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2418. return
  2419. }
  2420. }
  2421. func (c *HisApiController) DeletePrescription() {
  2422. prescription_id, _ := c.GetInt64("id")
  2423. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2424. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2425. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2426. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2427. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2428. //耗材保存处方出库
  2429. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2430. //已收费和已发药限制逻辑
  2431. isCharge := false
  2432. isMedicine := false
  2433. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2434. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2435. for _, item := range new_prescriptions {
  2436. if item.IsMedicine == 1 {
  2437. isMedicine = true
  2438. }
  2439. }
  2440. for _, item := range new_prescriptions {
  2441. if item.OrderStatus == 4 {
  2442. isCharge = true
  2443. }
  2444. }
  2445. if p_err != nil {
  2446. if new_prescription.ID > 0 {
  2447. if new_prescription.OrderStatus == 2 {
  2448. isCharge = true
  2449. }
  2450. }
  2451. }
  2452. for _, item := range advices {
  2453. if item.IsMedicine == 1 {
  2454. isMedicine = true
  2455. }
  2456. }
  2457. if isCharge {
  2458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2459. return
  2460. }
  2461. if isMedicine {
  2462. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2463. return
  2464. }
  2465. //已收费和已发药限制逻辑
  2466. if len(projects) > 0 {
  2467. for _, item := range projects {
  2468. service.DeletePrintInfo(item.ID) //删除打印信息
  2469. if goodOutConfig.IsOpen != 1 {
  2470. if stockConfig.IsOpen == 1 {
  2471. if item.Type == 3 && item.IsOut == 1 {
  2472. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2473. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2474. good.Total = good.Total + f_count
  2475. service.UpdateGoodInfo(&good)
  2476. operation_time := time.Now().Unix()
  2477. creater := c.GetAdminUserInfo().AdminUser.Id
  2478. //创建退库单
  2479. timeStr := time.Now().Format("2006-01-02")
  2480. timeArr := strings.Split(timeStr, "-")
  2481. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2482. total = total + 1
  2483. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2484. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2485. cancelStock := models.CancelStock{
  2486. OrderNumber: orderNumber,
  2487. OperaTime: operation_time,
  2488. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2489. Creater: creater,
  2490. Ctime: time.Now().Unix(),
  2491. Status: 1,
  2492. ReturnTime: item.RecordDate,
  2493. Type: 1,
  2494. StorehouseId: houseConfig.StorehouseOutInfo,
  2495. IsCheck: 1,
  2496. }
  2497. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2498. if msgerrkonde == gorm.ErrRecordNotFound {
  2499. service.AddSigleCancelStock(&cancelStock)
  2500. }
  2501. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2502. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2503. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2504. //查询该耗材是否出库
  2505. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2506. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2507. deaerler, _ := service.GetDealerById(info.Dealer)
  2508. var total_count int64
  2509. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2510. total_count += count
  2511. if info.ID > 0 {
  2512. if info.Count >= total_count {
  2513. //回退库存
  2514. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2515. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2516. var flush_count int64
  2517. for _, it := range goodList {
  2518. flush_count += it.StockCount
  2519. }
  2520. cancelStockInfo := models.CancelStockInfo{
  2521. GoodId: item.ProjectId,
  2522. CancelStockId: cancel.ID,
  2523. GoodTypeId: good.GoodTypeId,
  2524. Count: prescribingNumber,
  2525. Price: info.Price,
  2526. Total: 0,
  2527. ProductDate: info.ProductDate,
  2528. ExpiryDate: info.ExpiryDate,
  2529. Ctime: time.Now().Unix(),
  2530. Status: 1,
  2531. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2532. OrderNumber: cancel.OrderNumber,
  2533. Type: 0,
  2534. Dealer: deaerler.DealerName,
  2535. Manufacturer: manufacturer.ManufacturerName,
  2536. Number: info.Number,
  2537. RegisterAccount: "",
  2538. Remark: "",
  2539. WarehouseInfoId: info.WarehouseInfotId,
  2540. PatientId: info.PatientId,
  2541. RecordDate: info.SysRecordTime,
  2542. StorehouseId: houseConfig.StorehouseOutInfo,
  2543. IsCheck: 1,
  2544. }
  2545. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2546. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2547. flow := models.VmStockFlow{
  2548. WarehousingId: info.WarehouseInfotId,
  2549. GoodId: item.ProjectId,
  2550. Number: info.Number,
  2551. LicenseNumber: info.LicenseNumber,
  2552. Count: prescribingNumber,
  2553. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2554. PatientId: item.PatientId,
  2555. SystemTime: info.SysRecordTime,
  2556. ConsumableType: 7,
  2557. IsSys: 0,
  2558. WarehousingOrder: "",
  2559. WarehouseOutId: info.WarehouseOutId,
  2560. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2561. IsEdit: 0,
  2562. CancelStockId: cancel.ID,
  2563. CancelOrderNumber: cancel.OrderNumber,
  2564. Manufacturer: manufacturer.ID,
  2565. Dealer: 0,
  2566. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2567. UpdateCreator: 0,
  2568. Status: 1,
  2569. Ctime: time.Now().Unix(),
  2570. Mtime: 0,
  2571. Price: info.Price,
  2572. WarehousingDetailId: info.WarehouseInfotId,
  2573. WarehouseOutDetailId: info.ID,
  2574. CancelOutDetailId: cancelInfo.ID,
  2575. ProductDate: info.ProductDate,
  2576. ExpireDate: info.ExpiryDate,
  2577. StorehouseId: houseConfig.StorehouseOutInfo,
  2578. OverCount: flush_count,
  2579. }
  2580. service.CreateStockFlowOne(flow)
  2581. //退库数量增加
  2582. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2583. //出库数量减少
  2584. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2585. }
  2586. if info.Count < total_count {
  2587. //回退库存
  2588. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  2589. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2590. var flush_count int64
  2591. for _, it := range goodList {
  2592. flush_count += it.StockCount
  2593. }
  2594. cancelStockInfo := models.CancelStockInfo{
  2595. GoodId: item.ProjectId,
  2596. CancelStockId: cancel.ID,
  2597. GoodTypeId: good.GoodTypeId,
  2598. Count: info.Count,
  2599. Price: info.Price,
  2600. Total: 0,
  2601. ProductDate: info.ProductDate,
  2602. ExpiryDate: info.ExpiryDate,
  2603. Ctime: time.Now().Unix(),
  2604. Status: 1,
  2605. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2606. OrderNumber: cancel.OrderNumber,
  2607. Type: 0,
  2608. Dealer: deaerler.DealerName,
  2609. Manufacturer: manufacturer.ManufacturerName,
  2610. Number: info.Number,
  2611. RegisterAccount: "",
  2612. Remark: "",
  2613. WarehouseInfoId: info.WarehouseInfotId,
  2614. PatientId: info.PatientId,
  2615. RecordDate: info.SysRecordTime,
  2616. StorehouseId: houseConfig.StorehouseOutInfo,
  2617. IsCheck: 1,
  2618. }
  2619. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2620. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2621. flow := models.VmStockFlow{
  2622. WarehousingId: info.WarehouseInfotId,
  2623. GoodId: item.ProjectId,
  2624. Number: info.Number,
  2625. LicenseNumber: info.LicenseNumber,
  2626. Count: info.Count,
  2627. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2628. PatientId: item.PatientId,
  2629. SystemTime: info.SysRecordTime,
  2630. ConsumableType: 7,
  2631. IsSys: 0,
  2632. WarehousingOrder: "",
  2633. WarehouseOutId: info.WarehouseOutId,
  2634. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2635. IsEdit: 0,
  2636. CancelStockId: cancel.ID,
  2637. CancelOrderNumber: cancel.OrderNumber,
  2638. Manufacturer: manufacturer.ID,
  2639. Dealer: 0,
  2640. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2641. UpdateCreator: 0,
  2642. Status: 1,
  2643. Ctime: time.Now().Unix(),
  2644. Mtime: 0,
  2645. Price: info.Price,
  2646. WarehousingDetailId: info.WarehouseInfotId,
  2647. WarehouseOutDetailId: info.ID,
  2648. CancelOutDetailId: cancelInfo.ID,
  2649. ProductDate: info.ProductDate,
  2650. ExpireDate: info.ExpiryDate,
  2651. StorehouseId: houseConfig.StorehouseOutInfo,
  2652. OverCount: flush_count,
  2653. }
  2654. service.CreateStockFlowOne(flow)
  2655. //退库数量增加
  2656. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  2657. //出库数量减少
  2658. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  2659. }
  2660. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2661. var flush_count int64
  2662. for _, it := range goodList {
  2663. flush_count += it.StockCount
  2664. }
  2665. //查询已出库数量
  2666. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2667. if prescribingNumber < dialysisInfo.Count {
  2668. //改变数量
  2669. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2670. }
  2671. if prescribingNumber >= dialysisInfo.Count {
  2672. //删除出库表
  2673. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  2674. }
  2675. //更新库存
  2676. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  2677. //更新基础库库存
  2678. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  2679. }
  2680. }
  2681. }
  2682. }
  2683. //保存耗材出库
  2684. if goodOutConfig.IsOpen == 1 {
  2685. if item.Type == 3 {
  2686. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2687. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2688. good.Total = good.Total + f_count
  2689. service.UpdateGoodInfo(&good)
  2690. operation_time := time.Now().Unix()
  2691. creater := c.GetAdminUserInfo().AdminUser.Id
  2692. //创建退库单
  2693. timeStr := time.Now().Format("2006-01-02")
  2694. timeArr := strings.Split(timeStr, "-")
  2695. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2696. total = total + 1
  2697. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2698. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2699. cancelStock := models.CancelStock{
  2700. OrderNumber: orderNumber,
  2701. OperaTime: operation_time,
  2702. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2703. Creater: creater,
  2704. Ctime: time.Now().Unix(),
  2705. Status: 1,
  2706. ReturnTime: item.RecordDate,
  2707. Type: 1,
  2708. StorehouseId: houseConfig.StorehouseOutInfo,
  2709. IsCheck: 1,
  2710. }
  2711. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2712. if msgerrkonde == gorm.ErrRecordNotFound {
  2713. service.AddSigleCancelStock(&cancelStock)
  2714. }
  2715. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2716. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2717. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2718. //查询该耗材是否出库
  2719. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2720. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2721. deaerler, _ := service.GetDealerById(info.Dealer)
  2722. var total_count int64
  2723. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2724. total_count += count
  2725. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2726. var flush_count int64
  2727. for _, it := range goodList {
  2728. flush_count += it.StockCount
  2729. }
  2730. fmt.Println("历史出库数据", info.Count)
  2731. fmt.Println("出库数量", total_count)
  2732. if info.ID > 0 {
  2733. cancelStockInfo := models.CancelStockInfo{
  2734. GoodId: item.ProjectId,
  2735. CancelStockId: cancel.ID,
  2736. GoodTypeId: good.GoodTypeId,
  2737. Count: prescribingNumber,
  2738. Price: info.Price,
  2739. Total: 0,
  2740. ProductDate: info.ProductDate,
  2741. ExpiryDate: info.ExpiryDate,
  2742. Ctime: time.Now().Unix(),
  2743. Status: 1,
  2744. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2745. OrderNumber: cancel.OrderNumber,
  2746. Type: 0,
  2747. Dealer: deaerler.DealerName,
  2748. Manufacturer: manufacturer.ManufacturerName,
  2749. Number: info.Number,
  2750. RegisterAccount: "",
  2751. Remark: "",
  2752. WarehouseInfoId: info.WarehouseInfotId,
  2753. PatientId: info.PatientId,
  2754. RecordDate: info.SysRecordTime,
  2755. StorehouseId: houseConfig.StorehouseOutInfo,
  2756. IsCheck: 1,
  2757. }
  2758. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2759. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2760. //查询出库数量
  2761. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  2762. //出库数据 大于 退库数量
  2763. if len(list) > 0 {
  2764. for _, it := range list {
  2765. //回退库存
  2766. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  2767. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2768. var flush_count_one int64
  2769. for _, it := range goodList {
  2770. flush_count_one += it.StockCount
  2771. }
  2772. //查询该批次是否有退库数据
  2773. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  2774. creater := c.GetAdminUserInfo().AdminUser.Id
  2775. flow := models.VmStockFlow{
  2776. WarehousingId: it.WarehouseInfotId,
  2777. GoodId: it.GoodId,
  2778. Number: it.Number,
  2779. LicenseNumber: it.LicenseNumber,
  2780. Count: it.Count,
  2781. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2782. PatientId: it.PatientId,
  2783. SystemTime: it.SysRecordTime,
  2784. ConsumableType: 7,
  2785. IsSys: 0,
  2786. WarehousingOrder: "",
  2787. WarehouseOutId: it.WarehouseOutId,
  2788. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  2789. IsEdit: 0,
  2790. CancelStockId: cancel.ID,
  2791. CancelOrderNumber: cancel.OrderNumber,
  2792. Manufacturer: manufacturer.ID,
  2793. Dealer: 0,
  2794. Creator: creater,
  2795. UpdateCreator: 0,
  2796. Status: 1,
  2797. Ctime: time.Now().Unix(),
  2798. Mtime: 0,
  2799. Price: it.Price,
  2800. WarehousingDetailId: it.WarehouseInfotId,
  2801. WarehouseOutDetailId: it.ID,
  2802. CancelOutDetailId: cancelInfo.ID,
  2803. ProductDate: it.ProductDate,
  2804. ExpireDate: it.ExpiryDate,
  2805. StorehouseId: houseConfig.StorehouseOutInfo,
  2806. OverCount: flush_count_one,
  2807. }
  2808. service.CreateStockFlowOne(flow)
  2809. //if flow.ID > 0 {
  2810. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  2811. //}
  2812. }
  2813. }
  2814. //flow := models.VmStockFlow{
  2815. // WarehousingId: info.WarehouseInfotId,
  2816. // GoodId: item.ProjectId,
  2817. // Number: info.Number,
  2818. // LicenseNumber: info.LicenseNumber,
  2819. // Count: prescribingNumber,
  2820. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2821. // PatientId: item.PatientId,
  2822. // SystemTime: info.SysRecordTime,
  2823. // ConsumableType: 7,
  2824. // IsSys: 0,
  2825. // WarehousingOrder: "",
  2826. // WarehouseOutId: info.WarehouseOutId,
  2827. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2828. // IsEdit: 0,
  2829. // CancelStockId: cancel.ID,
  2830. // CancelOrderNumber: cancel.OrderNumber,
  2831. // Manufacturer: manufacturer.ID,
  2832. // Dealer: 0,
  2833. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  2834. // UpdateCreator: 0,
  2835. // Status: 1,
  2836. // Ctime: time.Now().Unix(),
  2837. // Mtime: 0,
  2838. // Price: info.Price,
  2839. // WarehousingDetailId: info.WarehouseInfotId,
  2840. // WarehouseOutDetailId: info.ID,
  2841. // CancelOutDetailId: cancelInfo.ID,
  2842. // ProductDate: info.ProductDate,
  2843. // ExpireDate: info.ExpiryDate,
  2844. // StorehouseId: houseConfig.StorehouseOutInfo,
  2845. // OverCount: flush_count,
  2846. //}
  2847. //service.CreateStockFlowOne(flow)
  2848. //退库数量增加
  2849. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  2850. //出库数量减少
  2851. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  2852. //查询已出库数量
  2853. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2854. if prescribingNumber < dialysisInfo.Count {
  2855. //改变数量
  2856. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  2857. }
  2858. if prescribingNumber >= dialysisInfo.Count {
  2859. //删除出库表
  2860. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  2861. }
  2862. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  2863. var flush_count_one int64
  2864. for _, it := range goodList {
  2865. flush_count_one += it.StockCount
  2866. }
  2867. //更新库存
  2868. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  2869. fmt.Println("msgerrkonde23332323", msgerrkonde)
  2870. //更新基础库库存
  2871. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  2872. }
  2873. }
  2874. }
  2875. }
  2876. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2877. fmt.Println(err)
  2878. }
  2879. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2880. fmt.Println(err)
  2881. if len(advices) > 0 {
  2882. for _, item := range advices {
  2883. redis := service.RedisClient()
  2884. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2885. redis.Set(keyFive, "", time.Second)
  2886. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2887. redis.Set(keyOne, "", time.Second)
  2888. redis.Close()
  2889. }
  2890. }
  2891. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  2892. if len(advices) > 0 {
  2893. for _, item := range advices {
  2894. creater := c.GetAdminUserInfo().AdminUser.Id
  2895. service.DrugAutoAddCancelInfo(item, creater)
  2896. }
  2897. }
  2898. } else {
  2899. if drugOutConfig.IsOpen == 1 {
  2900. if len(advices) > 0 {
  2901. for _, item := range advices {
  2902. creater := c.GetAdminUserInfo().AdminUser.Id
  2903. service.DrugAutoAddCancelInfo(item, creater)
  2904. }
  2905. }
  2906. } else {
  2907. if len(advices) > 0 {
  2908. for _, item := range advices {
  2909. creater := c.GetAdminUserInfo().AdminUser.Id
  2910. service.DrugAutoAddCancelInfo(item, creater)
  2911. }
  2912. }
  2913. }
  2914. }
  2915. c.ServeSuccessJSON(map[string]interface{}{
  2916. "msg": "删除成功",
  2917. })
  2918. return
  2919. }
  2920. func (c *HisApiController) DeleteDoctorAdvice() {
  2921. id, _ := c.GetInt64("id")
  2922. advice, _ := service.GetHisDoctorAdvicesById(id)
  2923. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2924. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  2925. //已收费和已发药的限制逻辑
  2926. isCharge := false
  2927. isMedicine := false
  2928. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2929. //获取今天该患者所有处方,判断是否发药或者收费
  2930. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2931. for _, item := range new_prescriptions {
  2932. if item.IsMedicine == 1 {
  2933. isMedicine = true
  2934. }
  2935. }
  2936. for _, item := range new_prescriptions {
  2937. if item.OrderStatus == 4 {
  2938. isCharge = true
  2939. }
  2940. }
  2941. if isMedicine {
  2942. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2943. return
  2944. }
  2945. if isCharge {
  2946. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2947. return
  2948. }
  2949. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  2950. for _, item := range advices {
  2951. if item.IsMedicine == 1 {
  2952. isMedicine = true
  2953. }
  2954. }
  2955. if isMedicine {
  2956. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  2957. return
  2958. }
  2959. if new_prescription.ID > 0 {
  2960. if new_prescription.OrderStatus == 2 {
  2961. isCharge = true
  2962. }
  2963. }
  2964. if isCharge {
  2965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2966. return
  2967. }
  2968. //已收费和已发药的限制逻辑
  2969. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2970. redis := service.RedisClient()
  2971. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2972. redis.Set(keyFive, "", time.Second)
  2973. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2974. redis.Set(keyOne, "", time.Second)
  2975. defer redis.Close()
  2976. if err == nil {
  2977. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  2978. //查询是否在处方中出库
  2979. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2980. if openConfig.IsOpen != 1 {
  2981. //判断该医嘱是否执行了
  2982. if advice.ExecutionState == 1 {
  2983. creater := c.GetAdminUserInfo().AdminUser.Id
  2984. service.DrugAutoAddCancelInfo(&advice, creater)
  2985. }
  2986. }
  2987. //开启保存处方扣减功能
  2988. if openConfig.IsOpen == 1 {
  2989. creater := c.GetAdminUserInfo().AdminUser.Id
  2990. service.DrugAutoAddCancelInfo(&advice, creater)
  2991. }
  2992. } else {
  2993. if drugOutConfig.IsOpen == 1 {
  2994. //查询是否在处方中出库
  2995. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2996. if openConfig.IsOpen != 1 {
  2997. //判断该医嘱是否执行了
  2998. if advice.ExecutionState == 1 {
  2999. creater := c.GetAdminUserInfo().AdminUser.Id
  3000. service.DrugAutoAddCancelInfo(&advice, creater)
  3001. }
  3002. }
  3003. //开启保存处方扣减功能
  3004. if openConfig.IsOpen == 1 {
  3005. creater := c.GetAdminUserInfo().AdminUser.Id
  3006. service.DrugAutoAddCancelInfo(&advice, creater)
  3007. }
  3008. } else {
  3009. //判断该医嘱是否执行了
  3010. if advice.ExecutionState == 1 {
  3011. creater := c.GetAdminUserInfo().AdminUser.Id
  3012. service.DrugAutoAddCancelInfo(&advice, creater)
  3013. }
  3014. }
  3015. }
  3016. c.ServeSuccessJSON(map[string]interface{}{
  3017. "msg": "删除成功",
  3018. })
  3019. return
  3020. } else {
  3021. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3022. return
  3023. }
  3024. }
  3025. func (c *HisApiController) DeleteProject() {
  3026. id, _ := c.GetInt64("id")
  3027. adminInfo := c.GetAdminUserInfo()
  3028. project, _ := service.GetHisProjectByID(id)
  3029. // var consumable models.DialysisBeforePrepare
  3030. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  3031. //耗材保存处方出库
  3032. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  3033. isCharge := false
  3034. isMedicine := false
  3035. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  3036. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  3037. for _, item := range new_prescriptions {
  3038. if item.IsMedicine == 1 {
  3039. isMedicine = true
  3040. }
  3041. }
  3042. for _, item := range new_prescriptions {
  3043. if item.OrderStatus == 4 {
  3044. isCharge = true
  3045. }
  3046. }
  3047. if isMedicine {
  3048. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  3049. return
  3050. }
  3051. if isCharge {
  3052. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  3053. return
  3054. }
  3055. if new_prescription.ID > 0 {
  3056. if new_prescription.OrderStatus == 2 {
  3057. isCharge = true
  3058. }
  3059. }
  3060. if isCharge {
  3061. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  3062. return
  3063. }
  3064. service.DeletePrintInfo(id)
  3065. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  3066. label.Status = 0
  3067. service.CreateHisLabelRecord(&label)
  3068. if goodOutConfig.IsOpen != 1 {
  3069. if stockConfig.IsOpen == 1 {
  3070. if project.Type == 2 {
  3071. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3072. fmt.Println(err)
  3073. }
  3074. if project.Type == 3 && project.IsOut == 1 {
  3075. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3076. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3077. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3078. operation_time := time.Now().Unix()
  3079. creater := adminInfo.AdminUser.Id
  3080. //创建退库单
  3081. timeStr := time.Now().Format("2006-01-02")
  3082. timeArr := strings.Split(timeStr, "-")
  3083. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3084. total = total + 1
  3085. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3086. cancelStock := models.CancelStock{
  3087. OrderNumber: orderNumber,
  3088. OperaTime: operation_time,
  3089. OrgId: adminInfo.CurrentOrgId,
  3090. Creater: creater,
  3091. Ctime: time.Now().Unix(),
  3092. Status: 1,
  3093. ReturnTime: project.RecordDate,
  3094. Type: 1,
  3095. StorehouseId: houseConfig.StorehouseOutInfo,
  3096. IsCheck: 1,
  3097. }
  3098. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3099. if msgerrkonde == gorm.ErrRecordNotFound {
  3100. service.AddSigleCancelStock(&cancelStock)
  3101. }
  3102. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3103. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3104. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3105. //查询是否有出库
  3106. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3107. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3108. deaerler, _ := service.GetDealerById(info.Dealer)
  3109. if info.ID > 0 {
  3110. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3111. if info.Count >= prescribingNumber {
  3112. cancelStockInfo := models.CancelStockInfo{
  3113. GoodId: project.ProjectId,
  3114. CancelStockId: cancel.ID,
  3115. GoodTypeId: good.GoodTypeId,
  3116. Count: prescribingNumber,
  3117. Price: info.Price,
  3118. Total: 0,
  3119. ProductDate: info.ProductDate,
  3120. ExpiryDate: info.ExpiryDate,
  3121. Ctime: time.Now().Unix(),
  3122. Status: 1,
  3123. OrgId: adminInfo.CurrentOrgId,
  3124. OrderNumber: cancel.OrderNumber,
  3125. Type: 0,
  3126. Dealer: deaerler.DealerName,
  3127. Manufacturer: manufacturer.ManufacturerName,
  3128. Number: info.Number,
  3129. RegisterAccount: "",
  3130. Remark: "",
  3131. WarehouseInfoId: info.WarehouseInfotId,
  3132. PatientId: info.PatientId,
  3133. RecordDate: info.SysRecordTime,
  3134. StorehouseId: houseConfig.StorehouseOutInfo,
  3135. IsCheck: 1,
  3136. }
  3137. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3138. //回退库存
  3139. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  3140. //退库数量增加
  3141. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3142. //出库数量减少
  3143. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3144. }
  3145. if info.Count < prescribingNumber {
  3146. cancelStockInfo := models.CancelStockInfo{
  3147. GoodId: project.ProjectId,
  3148. CancelStockId: cancel.ID,
  3149. GoodTypeId: good.GoodTypeId,
  3150. Count: info.Count,
  3151. Price: info.Price,
  3152. Total: 0,
  3153. ProductDate: info.ProductDate,
  3154. ExpiryDate: info.ExpiryDate,
  3155. Ctime: time.Now().Unix(),
  3156. Status: 1,
  3157. OrgId: adminInfo.CurrentOrgId,
  3158. OrderNumber: cancel.OrderNumber,
  3159. Type: 0,
  3160. Dealer: deaerler.DealerName,
  3161. Manufacturer: manufacturer.ManufacturerName,
  3162. Number: info.Number,
  3163. RegisterAccount: "",
  3164. Remark: "",
  3165. WarehouseInfoId: info.WarehouseInfotId,
  3166. PatientId: info.PatientId,
  3167. RecordDate: info.SysRecordTime,
  3168. StorehouseId: houseConfig.StorehouseOutInfo,
  3169. IsCheck: 1,
  3170. }
  3171. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3172. //回退库存
  3173. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3174. //退库数量增加
  3175. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  3176. //出库数量减少
  3177. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  3178. }
  3179. //查询剩余库存
  3180. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3181. var over_count int64
  3182. for _, it := range goodList {
  3183. over_count += it.StockCount
  3184. }
  3185. //出库数据 大于 退库数量
  3186. if info.Count >= prescribingNumber {
  3187. flow := models.VmStockFlow{
  3188. WarehousingId: info.WarehouseInfotId,
  3189. GoodId: project.ProjectId,
  3190. Number: info.Number,
  3191. LicenseNumber: info.LicenseNumber,
  3192. Count: prescribingNumber,
  3193. UserOrgId: adminInfo.CurrentOrgId,
  3194. PatientId: project.PatientId,
  3195. SystemTime: info.SysRecordTime,
  3196. ConsumableType: 7,
  3197. IsSys: 0,
  3198. WarehousingOrder: "",
  3199. WarehouseOutId: info.WarehouseOutId,
  3200. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3201. IsEdit: 0,
  3202. CancelStockId: cancel.ID,
  3203. CancelOrderNumber: cancel.OrderNumber,
  3204. Manufacturer: manufacturer.ID,
  3205. Dealer: 0,
  3206. Creator: adminInfo.AdminUser.Id,
  3207. UpdateCreator: 0,
  3208. Status: 1,
  3209. Ctime: time.Now().Unix(),
  3210. Mtime: 0,
  3211. Price: info.Price,
  3212. WarehousingDetailId: info.WarehouseInfotId,
  3213. WarehouseOutDetailId: info.ID,
  3214. CancelOutDetailId: cancelInfo.ID,
  3215. ProductDate: info.ProductDate,
  3216. ExpireDate: info.ExpiryDate,
  3217. StorehouseId: houseConfig.StorehouseOutInfo,
  3218. OverCount: over_count,
  3219. }
  3220. service.CreateStockFlowOne(flow)
  3221. }
  3222. //出库数据小于退库数据
  3223. if info.Count < prescribingNumber {
  3224. flow := models.VmStockFlow{
  3225. WarehousingId: info.WarehouseInfotId,
  3226. GoodId: project.ProjectId,
  3227. Number: info.Number,
  3228. LicenseNumber: info.LicenseNumber,
  3229. Count: info.Count,
  3230. UserOrgId: adminInfo.CurrentOrgId,
  3231. PatientId: project.PatientId,
  3232. SystemTime: info.SysRecordTime,
  3233. ConsumableType: 7,
  3234. IsSys: 0,
  3235. WarehousingOrder: "",
  3236. WarehouseOutId: info.WarehouseOutId,
  3237. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  3238. IsEdit: 0,
  3239. CancelStockId: cancel.ID,
  3240. CancelOrderNumber: cancel.OrderNumber,
  3241. Manufacturer: manufacturer.ID,
  3242. Dealer: 0,
  3243. Creator: adminInfo.AdminUser.Id,
  3244. UpdateCreator: 0,
  3245. Status: 1,
  3246. Ctime: time.Now().Unix(),
  3247. Mtime: 0,
  3248. Price: info.Price,
  3249. WarehousingDetailId: info.WarehouseInfotId,
  3250. WarehouseOutDetailId: info.ID,
  3251. CancelOutDetailId: cancelInfo.ID,
  3252. ProductDate: info.ProductDate,
  3253. ExpireDate: info.ExpiryDate,
  3254. StorehouseId: houseConfig.StorehouseOutInfo,
  3255. OverCount: over_count,
  3256. }
  3257. service.CreateStockFlowOne(flow)
  3258. }
  3259. //查询已出库数量
  3260. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3261. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  3262. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  3263. if prescribingNumber < dialysisInfo.Count {
  3264. //改变数量
  3265. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3266. }
  3267. if prescribingNumber >= dialysisInfo.Count {
  3268. //删除出库表
  3269. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3270. }
  3271. //更新剩余库存
  3272. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3273. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3274. var total_count_one int64
  3275. for _, it := range stockList {
  3276. total_count_one += it.StockCount
  3277. }
  3278. //基础库插入数据
  3279. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3280. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3281. var flush_count int64
  3282. for _, it := range goodListOne {
  3283. flush_count += it.StockCount
  3284. }
  3285. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3286. if errs != nil {
  3287. goodErrcode := models.XtGoodErrcode{
  3288. UserOrgId: project.UserOrgId,
  3289. Errcode: "手动出库更新剩余出库失败",
  3290. GoodId: project.ProjectId,
  3291. Status: 1,
  3292. Ctime: time.Now().Unix(),
  3293. Mtime: 0,
  3294. Count: 0,
  3295. StockCount: 0,
  3296. Creater: creater,
  3297. BatchNumberId: 0,
  3298. WarehouseOutId: 0,
  3299. }
  3300. service.CreateGoodErrcode(goodErrcode)
  3301. }
  3302. }
  3303. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3304. fmt.Println(err)
  3305. } else {
  3306. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3307. fmt.Println(err)
  3308. }
  3309. }
  3310. }
  3311. //保存处方出库
  3312. if goodOutConfig.IsOpen == 1 {
  3313. if project.Type == 3 {
  3314. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  3315. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3316. f_count, _ := strconv.ParseFloat(project.Count, 64)
  3317. operation_time := time.Now().Unix()
  3318. creater := adminInfo.AdminUser.Id
  3319. //创建退库单
  3320. timeStr := time.Now().Format("2006-01-02")
  3321. timeArr := strings.Split(timeStr, "-")
  3322. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  3323. total = total + 1
  3324. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  3325. cancelStock := models.CancelStock{
  3326. OrderNumber: orderNumber,
  3327. OperaTime: operation_time,
  3328. OrgId: adminInfo.CurrentOrgId,
  3329. Creater: creater,
  3330. Ctime: time.Now().Unix(),
  3331. Status: 1,
  3332. ReturnTime: project.RecordDate,
  3333. Type: 1,
  3334. StorehouseId: houseConfig.StorehouseOutInfo,
  3335. IsCheck: 1,
  3336. }
  3337. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  3338. if msgerrkonde == gorm.ErrRecordNotFound {
  3339. service.AddSigleCancelStock(&cancelStock)
  3340. }
  3341. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  3342. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  3343. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  3344. //获取出库数据
  3345. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  3346. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  3347. deaerler, _ := service.GetDealerById(info.Dealer)
  3348. if info.ID > 0 {
  3349. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  3350. if info.Count >= prescribingNumber {
  3351. cancelStockInfo := models.CancelStockInfo{
  3352. GoodId: project.ProjectId,
  3353. CancelStockId: cancel.ID,
  3354. GoodTypeId: good.GoodTypeId,
  3355. Count: prescribingNumber,
  3356. Price: info.Price,
  3357. Total: 0,
  3358. ProductDate: info.ProductDate,
  3359. ExpiryDate: info.ExpiryDate,
  3360. Ctime: time.Now().Unix(),
  3361. Status: 1,
  3362. OrgId: adminInfo.CurrentOrgId,
  3363. OrderNumber: cancel.OrderNumber,
  3364. Type: 0,
  3365. Dealer: deaerler.DealerName,
  3366. Manufacturer: manufacturer.ManufacturerName,
  3367. Number: info.Number,
  3368. RegisterAccount: "",
  3369. Remark: "",
  3370. WarehouseInfoId: info.WarehouseInfotId,
  3371. PatientId: info.PatientId,
  3372. RecordDate: info.SysRecordTime,
  3373. StorehouseId: houseConfig.StorehouseOutInfo,
  3374. IsCheck: 1,
  3375. }
  3376. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3377. //退库数量增加
  3378. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  3379. //出库数量减少
  3380. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  3381. }
  3382. if info.Count < prescribingNumber {
  3383. cancelStockInfo := models.CancelStockInfo{
  3384. GoodId: project.ProjectId,
  3385. CancelStockId: cancel.ID,
  3386. GoodTypeId: good.GoodTypeId,
  3387. Count: prescribingNumber,
  3388. Price: info.Price,
  3389. Total: 0,
  3390. ProductDate: info.ProductDate,
  3391. ExpiryDate: info.ExpiryDate,
  3392. Ctime: time.Now().Unix(),
  3393. Status: 1,
  3394. OrgId: adminInfo.CurrentOrgId,
  3395. OrderNumber: cancel.OrderNumber,
  3396. Type: 0,
  3397. Dealer: deaerler.DealerName,
  3398. Manufacturer: manufacturer.ManufacturerName,
  3399. Number: info.Number,
  3400. RegisterAccount: "",
  3401. Remark: "",
  3402. WarehouseInfoId: info.WarehouseInfotId,
  3403. PatientId: info.PatientId,
  3404. RecordDate: info.SysRecordTime,
  3405. StorehouseId: houseConfig.StorehouseOutInfo,
  3406. IsCheck: 1,
  3407. }
  3408. service.CreateCancelStockInfoOne(&cancelStockInfo)
  3409. //回退库存
  3410. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  3411. }
  3412. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3413. var over_count int64
  3414. for _, it := range goodList {
  3415. over_count += it.StockCount
  3416. }
  3417. //查询出库数量
  3418. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  3419. //出库数据 大于 退库数量
  3420. if len(list) > 0 {
  3421. for _, it := range list {
  3422. //回退库存
  3423. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  3424. //退库数量增加
  3425. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  3426. //出库数量减少
  3427. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  3428. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3429. var over_count_one int64
  3430. for _, it := range goodList {
  3431. over_count_one += it.StockCount
  3432. }
  3433. //查询该批次是否有退库数据
  3434. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  3435. flow := models.VmStockFlow{
  3436. WarehousingId: it.WarehouseInfotId,
  3437. GoodId: it.GoodId,
  3438. Number: it.Number,
  3439. LicenseNumber: it.LicenseNumber,
  3440. Count: it.Count,
  3441. UserOrgId: adminInfo.CurrentOrgId,
  3442. PatientId: it.PatientId,
  3443. SystemTime: it.SysRecordTime,
  3444. ConsumableType: 7,
  3445. IsSys: 0,
  3446. WarehousingOrder: "",
  3447. WarehouseOutId: it.WarehouseOutId,
  3448. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  3449. IsEdit: 0,
  3450. CancelStockId: cancel.ID,
  3451. CancelOrderNumber: cancel.OrderNumber,
  3452. Manufacturer: manufacturer.ID,
  3453. Dealer: 0,
  3454. Creator: adminInfo.AdminUser.Id,
  3455. UpdateCreator: 0,
  3456. Status: 1,
  3457. Ctime: time.Now().Unix(),
  3458. Mtime: 0,
  3459. Price: it.Price,
  3460. WarehousingDetailId: it.WarehouseInfotId,
  3461. WarehouseOutDetailId: it.ID,
  3462. CancelOutDetailId: cancelInfo.ID,
  3463. ProductDate: it.ProductDate,
  3464. ExpireDate: it.ExpiryDate,
  3465. StorehouseId: houseConfig.StorehouseOutInfo,
  3466. OverCount: over_count_one,
  3467. }
  3468. service.CreateStockFlowOne(flow)
  3469. }
  3470. }
  3471. //查询已出库数量
  3472. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  3473. if prescribingNumber < dialysisInfo.Count {
  3474. //改变数量
  3475. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  3476. }
  3477. if prescribingNumber >= dialysisInfo.Count {
  3478. //删除出库表
  3479. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  3480. }
  3481. //更新剩余库存
  3482. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  3483. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  3484. var total_count_one int64
  3485. for _, it := range stockList {
  3486. total_count_one += it.StockCount
  3487. }
  3488. //基础库插入数据
  3489. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  3490. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  3491. var flush_count int64
  3492. for _, it := range goodListOne {
  3493. flush_count += it.StockCount
  3494. }
  3495. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  3496. if errs != nil {
  3497. goodErrcode := models.XtGoodErrcode{
  3498. UserOrgId: project.UserOrgId,
  3499. Errcode: "手动出库更新剩余出库失败",
  3500. GoodId: project.ProjectId,
  3501. Status: 1,
  3502. Ctime: time.Now().Unix(),
  3503. Mtime: 0,
  3504. Count: 0,
  3505. StockCount: 0,
  3506. Creater: creater,
  3507. BatchNumberId: 0,
  3508. WarehouseOutId: 0,
  3509. }
  3510. service.CreateGoodErrcode(goodErrcode)
  3511. }
  3512. }
  3513. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3514. fmt.Println(err)
  3515. } else {
  3516. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  3517. fmt.Println(err)
  3518. }
  3519. }
  3520. c.ServeSuccessJSON(map[string]interface{}{
  3521. "msg": "删除成功",
  3522. })
  3523. return
  3524. }
  3525. func (c *HisApiController) CreateHisAdditionalCharge() {
  3526. his_patient_id, _ := c.GetInt64("his_patient_id")
  3527. patient_id, _ := c.GetInt64("patient_id")
  3528. record_date := c.GetString("record_date")
  3529. timeLayout := "2006-01-02"
  3530. loc, _ := time.LoadLocation("Local")
  3531. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3532. if err != nil {
  3533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3534. return
  3535. }
  3536. adminInfo := c.GetAdminUserInfo()
  3537. recordDateTime := theTime.Unix()
  3538. dataBody := make(map[string]interface{}, 0)
  3539. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  3540. if err != nil {
  3541. utils.ErrorLog(err.Error())
  3542. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3543. return
  3544. }
  3545. var additions []*models.HisAdditionalCharge
  3546. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  3547. additions, _ := dataBody["addition"].([]interface{})
  3548. if len(additions) > 0 {
  3549. for _, item := range additions {
  3550. items := item.(map[string]interface{})
  3551. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  3552. utils.ErrorLog("item_id")
  3553. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3554. return
  3555. }
  3556. item_id := int64(items["item_id"].(float64))
  3557. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  3558. utils.ErrorLog("item_name")
  3559. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3560. return
  3561. }
  3562. item_name := items["item_name"].(string)
  3563. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  3564. utils.ErrorLog("price")
  3565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3566. return
  3567. }
  3568. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  3569. ctime := time.Now().Unix()
  3570. additional := &models.HisAdditionalCharge{
  3571. PatientId: patient_id,
  3572. HisPatientId: his_patient_id,
  3573. UserOrgId: adminInfo.CurrentOrgId,
  3574. RecordDate: recordDateTime,
  3575. CreatedTime: ctime,
  3576. UpdatedTime: ctime,
  3577. Modifier: adminInfo.AdminUser.Id,
  3578. Creator: adminInfo.AdminUser.Id,
  3579. Price: price,
  3580. ItemName: item_name,
  3581. ItemId: item_id,
  3582. Status: 1,
  3583. }
  3584. additions = append(additions, additional)
  3585. }
  3586. }
  3587. }
  3588. for _, item := range additions {
  3589. service.CreateAddtionalCharge(item)
  3590. }
  3591. c.ServeSuccessJSON(map[string]interface{}{
  3592. "msg": "创建成功",
  3593. })
  3594. }
  3595. func (c *HisApiController) CreateHisPatientCaseHistory() {
  3596. blood_fat := c.GetString("blood_fat")
  3597. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  3598. blood_sugar := c.GetString("blood_sugar")
  3599. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  3600. chief_conplaint := c.GetString("chief_conplaint")
  3601. dbp := c.GetString("dbp")
  3602. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  3603. delivery_way, _ := c.GetInt64("delivery_way")
  3604. diagnostic := c.GetString("diagnostic")
  3605. family_history := c.GetString("family_history")
  3606. height := c.GetString("height")
  3607. history_of_present_illness := c.GetString("history_of_present_illness")
  3608. is_infect, _ := c.GetInt64("is_infect")
  3609. past_history := c.GetString("past_history")
  3610. patient_id, _ := c.GetInt64("patient_id")
  3611. his_patient_id, _ := c.GetInt64("his_patient_id")
  3612. personal_history := c.GetString("personal_history")
  3613. pulse := c.GetString("pulse")
  3614. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  3615. sbp := c.GetString("sbp")
  3616. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  3617. heightfloat, _ := strconv.ParseFloat(height, 64)
  3618. sicktype := c.GetString("sick_type")
  3619. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  3620. symptom := c.GetString("symptom")
  3621. sick_date := c.GetString("sick_date")
  3622. temperatures := c.GetString("temperature")
  3623. temperature, _ := strconv.ParseFloat(temperatures, 64)
  3624. record_date := c.GetString("record_date")
  3625. breathing := c.GetString("breathing")
  3626. doctor_advice := c.GetString("doctor_advice")
  3627. remark := c.GetString("remark")
  3628. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  3629. sick, _ := c.GetInt64("sick")
  3630. diagnose, _ := c.GetInt64("diagnose")
  3631. //id, _ := c.GetInt64("id")
  3632. timeLayout := "2006-01-02"
  3633. loc, _ := time.LoadLocation("Local")
  3634. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3635. allergic_history := c.GetString("allergic_history")
  3636. if err != nil {
  3637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3638. return
  3639. }
  3640. recordDateTime := theTime.Unix()
  3641. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  3642. if err != nil {
  3643. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3644. return
  3645. }
  3646. sickTimes := sickTime.Unix()
  3647. ctime := time.Now().Unix()
  3648. primary_disease := c.GetString("primary_disease")
  3649. confirm_failure_date := c.GetString("confirm_failure_date")
  3650. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  3651. drug_allergy_history := c.GetString("drug_allergy_history")
  3652. physical_examination := c.GetString("physical_examination")
  3653. special_inspection := c.GetString("special_inspection")
  3654. lab_apparatus := c.GetString("lab_apparatus")
  3655. caseHistory := models.HisPatientCaseHistory{
  3656. HisPatientId: his_patient_id,
  3657. PatientId: patient_id,
  3658. Temperature: temperature,
  3659. BloodSugar: bloodsugarfloat,
  3660. Pulse: pulsefloat,
  3661. Sbp: sbpfloat,
  3662. Dbp: dbpfloat,
  3663. Height: heightfloat,
  3664. BloodFat: bloodfatfloat,
  3665. SickType: sick_type,
  3666. Symptom: symptom,
  3667. SickDate: sickTimes,
  3668. IsInfect: is_infect,
  3669. HistoryOfPresentIllness: history_of_present_illness,
  3670. PastHistory: past_history,
  3671. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  3672. ChiefConplaint: chief_conplaint,
  3673. PersonalHistory: personal_history,
  3674. FamilyHistory: family_history,
  3675. Diagnostic: diagnostic,
  3676. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3677. Status: 1,
  3678. Ctime: ctime,
  3679. Mtime: ctime,
  3680. RecordDate: recordDateTime,
  3681. DeliveryWay: delivery_way,
  3682. Breathing: breathingfloat,
  3683. DoctorAdvice: doctor_advice,
  3684. Remark: remark,
  3685. Sick: sick,
  3686. Diagnose: diagnose,
  3687. AllergicHistory: allergic_history,
  3688. PrimaryDisease: primary_disease,
  3689. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  3690. DrugAllergyHistory: drug_allergy_history,
  3691. PhysicalExamination: physical_examination,
  3692. SpecialInspection: special_inspection,
  3693. LabApparatus: lab_apparatus,
  3694. }
  3695. //查询该患者是否有病历
  3696. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  3697. if errcodes == gorm.ErrRecordNotFound {
  3698. err = service.SaveHisPatientCaseHistory(&caseHistory)
  3699. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3700. if err != nil {
  3701. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3702. return
  3703. }
  3704. c.ServeSuccessJSON(map[string]interface{}{
  3705. "caseHistory": caseHistory,
  3706. "historyInfo": historyInfo,
  3707. })
  3708. return
  3709. } else if errcodes == nil {
  3710. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  3711. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  3712. if err != nil {
  3713. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3714. return
  3715. }
  3716. c.ServeSuccessJSON(map[string]interface{}{
  3717. "caseHistory": caseHistory,
  3718. "historyInfo": historyInfo,
  3719. })
  3720. }
  3721. //查询该患者是否有病历
  3722. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  3723. //if errcode == gorm.ErrRecordNotFound {
  3724. // err = service.SaveHisPatientCaseHistory(caseHistory)
  3725. // if err != nil {
  3726. // c.ServeSuccessJSON(map[string]interface{}{
  3727. // "msg": "保存成功",
  3728. // })
  3729. // }
  3730. //} else if errcode == nil {
  3731. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  3732. // return
  3733. //}
  3734. }
  3735. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  3736. patient_id, _ := c.GetInt64("patient_id", 0)
  3737. adminUser := c.GetAdminUserInfo()
  3738. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  3739. c.ServeSuccessJSON(map[string]interface{}{
  3740. "list": caseHistorys,
  3741. })
  3742. }
  3743. func (c *HisApiController) GetHisPatientCaseHistory() {
  3744. record_date, _ := c.GetInt64("record_date", 0)
  3745. patient_id, _ := c.GetInt64("patient_id", 0)
  3746. admin := c.GetAdminUserInfo()
  3747. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  3748. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  3749. c.ServeSuccessJSON(map[string]interface{}{
  3750. "info": info,
  3751. "case_history": case_history,
  3752. })
  3753. }
  3754. func (c *HisApiController) CreateCaseHistoryTemplate() {
  3755. template_name := c.GetString("template_name")
  3756. template_remark := c.GetString("template_remark")
  3757. doctor := c.GetAdminUserInfo().AdminUser.Id
  3758. diagnostic := c.GetString("diagnostic")
  3759. chief_conplaint := c.GetString("chief_conplain")
  3760. history_of_present_illness := c.GetString("history_of_present_illness")
  3761. past_history := c.GetString("past_history")
  3762. personal_history := c.GetString("personal_history")
  3763. family_history := c.GetString("family_history")
  3764. user_name := c.GetString("user_name")
  3765. doctor_advice := c.GetString("doctor_advice")
  3766. remark := c.GetString("remark")
  3767. //record_date := c.GetString("record_date")
  3768. //fmt.Println("record_date--------",record_date)
  3769. //timeLayout := "2006-01-02"
  3770. //loc, _ := time.LoadLocation("Local")
  3771. //
  3772. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3773. //if err != nil {
  3774. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3775. // return
  3776. //}
  3777. //recordDateTime := theTime.Unix()
  3778. ctime := time.Now().Unix()
  3779. template := models.HisCaseHistoryTemplate{
  3780. HistoryOfPresentIllness: history_of_present_illness,
  3781. PastHistory: past_history,
  3782. ChiefConplaint: chief_conplaint,
  3783. PersonalHistory: personal_history,
  3784. FamilyHistory: family_history,
  3785. Diagnostic: diagnostic,
  3786. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  3787. Status: 1,
  3788. Ctime: ctime,
  3789. Mtime: ctime,
  3790. RecordDate: time.Now().Unix(),
  3791. TemplateName: template_name,
  3792. TemplateRemark: template_remark,
  3793. Creator: doctor,
  3794. Modifier: doctor,
  3795. UserName: user_name,
  3796. DoctorAdvice: doctor_advice,
  3797. Remark: remark,
  3798. }
  3799. err := service.SaveHisPatientCaseHistoryTemplate(template)
  3800. if err == nil {
  3801. c.ServeSuccessJSON(map[string]interface{}{
  3802. "msg": "保存成功",
  3803. })
  3804. } else {
  3805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3806. return
  3807. }
  3808. }
  3809. func (c *HisApiController) GetCaseHistoryTemplate() {
  3810. timeLayout := "2006-01-02"
  3811. loc, _ := time.LoadLocation("Local")
  3812. keyword := c.GetString("keyword")
  3813. start_time := c.GetString("start_time")
  3814. end_time := c.GetString("end_time")
  3815. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3816. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3817. admin := c.GetAdminUserInfo()
  3818. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  3819. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  3820. c.ServeSuccessJSON(map[string]interface{}{
  3821. "template": template,
  3822. //"history": history,
  3823. })
  3824. }
  3825. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3826. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3827. utils.ErrorLog("drug_name")
  3828. return enums.ErrorCodeParamWrong
  3829. }
  3830. adviceName, _ := json["drug_name"].(string)
  3831. if len(adviceName) == 0 {
  3832. utils.ErrorLog("len(advice_name) == 0")
  3833. return enums.ErrorCodeParamWrong
  3834. }
  3835. advice.AdviceName = adviceName
  3836. adviceDesc, _ := json["advice_desc"].(string)
  3837. advice.AdviceDesc = adviceDesc
  3838. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3839. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3840. advice.DrugSpec = drugSpec
  3841. }
  3842. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3843. remark, _ := json["remark"].(string)
  3844. advice.Remark = remark
  3845. }
  3846. if json["id"] == nil {
  3847. advice.DrugId = 0
  3848. } else {
  3849. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3850. drug_id := int64(json["id"].(float64))
  3851. advice.DrugId = drug_id
  3852. }
  3853. }
  3854. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3855. advice_id := int64(json["advice_id"].(float64))
  3856. advice.ID = advice_id
  3857. if advice.ID > 0 {
  3858. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3859. if err == nil {
  3860. if hisAdvice.ID > 0 {
  3861. advice.ExecutionTime = hisAdvice.ExecutionTime
  3862. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3863. advice.ExecutionState = hisAdvice.ExecutionState
  3864. advice.CheckTime = hisAdvice.CheckTime
  3865. advice.Checker = hisAdvice.Checker
  3866. advice.CheckState = hisAdvice.CheckState
  3867. advice.StartTime = hisAdvice.StartTime
  3868. advice.FeedetlSn = hisAdvice.FeedetlSn
  3869. }
  3870. }
  3871. }
  3872. }
  3873. //
  3874. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3875. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3876. // advice.ExecutionTime = execution_time
  3877. //}
  3878. //
  3879. //
  3880. //
  3881. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3882. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3883. // advice.ExecutionStaff = execution_staff
  3884. //}
  3885. //
  3886. //
  3887. //
  3888. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3889. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3890. // advice.ExecutionState = execution_state
  3891. //}
  3892. //
  3893. //
  3894. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3895. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3896. // advice.CheckTime = check_time
  3897. //}
  3898. //
  3899. //
  3900. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3901. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3902. // advice.CheckState = check_state
  3903. //}
  3904. //
  3905. //
  3906. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3907. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3908. // advice.Checker = checker
  3909. //}
  3910. //
  3911. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3912. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3913. // advice.StartTime = start_time
  3914. //}
  3915. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3916. drugSpecUnit, _ := json["min_unit"].(string)
  3917. advice.DrugSpecUnit = drugSpecUnit
  3918. }
  3919. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3920. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3921. advice.SingleDose = singleDose
  3922. }
  3923. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3924. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3925. advice.SingleDoseUnit = singleDoseUnit
  3926. }
  3927. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3928. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3929. advice.PrescribingNumber = prescribingNumber
  3930. }
  3931. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3932. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3933. advice.PrescribingNumberUnit = prescribingNumberUnit
  3934. }
  3935. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3936. deliveryWay, _ := json["delivery_way"].(string)
  3937. advice.DeliveryWay = deliveryWay
  3938. }
  3939. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3940. executionFrequency, _ := json["execution_frequency"].(string)
  3941. advice.ExecutionFrequency = executionFrequency
  3942. }
  3943. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3944. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3945. advice.Price = price
  3946. }
  3947. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3948. med_list_codg, _ := json["medical_insurance_number"].(string)
  3949. advice.MedListCodg = med_list_codg
  3950. }
  3951. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3952. day := int64(json["day"].(float64))
  3953. advice.Day = day
  3954. }
  3955. return 0
  3956. }
  3957. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3958. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3959. id := int64(json["id"].(float64))
  3960. project.ID = id
  3961. historyProject, _ := service.GetHisProjectByID(id)
  3962. project.FeedetlSn = historyProject.FeedetlSn
  3963. }
  3964. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3965. project_id := int64(json["project_id"].(float64))
  3966. project.ProjectId = project_id
  3967. }
  3968. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3969. // price := int64(json["price"].(float64))
  3970. // formatInt_price := strconv.FormatInt(price, 10)
  3971. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3972. // project.Price = float_price
  3973. // }
  3974. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3975. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3976. project.Price = price
  3977. }
  3978. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3979. total, _ := json["total"].(string)
  3980. project.Count = total
  3981. }
  3982. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3983. medical_code, _ := json["medical_code"].(string)
  3984. project.MedListCodg = medical_code
  3985. }
  3986. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3987. single_dose, _ := json["single_dose"].(string)
  3988. project.SingleDose = single_dose
  3989. }
  3990. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3991. delivery_way, _ := json["delivery_way"].(string)
  3992. project.DeliveryWay = delivery_way
  3993. }
  3994. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3995. execution_frequency, _ := json["execution_frequency"].(string)
  3996. project.ExecutionFrequency = execution_frequency
  3997. }
  3998. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3999. remark, _ := json["remark"].(string)
  4000. project.Remark = remark
  4001. }
  4002. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4003. day, _ := json["number_days"].(string)
  4004. project.Day = day
  4005. }
  4006. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4007. unit, _ := json["unit"].(string)
  4008. project.Unit = unit
  4009. }
  4010. return 0
  4011. }
  4012. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4013. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4014. id := int64(json["id"].(float64))
  4015. historyAddtions, _ := service.GetHisAdditionByID(id)
  4016. additionalCharge.ID = id
  4017. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  4018. }
  4019. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4020. item_id := int64(json["item_id"].(float64))
  4021. additionalCharge.ItemId = item_id
  4022. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4023. if config.ID > 0 {
  4024. if len(config.Code) > 0 {
  4025. additionalCharge.MedListCodg = config.Code
  4026. }
  4027. }
  4028. }
  4029. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4030. // price := int64(json["price"].(float64))
  4031. // formatInt_price := strconv.FormatInt(price, 10)
  4032. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4033. // additionalCharge.Price = float_price
  4034. // }
  4035. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4036. // price := int64(json["price"].(float64))
  4037. // formatInt_price := strconv.FormatInt(price, 10)
  4038. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4039. // additionalCharge.Price = float_price
  4040. //}
  4041. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4042. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4043. additionalCharge.Price = price
  4044. }
  4045. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4046. count, _ := json["count"].(string)
  4047. counts, _ := strconv.ParseInt(count, 10, 64)
  4048. additionalCharge.Count = counts
  4049. }
  4050. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4051. item_name, _ := json["item_name"].(string)
  4052. additionalCharge.ItemName = item_name
  4053. }
  4054. return 0
  4055. }
  4056. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  4057. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4058. utils.ErrorLog("drug_name")
  4059. return enums.ErrorCodeParamWrong
  4060. }
  4061. adviceName, _ := json["drug_name"].(string)
  4062. if len(adviceName) == 0 {
  4063. utils.ErrorLog("len(advice_name) == 0")
  4064. return enums.ErrorCodeParamWrong
  4065. }
  4066. advice.AdviceName = adviceName
  4067. adviceDesc, _ := json["advice_desc"].(string)
  4068. advice.AdviceDesc = adviceDesc
  4069. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4070. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4071. advice.DrugSpec = drugSpec
  4072. }
  4073. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4074. remark, _ := json["remark"].(string)
  4075. advice.Remark = remark
  4076. }
  4077. if json["id"] == nil {
  4078. advice.DrugId = 0
  4079. } else {
  4080. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4081. drug_id := int64(json["id"].(float64))
  4082. advice.DrugId = drug_id
  4083. }
  4084. }
  4085. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  4086. groupno := int64(json["groupno"].(float64))
  4087. advice.Groupno = groupno
  4088. }
  4089. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  4090. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  4091. advice.HospApprFlag = hosp_appr_flag
  4092. }
  4093. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4094. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4095. advice.PrescribingNumber = prescribingNumber
  4096. }
  4097. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4098. // frequency_type := int64(json["frequency_type"].(float64))
  4099. // advice.FrequencyType = frequency_type
  4100. //}
  4101. //
  4102. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4103. // day_count := int64(json["day_count"].(float64))
  4104. // advice.DayCount = day_count
  4105. //}
  4106. //
  4107. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4108. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4109. // week_day, _ := json["week_day"].(string)
  4110. // advice.WeekDay = week_day
  4111. //}
  4112. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4113. drugSpecUnit, _ := json["min_unit"].(string)
  4114. advice.DrugSpecUnit = drugSpecUnit
  4115. }
  4116. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4117. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4118. advice.SingleDose = singleDose
  4119. }
  4120. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4121. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4122. advice.SingleDoseUnit = singleDoseUnit
  4123. }
  4124. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4125. deliveryWay, _ := json["delivery_way"].(string)
  4126. advice.DeliveryWay = deliveryWay
  4127. }
  4128. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4129. executionFrequency, _ := json["execution_frequency"].(string)
  4130. advice.ExecutionFrequency = executionFrequency
  4131. }
  4132. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4133. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4134. advice.Price = price
  4135. }
  4136. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4137. med_list_codg, _ := json["medical_insurance_number"].(string)
  4138. advice.MedListCodg = med_list_codg
  4139. }
  4140. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4141. day := int64(json["day"].(float64))
  4142. advice.Day = day
  4143. }
  4144. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4145. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4146. advice.PrescribingNumberUnit = prescribingNumberUnit
  4147. }
  4148. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  4149. advice_id := int64(json["advice_id"].(float64))
  4150. advice.ID = advice_id
  4151. if advice.ID > 0 {
  4152. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  4153. if err == nil {
  4154. if hisAdvice.ID > 0 {
  4155. advice.ExecutionTime = hisAdvice.ExecutionTime
  4156. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  4157. advice.ExecutionState = hisAdvice.ExecutionState
  4158. advice.CheckTime = hisAdvice.CheckTime
  4159. advice.Checker = hisAdvice.Checker
  4160. advice.CheckState = hisAdvice.CheckState
  4161. advice.StartTime = hisAdvice.StartTime
  4162. advice.HospApprFlag = hisAdvice.HospApprFlag
  4163. advice.IsMedicine = hisAdvice.IsMedicine
  4164. if hisAdvice.UserOrgId == 10028 {
  4165. 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 {
  4166. advice.ExecutionTime = 0
  4167. advice.ExecutionStaff = 0
  4168. advice.ExecutionState = 2
  4169. advice.CheckTime = 0
  4170. advice.Checker = 0
  4171. advice.CheckState = 2
  4172. }
  4173. } else {
  4174. 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 {
  4175. advice.ExecutionTime = 0
  4176. advice.ExecutionStaff = 0
  4177. advice.ExecutionState = 2
  4178. advice.CheckTime = 0
  4179. advice.Checker = 0
  4180. advice.CheckState = 2
  4181. }
  4182. }
  4183. //advice.Groupno = hisAdvice.Groupno
  4184. }
  4185. }
  4186. }
  4187. }
  4188. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  4189. //
  4190. //if drugStockConfig.IsOpen == 1 {
  4191. //
  4192. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  4193. // if advice.ID == 0 { //医嘱不存在
  4194. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  4195. // drug.Total = drug.Total - advice.PrescribingNumber
  4196. // service.UpdateBaseDrugLib(&drug)
  4197. //
  4198. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  4199. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  4200. // drug.Total = drug.Total - num
  4201. // service.UpdateBaseDrugLib(&drug)
  4202. // }
  4203. //
  4204. // } else if advice.ID > 0 { //医嘱存在
  4205. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  4206. // var num float64
  4207. //
  4208. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  4209. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  4210. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  4211. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  4212. // drug.Total = drug.Total + num
  4213. // service.UpdateBaseDrugLib(&drug)
  4214. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  4215. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  4216. // drug.Total = drug.Total - num
  4217. // service.UpdateBaseDrugLib(&drug)
  4218. // }
  4219. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  4220. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4221. // if num2 > advice.PrescribingNumber {
  4222. // num = num2 - advice.PrescribingNumber
  4223. // drug.Total = drug.Total + num
  4224. // service.UpdateBaseDrugLib(&drug)
  4225. // } else if num2 < advice.PrescribingNumber {
  4226. // num = advice.PrescribingNumber - num2
  4227. // drug.Total = drug.Total - num
  4228. // service.UpdateBaseDrugLib(&drug)
  4229. // }
  4230. //
  4231. // }
  4232. //
  4233. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  4234. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  4235. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  4236. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4237. // if num1 > num2 {
  4238. // num = num1 - num2
  4239. // drug.Total = drug.Total + num
  4240. // service.UpdateBaseDrugLib(&drug)
  4241. // } else if num1 < num2 {
  4242. // num = num2 - num1
  4243. // drug.Total = drug.Total - num
  4244. // service.UpdateBaseDrugLib(&drug)
  4245. // }
  4246. //
  4247. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  4248. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  4249. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  4250. // if hisAdvice.PrescribingNumber > num2 {
  4251. // num = hisAdvice.PrescribingNumber - num2
  4252. // drug.Total = drug.Total + num
  4253. // service.UpdateBaseDrugLib(&drug)
  4254. // } else if num2 < advice.PrescribingNumber {
  4255. // num = num2 - hisAdvice.PrescribingNumber
  4256. // drug.Total = drug.Total - num
  4257. // service.UpdateBaseDrugLib(&drug)
  4258. // }
  4259. //
  4260. // }
  4261. // }
  4262. // }
  4263. //}
  4264. //
  4265. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  4266. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  4267. // advice.ExecutionTime = execution_time
  4268. //}
  4269. //
  4270. //
  4271. //
  4272. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  4273. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  4274. // advice.ExecutionStaff = execution_staff
  4275. //}
  4276. //
  4277. //
  4278. //
  4279. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  4280. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  4281. // advice.ExecutionState = execution_state
  4282. //}
  4283. //
  4284. //
  4285. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  4286. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  4287. // advice.CheckTime = check_time
  4288. //}
  4289. //
  4290. //
  4291. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  4292. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  4293. // advice.CheckState = check_state
  4294. //}
  4295. //
  4296. //
  4297. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  4298. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  4299. // advice.Checker = checker
  4300. //}
  4301. //
  4302. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  4303. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  4304. // advice.StartTime = start_time
  4305. //}
  4306. return 0
  4307. }
  4308. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  4309. project.ExecutionStaff = 0
  4310. project.ExecutionState = 2
  4311. project.ExecutionTime = 0
  4312. project.Checker = 0
  4313. project.CheckState = 2
  4314. project.CheckTime = 0
  4315. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4316. id := int64(json["id"].(float64))
  4317. project.ID = id
  4318. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  4319. project.ExecutionStaff = temp_project.ExecutionStaff
  4320. project.ExecutionState = temp_project.ExecutionState
  4321. project.ExecutionTime = temp_project.ExecutionTime
  4322. project.Checker = temp_project.Checker
  4323. project.CheckState = temp_project.CheckState
  4324. project.CheckTime = temp_project.CheckTime
  4325. project.TeamId = temp_project.TeamId
  4326. }
  4327. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4328. types := int64(json["type"].(float64))
  4329. project.Type = types
  4330. }
  4331. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4332. project_id := int64(json["project_id"].(float64))
  4333. project.ProjectId = project_id
  4334. }
  4335. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  4336. team_id := int64(json["team_id"].(float64))
  4337. project.TeamId = team_id
  4338. }
  4339. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4340. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4341. project.Price = price
  4342. }
  4343. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4344. total, _ := json["total"].(string)
  4345. //totals, _ := strconv.ParseInt(total, 10, 64)
  4346. project.Count = total
  4347. }
  4348. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4349. medical_code, _ := json["medical_code"].(string)
  4350. project.MedListCodg = medical_code
  4351. }
  4352. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4353. single_dose, _ := json["single_dose"].(string)
  4354. project.SingleDose = single_dose
  4355. }
  4356. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4357. delivery_way, _ := json["delivery_way"].(string)
  4358. project.DeliveryWay = delivery_way
  4359. }
  4360. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4361. execution_frequency, _ := json["execution_frequency"].(string)
  4362. project.ExecutionFrequency = execution_frequency
  4363. }
  4364. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4365. remark, _ := json["remark"].(string)
  4366. project.Remark = remark
  4367. }
  4368. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4369. day, _ := json["number_days"].(string)
  4370. project.Day = day
  4371. }
  4372. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4373. unit, _ := json["unit"].(string)
  4374. project.Unit = unit
  4375. }
  4376. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  4377. // frequency_type := int64(json["frequency_type"].(float64))
  4378. // project.FrequencyType = frequency_type
  4379. //}
  4380. //
  4381. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  4382. // day_count := int64(json["day_count"].(float64))
  4383. // project.DayCount = day_count
  4384. //}
  4385. //
  4386. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  4387. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  4388. // week_day, _ := json["week_day"].(string)
  4389. // project.WeekDay = week_day
  4390. //}
  4391. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  4392. //
  4393. //if project.ID == 0 {
  4394. // if stockConfig.IsOpen == 1 {
  4395. // if project.Type == 3 {
  4396. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4397. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  4398. // good.Total = good.Total - f_count
  4399. // service.UpdateGoodInfo(&good)
  4400. // }
  4401. // }
  4402. //
  4403. //} else {
  4404. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  4405. //
  4406. // if stockConfig.IsOpen == 1 {
  4407. // if project.Type == 3 {
  4408. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  4409. // if project.Count < temp_project.Count {
  4410. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4411. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4412. //
  4413. // other_count := f_count_two - f_count_one
  4414. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4415. // good.Total = good.Total + other_count_two
  4416. // service.UpdateGoodInfo(&good)
  4417. // } else if project.Count > temp_project.Count {
  4418. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  4419. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  4420. //
  4421. // other_count := f_count_one - f_count_two
  4422. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  4423. // good.Total = good.Total - other_count_two
  4424. // service.UpdateGoodInfo(&good)
  4425. // }
  4426. //
  4427. // }
  4428. // }
  4429. //
  4430. //}
  4431. return 0
  4432. }
  4433. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  4434. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4435. id := int64(json["id"].(float64))
  4436. additionalCharge.ID = id
  4437. }
  4438. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  4439. item_id := int64(json["item_id"].(float64))
  4440. additionalCharge.ItemId = item_id
  4441. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  4442. if config.ID > 0 {
  4443. if len(config.Code) > 0 {
  4444. additionalCharge.MedListCodg = config.Code
  4445. }
  4446. }
  4447. }
  4448. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4449. // price := int64(json["price"].(float64))
  4450. // formatInt_price := strconv.FormatInt(price, 10)
  4451. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4452. // additionalCharge.Price = float_price
  4453. // }
  4454. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  4455. // price := int64(json["price"].(float64))
  4456. // formatInt_price := strconv.FormatInt(price, 10)
  4457. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  4458. // additionalCharge.Price = float_price
  4459. //}
  4460. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4461. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4462. additionalCharge.Price = price
  4463. }
  4464. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  4465. count, _ := json["count"].(string)
  4466. counts, _ := strconv.ParseInt(count, 10, 64)
  4467. additionalCharge.Count = counts
  4468. }
  4469. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  4470. item_name, _ := json["item_name"].(string)
  4471. additionalCharge.ItemName = item_name
  4472. }
  4473. return 0
  4474. }
  4475. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  4476. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  4477. utils.ErrorLog("drug_name")
  4478. return enums.ErrorCodeParamWrong
  4479. }
  4480. adviceName, _ := json["drug_name"].(string)
  4481. if len(adviceName) == 0 {
  4482. utils.ErrorLog("len(advice_name) == 0")
  4483. return enums.ErrorCodeParamWrong
  4484. }
  4485. advice.AdviceName = adviceName
  4486. adviceDesc, _ := json["advice_desc"].(string)
  4487. advice.AdviceDesc = adviceDesc
  4488. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  4489. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  4490. advice.DrugSpec = drugSpec
  4491. }
  4492. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4493. remark, _ := json["remark"].(string)
  4494. advice.Remark = remark
  4495. }
  4496. if json["id"] == nil {
  4497. advice.DrugId = 0
  4498. } else {
  4499. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  4500. drug_id := int64(json["id"].(float64))
  4501. advice.DrugId = drug_id
  4502. }
  4503. }
  4504. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  4505. drugSpecUnit, _ := json["min_unit"].(string)
  4506. advice.DrugSpecUnit = drugSpecUnit
  4507. }
  4508. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4509. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  4510. advice.SingleDose = singleDose
  4511. }
  4512. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  4513. singleDoseUnit, _ := json["single_dose_unit"].(string)
  4514. advice.SingleDoseUnit = singleDoseUnit
  4515. }
  4516. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  4517. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  4518. advice.PrescribingNumber = prescribingNumber
  4519. }
  4520. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  4521. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  4522. advice.PrescribingNumberUnit = prescribingNumberUnit
  4523. }
  4524. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4525. deliveryWay, _ := json["delivery_way"].(string)
  4526. advice.DeliveryWay = deliveryWay
  4527. }
  4528. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4529. executionFrequency, _ := json["execution_frequency"].(string)
  4530. advice.ExecutionFrequency = executionFrequency
  4531. }
  4532. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  4533. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  4534. advice.Price = price
  4535. }
  4536. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  4537. med_list_codg, _ := json["medical_insurance_number"].(string)
  4538. advice.MedListCodg = med_list_codg
  4539. }
  4540. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  4541. day := int64(json["day"].(float64))
  4542. advice.Day = day
  4543. }
  4544. return 0
  4545. }
  4546. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  4547. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  4548. types := int64(json["type"].(float64))
  4549. project.Type = types
  4550. }
  4551. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  4552. project_id := int64(json["project_id"].(float64))
  4553. project.ProjectId = project_id
  4554. }
  4555. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  4556. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  4557. project.Price = price
  4558. }
  4559. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  4560. total, _ := json["total"].(string)
  4561. //totals, _ := strconv.ParseInt(total, 10, 64)
  4562. project.Count = total
  4563. }
  4564. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  4565. medical_code, _ := json["medical_code"].(string)
  4566. project.MedListCodg = medical_code
  4567. }
  4568. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  4569. single_dose, _ := json["single_dose"].(string)
  4570. project.SingleDose = single_dose
  4571. }
  4572. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  4573. delivery_way, _ := json["delivery_way"].(string)
  4574. project.DeliveryWay = delivery_way
  4575. }
  4576. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  4577. execution_frequency, _ := json["execution_frequency"].(string)
  4578. project.ExecutionFrequency = execution_frequency
  4579. }
  4580. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  4581. remark, _ := json["remark"].(string)
  4582. project.Remark = remark
  4583. }
  4584. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  4585. day, _ := json["number_days"].(string)
  4586. project.Day = day
  4587. }
  4588. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  4589. unit, _ := json["unit"].(string)
  4590. project.Unit = unit
  4591. }
  4592. return 0
  4593. }
  4594. func (c *HisApiController) GetHisOrderList() {
  4595. page, _ := c.GetInt64("page", -1)
  4596. limit, _ := c.GetInt64("limit", -1)
  4597. start_time := c.GetString("start_time")
  4598. end_time := c.GetString("end_time")
  4599. types, _ := c.GetInt64("type", 0)
  4600. keywords := c.GetString("keywords")
  4601. p_type, _ := c.GetInt64("p_type", 0)
  4602. sort_type, _ := c.GetInt64("sort_type", 0)
  4603. charge_type, _ := c.GetInt64("charge_type", 0)
  4604. timeLayout := "2006-01-02"
  4605. loc, _ := time.LoadLocation("Local")
  4606. var startTime int64
  4607. if len(start_time) > 0 {
  4608. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4609. if err != nil {
  4610. //fmt.Println(err)
  4611. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4612. return
  4613. }
  4614. startTime = theTime.Unix()
  4615. }
  4616. var endTime int64
  4617. if len(end_time) > 0 {
  4618. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4619. if err != nil {
  4620. utils.ErrorLog(err.Error())
  4621. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4622. return
  4623. }
  4624. endTime = theTime.Unix()
  4625. }
  4626. adminUser := c.GetAdminUserInfo()
  4627. org_id := adminUser.CurrentOrgId
  4628. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  4629. for _, item := range order {
  4630. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  4631. item.DoctorName = info.Doctor
  4632. item.DepartmentName = info.XtHisDepartment.Name
  4633. }
  4634. if err == nil {
  4635. c.ServeSuccessJSON(map[string]interface{}{
  4636. "order": order,
  4637. "total": total,
  4638. })
  4639. } else {
  4640. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4641. return
  4642. }
  4643. }
  4644. func (c *HisApiController) GetHisOrder() {
  4645. patient_id, _ := c.GetInt64("patient_id", 0)
  4646. number := c.GetString("number")
  4647. adminInfo := c.GetAdminUserInfo()
  4648. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  4649. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  4650. if err == nil {
  4651. c.ServeSuccessJSON(map[string]interface{}{
  4652. "order": order,
  4653. "prescription": prescriptions,
  4654. })
  4655. } else {
  4656. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4657. return
  4658. }
  4659. }
  4660. func (c *HisApiController) GetHisPrescriptionList() {
  4661. record_date := c.GetString("record_date")
  4662. keywords := c.GetString("keywords")
  4663. page, _ := c.GetInt64("page")
  4664. limit, _ := c.GetInt64("limit")
  4665. sch_type, _ := c.GetInt64("sch_type")
  4666. timeLayout := "2006-01-02"
  4667. loc, _ := time.LoadLocation("Local")
  4668. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4669. if err != nil {
  4670. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4671. return
  4672. }
  4673. recordDateTime := theTime.Unix()
  4674. adminInfo := c.GetAdminUserInfo()
  4675. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  4676. //adminInfo := c.GetAdminUserInfo()
  4677. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  4678. //fmt.Println(prescriptionOrder)
  4679. if err == nil {
  4680. c.ServeSuccessJSON(map[string]interface{}{
  4681. "order": prescriptionOrder,
  4682. "total": total,
  4683. })
  4684. } else {
  4685. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4686. return
  4687. }
  4688. }
  4689. func (c *HisApiController) GetHisPrescriptionInfo() {
  4690. id, _ := c.GetInt64("id")
  4691. adminInfo := c.GetAdminUserInfo()
  4692. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  4693. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  4694. if err == nil {
  4695. c.ServeSuccessJSON(map[string]interface{}{
  4696. "order": prescriptionOrder,
  4697. "prescription": prescription,
  4698. })
  4699. } else {
  4700. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4701. return
  4702. }
  4703. }
  4704. func (c *HisApiController) GetMedicalInsuranceConfig() {
  4705. adminUser := c.GetAdminUserInfo()
  4706. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  4707. c.ServeSuccessJSON(map[string]interface{}{
  4708. "config": config,
  4709. })
  4710. }
  4711. type ResultTwo struct {
  4712. ErrMsg interface{} `json:"err_msg"`
  4713. InfRefmsgid string `json:"inf_refmsgid"`
  4714. Infcode int64 `json:"infcode"`
  4715. Output struct {
  4716. Baseinfo struct {
  4717. Age float64 `json:"age"`
  4718. Brdy string `json:"brdy"`
  4719. Certno string `json:"certno"`
  4720. Gend string `json:"gend"`
  4721. Naty string `json:"naty"`
  4722. PsnCertType string `json:"psn_cert_type"`
  4723. PsnName string `json:"psn_name"`
  4724. PsnNo string `json:"psn_no"`
  4725. } `json:"baseinfo"`
  4726. Idetinfo []interface{} `json:"idetinfo"`
  4727. Iinfo []struct {
  4728. Balc float64 `json:"balc"`
  4729. CvlservFlag string `json:"cvlserv_flag"`
  4730. EmpName string `json:"emp_name"`
  4731. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  4732. Insutype string `json:"insutype"`
  4733. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  4734. PausInsuDate interface{} `json:"paus_insu_date"`
  4735. PsnInsuDate string `json:"psn_insu_date"`
  4736. PsnInsuStas string `json:"psn_insu_stas"`
  4737. PsnType string `json:"psn_type"`
  4738. } `json:"insuinfo"`
  4739. } `json:"output"`
  4740. RefmsgTime string `json:"refmsg_time"`
  4741. RespondTime string `json:"respond_time"`
  4742. Signtype interface{} `json:"signtype"`
  4743. WarnInfo interface{} `json:"warn_info"`
  4744. }
  4745. type ResultThree struct {
  4746. Cainfo interface{} `json:"cainfo"`
  4747. ErrMsg interface{} `json:"err_msg"`
  4748. InfRefmsgid string `json:"inf_refmsgid"`
  4749. Infcode int64 `json:"infcode"`
  4750. Output struct {
  4751. Data struct {
  4752. IptOtpNo string `json:"ipt_otp_no"`
  4753. MdtrtID string `json:"mdtrt_id"`
  4754. PsnNo string `json:"psn_no"`
  4755. } `json:"data"`
  4756. } `json:"output"`
  4757. RefmsgTime string `json:"refmsg_time"`
  4758. RespondTime string `json:"respond_time"`
  4759. Signtype interface{} `json:"signtype"`
  4760. WarnMsg interface{} `json:"warn_msg"`
  4761. }
  4762. type ResultFour struct {
  4763. Cainfo string `json:"cainfo"`
  4764. ErrMsg string `json:"err_msg"`
  4765. InfRefmsgid string `json:"inf_refmsgid"`
  4766. Infcode int64 `json:"infcode"`
  4767. Output struct {
  4768. Result []struct {
  4769. BasMednFlag string `json:"bas_medn_flag"`
  4770. ChldMedcFlag string `json:"chld_medc_flag"`
  4771. ChrgitmLv string `json:"chrgitm_lv"`
  4772. Cnt float64 `json:"cnt"`
  4773. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  4774. DrtReimFlag string `json:"drt_reim_flag"`
  4775. FeedetlSn string `json:"feedetl_sn"`
  4776. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4777. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  4778. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4779. ListSpItemFlag string `json:"list_sp_item_flag"`
  4780. LmtUsedFlag string `json:"lmt_used_flag"`
  4781. MedChrgitmType string `json:"med_chrgitm_type"`
  4782. Memo string `json:"memo"`
  4783. OverlmtAmt float64 `json:"overlmt_amt"`
  4784. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4785. Pric float64 `json:"pric"`
  4786. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  4787. SelfpayProp float64 `json:"selfpay_prop"`
  4788. } `json:"result"`
  4789. } `json:"output"`
  4790. RefmsgTime string `json:"refmsg_time"`
  4791. RespondTime string `json:"respond_time"`
  4792. Signtype string `json:"signtype"`
  4793. WarnMsg string `json:"warn_msg"`
  4794. }
  4795. type ResultFive struct {
  4796. Insutype string `json:"insutype"`
  4797. }
  4798. type ResultSix struct {
  4799. Cainfo interface{} `json:"cainfo"`
  4800. ErrMsg interface{} `json:"err_msg"`
  4801. InfRefmsgid string `json:"inf_refmsgid"`
  4802. Infcode int64 `json:"infcode"`
  4803. Output struct {
  4804. } `json:"output"`
  4805. RefmsgTime string `json:"refmsg_time"`
  4806. RespondTime string `json:"respond_time"`
  4807. Signtype interface{} `json:"signtype"`
  4808. WarnMsg interface{} `json:"warn_msg"`
  4809. }
  4810. type ResultSeven struct {
  4811. Cainfo string `json:"cainfo"`
  4812. ErrMsg string `json:"err_msg"`
  4813. InfRefmsgid string `json:"inf_refmsgid"`
  4814. Infcode int64 `json:"infcode"`
  4815. Output struct {
  4816. Setldetail []interface{} `json:"setldetail"`
  4817. Setlinfo struct {
  4818. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4819. AcctPay float64 `json:"acct_pay"`
  4820. ActPayDedc float64 `json:"act_pay_dedc"`
  4821. Age float64 `json:"age"`
  4822. Balc float64 `json:"balc"`
  4823. Brdy string `json:"brdy"`
  4824. Certno string `json:"certno"`
  4825. ClrOptins string `json:"clr_optins"`
  4826. ClrType string `json:"clr_type"`
  4827. ClrWay string `json:"clr_way"`
  4828. CvlservFlag string `json:"cvlserv_flag"`
  4829. CvlservPay float64 `json:"cvlserv_pay"`
  4830. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4831. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4832. Gend string `json:"gend"`
  4833. HifesPay float64 `json:"hifes_pay"`
  4834. HifmiPay float64 `json:"hifmi_pay"`
  4835. HifobPay float64 `json:"hifob_pay"`
  4836. HifpPay float64 `json:"hifp_pay"`
  4837. HospPartAmt float64 `json:"hosp_part_amt"`
  4838. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4839. Insutype string `json:"insutype"`
  4840. MafPay float64 `json:"maf_pay"`
  4841. MdtrtCertType string `json:"mdtrt_cert_type"`
  4842. MdtrtID string `json:"mdtrt_id"`
  4843. MedType string `json:"med_type"`
  4844. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4845. MedinsSetlID string `json:"medins_setl_id"`
  4846. Naty string `json:"naty"`
  4847. OthPay float64 `json:"oth_pay"`
  4848. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4849. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4850. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4851. PsnCashPay float64 `json:"psn_cash_pay"`
  4852. PsnCertType string `json:"psn_cert_type"`
  4853. PsnName string `json:"psn_name"`
  4854. PsnNo string `json:"psn_no"`
  4855. PsnPartAmt float64 `json:"psn_part_amt"`
  4856. PsnType string `json:"psn_type"`
  4857. SetlID string `json:"setl_id"`
  4858. SetlTime string `json:"setl_time"`
  4859. } `json:"setlinfo"`
  4860. } `json:"output"`
  4861. RefmsgTime string `json:"refmsg_time"`
  4862. RespondTime string `json:"respond_time"`
  4863. Signtype interface{} `json:"signtype"`
  4864. WarnMsg interface{} `json:"warn_msg"`
  4865. }
  4866. type ResultEight struct {
  4867. Cainfo string `json:"cainfo"`
  4868. ErrMsg string `json:"err_msg"`
  4869. InfRefmsgid string `json:"inf_refmsgid"`
  4870. Infcode int64 `json:"infcode"`
  4871. Output struct {
  4872. Stmtinfo struct {
  4873. SetlOptins string `json:"setl_optins"`
  4874. StmtRslt string `json:"stmt_rslt"`
  4875. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  4876. } `json:"stmtinfo"`
  4877. } `json:"output"`
  4878. RefmsgTime string `json:"refmsg_time"`
  4879. RespondTime string `json:"respond_time"`
  4880. Signtype interface{} `json:"signtype"`
  4881. WarnMsg interface{} `json:"warn_msg"`
  4882. }
  4883. type ResultNine struct {
  4884. Cainfo string `json:"cainfo"`
  4885. ErrMsg string `json:"err_msg"`
  4886. InfRefmsgid string `json:"inf_refmsgid"`
  4887. Infcode int64 `json:"infcode"`
  4888. Output struct {
  4889. FileQuryNo string `json:"file_qury_no"`
  4890. } `json:"output"`
  4891. RefmsgTime string `json:"refmsg_time"`
  4892. RespondTime string `json:"respond_time"`
  4893. Signtype interface{} `json:"signtype"`
  4894. WarnMsg interface{} `json:"warn_msg"`
  4895. }
  4896. type ResultTen struct {
  4897. Cainfo string `json:"cainfo"`
  4898. ErrMsg string `json:"err_msg"`
  4899. InfRefmsgid string `json:"inf_refmsgid"`
  4900. Infcode int64 `json:"infcode"`
  4901. Output struct {
  4902. DldEndtime string `json:"dld_endtime"`
  4903. FileQuryNo string `json:"file_qury_no"`
  4904. Filename string `json:"filename"`
  4905. } `json:"output"`
  4906. RefmsgTime string `json:"refmsg_time"`
  4907. RespondTime string `json:"respond_time"`
  4908. Signtype interface{} `json:"signtype"`
  4909. WarnMsg interface{} `json:"warn_msg"`
  4910. }
  4911. type ResultEleven struct {
  4912. Cainfo string `json:"cainfo"`
  4913. ErrMsg string `json:"err_msg"`
  4914. InfRefmsgid string `json:"inf_refmsgid"`
  4915. Infcode int64 `json:"infcode"`
  4916. Output struct {
  4917. Setlinfo struct {
  4918. FixmedinsName string `json:"fixmedins_name"`
  4919. FixmedinsCode string `json:"fixmedins_code"`
  4920. PsnNo string `json:"psn_no"`
  4921. PsnName string `json:"psn_name"`
  4922. HifobPay float64 `json:"hifob_pay"`
  4923. Gend string `json:"gend"`
  4924. Brdy string `json:"brdy"`
  4925. PsnCertType string `json:"psn_cert_type"`
  4926. PsnType string `json:"psn_type"`
  4927. EmpName string `json:"emp_name"`
  4928. Certno string `json:"certno"`
  4929. Insutype string `json:"insutype"`
  4930. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4931. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4932. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4933. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4934. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4935. ActPayDedc float64 `json:"act_pay_dedc"`
  4936. HifpPay float64 `json:"hifp_pay"`
  4937. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4938. CvlservPay float64 `json:"cvlserv_pay"`
  4939. HifesPay float64 `json:"hifes_pay"`
  4940. HifmiPay float64 `json:"hifmi_pay"`
  4941. MafPay float64 `json:"maf_pay"`
  4942. OthPay float64 `json:"oth_pay"`
  4943. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4944. PsnPay float64 `json:"psn_pay"`
  4945. AcctPay float64 `json:"acct_pay"`
  4946. CashPayamt float64 `json:"cash_payamt"`
  4947. Balc float64 `json:"balc"`
  4948. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4949. MedinsSetlId string `json:"medins_setl_id"`
  4950. RefdSetlFlag string `json:"refd_setl_flag"`
  4951. SetlTime string `json:"setl_time"`
  4952. MedType string `json:"med_type"`
  4953. } `json:"setlinfo"`
  4954. } `json:"output"`
  4955. RefmsgTime string `json:"refmsg_time"`
  4956. RespondTime string `json:"respond_time"`
  4957. Signtype interface{} `json:"signtype"`
  4958. WarnMsg interface{} `json:"warn_msg"`
  4959. }
  4960. type Custom struct {
  4961. DetItemFeeSumamt string
  4962. Cut string
  4963. FeedetlSn string
  4964. Price string
  4965. MedListCodg string
  4966. Type int64
  4967. AdviceId int64
  4968. ProjectId int64
  4969. ItemId int64
  4970. }
  4971. // 获取个人信息----挂号-----上传就诊信息
  4972. func (c *HisApiController) GetRegisterInfo() {
  4973. id, _ := c.GetInt64("id")
  4974. record_time := c.GetString("record_time")
  4975. settlementValue, _ := c.GetInt64("settlement_value")
  4976. medical_insurance_card := c.GetString("medical_insurance_card")
  4977. name := c.GetString("name")
  4978. id_card_type, _ := c.GetInt64("id_card_type")
  4979. certificates, _ := c.GetInt64("certificates")
  4980. medical_care, _ := c.GetInt64("medical_care")
  4981. birthday := c.GetString("birthday")
  4982. age, _ := c.GetInt64("age")
  4983. id_card := c.GetString("id_card")
  4984. register_type, _ := c.GetInt64("register")
  4985. doctor, _ := c.GetInt64("doctor")
  4986. department, _ := c.GetInt64("department")
  4987. gender, _ := c.GetInt64("sex")
  4988. phone := c.GetString("phone")
  4989. registration_fee, _ := c.GetFloat("registration_fee")
  4990. medical_expenses, _ := c.GetFloat("medical_expenses")
  4991. social_type, _ := c.GetInt64("social_type")
  4992. //diagnosis_id, _ := c.GetInt64("diagnosis")
  4993. diagnosis_ids := c.GetString("diagnosis")
  4994. sick_type, _ := c.GetInt64("sick_type")
  4995. reg_type := c.GetString("p_type")
  4996. timeLayout := "2006-01-02"
  4997. loc, _ := time.LoadLocation("Local")
  4998. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  4999. birthUnix := birthdays.Unix()
  5000. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5001. if err != nil {
  5002. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5003. return
  5004. }
  5005. recordDateTime := theTime.Unix()
  5006. adminInfo := c.GetAdminUserInfo()
  5007. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  5008. if tempPatient.ID == 0 {
  5009. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  5010. return
  5011. }
  5012. var patient service.Patients
  5013. if id == 0 {
  5014. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  5015. } else {
  5016. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  5017. }
  5018. if patient.ID == 0 {
  5019. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  5020. return
  5021. }
  5022. if len(patient.IdCardNo) == 0 {
  5023. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  5024. return
  5025. }
  5026. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5027. if len(his) >= 1 {
  5028. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  5029. if len(his) >= 1 && order.ID == 0 {
  5030. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  5031. return
  5032. }
  5033. }
  5034. timeStr := time.Now().Format("2006-01-02 15:04:05")
  5035. fmt.Println(timeStr)
  5036. timeArr := strings.Split(timeStr, " ")
  5037. fmt.Println(timeArr)
  5038. timeArrTwo := strings.Split(timeArr[0], "-")
  5039. timeArrThree := strings.Split(timeArr[1], ":")
  5040. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  5041. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  5042. if len(lists) == 0 {
  5043. var hisPatient models.XtHisPatient
  5044. hisPatient = models.XtHisPatient{
  5045. Name: name,
  5046. Age: age,
  5047. Gender: gender,
  5048. Birthday: birthUnix,
  5049. Phone: phone,
  5050. MedicalTreatmentType: medical_care,
  5051. IdType: certificates,
  5052. IdCardNo: id_card,
  5053. BalanceAccountsType: settlementValue,
  5054. SocialType: social_type,
  5055. MedicalInsuranceNumber: medical_insurance_card,
  5056. RegisterType: register_type,
  5057. RegisterCost: registration_fee,
  5058. TreatmentCost: medical_expenses,
  5059. AdminUserId: adminInfo.AdminUser.Id,
  5060. UserOrgId: adminInfo.CurrentOrgId,
  5061. Status: 1,
  5062. RecordDate: recordDateTime,
  5063. IsReturn: 1,
  5064. PatientId: patient.ID,
  5065. Ctime: time.Now().Unix(),
  5066. Mtime: time.Now().Unix(),
  5067. Number: str,
  5068. IdCardType: id_card_type,
  5069. Departments: department,
  5070. Doctor: doctor,
  5071. PType: reg_type,
  5072. Diagnosis: diagnosis_ids,
  5073. SickType: sick_type,
  5074. }
  5075. service.CreateHisPatient(&hisPatient)
  5076. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5077. c.ServeSuccessJSON(map[string]interface{}{
  5078. "his_info": hisPatient,
  5079. })
  5080. } else {
  5081. //chrgBchno := rand.Intn(1000000) + 10000
  5082. var hisPatient models.XtHisPatient
  5083. hisPatient = models.XtHisPatient{
  5084. Name: name,
  5085. Age: age,
  5086. Gender: gender,
  5087. Birthday: birthUnix,
  5088. Phone: phone,
  5089. MedicalTreatmentType: medical_care,
  5090. IdType: certificates,
  5091. IdCardNo: id_card,
  5092. BalanceAccountsType: settlementValue,
  5093. SocialType: social_type,
  5094. MedicalInsuranceNumber: medical_insurance_card,
  5095. RegisterType: register_type,
  5096. RegisterCost: registration_fee,
  5097. TreatmentCost: medical_expenses,
  5098. AdminUserId: adminInfo.AdminUser.Id,
  5099. UserOrgId: adminInfo.CurrentOrgId,
  5100. Status: 1,
  5101. RecordDate: recordDateTime,
  5102. IsReturn: 1,
  5103. PatientId: patient.ID,
  5104. Ctime: time.Now().Unix(),
  5105. Mtime: time.Now().Unix(),
  5106. Number: str,
  5107. IdCardType: id_card_type,
  5108. Departments: department,
  5109. Doctor: doctor,
  5110. PType: reg_type,
  5111. Diagnosis: diagnosis_ids,
  5112. SickType: sick_type,
  5113. }
  5114. service.CreateHisPatient(&hisPatient)
  5115. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  5116. c.ServeSuccessJSON(map[string]interface{}{
  5117. "his_info": hisPatient,
  5118. })
  5119. }
  5120. }
  5121. // 上传明细----结算
  5122. func (c *HisApiController) GetUploadInfo() {
  5123. id, _ := c.GetInt64("id")
  5124. record_time := c.GetString("record_time")
  5125. his_patient_id, _ := c.GetInt64("his_patient_id")
  5126. pay_way, _ := c.GetInt64("pay_way")
  5127. pay_price, _ := c.GetFloat("pay_price")
  5128. pay_card_no := c.GetString("pay_card_no")
  5129. discount_price, _ := c.GetFloat("discount_price")
  5130. preferential_price, _ := c.GetFloat("preferential_price")
  5131. reality_price, _ := c.GetFloat("reality_price")
  5132. found_price, _ := c.GetFloat("found_price")
  5133. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  5134. private_price, _ := c.GetFloat("private_price")
  5135. timeLayout := "2006-01-02"
  5136. loc, _ := time.LoadLocation("Local")
  5137. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5138. fapiao_code := c.GetString("fapiao_code")
  5139. fapiao_number := c.GetString("fapiao_number")
  5140. diagnosis_id := c.GetString("diagnosis")
  5141. sick_type, _ := c.GetInt64("sick_type")
  5142. reg_type, _ := c.GetInt64("p_type")
  5143. order_id, _ := c.GetInt64("order_id")
  5144. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  5145. tmp_decimal := c.GetString("tmp_decimal")
  5146. var decimal float64 //本次使用的押金
  5147. var errmsg error
  5148. tx := service.XTWriteDB().Begin() //开了事务
  5149. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  5150. defer func() {
  5151. if errmsg != nil {
  5152. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  5153. tx.Rollback()
  5154. } else {
  5155. tx.Commit()
  5156. }
  5157. }()
  5158. fmt.Println("dec_way", dec_way)
  5159. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  5160. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  5161. return
  5162. }
  5163. if len(tmp_decimal) > 0 {
  5164. if tmp_decimal[0] == 45 {
  5165. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  5166. return
  5167. }
  5168. }
  5169. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  5170. fmt.Println(errs)
  5171. //if errs != nil {
  5172. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  5173. // return
  5174. //}
  5175. decimal = tt
  5176. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  5177. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  5178. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5179. if err != nil {
  5180. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5181. return
  5182. }
  5183. recordDateTime := theTime.Unix()
  5184. adminUser := c.GetAdminUserInfo()
  5185. var prescriptions []*models.HisPrescription
  5186. var prescriptionsOne []*models.HisPrescription
  5187. var start_time int64
  5188. var end_time int64
  5189. ids_str := c.GetString("ids")
  5190. ids_arr := strings.Split(ids_str, ",")
  5191. if tempOrder.ID == 0 {
  5192. if settle_accounts_type == 1 { //日结
  5193. fmt.Println(reg_type)
  5194. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5195. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  5196. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  5197. } else {
  5198. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5199. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5200. }
  5201. } else { //月结
  5202. start_time_str := c.GetString("start_time")
  5203. end_time_str := c.GetString("end_time")
  5204. timeLayout := "2006-01-02"
  5205. loc, _ := time.LoadLocation("Local")
  5206. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5207. if err != nil {
  5208. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5209. return
  5210. }
  5211. recordStartTime := theStartTime.Unix()
  5212. start_time = recordStartTime
  5213. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5214. if err != nil {
  5215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5216. return
  5217. }
  5218. recordEndTime := theEndTime.Unix()
  5219. end_time = recordEndTime
  5220. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  5221. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  5222. }
  5223. var goods []*models.DialysisBeforePrepareGoods
  5224. var newGoods []*models.NewDialysisBeforePrepareGoods
  5225. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5226. var infos []*models.HisDoctorAdviceInfo
  5227. var infoList []*models.HisDoctorAdviceInfo
  5228. var hisAdvice []*models.HisDoctorAdviceInfo
  5229. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5230. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5231. //判断库存不足
  5232. //结算出库开关
  5233. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5234. if settConfig.IsOpen == 1 {
  5235. //判断库存的地方
  5236. for _, info := range prescriptions {
  5237. if info.Type == 1 {
  5238. infos = append(infos, info.HisDoctorAdviceInfo...)
  5239. }
  5240. if info.Type == 2 {
  5241. for _, sumItem := range info.HisPrescriptionProject {
  5242. if sumItem.Type == 3 {
  5243. var good models.DialysisBeforePrepareGoods
  5244. var newGood models.NewDialysisBeforePrepareGoods
  5245. good.GoodId = sumItem.GoodInfo.ID
  5246. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5247. count, _ := strconv.Atoi(sumItem.Count)
  5248. good.Count = int64(count)
  5249. good.StorehouseId = houseConfig.StorehouseOutInfo
  5250. good.ProjectId = sumItem.ID
  5251. goods = append(goods, &good)
  5252. newGood.GoodId = sumItem.GoodInfo.ID
  5253. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5254. count2, _ := strconv.Atoi(sumItem.Count)
  5255. newGood.Count = int64(count2)
  5256. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5257. newGood.ProjectId = sumItem.ID
  5258. newGoods = append(newGoods, &newGood)
  5259. }
  5260. }
  5261. }
  5262. }
  5263. for _, info := range prescriptionsOne {
  5264. if info.Type == 1 {
  5265. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5266. }
  5267. if info.Type == 2 {
  5268. for _, sumItem := range info.HisPrescriptionProject {
  5269. if sumItem.Type == 3 {
  5270. var newGood models.NewDialysisBeforePrepareGoods
  5271. newGood.GoodId = sumItem.GoodInfo.ID
  5272. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5273. count2, _ := strconv.Atoi(sumItem.Count)
  5274. newGood.Count = int64(count2)
  5275. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5276. newGood.ProjectId = sumItem.ID
  5277. newGoodOne = append(newGoodOne, &newGood)
  5278. }
  5279. }
  5280. }
  5281. }
  5282. //判断
  5283. for _, itemOne := range infos {
  5284. for _, itemTwo := range hisAdvice {
  5285. if itemOne.DrugId == itemTwo.DrugId {
  5286. itemTwo.Child = append(itemTwo.Child, itemOne)
  5287. }
  5288. }
  5289. }
  5290. for _, itemTwo := range hisAdvice {
  5291. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5292. var sum_out_count int64
  5293. for _, itemThree := range itemTwo.Child {
  5294. var prescribing_number int64
  5295. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5296. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5297. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5298. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5299. }
  5300. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5301. prescribing_number = parseIntPrescribingNumber
  5302. }
  5303. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5304. prescribing_number = parseIntPrescribingNumber
  5305. }
  5306. sum_out_count += prescribing_number
  5307. }
  5308. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5309. fmt.Println("sum_out_count233232323232wo", sum_out_count)
  5310. fmt.Println("drugStockOut.FlushCount", drugStockOut.FlushCount)
  5311. if sum_out_count > drugStockOut.FlushCount {
  5312. c.ServeSuccessJSON(map[string]interface{}{
  5313. "msg": "2",
  5314. "drug": medical,
  5315. })
  5316. return
  5317. }
  5318. }
  5319. fmt.Println("newGoods99999988882os", newGoods)
  5320. for _, itemOne := range newGoods {
  5321. for _, item := range newGoodOne {
  5322. if itemOne.GoodId == item.GoodId {
  5323. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  5324. }
  5325. }
  5326. }
  5327. for _, item := range newGoodOne {
  5328. var sum_out_count_one int64
  5329. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5330. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5331. sum_out_count_one += itemOne.Count
  5332. }
  5333. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5334. fmt.Println("sum_out_count_one", sum_out_count_one)
  5335. fmt.Println("list.FlushCount", list.FlushCount)
  5336. if sum_out_count_one > list.FlushCount {
  5337. c.ServeSuccessJSON(map[string]interface{}{
  5338. "msg": "3",
  5339. "good": good,
  5340. })
  5341. return
  5342. }
  5343. }
  5344. }
  5345. timestamp := time.Now().Unix()
  5346. tempTime := time.Unix(timestamp, 0)
  5347. timeFormat := tempTime.Format("20060102150405")
  5348. chrgBchno := rand.Intn(100000) + 10000
  5349. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5350. strconv.FormatInt(his.PatientId, 10)
  5351. var ids []int64
  5352. for _, item := range prescriptions {
  5353. ids = append(ids, item.ID)
  5354. }
  5355. var total float64
  5356. for _, item := range prescriptions {
  5357. fmt.Println(item)
  5358. if item.Type == 1 { //药品
  5359. for _, subItem := range item.HisDoctorAdviceInfo {
  5360. total = total + (subItem.Price * subItem.PrescribingNumber)
  5361. }
  5362. }
  5363. if item.Type == 2 { //项目
  5364. for _, subItem := range item.HisPrescriptionProject {
  5365. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5366. total = total + (subItem.Price * cnt)
  5367. }
  5368. }
  5369. for _, subItem := range item.HisAdditionalCharge {
  5370. total = total + (subItem.Price * float64(subItem.Count))
  5371. }
  5372. }
  5373. if reg_type == 1111 || reg_type == 1112 {
  5374. reg_type = 11
  5375. }
  5376. tm := time.Unix(time.Now().Unix(), 0)
  5377. allTotal := fmt.Sprintf("%.4f", total)
  5378. totals, _ := strconv.ParseFloat(allTotal, 64)
  5379. order := &models.HisOrder{
  5380. UserOrgId: adminUser.CurrentOrgId,
  5381. HisPatientId: his.ID,
  5382. PatientId: id,
  5383. SettleAccountsDate: recordDateTime,
  5384. Ctime: time.Now().Unix(),
  5385. Mtime: time.Now().Unix(),
  5386. Status: 1,
  5387. OrderStatus: 2,
  5388. MdtrtId: his.Number,
  5389. Number: chrg_bchno,
  5390. MedfeeSumamt: totals,
  5391. PayWay: pay_way,
  5392. PayPrice: pay_price,
  5393. MedType: strconv.Itoa(int(reg_type)),
  5394. PayCardNo: pay_card_no,
  5395. DiscountPrice: discount_price,
  5396. PreferentialPrice: preferential_price,
  5397. RealityPrice: reality_price,
  5398. FoundPrice: found_price,
  5399. MedicalInsurancePrice: medical_insurance_price,
  5400. PrivatePrice: private_price,
  5401. SettleEndTime: end_time,
  5402. SettleStartTime: start_time,
  5403. PsnPartAmt: totals,
  5404. PsnCashPay: totals,
  5405. SettleType: settle_accounts_type,
  5406. FaPiaoCode: fapiao_code,
  5407. FaPiaoNumber: fapiao_number,
  5408. Diagnosis: diagnosis_id,
  5409. PType: 2,
  5410. SetlTime: tm.Format("2006-01-02 15:04:05"),
  5411. Decimal: decimal,
  5412. }
  5413. err = service.CreateOrderTX(order, tx)
  5414. if err != nil {
  5415. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5416. return
  5417. }
  5418. var customs []*Custom
  5419. for _, item := range prescriptions {
  5420. if item.Type == 1 { //药品a
  5421. for _, subItem := range item.HisDoctorAdviceInfo {
  5422. cus := &Custom{
  5423. AdviceId: subItem.ID,
  5424. ProjectId: 0,
  5425. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  5426. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  5427. FeedetlSn: subItem.FeedetlSn,
  5428. Price: fmt.Sprintf("%.4f", subItem.Price),
  5429. MedListCodg: subItem.MedListCodg,
  5430. Type: 1,
  5431. }
  5432. customs = append(customs, cus)
  5433. }
  5434. }
  5435. if item.Type == 2 { //项目
  5436. for _, subItem := range item.HisPrescriptionProject {
  5437. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5438. cus := &Custom{
  5439. AdviceId: 0,
  5440. ProjectId: subItem.ID,
  5441. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  5442. Cut: fmt.Sprintf("%.4f", cnt),
  5443. FeedetlSn: subItem.FeedetlSn,
  5444. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  5445. MedListCodg: subItem.MedListCodg,
  5446. Type: 2,
  5447. }
  5448. customs = append(customs, cus)
  5449. }
  5450. }
  5451. for _, item := range item.HisAdditionalCharge {
  5452. cus := &Custom{
  5453. ItemId: item.ID,
  5454. AdviceId: 0,
  5455. ProjectId: 0,
  5456. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  5457. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  5458. FeedetlSn: item.FeedetlSn,
  5459. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  5460. MedListCodg: item.XtHisAddtionConfig.Code,
  5461. Type: 3,
  5462. }
  5463. customs = append(customs, cus)
  5464. }
  5465. }
  5466. for _, item := range customs {
  5467. var advice_id int64 = 0
  5468. var project_id int64 = 0
  5469. var item_id int64 = 0
  5470. var types int64 = 0
  5471. if item.Type == 1 {
  5472. advice_id = item.AdviceId
  5473. project_id = 0
  5474. item_id = 0
  5475. } else if item.Type == 2 {
  5476. advice_id = 0
  5477. item_id = 0
  5478. project_id = item.ProjectId
  5479. } else if item.Type == 3 {
  5480. advice_id = 0
  5481. item_id = item.ItemId
  5482. project_id = 0
  5483. }
  5484. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5485. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5486. pric, _ := strconv.ParseFloat(item.Price, 32)
  5487. info := &models.HisOrderInfo{
  5488. OrderNumber: order.Number,
  5489. UploadDate: time.Now().Unix(),
  5490. AdviceId: advice_id,
  5491. DetItemFeeSumamt: detItemFeeSumamt,
  5492. Cnt: cut,
  5493. Pric: pric,
  5494. PatientId: id,
  5495. Status: 1,
  5496. Mtime: time.Now().Unix(),
  5497. Ctime: time.Now().Unix(),
  5498. UserOrgId: adminUser.CurrentOrgId,
  5499. HisPatientId: his.ID,
  5500. OrderId: order.ID,
  5501. ProjectId: project_id,
  5502. Type: types,
  5503. ItemId: item_id,
  5504. }
  5505. service.CreateOrderInfoTX(info, tx)
  5506. }
  5507. his.Diagnosis = diagnosis_id
  5508. his.SickType = sick_type
  5509. his.RegisterType = reg_type
  5510. his.MedicalTreatmentType = reg_type
  5511. service.UpdataHisPateintTX(&his, tx)
  5512. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  5513. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  5514. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  5515. //判断是否使用了押金
  5516. if dec_way == "true" {
  5517. tmpstring := strconv.FormatInt(order.ID, 10)
  5518. //扣押金
  5519. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  5520. order.Decimal = decimal
  5521. service.UpDateOrderTwo(order)
  5522. if errmsg != nil {
  5523. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  5524. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5525. return
  5526. }
  5527. }
  5528. if err == nil {
  5529. for _, info := range prescriptions {
  5530. if info.Type == 1 {
  5531. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  5532. }
  5533. if info.Type == 2 {
  5534. for _, sumItem := range info.HisPrescriptionProject {
  5535. if sumItem.Type == 3 {
  5536. var good models.DialysisBeforePrepareGoods
  5537. var newGood models.NewDialysisBeforePrepareGoods
  5538. var oldGood models.OldDialysisBeforePrepareGoods
  5539. good.GoodId = sumItem.GoodInfo.ID
  5540. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5541. count, _ := strconv.Atoi(sumItem.Count)
  5542. good.Count = int64(count)
  5543. good.StorehouseId = houseConfig.StorehouseOutInfo
  5544. good.ProjectId = sumItem.ID
  5545. good.PatientId = sumItem.PatientId
  5546. goods = append(goods, &good)
  5547. newGood.GoodId = sumItem.GoodInfo.ID
  5548. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5549. count2, _ := strconv.Atoi(sumItem.Count)
  5550. newGood.Count = int64(count2)
  5551. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5552. newGood.ProjectId = sumItem.ID
  5553. newGood.PatientId = sumItem.HisPatientId
  5554. newGoods = append(newGoods, &newGood)
  5555. oldGood.GoodId = sumItem.GoodInfo.ID
  5556. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5557. count3, _ := strconv.Atoi(sumItem.Count)
  5558. oldGood.Count = int64(count3)
  5559. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5560. oldGood.ProjectId = sumItem.ID
  5561. oldGood.RecordDate = sumItem.RecordDate
  5562. oldGood.PatientId = sumItem.HisPatientId
  5563. oldGoods = append(oldGoods, &oldGood)
  5564. }
  5565. }
  5566. }
  5567. }
  5568. if settConfig.IsOpen == 1 {
  5569. for _, item := range infoList {
  5570. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  5571. if medical.IsUse == 2 {
  5572. //药品出库
  5573. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  5574. //查询默认仓库
  5575. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  5576. //查询默认仓库剩余多少库存
  5577. var sum_count int64
  5578. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  5579. for _, its := range stockInfo {
  5580. if its.MaxUnit == medical.MaxUnit {
  5581. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  5582. }
  5583. sum_count += its.StockMaxNumber + its.StockMinNumber
  5584. }
  5585. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  5586. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  5587. }
  5588. }
  5589. orgId := c.GetAdminUserInfo().CurrentOrgId
  5590. if len(oldGoods) > 0 {
  5591. timeStr := time.Now().Format("2006-01-02")
  5592. timeArr := strings.Split(timeStr, "-")
  5593. total, _ := service.FindAllWarehouseOut(orgId)
  5594. total = total + 1
  5595. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  5596. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  5597. number = number + total
  5598. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  5599. operation_time := time.Now().Unix()
  5600. creater := c.GetAdminUserInfo().AdminUser.Id
  5601. //查询默认出库仓库库存
  5602. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  5603. recordDateStr := time.Now().Format("2006-01-02")
  5604. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  5605. nowtime := recordDate.Unix()
  5606. warehouseOut := models.WarehouseOut{
  5607. WarehouseOutOrderNumber: warehousing_out_order,
  5608. OperationTime: operation_time,
  5609. OrgId: orgId,
  5610. Creater: creater,
  5611. Ctime: time.Now().Unix(),
  5612. Status: 1,
  5613. WarehouseOutTime: nowtime,
  5614. Type: 1,
  5615. StorehouseId: storeConfig.StorehouseOutInfo,
  5616. IsCheck: 1,
  5617. OrderId: order.ID,
  5618. IsSys: 5,
  5619. }
  5620. //查询是否生成出库单
  5621. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  5622. if out.ID == 0 {
  5623. service.AddSigleWarehouseOut(&warehouseOut)
  5624. }
  5625. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  5626. for _, item := range oldGoods {
  5627. dialyPrepareOne := models.DialysisBeforePrepare{
  5628. GoodTypeId: item.GoodTypeId,
  5629. GoodId: item.GoodId,
  5630. PatientId: his.PatientId,
  5631. RecordDate: item.RecordDate,
  5632. UserOrgId: adminUser.CurrentOrgId,
  5633. Count: item.Count,
  5634. Ctime: time.Now().Unix(),
  5635. Creater: adminUser.AdminUser.Id,
  5636. CommdityCode: item.CommdityCode,
  5637. Status: 1,
  5638. StorehouseId: houseConfig.StorehouseOutInfo,
  5639. }
  5640. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  5641. //非零用
  5642. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  5643. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  5644. //查询剩余库存
  5645. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5646. var sum_count int64
  5647. for _, item := range goodList {
  5648. sum_count += item.StockCount
  5649. }
  5650. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  5651. //耗材
  5652. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  5653. }
  5654. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  5655. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  5656. //查询剩余库存
  5657. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5658. var sum_count int64
  5659. for _, item := range goodList {
  5660. sum_count += item.StockCount
  5661. }
  5662. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  5663. //耗材
  5664. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  5665. }
  5666. }
  5667. }
  5668. }
  5669. c.ServeSuccessJSON(map[string]interface{}{
  5670. "msg": "结算成功",
  5671. })
  5672. }
  5673. } else {
  5674. if tempOrder.IsPre > 0 {
  5675. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  5676. totals, _ := strconv.ParseFloat(allTotal, 64)
  5677. tempOrder.OrderStatus = 2
  5678. tempOrder.PayWay = pay_way
  5679. tempOrder.PayPrice = pay_price
  5680. tempOrder.PayCardNo = pay_card_no
  5681. tempOrder.DiscountPrice = discount_price
  5682. tempOrder.PreferentialPrice = preferential_price
  5683. tempOrder.RealityPrice = reality_price
  5684. tempOrder.FoundPrice = found_price
  5685. tempOrder.MedicalInsurancePrice = medical_insurance_price
  5686. tempOrder.PrivatePrice = private_price
  5687. tempOrder.FaPiaoCode = fapiao_code
  5688. tempOrder.FaPiaoNumber = fapiao_number
  5689. tempOrder.PType = 2
  5690. tempOrder.MedfeeSumamt = totals
  5691. tempOrder.Diagnosis = diagnosis_id
  5692. err = service.SaveHisOrder(&tempOrder)
  5693. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  5694. if err != nil {
  5695. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5696. return
  5697. }
  5698. if err == nil {
  5699. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5700. var goods []*models.DialysisBeforePrepareGoods
  5701. var newGoods []*models.NewDialysisBeforePrepareGoods
  5702. var infos []*models.HisDoctorAdviceInfo
  5703. var hisAdvice []*models.HisDoctorAdviceInfo
  5704. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  5705. var infolist []*models.HisDoctorAdviceInfo
  5706. var oldGoods []*models.OldDialysisBeforePrepareGoods
  5707. for _, info := range prescriptions {
  5708. if info.Type == 1 {
  5709. infos = append(infos, info.HisDoctorAdviceInfo...)
  5710. }
  5711. if info.Type == 2 {
  5712. for _, sumItem := range info.HisPrescriptionProject {
  5713. if sumItem.Type == 3 {
  5714. var good models.DialysisBeforePrepareGoods
  5715. var newGood models.NewDialysisBeforePrepareGoods
  5716. good.GoodId = sumItem.GoodInfo.ID
  5717. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5718. count, _ := strconv.Atoi(sumItem.Count)
  5719. good.Count = int64(count)
  5720. good.StorehouseId = houseConfig.StorehouseOutInfo
  5721. good.ProjectId = sumItem.ID
  5722. goods = append(goods, &good)
  5723. newGood.GoodId = sumItem.GoodInfo.ID
  5724. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5725. count2, _ := strconv.Atoi(sumItem.Count)
  5726. newGood.Count = int64(count2)
  5727. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5728. newGood.ProjectId = sumItem.ID
  5729. newGoods = append(newGoods, &newGood)
  5730. }
  5731. }
  5732. }
  5733. }
  5734. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5735. if settConfig.IsOpen == 1 {
  5736. //判断库存的地方
  5737. for _, info := range prescriptions {
  5738. if info.Type == 1 {
  5739. infolist = append(infolist, info.HisDoctorAdviceInfo...)
  5740. }
  5741. if info.Type == 2 {
  5742. for _, sumItem := range info.HisPrescriptionProject {
  5743. if sumItem.Type == 3 {
  5744. var good models.DialysisBeforePrepareGoods
  5745. var newGood models.NewDialysisBeforePrepareGoods
  5746. var oldGood models.OldDialysisBeforePrepareGoods
  5747. good.GoodId = sumItem.GoodInfo.ID
  5748. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5749. count, _ := strconv.Atoi(sumItem.Count)
  5750. good.Count = int64(count)
  5751. good.StorehouseId = houseConfig.StorehouseOutInfo
  5752. good.ProjectId = sumItem.ID
  5753. goods = append(goods, &good)
  5754. newGood.GoodId = sumItem.GoodInfo.ID
  5755. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5756. count2, _ := strconv.Atoi(sumItem.Count)
  5757. newGood.Count = int64(count2)
  5758. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5759. newGood.ProjectId = sumItem.ID
  5760. newGoods = append(newGoods, &newGood)
  5761. oldGood.GoodId = sumItem.GoodInfo.ID
  5762. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5763. count3, _ := strconv.Atoi(sumItem.Count)
  5764. oldGood.Count = int64(count3)
  5765. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  5766. oldGood.ProjectId = sumItem.ID
  5767. oldGood.RecordDate = sumItem.RecordDate
  5768. oldGoods = append(oldGoods, &oldGood)
  5769. }
  5770. }
  5771. }
  5772. }
  5773. for _, info := range prescriptionsOne {
  5774. if info.Type == 1 {
  5775. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  5776. }
  5777. if info.Type == 2 {
  5778. for _, sumItem := range info.HisPrescriptionProject {
  5779. if sumItem.Type == 3 {
  5780. var newGood models.NewDialysisBeforePrepareGoods
  5781. newGood.GoodId = sumItem.GoodInfo.ID
  5782. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  5783. count2, _ := strconv.Atoi(sumItem.Count)
  5784. newGood.Count = int64(count2)
  5785. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5786. newGood.ProjectId = sumItem.ID
  5787. newGoodOne = append(newGoodOne, &newGood)
  5788. }
  5789. }
  5790. }
  5791. }
  5792. //判断
  5793. for _, itemOne := range infos {
  5794. for _, itemTwo := range hisAdvice {
  5795. if itemOne.DrugId == itemTwo.DrugId {
  5796. itemTwo.Child = append(itemTwo.ChildDoctorAdvice, itemOne)
  5797. }
  5798. }
  5799. }
  5800. for _, itemTwo := range hisAdvice {
  5801. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  5802. var sum_out_count int64
  5803. for _, itemThree := range itemTwo.Child {
  5804. var prescribing_number int64
  5805. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  5806. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  5807. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  5808. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  5809. }
  5810. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  5811. prescribing_number = parseIntPrescribingNumber
  5812. }
  5813. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  5814. prescribing_number = parseIntPrescribingNumber
  5815. }
  5816. sum_out_count += prescribing_number
  5817. }
  5818. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  5819. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  5820. if sum_out_count > drugStockOut.FlushCount {
  5821. c.ServeSuccessJSON(map[string]interface{}{
  5822. "msg": "2",
  5823. "drug": medical,
  5824. })
  5825. return
  5826. }
  5827. }
  5828. for _, itemOne := range newGoods {
  5829. for _, item := range newGoodOne {
  5830. if itemOne.ProjectId == item.ProjectId {
  5831. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, item)
  5832. }
  5833. }
  5834. }
  5835. for _, item := range newGoodOne {
  5836. var sum_out_count_one int64
  5837. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  5838. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  5839. sum_out_count_one += itemOne.Count
  5840. }
  5841. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  5842. fmt.Println("sum_out_count_one", sum_out_count_one)
  5843. fmt.Println("list.FlushCount", list.FlushCount)
  5844. if sum_out_count_one > list.FlushCount {
  5845. c.ServeSuccessJSON(map[string]interface{}{
  5846. "msg": "3",
  5847. "good": good,
  5848. })
  5849. return
  5850. }
  5851. }
  5852. for _, item := range infolist {
  5853. service.HisDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item)
  5854. }
  5855. for _, item := range oldGoods {
  5856. dialyPrepareOne := models.DialysisBeforePrepare{
  5857. GoodTypeId: item.GoodTypeId,
  5858. GoodId: item.GoodId,
  5859. PatientId: item.PatientId,
  5860. RecordDate: item.RecordDate,
  5861. UserOrgId: item.UserOrgId,
  5862. Count: item.Count,
  5863. Ctime: time.Now().Unix(),
  5864. Creater: adminUser.AdminUser.Id,
  5865. CommdityCode: item.CommdityCode,
  5866. Status: 1,
  5867. StorehouseId: houseConfig.StorehouseOutInfo,
  5868. }
  5869. err = service.CreateDialysisBeforePrepareOne(&dialyPrepareOne)
  5870. }
  5871. service.ConsumablesDeliveryTotal(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, goods, newGoods, adminUser.AdminUser.Id)
  5872. }
  5873. c.ServeSuccessJSON(map[string]interface{}{
  5874. "msg": "结算成功",
  5875. })
  5876. }
  5877. }
  5878. }
  5879. }
  5880. // 退款
  5881. func (c *HisApiController) Refund() {
  5882. order_id, _ := c.GetInt64("order_id")
  5883. order, _ := service.GetHisOrderByID(order_id)
  5884. adminUser := c.GetAdminUserInfo()
  5885. orgid := c.GetAdminUserInfo().CurrentOrgId
  5886. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  5887. if err != nil {
  5888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5889. return
  5890. }
  5891. tmp := strconv.FormatInt(order.ID, 10)
  5892. //当押金不为零时产生退费记录
  5893. if order.Decimal != 0 {
  5894. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  5895. if err != nil {
  5896. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5897. return
  5898. }
  5899. }
  5900. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  5901. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  5902. var goods []*models.DialysisBeforePrepareGoods
  5903. var newGoods []*models.NewDialysisBeforePrepareGoods
  5904. var infos []*models.HisDoctorAdviceInfo
  5905. for _, info := range orders {
  5906. if info.AdviceId > 0 && info.ProjectId == 0 {
  5907. infos = append(infos, &info.HisDoctorAdviceInfo)
  5908. }
  5909. if info.ProjectId > 0 && info.AdviceId == 0 {
  5910. if info.HisPrescriptionProject.Type == 3 {
  5911. var good models.DialysisBeforePrepareGoods
  5912. var newGood models.NewDialysisBeforePrepareGoods
  5913. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  5914. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  5915. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  5916. good.Count = int64(count)
  5917. good.StorehouseId = houseConfig.StorehouseOutInfo
  5918. good.ProjectId = info.HisPrescriptionProject.ID
  5919. good.PatientId = info.PatientId
  5920. good.OrderId = order_id
  5921. goods = append(goods, &good)
  5922. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  5923. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  5924. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  5925. newGood.Count = int64(count2)
  5926. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  5927. newGood.ProjectId = info.HisPrescriptionProject.ID
  5928. newGood.RecordDate = order.SettleAccountsDate
  5929. newGood.UserOrgId = order.UserOrgId
  5930. newGood.PatientId = info.PatientId
  5931. newGood.OrderId = order_id
  5932. newGoods = append(newGoods, &newGood)
  5933. }
  5934. }
  5935. }
  5936. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  5937. if settConfig.IsOpen == 1 {
  5938. for _, item := range infos {
  5939. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  5940. }
  5941. for _, item := range newGoods {
  5942. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  5943. }
  5944. }
  5945. c.ServeSuccessJSON(map[string]interface{}{
  5946. "msg": "退费成功",
  5947. })
  5948. }
  5949. func (c *HisApiController) RefundNumber() {
  5950. his_patient_id, _ := c.GetInt64("id")
  5951. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5952. info.Status = 0
  5953. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  5954. if count > 0 {
  5955. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  5956. return
  5957. }
  5958. err := service.SaveHisPatient(info)
  5959. if err == nil {
  5960. c.ServeSuccessJSON(map[string]interface{}{
  5961. "msg": "退号成功",
  5962. })
  5963. } else {
  5964. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5965. return
  5966. }
  5967. }
  5968. func (this *HisApiController) AdditionalCharge() {
  5969. dataBody := make(map[string]interface{}, 0)
  5970. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5971. fmt.Println(err)
  5972. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  5973. patient_id := int64(dataBody["patient_id"].(float64))
  5974. medicineData, _ := dataBody["medicineData"].([]interface{})
  5975. adminUserInfo := this.GetAdminUserInfo()
  5976. orgId := adminUserInfo.CurrentOrgId
  5977. admin_user_id := adminUserInfo.AdminUser.Id
  5978. timeStr := time.Now().Format("2006-01-02")
  5979. timeLayout := "2006-01-02 15:04:05"
  5980. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  5981. timenow := timeStringToTime.Unix()
  5982. var additionalCharges []*models.HisAdditionalCharge
  5983. for _, item := range medicineData {
  5984. var randNum int
  5985. randNum = rand.Intn(10000) + 1000
  5986. timestamp := time.Now().Unix()
  5987. tempTime := time.Unix(timestamp, 0)
  5988. timeFormat := tempTime.Format("20060102150405")
  5989. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  5990. items := item.(map[string]interface{})
  5991. money := items["price"].(string)
  5992. item_id_str := items["item_id"].(string)
  5993. name := items["name"].(string)
  5994. id_str := items["id"].(string)
  5995. moneys, _ := strconv.ParseInt(money, 10, 64)
  5996. monStr := strconv.FormatInt(moneys, 10)
  5997. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  5998. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  5999. id, _ := strconv.ParseInt(id_str, 10, 64)
  6000. additionalCharge := &models.HisAdditionalCharge{
  6001. ID: id,
  6002. HisPatientId: his_patient_id,
  6003. UserOrgId: orgId,
  6004. PatientId: patient_id,
  6005. RecordDate: timenow,
  6006. Price: monneyStr,
  6007. Status: 1,
  6008. ItemName: name,
  6009. ItemId: item_id,
  6010. AdminUserId: admin_user_id,
  6011. CreatedTime: time.Now().Unix(),
  6012. OrderStatus: 0,
  6013. PrescriptionNumber: "",
  6014. BatchNumber: "",
  6015. FeedetlSn: p_number,
  6016. }
  6017. service.CreateAdditionalCharge(additionalCharge)
  6018. additionalCharges = append(additionalCharges, additionalCharge)
  6019. }
  6020. this.ServeSuccessJSON(map[string]interface{}{
  6021. "msg": "添加成功",
  6022. "additional_charges": additionalCharges,
  6023. })
  6024. }
  6025. func (this *HisApiController) DeleteAddition() {
  6026. id, _ := this.GetInt64("id")
  6027. //TODO 需要判断是否已经结算
  6028. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  6029. if err == nil {
  6030. this.ServeSuccessJSON(map[string]interface{}{
  6031. "msg": "删除成功",
  6032. })
  6033. return
  6034. } else {
  6035. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6036. return
  6037. }
  6038. }
  6039. func (this *HisApiController) GetAdminUsers() {
  6040. adminUser := this.GetAdminUserInfo()
  6041. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  6042. this.ServeSuccessJSON(map[string]interface{}{
  6043. "doctors": doctors,
  6044. })
  6045. }
  6046. func (this *HisApiController) GetLastOrNextHisPrescription() {
  6047. change_type, _ := this.GetInt64("type", 0)
  6048. record_date := this.GetString("record_time")
  6049. patient_id, _ := this.GetInt64("patient_id", 0)
  6050. p_type, _ := this.GetInt64("p_type", 0)
  6051. timeLayout := "2006-01-02"
  6052. loc, _ := time.LoadLocation("Local")
  6053. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  6054. record_time := theAdviceRecordTime.Unix()
  6055. adminUserInfo := this.GetAdminUserInfo()
  6056. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  6057. if err == nil {
  6058. if len(prescriptions) == 0 {
  6059. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  6060. return
  6061. } else {
  6062. this.ServeSuccessJSON(map[string]interface{}{
  6063. "prescriptions": prescriptions,
  6064. })
  6065. return
  6066. }
  6067. } else {
  6068. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6069. return
  6070. }
  6071. }
  6072. func (this *HisApiController) GetCallHisPrescription() {
  6073. patient_id, _ := this.GetInt64("patient_id", 0)
  6074. timeLayout := "2006-01-02"
  6075. loc, _ := time.LoadLocation("Local")
  6076. start_time := this.GetString("start_time")
  6077. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6078. end_time := this.GetString("end_time")
  6079. p_type, _ := this.GetInt64("p_type")
  6080. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6081. adminUserInfo := this.GetAdminUserInfo()
  6082. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  6083. if err == nil {
  6084. this.ServeSuccessJSON(map[string]interface{}{
  6085. "prescriptions": prescriptions,
  6086. })
  6087. return
  6088. } else {
  6089. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6090. return
  6091. }
  6092. }
  6093. func (this *HisApiController) GetHisDayPrescription() {
  6094. timeLayout := "2006-01-02"
  6095. loc, _ := time.LoadLocation("Local")
  6096. start_time := this.GetString("start_time")
  6097. patient_id, _ := this.GetInt64("patient_id", 0)
  6098. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6099. end_time := this.GetString("end_time")
  6100. p_type, _ := this.GetInt64("p_type")
  6101. order_status, _ := this.GetInt64("type")
  6102. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6103. adminUserInfo := this.GetAdminUserInfo()
  6104. var dayHisPrescription []*models.HisPrescription
  6105. var err error
  6106. if order_status == 1 || order_status == 0 {
  6107. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6108. } else if order_status == 2 {
  6109. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  6110. }
  6111. var settle_total float64
  6112. for _, item := range dayHisPrescription {
  6113. if len(item.HisPrescriptionProject) > 0 {
  6114. for _, subItem := range item.HisPrescriptionProject {
  6115. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6116. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6117. settle_total = settle_total + total
  6118. }
  6119. }
  6120. if len(item.HisDoctorAdviceInfo) > 0 {
  6121. for _, subItem := range item.HisDoctorAdviceInfo {
  6122. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6123. settle_total = settle_total + total
  6124. }
  6125. }
  6126. }
  6127. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6128. if err == nil {
  6129. this.ServeSuccessJSON(map[string]interface{}{
  6130. "day_prescription": dayHisPrescription,
  6131. "settle_total": settle_total,
  6132. })
  6133. return
  6134. } else {
  6135. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6136. return
  6137. }
  6138. }
  6139. func (c *HisApiController) GetHisChargePatientList() {
  6140. record_date := c.GetString("record_date")
  6141. order_status, _ := c.GetInt64("type")
  6142. timeLayout := "2006-01-02"
  6143. loc, _ := time.LoadLocation("Local")
  6144. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6145. if err != nil {
  6146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6147. return
  6148. }
  6149. recordDateTime := theTime.Unix()
  6150. adminInfo := c.GetAdminUserInfo()
  6151. var tempPatients []*service.NewTempPatients
  6152. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6153. if order_status != 2 {
  6154. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6155. } else {
  6156. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  6157. }
  6158. var patients []*service.NewTempPatients
  6159. var patients_two []*service.NewTempPatients
  6160. for _, item := range tempPatients {
  6161. //过滤掉没挂号的和没开处方的
  6162. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  6163. patients = append(patients, item)
  6164. }
  6165. //过滤掉没挂号的
  6166. if len(item.HisPatient) > 0 {
  6167. patients_two = append(patients_two, item)
  6168. }
  6169. }
  6170. c.ServeSuccessJSON(map[string]interface{}{
  6171. "list": patients,
  6172. "list_two": patients_two,
  6173. })
  6174. }
  6175. func (c *HisApiController) GetHisUnRegisterPatientList() {
  6176. record_date := c.GetString("record_date")
  6177. timeLayout := "2006-01-02"
  6178. loc, _ := time.LoadLocation("Local")
  6179. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6180. if err != nil {
  6181. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6182. return
  6183. }
  6184. recordDateTime := theTime.Unix()
  6185. adminUser := c.GetAdminUserInfo()
  6186. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  6187. var patients []*service.Patients
  6188. for _, item := range tempPatients {
  6189. if item.HisPatient.ID == 0 {
  6190. patients = append(patients, item)
  6191. }
  6192. }
  6193. c.ServeSuccessJSON(map[string]interface{}{
  6194. "list": patients,
  6195. //"list_two": patients_two,
  6196. })
  6197. }
  6198. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  6199. newArr = make([]*service.Patients, 0)
  6200. for i := 0; i < len(patient); i++ {
  6201. repeat := false
  6202. for j := i + 1; j < len(patient); j++ {
  6203. if patient[i].ID == patient[j].ID {
  6204. repeat = true
  6205. break
  6206. }
  6207. }
  6208. if !repeat {
  6209. newArr = append(newArr, patient[i])
  6210. }
  6211. }
  6212. return
  6213. }
  6214. func (c *HisApiController) GetHisChargePatientInfo() {
  6215. patient_id, _ := c.GetInt64("patient_id")
  6216. his_patient_id, _ := c.GetInt64("his_patient_id")
  6217. record_date := c.GetString("record_date")
  6218. //start_time := c.GetString("start_time")
  6219. //end_time := c.GetString("end_time")
  6220. order_status, _ := c.GetInt64("type", 0)
  6221. p_type, _ := c.GetInt64("p_type", 0)
  6222. order_id, _ := c.GetInt64("order_id", 0)
  6223. timeLayout := "2006-01-02"
  6224. loc, _ := time.LoadLocation("Local")
  6225. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6226. if err != nil {
  6227. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6228. return
  6229. }
  6230. recordDateTime := theTime.Unix()
  6231. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6232. //if err != nil {
  6233. //
  6234. //}
  6235. //startRecordDateTime := startTime.Unix()
  6236. //
  6237. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6238. //if err != nil {
  6239. //
  6240. //}
  6241. //endRecordDateTime := endTime.Unix()
  6242. admin := c.GetAdminUserInfo()
  6243. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6244. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6245. var prescriptions []*models.HisPrescription
  6246. //var unChargeMonthPrescriptions []*models.HisPrescription
  6247. order, _ := service.GetHisOrderByID(order_id)
  6248. if order_status == 1 || order_status == 0 {
  6249. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  6250. } else if order_status == 2 {
  6251. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6252. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6253. }
  6254. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6255. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6256. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6257. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6258. //获取所有科室信息
  6259. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6260. c.ServeSuccessJSON(map[string]interface{}{
  6261. "his_info": his_patient_info,
  6262. "xt_info": xt_patient_info,
  6263. "prescription": prescriptions,
  6264. "case_history": case_history,
  6265. "info": patientPrescriptionInfo,
  6266. "last_info": lastPatientPrescriptionInfo,
  6267. "order": order,
  6268. "doctors": doctors,
  6269. "department": department,
  6270. })
  6271. return
  6272. }
  6273. func (c *HisApiController) GetAllOrderDetail() {
  6274. order_id, _ := c.GetInt64("id", 0)
  6275. order, _ := service.GetHisOrderByID(order_id)
  6276. if order.ID == 0 {
  6277. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6278. return
  6279. }
  6280. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6281. org_id := c.GetAdminUserInfo().CurrentOrgId
  6282. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6283. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6284. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6285. c.ServeSuccessJSON(map[string]interface{}{
  6286. "order": order,
  6287. "order_info": order_info,
  6288. "patient": patient,
  6289. "admin_info": adminInfo,
  6290. "hospital_record": record,
  6291. })
  6292. return
  6293. }
  6294. func (c *HisApiController) GetAllOrderDetailCollect() {
  6295. order_id, _ := c.GetInt64("id", 0)
  6296. order, _ := service.GetHisOrderByID(order_id)
  6297. if order.ID == 0 {
  6298. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6299. return
  6300. }
  6301. org_id := c.GetAdminUserInfo().CurrentOrgId
  6302. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6303. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6304. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6305. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  6306. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  6307. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6308. var bedCostTotal float64 = 0 //床位总费
  6309. //var bedCostSelfTotal float64 = 0 //床位自费
  6310. var operationCostTotal float64 = 0 //手术费
  6311. //var operationCostSelfTotal float64 = 0 //手术费
  6312. var otherCostTotal float64 = 0 //其他费用
  6313. //var otherCostSelfTotal float64 = 0 //其他费用
  6314. var materialCostTotal float64 = 0 //材料费
  6315. //var materialCostSelfTotal float64 = 0 //材料费
  6316. var westernMedicineCostTotal float64 = 0 //西药费
  6317. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  6318. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6319. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6320. var checkCostTotal float64 = 0 //检查费
  6321. //var checkCostSelfTotal float64 = 0 //检查费
  6322. var laboratoryCostTotal float64 = 0 //化验费
  6323. //var laboratoryCostSelfTotal float64 = 0 //化验费
  6324. var treatCostTotal float64 = 0 //治疗费用
  6325. //var treatCostSelfTotal float64 = 0 //治疗费用
  6326. var zhenChaCostTotal float64 = 0 //其他费用
  6327. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6328. decimal.DivisionPrecision = 2
  6329. var BalanceAccountsType int64
  6330. if his.ID > 0 {
  6331. BalanceAccountsType = his.BalanceAccountsType
  6332. } else {
  6333. BalanceAccountsType = record.BalanceAccountsType
  6334. }
  6335. if BalanceAccountsType != 2 {
  6336. for _, item := range order_info {
  6337. if org_id == 10215 {
  6338. if item.MedChrgitmType == "01" { //床位费
  6339. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6340. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6341. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6342. }
  6343. if item.MedChrgitmType == "02" { //诊察费
  6344. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6345. //zhenChaCostSelfTotal = zhenChaCostTotal
  6346. }
  6347. if item.MedChrgitmType == "03" { //检查费
  6348. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6349. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6350. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6351. }
  6352. //if item.MedChrgitmType == "02" { //检查费
  6353. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6354. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6355. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6356. //}
  6357. if item.MedChrgitmType == "04" { //化验费
  6358. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6359. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6360. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6361. }
  6362. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6363. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6364. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6365. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6366. }
  6367. if item.MedChrgitmType == "06" { //手术费
  6368. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6369. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6370. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6371. }
  6372. if item.MedChrgitmType == "08" { //材料费
  6373. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6374. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6375. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6376. }
  6377. if item.MedChrgitmType == "09" { //西药费
  6378. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6379. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6380. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6381. }
  6382. if item.MedChrgitmType == "11" { //中成费
  6383. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6384. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6385. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6386. }
  6387. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6388. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6389. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6390. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6391. }
  6392. } else if org_id == 10188 || org_id == 10217 {
  6393. if item.MedChrgitmType == "01" { //床位费
  6394. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6395. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6396. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6397. }
  6398. if item.MedChrgitmType == "02" { //诊察费
  6399. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6400. //zhenChaCostSelfTotal = zhenChaCostTotal
  6401. }
  6402. if item.MedChrgitmType == "03" { //检查费
  6403. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6404. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6405. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6406. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6407. }
  6408. //if item.MedChrgitmType == "02" { //检查费
  6409. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6410. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6411. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6412. //}
  6413. if item.MedChrgitmType == "04" { //化验费
  6414. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6415. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6416. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6417. }
  6418. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6419. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6420. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6421. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6422. }
  6423. if item.MedChrgitmType == "06" { //手术费
  6424. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6425. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6426. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6427. }
  6428. if item.MedChrgitmType == "08" { //材料费
  6429. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6430. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6431. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6432. }
  6433. if item.MedChrgitmType == "09" { //西药费
  6434. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6435. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6436. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6437. }
  6438. if item.MedChrgitmType == "11" { //中成费
  6439. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6440. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6441. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6442. }
  6443. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6444. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6445. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6446. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6447. }
  6448. } else {
  6449. if item.MedChrgitmType == "01" { //床位费
  6450. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6451. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6452. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6453. }
  6454. //if item.MedChrgitmType == "02" { //诊察费
  6455. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6456. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6457. //}
  6458. if item.MedChrgitmType == "03" { //检查费
  6459. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6460. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6461. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6462. }
  6463. //if item.MedChrgitmType == "02" { //检查费
  6464. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6465. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6466. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6467. //}
  6468. if item.MedChrgitmType == "04" { //化验费
  6469. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6470. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6471. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6472. }
  6473. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6474. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6475. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6476. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6477. }
  6478. if item.MedChrgitmType == "06" { //手术费
  6479. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6480. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6481. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6482. }
  6483. if item.MedChrgitmType == "08" { //材料费
  6484. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6485. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6486. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6487. }
  6488. if item.MedChrgitmType == "09" { //西药费
  6489. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6490. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6491. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6492. }
  6493. if item.MedChrgitmType == "11" { //中成费
  6494. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6495. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6496. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6497. }
  6498. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6499. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6500. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6501. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6502. }
  6503. }
  6504. }
  6505. c.ServeSuccessJSON(map[string]interface{}{
  6506. "order": order,
  6507. "order_info": order_info,
  6508. "patient": patient,
  6509. "admin_info": adminInfo,
  6510. "his_hospital": record,
  6511. "bedCostTotal": bedCostTotal,
  6512. "operationCostTotal": operationCostTotal,
  6513. "otherCostTotal": otherCostTotal,
  6514. "materialCostTotal": materialCostTotal,
  6515. "westernMedicineCostTotal": westernMedicineCostTotal,
  6516. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6517. "checkCostTotal": checkCostTotal,
  6518. "zhenChaCostTotal": zhenChaCostTotal,
  6519. "laboratoryCostTotal": laboratoryCostTotal,
  6520. "treatCostTotal": treatCostTotal,
  6521. })
  6522. } else {
  6523. for _, item := range order_info {
  6524. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6525. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6526. item.MedChrgitmType = "09"
  6527. }
  6528. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6529. if item.HisPrescriptionProject.Type == 2 {
  6530. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6531. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6532. case 0:
  6533. item.MedChrgitmType = "0"
  6534. break
  6535. case 1:
  6536. item.MedChrgitmType = "14"
  6537. break
  6538. case 2:
  6539. item.MedChrgitmType = "05"
  6540. break
  6541. case 3:
  6542. item.MedChrgitmType = "03"
  6543. break
  6544. case 4:
  6545. item.MedChrgitmType = "03"
  6546. break
  6547. case 5:
  6548. item.MedChrgitmType = "08"
  6549. break
  6550. case 6:
  6551. item.MedChrgitmType = "14"
  6552. break
  6553. case 7:
  6554. item.MedChrgitmType = "14"
  6555. break
  6556. case 8:
  6557. item.MedChrgitmType = "03"
  6558. break
  6559. case 9:
  6560. item.MedChrgitmType = "14"
  6561. break
  6562. case 10:
  6563. item.MedChrgitmType = "14"
  6564. break
  6565. case 11:
  6566. item.MedChrgitmType = "06"
  6567. break
  6568. case 12:
  6569. item.MedChrgitmType = "12"
  6570. break
  6571. case 13:
  6572. item.MedChrgitmType = "01"
  6573. break
  6574. case 14:
  6575. item.MedChrgitmType = "04"
  6576. break
  6577. case 15:
  6578. item.MedChrgitmType = "14"
  6579. break
  6580. }
  6581. } else {
  6582. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6583. case 1:
  6584. item.MedChrgitmType = "14"
  6585. break
  6586. case 2:
  6587. item.MedChrgitmType = "05"
  6588. break
  6589. case 3:
  6590. item.MedChrgitmType = "04"
  6591. break
  6592. case 4:
  6593. item.MedChrgitmType = "14"
  6594. break
  6595. case 5:
  6596. item.MedChrgitmType = "08"
  6597. break
  6598. case 6:
  6599. item.MedChrgitmType = "14"
  6600. break
  6601. case 7:
  6602. item.MedChrgitmType = "14"
  6603. break
  6604. case 8:
  6605. item.MedChrgitmType = "03"
  6606. break
  6607. case 9:
  6608. item.MedChrgitmType = "14"
  6609. break
  6610. }
  6611. }
  6612. } else if item.HisPrescriptionProject.Type == 3 {
  6613. item.MedChrgitmType = "08"
  6614. }
  6615. }
  6616. }
  6617. for _, item := range order_info {
  6618. if org_id == 10215 {
  6619. if item.MedChrgitmType == "01" { //床位费
  6620. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6621. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6622. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6623. }
  6624. if item.MedChrgitmType == "02" { //诊察费
  6625. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6626. //zhenChaCostSelfTotal = zhenChaCostTotal
  6627. }
  6628. if item.MedChrgitmType == "03" { //检查费
  6629. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6630. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6631. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6632. }
  6633. //if item.MedChrgitmType == "02" { //检查费
  6634. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6635. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6636. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6637. //}
  6638. if item.MedChrgitmType == "04" { //化验费
  6639. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6640. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6641. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6642. }
  6643. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6644. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6645. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6646. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6647. }
  6648. if item.MedChrgitmType == "06" { //手术费
  6649. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6650. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6651. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6652. }
  6653. if item.MedChrgitmType == "08" { //材料费
  6654. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6655. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6656. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6657. }
  6658. if item.MedChrgitmType == "09" { //西药费
  6659. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6660. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6661. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6662. }
  6663. if item.MedChrgitmType == "11" { //中成费
  6664. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6665. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6666. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6667. }
  6668. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  6669. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6670. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6671. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6672. }
  6673. } else {
  6674. if item.MedChrgitmType == "01" { //床位费
  6675. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6676. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6677. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6678. }
  6679. //if item.MedChrgitmType == "02" { //诊察费
  6680. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6681. // //zhenChaCostSelfTotal = zhenChaCostTotal
  6682. //}
  6683. if item.MedChrgitmType == "03" { //检查费
  6684. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6685. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6686. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6687. }
  6688. //if item.MedChrgitmType == "02" { //检查费
  6689. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6690. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6691. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6692. //}
  6693. if item.MedChrgitmType == "04" { //化验费
  6694. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6695. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6696. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6697. }
  6698. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  6699. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6700. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6701. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6702. }
  6703. if item.MedChrgitmType == "06" { //手术费
  6704. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6705. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6706. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6707. }
  6708. if item.MedChrgitmType == "08" { //材料费
  6709. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6710. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6711. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6712. }
  6713. if item.MedChrgitmType == "09" { //西药费
  6714. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6715. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6716. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6717. }
  6718. if item.MedChrgitmType == "11" { //中成费
  6719. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6720. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6721. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6722. }
  6723. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  6724. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6725. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  6726. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  6727. }
  6728. }
  6729. }
  6730. c.ServeSuccessJSON(map[string]interface{}{
  6731. "order": order,
  6732. "order_info": order_info,
  6733. "patient": patient,
  6734. "admin_info": adminInfo,
  6735. "his_hospital": record,
  6736. "bedCostTotal": bedCostTotal,
  6737. "operationCostTotal": operationCostTotal,
  6738. "otherCostTotal": otherCostTotal,
  6739. "materialCostTotal": materialCostTotal,
  6740. "westernMedicineCostTotal": westernMedicineCostTotal,
  6741. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  6742. "checkCostTotal": checkCostTotal,
  6743. "zhenChaCostTotal": zhenChaCostTotal,
  6744. "laboratoryCostTotal": laboratoryCostTotal,
  6745. "treatCostTotal": treatCostTotal,
  6746. })
  6747. }
  6748. }
  6749. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  6750. page, _ := c.GetInt64("page")
  6751. limit, _ := c.GetInt64("limit")
  6752. keywords := c.GetString("keywords")
  6753. start_time := c.GetString("start_time")
  6754. end_time := c.GetString("end_time")
  6755. //clr_type := c.GetString("clr_type")
  6756. insutype := c.GetString("insutype")
  6757. timeLayout := "2006-01-02"
  6758. loc, _ := time.LoadLocation("Local")
  6759. var theStartTIme int64
  6760. if len(start_time) > 0 {
  6761. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6762. theStartTIme = theTime.Unix()
  6763. }
  6764. var theEndtTIme int64
  6765. if len(end_time) > 0 {
  6766. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6767. theEndtTIme = theTime.Unix()
  6768. }
  6769. if page <= 0 {
  6770. page = 1
  6771. }
  6772. if limit <= 0 {
  6773. limit = 10
  6774. }
  6775. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  6776. c.ServeSuccessJSON(map[string]interface{}{
  6777. "total": total,
  6778. "list": list,
  6779. })
  6780. return
  6781. }
  6782. func (c *HisApiController) GetPutOnRecordList() {
  6783. page, _ := c.GetInt64("page")
  6784. limit, _ := c.GetInt64("limit")
  6785. keywords := c.GetString("keywords")
  6786. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  6787. if page <= 0 {
  6788. page = 1
  6789. }
  6790. if limit <= 0 {
  6791. limit = 10
  6792. }
  6793. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  6794. c.ServeSuccessJSON(map[string]interface{}{
  6795. "total": total,
  6796. "list": list,
  6797. })
  6798. return
  6799. }
  6800. func (c *HisApiController) GetCompareData() {
  6801. start_time := c.GetString("start_time")
  6802. end_time := c.GetString("end_time")
  6803. insutype := c.GetString("insutype")
  6804. clr_type := c.GetString("clr_type")
  6805. timeLayout := "2006-01-02"
  6806. loc, _ := time.LoadLocation("Local")
  6807. var theStartTIme int64
  6808. if len(start_time) > 0 {
  6809. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6810. if err != nil {
  6811. theStartTIme = 0
  6812. }
  6813. theStartTIme = theTime.Unix()
  6814. }
  6815. var theEndtTIme int64
  6816. if len(end_time) > 0 {
  6817. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6818. if err != nil {
  6819. theEndtTIme = 0
  6820. }
  6821. theEndtTIme = theTime.Unix()
  6822. }
  6823. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  6824. fmt.Println(err)
  6825. if err == nil {
  6826. c.ServeSuccessJSON(map[string]interface{}{
  6827. "list": formData,
  6828. })
  6829. } else {
  6830. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6831. return
  6832. }
  6833. }
  6834. func (c *HisApiController) GetFaPiaoData() {
  6835. order_id, _ := c.GetInt64("order_id")
  6836. patient_id, _ := c.GetInt64("patient_id")
  6837. number := c.GetString("number")
  6838. adminUser := c.GetAdminUserInfo()
  6839. order, _ := service.GetHisOrderByID(order_id)
  6840. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  6841. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  6842. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  6843. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  6844. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  6845. patient, _ := service.GetPatientByID(adminUser.CurrentOrgId, patient_id)
  6846. var bedCostTotal float64 = 0 //床位总费
  6847. var bedCostSelfTotal float64 = 0 //床位自费
  6848. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  6849. var operationCostTotal float64 = 0 //手术费
  6850. var operationCostSelfTotal float64 = 0 //手术费
  6851. var operationCostPartSelfTotal float64 = 0 //手术费
  6852. var otherCostTotal float64 = 0 //其他费用
  6853. var otherCostSelfTotal float64 = 0 //其他费用
  6854. var otherCostPartSelfTotal float64 = 0 //其他费用
  6855. var materialCostTotal float64 = 0 //材料费
  6856. var materialCostSelfTotal float64 = 0 //材料费
  6857. var materialCostPartSelfTotal float64 = 0 //材料费
  6858. var westernMedicineCostTotal float64 = 0 //西药费
  6859. var westernMedicineCostSelfTotal float64 = 0 //西药费
  6860. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  6861. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  6862. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  6863. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  6864. var checkCostTotal float64 = 0 //检查费
  6865. var checkCostSelfTotal float64 = 0 //检查费
  6866. var checkCostPartSelfTotal float64 = 0 //检查费
  6867. var laboratoryCostTotal float64 = 0 //化验费
  6868. var laboratoryCostSelfTotal float64 = 0 //化验费
  6869. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  6870. var treatCostTotal float64 = 0 //治疗费用
  6871. var treatCostSelfTotal float64 = 0 //治疗费用
  6872. var treatCostPartSelfTotal float64 = 0 //治疗费用
  6873. var zhenChaCostTotal float64 = 0 //其他费用
  6874. var zhenChaCostSelfTotal float64 = 0 //其他费用
  6875. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  6876. decimal.DivisionPrecision = 2
  6877. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  6878. var balanceAccountsType int64
  6879. if his.ID > 0 {
  6880. balanceAccountsType = his.BalanceAccountsType
  6881. } else {
  6882. balanceAccountsType = his_hospital_record.BalanceAccountsType
  6883. }
  6884. if balanceAccountsType == 2 {
  6885. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  6886. for _, item := range orderInfos_two {
  6887. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  6888. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  6889. item.MedChrgitmType = "09"
  6890. }
  6891. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  6892. if item.HisPrescriptionProject.Type == 2 {
  6893. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  6894. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6895. case 0:
  6896. item.MedChrgitmType = "0"
  6897. break
  6898. case 1:
  6899. item.MedChrgitmType = "14"
  6900. break
  6901. case 2:
  6902. item.MedChrgitmType = "05"
  6903. break
  6904. case 3:
  6905. item.MedChrgitmType = "03"
  6906. break
  6907. case 4:
  6908. item.MedChrgitmType = "03"
  6909. break
  6910. case 5:
  6911. item.MedChrgitmType = "08"
  6912. break
  6913. case 6:
  6914. item.MedChrgitmType = "14"
  6915. break
  6916. case 7:
  6917. item.MedChrgitmType = "14"
  6918. break
  6919. case 8:
  6920. item.MedChrgitmType = "03"
  6921. break
  6922. case 9:
  6923. item.MedChrgitmType = "14"
  6924. break
  6925. case 10:
  6926. item.MedChrgitmType = "14"
  6927. break
  6928. case 11:
  6929. item.MedChrgitmType = "06"
  6930. break
  6931. case 12:
  6932. item.MedChrgitmType = "12"
  6933. break
  6934. case 13:
  6935. item.MedChrgitmType = "01"
  6936. break
  6937. case 14:
  6938. item.MedChrgitmType = "04"
  6939. break
  6940. case 15:
  6941. item.MedChrgitmType = "02"
  6942. break
  6943. }
  6944. } else {
  6945. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  6946. case 1:
  6947. item.MedChrgitmType = "14"
  6948. break
  6949. case 2:
  6950. item.MedChrgitmType = "05"
  6951. break
  6952. case 3:
  6953. item.MedChrgitmType = "03"
  6954. break
  6955. case 4:
  6956. item.MedChrgitmType = "03"
  6957. break
  6958. case 5:
  6959. item.MedChrgitmType = "08"
  6960. break
  6961. case 6:
  6962. item.MedChrgitmType = "14"
  6963. break
  6964. case 7:
  6965. item.MedChrgitmType = "14"
  6966. break
  6967. case 8:
  6968. item.MedChrgitmType = "03"
  6969. break
  6970. case 9:
  6971. item.MedChrgitmType = "14"
  6972. break
  6973. }
  6974. }
  6975. } else if item.HisPrescriptionProject.Type == 3 {
  6976. item.MedChrgitmType = "08"
  6977. }
  6978. }
  6979. }
  6980. for _, item := range orderInfos_two {
  6981. fmt.Println(item.MedChrgitmType)
  6982. if item.MedChrgitmType == "01" { //床位费
  6983. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6984. bedCostSelfTotal = bedCostTotal
  6985. }
  6986. if item.MedChrgitmType == "02" { //诊察费
  6987. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6988. zhenChaCostSelfTotal = zhenChaCostTotal
  6989. }
  6990. if item.MedChrgitmType == "03" { //检查费
  6991. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6992. checkCostSelfTotal = checkCostTotal
  6993. }
  6994. if item.MedChrgitmType == "04" { //化验费
  6995. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  6996. laboratoryCostSelfTotal = laboratoryCostTotal
  6997. }
  6998. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  6999. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7000. treatCostSelfTotal = treatCostTotal
  7001. }
  7002. if item.MedChrgitmType == "06" { //手术费
  7003. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7004. operationCostSelfTotal = treatCostTotal
  7005. }
  7006. if item.MedChrgitmType == "08" { //材料费
  7007. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7008. materialCostSelfTotal = materialCostTotal
  7009. }
  7010. if item.MedChrgitmType == "09" { //西药费
  7011. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7012. westernMedicineCostSelfTotal = westernMedicineCostTotal
  7013. }
  7014. if item.MedChrgitmType == "11" { //中成费
  7015. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7016. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  7017. }
  7018. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  7019. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  7020. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7021. otherCostSelfTotal = otherCostTotal
  7022. }
  7023. } else {
  7024. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7025. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7026. otherCostSelfTotal = otherCostTotal
  7027. }
  7028. }
  7029. }
  7030. } else {
  7031. for _, item := range orderInfos {
  7032. if item.MedChrgitmType == "01" { //床位费
  7033. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7034. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7035. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7036. }
  7037. if item.MedChrgitmType == "02" { //诊察费
  7038. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7039. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7040. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7041. }
  7042. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  7043. if item.MedChrgitmType == "03" { //检查费
  7044. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7045. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7046. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7047. }
  7048. } else {
  7049. if item.MedChrgitmType == "03" { //检查费
  7050. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7051. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7052. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7053. }
  7054. }
  7055. if item.MedChrgitmType == "04" { //化验费
  7056. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7057. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7058. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7059. }
  7060. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  7061. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7062. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7063. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7064. }
  7065. if item.MedChrgitmType == "06" { //手术费
  7066. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7067. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7068. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7069. }
  7070. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  7071. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7072. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7073. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7074. }
  7075. if item.MedChrgitmType == "09" { //西药费
  7076. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7077. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7078. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7079. }
  7080. if item.MedChrgitmType == "11" { //中成费
  7081. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7082. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7083. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7084. }
  7085. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  7086. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  7087. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  7088. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  7089. }
  7090. }
  7091. }
  7092. timeLayout := "2006-01-02"
  7093. loc, _ := time.LoadLocation("Local")
  7094. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  7095. if err != nil {
  7096. }
  7097. startRecordDateTime := startTime.Unix()
  7098. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  7099. if err != nil {
  7100. }
  7101. endRecordDateTime := endTime.Unix()
  7102. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  7103. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  7104. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  7105. c.ServeSuccessJSON(map[string]interface{}{
  7106. "order_number": order.Number, //业务流水号
  7107. "id_card_no": his.IdCardNo, //社会保障号
  7108. "department_name": department.Name, //科室
  7109. "number": his.Number, //门诊号
  7110. "date": order.SettleAccountsDate, //结算日期
  7111. "name": order.PsnName, //姓名
  7112. "gender": patient.Gender, //性别
  7113. "psn_cash_money": order.PsnCashPay, //个人支付
  7114. "pay_way": "门诊", //结算方式
  7115. "medfee_sumamt": order.MedfeeSumamt, //总费用
  7116. "admin_user_name": admin.UserName, //收款员
  7117. "order": order,
  7118. "order_info": orderInfos_two,
  7119. "his": his,
  7120. "bedCostTotal": bedCostTotal,
  7121. "bedCostSelfTotal": bedCostSelfTotal,
  7122. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  7123. "operationCostTotal": operationCostTotal,
  7124. "operationCostSelfTotal": operationCostSelfTotal,
  7125. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  7126. "otherCostTotal": otherCostTotal,
  7127. "otherCostSelfTotal": otherCostSelfTotal,
  7128. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  7129. "materialCostTotal": materialCostTotal,
  7130. "materialCostSelfTotal": materialCostSelfTotal,
  7131. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  7132. "westernMedicineCostTotal": westernMedicineCostTotal,
  7133. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  7134. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  7135. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  7136. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  7137. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  7138. "checkCostTotal": checkCostTotal,
  7139. "checkCostSelfTotal": checkCostSelfTotal,
  7140. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  7141. "laboratoryCostTotal": laboratoryCostTotal,
  7142. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  7143. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  7144. "treatCostTotal": treatCostTotal,
  7145. "treatCostSelfTotal": treatCostSelfTotal,
  7146. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  7147. "zhenChaCostTotal": zhenChaCostTotal,
  7148. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  7149. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  7150. "his_hospital_record": his_hospital_record,
  7151. "pre_pay_money": pre_pay_money,
  7152. "refund_sum": sum,
  7153. })
  7154. }
  7155. func (this *HisApiController) GetIncomeStatisticsData() {
  7156. start_time := this.GetString("start_time")
  7157. end_time := this.GetString("end_time")
  7158. key_words := this.GetString("key_words")
  7159. limit, _ := this.GetInt64("limit")
  7160. page, _ := this.GetInt64("page")
  7161. if page <= 0 {
  7162. page = 1
  7163. }
  7164. if limit <= 0 {
  7165. limit = 10
  7166. }
  7167. statistics_type, _ := this.GetInt64("statistics_type")
  7168. admin := this.GetAdminUserInfo()
  7169. timeLayout := "2006-01-02"
  7170. loc, _ := time.LoadLocation("Local")
  7171. var theStartTIme int64
  7172. if len(start_time) > 0 {
  7173. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7174. if err != nil {
  7175. theStartTIme = 0
  7176. }
  7177. theStartTIme = theTime.Unix()
  7178. }
  7179. var theEndtTIme int64
  7180. if len(end_time) > 0 {
  7181. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7182. if err != nil {
  7183. theEndtTIme = 0
  7184. }
  7185. theEndtTIme = theTime.Unix()
  7186. }
  7187. if statistics_type == 1 {
  7188. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7189. this.ServeSuccessJSON(map[string]interface{}{
  7190. "list": list,
  7191. "total": total,
  7192. })
  7193. } else {
  7194. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  7195. this.ServeSuccessJSON(map[string]interface{}{
  7196. "list": list,
  7197. "total": total,
  7198. })
  7199. }
  7200. }
  7201. func (c *HisApiController) PostProjectInformation() {
  7202. adminUser := c.GetAdminUserInfo()
  7203. orgId := adminUser.CurrentOrgId
  7204. dataBody := make(map[string]interface{}, 0)
  7205. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7206. if err != nil {
  7207. utils.ErrorLog(err.Error())
  7208. return
  7209. }
  7210. utils.ErrorLog("%v", dataBody)
  7211. var projectList []*models.HisProject
  7212. var total_goods []interface{}
  7213. tempProjects := dataBody["projects"].([]interface{})
  7214. total_goods = tempProjects
  7215. for index, projectMap := range tempProjects {
  7216. projectM := projectMap.(map[string]interface{})
  7217. var project models.HisProject
  7218. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  7219. utils.ErrorLog("project_name")
  7220. return
  7221. }
  7222. project_name, _ := projectM["project_name"].(string)
  7223. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  7224. err_log := models.ExportErrLog{
  7225. LogType: 6,
  7226. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7227. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  7228. Status: 1,
  7229. CreateTime: time.Now().Unix(),
  7230. UpdateTime: time.Now().Unix(),
  7231. ExportTime: time.Now().Unix(),
  7232. }
  7233. service.CreateExportErrLog(&err_log)
  7234. continue
  7235. }
  7236. project.ProjectName = project_name
  7237. prices := projectM["price"].(string)
  7238. price, _ := strconv.ParseFloat(prices, 64)
  7239. if price <= 0 { //名字为空则生成一条导入错误日志
  7240. err_log := models.ExportErrLog{
  7241. LogType: 6,
  7242. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7243. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  7244. Status: 1,
  7245. CreateTime: time.Now().Unix(),
  7246. UpdateTime: time.Now().Unix(),
  7247. ExportTime: time.Now().Unix(),
  7248. }
  7249. service.CreateExportErrLog(&err_log)
  7250. continue
  7251. }
  7252. project.Price = price
  7253. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  7254. utils.ErrorLog("unit_id")
  7255. return
  7256. }
  7257. unit := projectM["unit"].(string)
  7258. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  7259. err_log := models.ExportErrLog{
  7260. LogType: 6,
  7261. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7262. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  7263. Status: 1,
  7264. CreateTime: time.Now().Unix(),
  7265. UpdateTime: time.Now().Unix(),
  7266. ExportTime: time.Now().Unix(),
  7267. }
  7268. service.CreateExportErrLog(&err_log)
  7269. continue
  7270. }
  7271. project.Unit = unit
  7272. cost_classify := projectM["cost_classify"].(string)
  7273. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  7274. err_log := models.ExportErrLog{
  7275. LogType: 6,
  7276. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7277. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7278. Status: 1,
  7279. CreateTime: time.Now().Unix(),
  7280. UpdateTime: time.Now().Unix(),
  7281. ExportTime: time.Now().Unix(),
  7282. }
  7283. service.CreateExportErrLog(&err_log)
  7284. continue
  7285. }
  7286. var costClassify = "费用类别"
  7287. var cost_classify_id int64
  7288. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  7289. if len(cost_classify) != 0 {
  7290. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  7291. if errcode == gorm.ErrRecordNotFound {
  7292. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  7293. dataconfig := models.DictDataconfig{
  7294. ParentId: costClassifyConfig.ID,
  7295. Module: "system",
  7296. OrgId: orgId,
  7297. Name: cost_classify,
  7298. FieldName: "",
  7299. Value: costConfig.Value + 1,
  7300. CreatedTime: "",
  7301. UpdatedTime: "",
  7302. CreateUserId: adminUser.AdminUser.Id,
  7303. Status: 1,
  7304. Remark: "",
  7305. DeleteIdSystem: 0,
  7306. Title: "",
  7307. Content: "",
  7308. Order: 0,
  7309. Code: "",
  7310. }
  7311. service.CreatedDicConfig(&dataconfig)
  7312. }
  7313. }
  7314. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  7315. for _, it := range costClassList {
  7316. if cost_classify == it.Name {
  7317. cost_classify_id = int64(it.Value)
  7318. }
  7319. }
  7320. project.CostClassify = cost_classify_id
  7321. executive_section := projectM["executive_section"].(string)
  7322. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  7323. err_log := models.ExportErrLog{
  7324. LogType: 6,
  7325. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7326. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  7327. Status: 1,
  7328. CreateTime: time.Now().Unix(),
  7329. UpdateTime: time.Now().Unix(),
  7330. ExportTime: time.Now().Unix(),
  7331. }
  7332. service.CreateExportErrLog(&err_log)
  7333. continue
  7334. }
  7335. if len(executive_section) != 0 {
  7336. //查找科室是否有内容
  7337. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  7338. if errcodedepart == gorm.ErrRecordNotFound {
  7339. department := models.XtHisDepartment{
  7340. Name: executive_section,
  7341. Status: 1,
  7342. UserOrgId: adminUser.CurrentOrgId,
  7343. CreatedTime: time.Now().Unix(),
  7344. }
  7345. service.CreateDePartment(&department)
  7346. }
  7347. }
  7348. var executive_section_id int64
  7349. departMentList, _ := service.GetAllDepartMent(orgId)
  7350. for _, it := range departMentList {
  7351. if executive_section == it.Name {
  7352. executive_section_id = it.ID
  7353. }
  7354. }
  7355. project.ExecutiveSection = executive_section_id
  7356. medical_coverage := projectM["medical_coverage"].(string)
  7357. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  7358. err_log := models.ExportErrLog{
  7359. LogType: 6,
  7360. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7361. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  7362. Status: 1,
  7363. CreateTime: time.Now().Unix(),
  7364. UpdateTime: time.Now().Unix(),
  7365. ExportTime: time.Now().Unix(),
  7366. }
  7367. service.CreateExportErrLog(&err_log)
  7368. continue
  7369. }
  7370. var medicalCoverage = "医保等级"
  7371. var medical_coverage_id int64
  7372. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  7373. if len(medical_coverage) != 0 {
  7374. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  7375. if errormedicalcoverage == gorm.ErrRecordNotFound {
  7376. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  7377. dataconfig := models.DictDataconfig{
  7378. ParentId: medicalCoverageConfig.ID,
  7379. Module: "system",
  7380. OrgId: orgId,
  7381. Name: medical_coverage,
  7382. FieldName: "",
  7383. Value: medicalCoverageConfig.Value + 1,
  7384. CreatedTime: "",
  7385. UpdatedTime: "",
  7386. CreateUserId: adminUser.AdminUser.Id,
  7387. Status: 1,
  7388. Remark: "",
  7389. DeleteIdSystem: 0,
  7390. Title: "",
  7391. Content: "",
  7392. Order: 0,
  7393. Code: "",
  7394. }
  7395. service.CreatedDicConfig(&dataconfig)
  7396. }
  7397. }
  7398. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  7399. for _, it := range medicalCoverageList {
  7400. if medical_coverage == it.Name {
  7401. medical_coverage_id = int64(it.Value)
  7402. }
  7403. }
  7404. project.MedicalCoverage = medical_coverage_id
  7405. pinyin := projectM["pinyin"].(string)
  7406. project.Pinyin = pinyin
  7407. wubi := projectM["wubi"].(string)
  7408. project.Wubi = wubi
  7409. statistical_classification := projectM["statistical_classification"].(string)
  7410. var statisticalClassification = "统计分类"
  7411. var statistical_classification_id int64
  7412. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  7413. if len(statistical_classification) != 0 {
  7414. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  7415. if classificationerrcodes == gorm.ErrRecordNotFound {
  7416. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  7417. dataconfig := models.DictDataconfig{
  7418. ParentId: classiFication.ID,
  7419. Module: "system",
  7420. OrgId: orgId,
  7421. Name: statistical_classification,
  7422. FieldName: "",
  7423. Value: classiFicationConfig.Value + 1,
  7424. CreatedTime: "",
  7425. UpdatedTime: "",
  7426. CreateUserId: adminUser.AdminUser.Id,
  7427. Status: 1,
  7428. Remark: "",
  7429. DeleteIdSystem: 0,
  7430. Title: "",
  7431. Content: "",
  7432. Order: 0,
  7433. Code: "",
  7434. }
  7435. service.CreatedDicConfig(&dataconfig)
  7436. }
  7437. }
  7438. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  7439. for _, it := range classiFicationList {
  7440. if statistical_classification == it.Name {
  7441. statistical_classification_id = int64(it.Value)
  7442. }
  7443. }
  7444. project.StatisticalClassification = statistical_classification_id
  7445. disease_directory := int64(projectM["disease_directory"].(float64))
  7446. project.DiseaseDirectory = disease_directory
  7447. is_record := int64(projectM["is_record"].(float64))
  7448. project.IsRecord = is_record
  7449. medical_code := projectM["medical_code"].(string)
  7450. project.MedicalCode = medical_code
  7451. tube_color := projectM["tube_color"].(string)
  7452. var tubeColor = "试管颜色"
  7453. var tube_color_id int64
  7454. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  7455. if len(tube_color) != 0 {
  7456. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  7457. if errcodetube == gorm.ErrRecordNotFound {
  7458. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  7459. dataconfig := models.DictDataconfig{
  7460. ParentId: tubeColorConfig.ID,
  7461. Module: "system",
  7462. OrgId: orgId,
  7463. Name: tube_color,
  7464. FieldName: "",
  7465. Value: tubeConfig.Value + 1,
  7466. CreatedTime: "",
  7467. UpdatedTime: "",
  7468. CreateUserId: adminUser.AdminUser.Id,
  7469. Status: 1,
  7470. Remark: "",
  7471. DeleteIdSystem: 0,
  7472. Title: "",
  7473. Content: "",
  7474. Order: 0,
  7475. Code: "",
  7476. }
  7477. service.CreatedDicConfig(&dataconfig)
  7478. }
  7479. }
  7480. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  7481. for _, it := range tubeColorList {
  7482. if tube_color == it.Name {
  7483. tube_color_id = int64(it.Value)
  7484. }
  7485. }
  7486. project.TubeColor = tube_color_id
  7487. single_dose := projectM["single_dose"].(string)
  7488. project.SingleDose = single_dose
  7489. execution_frequency := projectM["execution_frequency"].(string)
  7490. project.ExecutionFrequency = execution_frequency
  7491. delivery_way := projectM["delivery_way"].(string)
  7492. project.DeliveryWay = delivery_way
  7493. number_days := projectM["number_days"].(string)
  7494. project.NumberDays = number_days
  7495. total := projectM["total"].(string)
  7496. project.Total = total
  7497. medical_status := int64(projectM["medical_status"].(float64))
  7498. project.MedicalStatus = medical_status
  7499. category := int64(projectM["category"].(float64))
  7500. project.Category = category
  7501. specail_project := int64(projectM["specail_project"].(float64))
  7502. project.SpecailProject = specail_project
  7503. social_security_directory_code := projectM["social_security_directory_code"].(string)
  7504. project.SocialSecurityDirectoryCode = social_security_directory_code
  7505. remark := projectM["remark"].(string)
  7506. project.Remark = remark
  7507. record_date := projectM["record_date"].(string)
  7508. timeLayout := "2006-01-02"
  7509. loc, _ := time.LoadLocation("Local")
  7510. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7511. project.RecordDate = theTime.Unix()
  7512. projectList = append(projectList, &project)
  7513. }
  7514. export_time := time.Now().Unix()
  7515. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  7516. if len(projectList) > 0 {
  7517. for _, item := range projectList {
  7518. project := models.HisProject{
  7519. ProjectName: item.ProjectName,
  7520. Price: item.Price,
  7521. Unit: item.Unit,
  7522. CostClassify: item.CostClassify,
  7523. ExecutiveSection: item.ExecutiveSection,
  7524. MedicalCoverage: item.MedicalCoverage,
  7525. UserOrgId: orgId,
  7526. Status: 1,
  7527. CreatedTime: time.Now().Unix(),
  7528. Pinyin: item.Pinyin,
  7529. Wubi: item.Wubi,
  7530. StatisticalClassification: item.StatisticalClassification,
  7531. DiseaseDirectory: item.DiseaseDirectory,
  7532. IsRecord: item.IsRecord,
  7533. MedicalCode: item.MedicalCode,
  7534. TubeColor: item.TubeColor,
  7535. SingleDose: item.SingleDose,
  7536. DeliveryWay: item.DeliveryWay,
  7537. NumberDays: item.NumberDays,
  7538. Total: item.Total,
  7539. Category: item.Category,
  7540. MedicalStatus: item.MedicalStatus,
  7541. SpecailProject: item.SpecailProject,
  7542. RecordDate: item.RecordDate,
  7543. Remark: item.Remark,
  7544. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  7545. ExecutionFrequency: item.ExecutionFrequency,
  7546. }
  7547. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  7548. if errcodeproject == gorm.ErrRecordNotFound {
  7549. service.CreateProjectInfomation(&project)
  7550. } else if errcodeproject == nil {
  7551. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  7552. }
  7553. log := models.ExportLog{
  7554. LogType: 6,
  7555. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7556. TotalNum: int64(len(total_goods)),
  7557. FailNum: int64(len(errLogs)),
  7558. SuccessNum: int64(len(projectList)),
  7559. CreateTime: time.Now().Unix(),
  7560. UpdateTime: time.Now().Unix(),
  7561. ExportTime: export_time,
  7562. Status: 1,
  7563. }
  7564. service.CreateExportLog(&log)
  7565. c.ServeSuccessJSON(map[string]interface{}{
  7566. "msg": "导入成功",
  7567. "total_num": len(total_goods),
  7568. "success_num": len(projectList),
  7569. "fail_num": int64(len(errLogs)),
  7570. })
  7571. }
  7572. } else {
  7573. log := models.ExportLog{
  7574. LogType: 6,
  7575. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7576. TotalNum: int64(len(total_goods)),
  7577. FailNum: int64(len(errLogs)),
  7578. SuccessNum: int64(len(projectList)),
  7579. CreateTime: time.Now().Unix(),
  7580. UpdateTime: time.Now().Unix(),
  7581. ExportTime: export_time,
  7582. Status: 1,
  7583. }
  7584. service.CreateExportLog(&log)
  7585. c.ServeSuccessJSON(map[string]interface{}{
  7586. "msg": "导入成功",
  7587. "total_num": len(total_goods),
  7588. "success_num": len(projectList),
  7589. "fail_num": int64(len(errLogs)),
  7590. })
  7591. }
  7592. }
  7593. //func (this *HisApiController) EditProjectInformation(){
  7594. //
  7595. // id, _ := this.GetInt64("id")
  7596. // project_team := this.GetString("project_team")
  7597. // price := this.GetString("price")
  7598. // price_float, _ := strconv.ParseFloat(price, 64)
  7599. // pinyin := this.GetString("pinyin")
  7600. // wubi := this.GetString("wubi")
  7601. // tube_color, _ := this.GetInt64("tube_color")
  7602. // team_type, _ := this.GetInt64("team_type")
  7603. // remark := this.GetString("remark")
  7604. // ids := this.GetString("ids")
  7605. // item_id := this.GetString("item_id")
  7606. // projectTeam := models.XtHisProjectTeam{
  7607. // ProjectTeam: project_team,
  7608. // Price: price_float,
  7609. // Pinyin: pinyin,
  7610. // Wubi: wubi,
  7611. // TubeColor: tube_color,
  7612. // TeamType: team_type,
  7613. // Remark: remark,
  7614. // ProjectId: ids,
  7615. // ItemId: item_id,
  7616. // }
  7617. //
  7618. //
  7619. // dataBody := make(map[string]interface{}, 0)
  7620. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  7621. // if err != nil {
  7622. // utils.ErrorLog(err.Error())
  7623. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7624. // return
  7625. // }
  7626. //
  7627. // err = service.UpdatedProjectTeam(id, &projectTeam)
  7628. //
  7629. //
  7630. // if err != nil {
  7631. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  7632. // return
  7633. // }
  7634. //
  7635. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  7636. // infos, _ := dataBody["info"].([]interface{})
  7637. // if len(infos) > 0 {
  7638. // var ids []string
  7639. //
  7640. // for _, item := range infos {
  7641. // items := item.(map[string]interface{})
  7642. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  7643. // utils.ErrorLog("id")
  7644. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7645. // return
  7646. // }
  7647. // id := int64(items["id"].(float64))
  7648. //
  7649. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  7650. // utils.ErrorLog("type")
  7651. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7652. // return
  7653. // }
  7654. // types := int64(items["type"].(float64))
  7655. //
  7656. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  7657. // utils.ErrorLog("number")
  7658. // }
  7659. //
  7660. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  7661. //
  7662. // projectList := models.XtHisProjectList{
  7663. // Number: number,
  7664. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  7665. // ProjectId: id,
  7666. // Status: 1,
  7667. // CreatedTime: time.Now().Unix(),
  7668. // UpdatedTime: time.Now().Unix(),
  7669. // TeamId: projectTeam.ID,
  7670. // Type: types,
  7671. // }
  7672. // list := projectList
  7673. //
  7674. // service.CreateProjectList(&list)
  7675. //
  7676. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  7677. //
  7678. // }
  7679. // ids_str := strings.Join(ids, ",")
  7680. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  7681. // service.SaveProjectTeam(&projectTeam)
  7682. // this.ServeSuccessJSON(map[string]interface{}{
  7683. // "projectTeam": projectTeam,
  7684. // })
  7685. // }
  7686. // }
  7687. //}
  7688. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  7689. name := c.GetString("name")
  7690. mode_id, _ := c.GetInt64("mode", 0)
  7691. types, _ := c.GetInt64("type", 0)
  7692. patient_id, _ := c.GetInt64("patient_id", 0)
  7693. types = 1
  7694. adminInfo := c.GetAdminUserInfo()
  7695. template := &models.HisPrescriptionTemplate{
  7696. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  7697. PatientId: patient_id,
  7698. Type: types,
  7699. Status: 1,
  7700. Ctime: time.Now().Unix(),
  7701. Mtime: time.Now().Unix(),
  7702. Name: name,
  7703. Mode: mode_id,
  7704. }
  7705. dataBody := make(map[string]interface{}, 0)
  7706. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  7707. if err != nil {
  7708. utils.ErrorLog(err.Error())
  7709. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7710. return
  7711. }
  7712. err = service.CreateHisPrescriptionTemplate(template)
  7713. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  7714. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  7715. if len(prescriptions) > 0 {
  7716. for _, item := range prescriptions {
  7717. items := item.(map[string]interface{})
  7718. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  7719. utils.ErrorLog("type")
  7720. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7721. return
  7722. }
  7723. types := int64(items["type"].(float64))
  7724. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  7725. utils.ErrorLog("med_type")
  7726. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7727. return
  7728. }
  7729. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  7730. ctime := time.Now().Unix()
  7731. prescription := &models.HisPrescriptionInfoTemplate{
  7732. PatientId: patient_id,
  7733. UserOrgId: adminInfo.CurrentOrgId,
  7734. Ctime: ctime,
  7735. Mtime: ctime,
  7736. Type: types,
  7737. Modifier: adminInfo.AdminUser.Id,
  7738. Creator: adminInfo.AdminUser.Id,
  7739. Status: 1,
  7740. PTemplateId: template.ID,
  7741. MedType: med_type,
  7742. }
  7743. service.CreateHisPrescriptionInfoTemplate(prescription)
  7744. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  7745. advices := items["advices"].([]interface{})
  7746. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  7747. ctime := time.Now().Unix()
  7748. mtime := ctime
  7749. if len(advices) > 0 {
  7750. for _, advice := range advices {
  7751. var s models.HisPrescriptionAdviceTemplate
  7752. s.PrescriptionId = prescription.ID
  7753. s.AdviceType = 2
  7754. s.StopState = 2
  7755. s.ExecutionState = 2
  7756. s.Status = 1
  7757. s.UserOrgId = adminInfo.CurrentOrgId
  7758. s.CreatedTime = ctime
  7759. s.UpdatedTime = mtime
  7760. s.PatientId = patient_id
  7761. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  7762. if errcode > 0 {
  7763. c.ServeFailJSONWithSGJErrorCode(errcode)
  7764. return
  7765. }
  7766. service.CreateHisPrescriptionAdviceTemplate(&s)
  7767. }
  7768. }
  7769. }
  7770. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  7771. projects := items["project"].([]interface{})
  7772. if len(projects) > 0 {
  7773. for _, project := range projects {
  7774. var p models.HisPrescriptionProjectTemplate
  7775. p.PrescriptionId = prescription.ID
  7776. p.Ctime = time.Now().Unix()
  7777. p.Mtime = time.Now().Unix()
  7778. p.PatientId = patient_id
  7779. p.UserOrgId = adminInfo.CurrentOrgId
  7780. p.Status = 1
  7781. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  7782. if errcode > 0 {
  7783. c.ServeFailJSONWithSGJErrorCode(errcode)
  7784. return
  7785. }
  7786. service.CreateHisPrescriptionProjectTemplate(&p)
  7787. }
  7788. }
  7789. }
  7790. }
  7791. c.ServeSuccessJSON(map[string]interface{}{
  7792. "msg": "创建成功",
  7793. })
  7794. }
  7795. }
  7796. }
  7797. func (c *HisApiController) PreSettle() {
  7798. id, _ := c.GetInt64("id")
  7799. record_time := c.GetString("record_time")
  7800. his_patient_id, _ := c.GetInt64("his_patient_id")
  7801. timeLayout := "2006-01-02"
  7802. loc, _ := time.LoadLocation("Local")
  7803. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7804. diagnosis_id := c.GetString("diagnosis")
  7805. sick_type, _ := c.GetInt64("sick_type")
  7806. reg_type, _ := c.GetInt64("p_type")
  7807. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  7808. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7809. if err != nil {
  7810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7811. return
  7812. }
  7813. recordDateTime := theTime.Unix()
  7814. adminUser := c.GetAdminUserInfo()
  7815. var prescriptions []*models.HisPrescription
  7816. var start_time int64
  7817. var end_time int64
  7818. ids_str := c.GetString("ids")
  7819. ids_arr := strings.Split(ids_str, ",")
  7820. fmt.Println(reg_type)
  7821. if settle_accounts_type == 1 { //日结
  7822. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7823. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  7824. } else {
  7825. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  7826. }
  7827. fmt.Println(prescriptions)
  7828. } else { //月结
  7829. start_time_str := c.GetString("start_time")
  7830. end_time_str := c.GetString("end_time")
  7831. timeLayout := "2006-01-02"
  7832. loc, _ := time.LoadLocation("Local")
  7833. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7834. if err != nil {
  7835. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7836. return
  7837. }
  7838. recordStartTime := theStartTime.Unix()
  7839. start_time = recordStartTime
  7840. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7841. if err != nil {
  7842. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7843. return
  7844. }
  7845. recordEndTime := theEndTime.Unix()
  7846. end_time = recordEndTime
  7847. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  7848. }
  7849. if reg_type == 1111 || reg_type == 1112 {
  7850. reg_type = 11
  7851. }
  7852. timestamp := time.Now().Unix()
  7853. tempTime := time.Unix(timestamp, 0)
  7854. timeFormat := tempTime.Format("20060102150405")
  7855. chrgBchno := rand.Intn(100000) + 10000
  7856. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7857. strconv.FormatInt(his.PatientId, 10)
  7858. var ids []int64
  7859. for _, item := range prescriptions {
  7860. ids = append(ids, item.ID)
  7861. }
  7862. fmt.Println(ids)
  7863. var total float64
  7864. for _, item := range prescriptions {
  7865. fmt.Println(item)
  7866. if item.Type == 1 { //药品
  7867. for _, subItem := range item.HisDoctorAdviceInfo {
  7868. total = total + (subItem.Price * subItem.PrescribingNumber)
  7869. }
  7870. }
  7871. if item.Type == 2 { //项目
  7872. for _, subItem := range item.HisPrescriptionProject {
  7873. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7874. total = total + (subItem.Price * cnt)
  7875. }
  7876. }
  7877. for _, subItem := range item.HisAdditionalCharge {
  7878. total = total + (subItem.Price * float64(subItem.Count))
  7879. }
  7880. }
  7881. allTotal := fmt.Sprintf("%.2f", total)
  7882. totals, _ := strconv.ParseFloat(allTotal, 64)
  7883. order := &models.HisOrder{
  7884. UserOrgId: adminUser.CurrentOrgId,
  7885. HisPatientId: his.ID,
  7886. PatientId: id,
  7887. SettleAccountsDate: recordDateTime,
  7888. Ctime: time.Now().Unix(),
  7889. Mtime: time.Now().Unix(),
  7890. Status: 1,
  7891. OrderStatus: 1,
  7892. MdtrtId: his.Number,
  7893. Number: chrg_bchno,
  7894. MedfeeSumamt: totals,
  7895. SettleEndTime: end_time,
  7896. SettleStartTime: start_time,
  7897. SettleType: settle_accounts_type,
  7898. PsnPartAmt: totals,
  7899. PsnCashPay: totals,
  7900. PType: 2,
  7901. IsPre: 1,
  7902. MedType: strconv.Itoa(int(reg_type)),
  7903. Diagnosis: diagnosis_id,
  7904. }
  7905. err = service.CreateOrder(order)
  7906. if err != nil {
  7907. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7908. return
  7909. }
  7910. var customs []*Custom
  7911. for _, item := range prescriptions {
  7912. fmt.Println(item.Type)
  7913. if item.Type == 1 { //药品
  7914. for _, subItem := range item.HisDoctorAdviceInfo {
  7915. cus := &Custom{
  7916. AdviceId: subItem.ID,
  7917. ProjectId: 0,
  7918. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  7919. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  7920. FeedetlSn: subItem.FeedetlSn,
  7921. Price: fmt.Sprintf("%.2f", subItem.Price),
  7922. MedListCodg: subItem.MedListCodg,
  7923. Type: 1,
  7924. }
  7925. customs = append(customs, cus)
  7926. }
  7927. }
  7928. if item.Type == 2 { //项目
  7929. for _, subItem := range item.HisPrescriptionProject {
  7930. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7931. cus := &Custom{
  7932. AdviceId: 0,
  7933. ProjectId: subItem.ID,
  7934. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  7935. Cut: fmt.Sprintf("%.2f", cnt),
  7936. FeedetlSn: subItem.FeedetlSn,
  7937. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  7938. MedListCodg: subItem.MedListCodg,
  7939. Type: 2,
  7940. }
  7941. customs = append(customs, cus)
  7942. }
  7943. }
  7944. for _, item := range item.HisAdditionalCharge {
  7945. cus := &Custom{
  7946. ItemId: item.ID,
  7947. AdviceId: 0,
  7948. ProjectId: 0,
  7949. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  7950. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  7951. FeedetlSn: item.FeedetlSn,
  7952. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  7953. MedListCodg: item.XtHisAddtionConfig.Code,
  7954. Type: 3,
  7955. }
  7956. customs = append(customs, cus)
  7957. }
  7958. }
  7959. fmt.Println(customs)
  7960. for _, item := range customs {
  7961. var advice_id int64 = 0
  7962. var project_id int64 = 0
  7963. var item_id int64 = 0
  7964. var types int64 = 0
  7965. if item.Type == 1 {
  7966. advice_id = item.AdviceId
  7967. project_id = 0
  7968. item_id = 0
  7969. } else if item.Type == 2 {
  7970. advice_id = 0
  7971. item_id = 0
  7972. project_id = item.ProjectId
  7973. } else if item.Type == 3 {
  7974. advice_id = 0
  7975. item_id = item.ItemId
  7976. project_id = 0
  7977. }
  7978. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7979. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7980. pric, _ := strconv.ParseFloat(item.Price, 32)
  7981. info := &models.HisOrderInfo{
  7982. OrderNumber: order.Number,
  7983. UploadDate: time.Now().Unix(),
  7984. AdviceId: advice_id,
  7985. DetItemFeeSumamt: detItemFeeSumamt,
  7986. Cnt: cut,
  7987. Pric: pric,
  7988. PatientId: id,
  7989. Status: 1,
  7990. Mtime: time.Now().Unix(),
  7991. Ctime: time.Now().Unix(),
  7992. UserOrgId: adminUser.CurrentOrgId,
  7993. HisPatientId: his.ID,
  7994. OrderId: order.ID,
  7995. ProjectId: project_id,
  7996. Type: types,
  7997. ItemId: item_id,
  7998. }
  7999. service.CreateOrderInfo(info)
  8000. }
  8001. his.SickType = sick_type
  8002. service.UpdataHisPateint(&his)
  8003. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  8004. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  8005. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  8006. if err == nil {
  8007. c.ServeSuccessJSON(map[string]interface{}{
  8008. "msg": "结算成功",
  8009. })
  8010. }
  8011. }
  8012. type CustomOrderInfo struct {
  8013. Name string
  8014. Spec string
  8015. Unit string
  8016. Count float64
  8017. Price float64
  8018. Total float64
  8019. }
  8020. func (c *HisApiController) GetPrivateExpensesInfo() {
  8021. order_id, _ := c.GetInt64("id", 0)
  8022. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  8023. order, _ := service.GetHisOrderByID(order_id)
  8024. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  8025. if order.ID == 0 {
  8026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8027. return
  8028. }
  8029. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  8030. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  8031. org_id := c.GetAdminUserInfo().CurrentOrgId
  8032. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8033. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8034. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  8035. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  8036. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  8037. var orderInfos_four []*models.HisOrderInfoTwo
  8038. for _, item := range orderInfos_three {
  8039. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  8040. item.HisPrescriptionProject.IsCheckTeam = 1
  8041. orderInfos_four = append(orderInfos_four, item)
  8042. }
  8043. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  8044. item.HisPrescriptionProject.IsCheckTeam = 2
  8045. orderInfos_two = append(orderInfos_two, item)
  8046. }
  8047. }
  8048. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  8049. var cus_slice []CustomOrderInfo
  8050. for _, item := range new_order_info {
  8051. var cus CustomOrderInfo
  8052. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  8053. cus.Unit = ""
  8054. cus.Spec = ""
  8055. var total float64
  8056. for _, subItem := range orderInfos_four {
  8057. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  8058. total = total + subItem.DetItemFeeSumamt
  8059. fmt.Println(subItem.DetItemFeeSumamt)
  8060. }
  8061. }
  8062. cus.Count = 1
  8063. cus.Total = total
  8064. cus_slice = append(cus_slice, cus)
  8065. }
  8066. orderInfos = append(orderInfos, orderInfos_two...)
  8067. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  8068. orderInfos = append(orderInfos, orderInfos_three...)
  8069. }
  8070. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  8071. c.ServeSuccessJSON(map[string]interface{}{
  8072. "order": order,
  8073. "order_info": orderInfos,
  8074. "patient": patient,
  8075. "admin_info": adminInfo,
  8076. "his": his,
  8077. "current_admin": role,
  8078. "org_config": miConfig,
  8079. "new_order_info": cus_slice,
  8080. })
  8081. }
  8082. func (this *HisApiController) ChangeMedType() {
  8083. med_type := this.GetString("med_type")
  8084. old_med_type := this.GetString("old_med_type")
  8085. ids := this.GetString("ids")
  8086. settle_type, _ := this.GetInt64("settle_type")
  8087. start_time := this.GetString("start_time")
  8088. end_time := this.GetString("end_time")
  8089. ids_arr := strings.Split(ids, ",")
  8090. if settle_type == 1 { //日结
  8091. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  8092. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  8093. prescription.MedType = med_type
  8094. err := service.SaveHisPrescription(&prescription)
  8095. if err == nil {
  8096. this.ServeSuccessJSON(map[string]interface{}{
  8097. "msg": "修改成功",
  8098. })
  8099. } else {
  8100. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8101. return
  8102. }
  8103. } else if settle_type == 2 {
  8104. timeLayout := "2006-01-02"
  8105. loc, _ := time.LoadLocation("Local")
  8106. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8107. if err != nil {
  8108. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8109. return
  8110. }
  8111. recordStartTime := theStartTime.Unix()
  8112. start_time_timestamp := recordStartTime
  8113. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  8114. if err != nil {
  8115. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8116. return
  8117. }
  8118. recordEndTime := theEndTime.Unix()
  8119. end_time_timestamp := recordEndTime
  8120. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  8121. if updateErr == nil {
  8122. this.ServeSuccessJSON(map[string]interface{}{
  8123. "msg": "修改成功",
  8124. })
  8125. } else {
  8126. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8127. return
  8128. }
  8129. }
  8130. }
  8131. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  8132. patient_id, _ := c.GetInt64("patient_id")
  8133. his_patient_id, _ := c.GetInt64("his_patient_id")
  8134. record_date := c.GetString("record_date")
  8135. start_time := c.GetString("start_time")
  8136. end_time := c.GetString("end_time")
  8137. order_status, _ := c.GetInt64("type", 0)
  8138. p_type, _ := c.GetInt64("p_type", 0)
  8139. order_id, _ := c.GetInt64("order_id", 0)
  8140. timeLayout := "2006-01-02"
  8141. loc, _ := time.LoadLocation("Local")
  8142. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8143. if err != nil {
  8144. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8145. return
  8146. }
  8147. recordDateTime := theTime.Unix()
  8148. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8149. if err != nil {
  8150. }
  8151. startRecordDateTime := startTime.Unix()
  8152. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8153. if err != nil {
  8154. }
  8155. endRecordDateTime := endTime.Unix()
  8156. admin := c.GetAdminUserInfo()
  8157. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8158. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8159. order, _ := service.GetHisOrderByID(order_id)
  8160. var monthPrescriptions []*models.HisPrescription
  8161. if order_status == 1 || order_status == 0 {
  8162. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8163. } else if order_status == 2 {
  8164. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8165. }
  8166. var settle_total float64
  8167. for _, item := range monthPrescriptions {
  8168. if len(item.HisPrescriptionProject) > 0 {
  8169. for _, subItem := range item.HisPrescriptionProject {
  8170. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8171. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8172. settle_total = settle_total + total
  8173. }
  8174. }
  8175. if len(item.HisDoctorAdviceInfo) > 0 {
  8176. for _, subItem := range item.HisDoctorAdviceInfo {
  8177. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8178. settle_total = settle_total + total
  8179. }
  8180. }
  8181. }
  8182. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8183. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8184. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8185. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8186. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8187. //获取所有科室信息
  8188. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8189. c.ServeSuccessJSON(map[string]interface{}{
  8190. "his_info": his_patient_info,
  8191. "xt_info": xt_patient_info,
  8192. "case_history": case_history,
  8193. "info": patientPrescriptionInfo,
  8194. "last_info": lastPatientPrescriptionInfo,
  8195. "month_prescriptions": monthPrescriptions,
  8196. "order": order,
  8197. "doctors": doctors,
  8198. "department": department,
  8199. "settle_total": settle_total,
  8200. })
  8201. return
  8202. }
  8203. func (c *HisApiController) GetHisMonthPatientInfo() {
  8204. patient_id, _ := c.GetInt64("patient_id")
  8205. his_patient_id, _ := c.GetInt64("his_patient_id")
  8206. record_date := c.GetString("record_date")
  8207. number := c.GetString("number")
  8208. start_time := c.GetString("start_time")
  8209. end_time := c.GetString("end_time")
  8210. p_type, _ := c.GetInt64("p_type")
  8211. timeLayout := "2006-01-02"
  8212. loc, _ := time.LoadLocation("Local")
  8213. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8214. if err != nil {
  8215. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8216. return
  8217. }
  8218. recordDateTime := theTime.Unix()
  8219. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8220. if err != nil {
  8221. }
  8222. startRecordDateTime := startTime.Unix()
  8223. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8224. if err != nil {
  8225. }
  8226. endRecordDateTime := endTime.Unix()
  8227. admin := c.GetAdminUserInfo()
  8228. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  8229. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8230. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  8231. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8232. var settle_total float64
  8233. for _, item := range monthPrescriptions {
  8234. if len(item.HisPrescriptionProject) > 0 {
  8235. for _, subItem := range item.HisPrescriptionProject {
  8236. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8237. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8238. settle_total = settle_total + total
  8239. }
  8240. }
  8241. if len(item.HisDoctorAdviceInfo) > 0 {
  8242. for _, subItem := range item.HisDoctorAdviceInfo {
  8243. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8244. settle_total = settle_total + total
  8245. }
  8246. }
  8247. }
  8248. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8249. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8250. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8251. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8252. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  8253. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8254. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  8255. //获取所有科室信息
  8256. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8257. c.ServeSuccessJSON(map[string]interface{}{
  8258. "his_info": his_patient_info,
  8259. "xt_info": xt_patient_info,
  8260. "case_history": case_history,
  8261. "info": patientPrescriptionInfo,
  8262. "month_prescriptions": monthPrescriptions,
  8263. "order": order,
  8264. "doctors": doctors,
  8265. "department": department,
  8266. "count": count,
  8267. "drugStockConfig": drugStockConfig,
  8268. "last_info": lastPatientPrescriptionInfo,
  8269. "settle_total": settle_total,
  8270. })
  8271. return
  8272. }
  8273. func (c *HisApiController) GetAllOrder() {
  8274. org_id := c.GetAdminUserInfo().CurrentOrgId
  8275. orders, _ := service.GetNewHisOrderList(org_id)
  8276. c.ServeSuccessJSON(map[string]interface{}{
  8277. "order": orders,
  8278. })
  8279. return
  8280. }
  8281. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  8282. newArr = make([]*models.HisOrderInfoTwo, 0)
  8283. for i := 0; i < len(arr); i++ {
  8284. repeat := false
  8285. for j := i + 1; j < len(arr); j++ {
  8286. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  8287. repeat = true
  8288. break
  8289. }
  8290. }
  8291. if !repeat {
  8292. newArr = append(newArr, arr[i])
  8293. }
  8294. }
  8295. return
  8296. }
  8297. // 修改处方退库操作 参数传修改之前的处方数据
  8298. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  8299. if advice.ExecutionState == 1 {
  8300. //查询该病人该药品是否有库存记录
  8301. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  8302. if errcode == gorm.ErrRecordNotFound {
  8303. } else {
  8304. //退库
  8305. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  8306. if advice.PrescribingNumberUnit == drug.MinUnit {
  8307. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8308. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8309. //退库
  8310. warehouseInfo := models.DrugWarehouseInfo{
  8311. StockMinNumber: prescribingNumber,
  8312. }
  8313. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  8314. operation_time := time.Now().Unix()
  8315. creater := advice.AdviceDoctor
  8316. ctime := time.Now().Unix()
  8317. timeStr := time.Now().Format("2006-01-02")
  8318. timeArr := strings.Split(timeStr, "-")
  8319. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8320. total = total + 1
  8321. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8322. cancelStock := models.DrugCancelStock{
  8323. OrderNumber: orderNumber,
  8324. OperaTime: operation_time,
  8325. OrgId: advice.UserOrgId,
  8326. Creater: creater,
  8327. Ctime: ctime,
  8328. Status: 1,
  8329. ReturnTime: advice.AdviceDate,
  8330. Dealer: info.Dealer,
  8331. Manufacturer: info.Manufacturer,
  8332. Type: 1,
  8333. }
  8334. service.AddSigleDrugCancelStock(&cancelStock)
  8335. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8336. dealer, _ := service.GetDealerById(info.Dealer)
  8337. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8338. cancelStockInfo := models.DrugCancelStockInfo{
  8339. OrderNumber: cancelInfo.OrderNumber,
  8340. CancelStockId: cancelInfo.ID,
  8341. DrugId: info.DrugId,
  8342. Count: info.Count,
  8343. Status: 1,
  8344. Ctime: ctime,
  8345. OrgId: advice.UserOrgId,
  8346. Type: 1,
  8347. Manufacturer: manufactureName.ManufacturerName,
  8348. Dealer: dealer.DealerName,
  8349. Total: 0,
  8350. RetailPrice: info.RetailPrice,
  8351. RetailTotalPrice: info.RetailTotalPrice,
  8352. Price: info.Price,
  8353. RegisterAccount: "",
  8354. Remark: info.Remark,
  8355. BatchNumber: info.BatchNumber,
  8356. MaxUnit: info.CountUnit,
  8357. ProductDate: info.ProductDate,
  8358. ExpiryDate: info.ExpiryDate,
  8359. BatchNumberId: info.WarehouseInfoId,
  8360. }
  8361. flow := models.DrugFlow{
  8362. WarehousingId: 0,
  8363. DrugId: info.DrugId,
  8364. Number: "",
  8365. BatchNumber: info.BatchNumber,
  8366. Count: info.Count,
  8367. UserOrgId: advice.UserOrgId,
  8368. PatientId: 0,
  8369. SystemTime: ctime,
  8370. ConsumableType: 4,
  8371. IsSys: 0,
  8372. WarehousingOrder: "",
  8373. WarehouseOutId: 0,
  8374. WarehouseOutOrderNumber: "",
  8375. IsEdit: 0,
  8376. CancelStockId: cancelStock.ID,
  8377. CancelOrderNumber: cancelStock.OrderNumber,
  8378. Manufacturer: info.Manufacturer,
  8379. Dealer: info.Dealer,
  8380. Creator: advice.UserOrgId,
  8381. UpdateCreator: 0,
  8382. Status: 1,
  8383. Ctime: time.Now().Unix(),
  8384. Mtime: 0,
  8385. Price: info.Price,
  8386. WarehousingDetailId: 0,
  8387. WarehouseOutDetailId: 0,
  8388. CancelOutDetailId: 0,
  8389. ExpireDate: info.ExpiryDate,
  8390. ProductDate: info.ProductDate,
  8391. MaxUnit: info.CountUnit,
  8392. MinUnit: "",
  8393. }
  8394. service.CreatedCancelStock(cancelStockInfo)
  8395. service.CreateDrugFlowOne(flow)
  8396. } else {
  8397. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  8398. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  8399. if advice.PrescribingNumberUnit == drug.MaxUnit {
  8400. warehouseInfo := models.DrugWarehouseInfo{
  8401. StockMinNumber: prescribingNumber,
  8402. }
  8403. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  8404. }
  8405. operation_time := time.Now().Unix()
  8406. creater := advice.AdviceDoctor
  8407. ctime := time.Now().Unix()
  8408. timeStr := time.Now().Format("2006-01-02")
  8409. timeArr := strings.Split(timeStr, "-")
  8410. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  8411. total = total + 1
  8412. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  8413. cancelStock := models.DrugCancelStock{
  8414. OrderNumber: orderNumber,
  8415. OperaTime: operation_time,
  8416. OrgId: advice.UserOrgId,
  8417. Creater: creater,
  8418. Ctime: ctime,
  8419. Status: 1,
  8420. ReturnTime: advice.AdviceDate,
  8421. Dealer: info.Dealer,
  8422. Manufacturer: info.Manufacturer,
  8423. Type: 1,
  8424. }
  8425. service.AddSigleDrugCancelStock(&cancelStock)
  8426. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  8427. dealer, _ := service.GetDealerById(info.Dealer)
  8428. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  8429. cancelStockInfo := models.DrugCancelStockInfo{
  8430. OrderNumber: cancelInfo.OrderNumber,
  8431. CancelStockId: cancelInfo.ID,
  8432. DrugId: info.DrugId,
  8433. Count: info.Count,
  8434. Status: 1,
  8435. Ctime: ctime,
  8436. OrgId: advice.UserOrgId,
  8437. Type: 1,
  8438. Manufacturer: manufactureName.ManufacturerName,
  8439. Dealer: dealer.DealerName,
  8440. Total: 0,
  8441. RetailPrice: info.RetailPrice,
  8442. RetailTotalPrice: info.RetailTotalPrice,
  8443. Price: info.Price,
  8444. RegisterAccount: "",
  8445. Remark: info.Remark,
  8446. BatchNumber: info.BatchNumber,
  8447. MaxUnit: info.CountUnit,
  8448. ProductDate: info.ProductDate,
  8449. ExpiryDate: info.ExpiryDate,
  8450. BatchNumberId: info.WarehouseInfoId,
  8451. }
  8452. flow := models.DrugFlow{
  8453. WarehousingId: 0,
  8454. DrugId: info.DrugId,
  8455. Number: "",
  8456. BatchNumber: info.BatchNumber,
  8457. Count: info.Count,
  8458. UserOrgId: advice.UserOrgId,
  8459. PatientId: 0,
  8460. SystemTime: ctime,
  8461. ConsumableType: 4,
  8462. IsSys: 0,
  8463. WarehousingOrder: "",
  8464. WarehouseOutId: 0,
  8465. WarehouseOutOrderNumber: "",
  8466. IsEdit: 0,
  8467. CancelStockId: cancelStock.ID,
  8468. CancelOrderNumber: cancelStock.OrderNumber,
  8469. Manufacturer: info.Manufacturer,
  8470. Dealer: info.Dealer,
  8471. Creator: advice.AdviceDoctor,
  8472. UpdateCreator: 0,
  8473. Status: 1,
  8474. Ctime: time.Now().Unix(),
  8475. Mtime: 0,
  8476. Price: info.Price,
  8477. WarehousingDetailId: 0,
  8478. WarehouseOutDetailId: 0,
  8479. CancelOutDetailId: 0,
  8480. ExpireDate: info.ExpiryDate,
  8481. ProductDate: info.ProductDate,
  8482. MaxUnit: info.CountUnit,
  8483. MinUnit: "",
  8484. }
  8485. service.CreatedCancelStock(cancelStockInfo)
  8486. service.CreateDrugFlowOne(flow)
  8487. }
  8488. }
  8489. }
  8490. return err
  8491. }
  8492. func (this *HisApiController) DeleteNCDS() {
  8493. id, _ := this.GetInt64("id", 0)
  8494. if id > 0 {
  8495. service.DeletePsnNCDSRecordById(id)
  8496. this.ServeSuccessJSON(map[string]interface{}{
  8497. "msg": "删除成功",
  8498. })
  8499. } else {
  8500. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  8501. return
  8502. }
  8503. }
  8504. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  8505. id, _ := c.GetInt64("id")
  8506. advice, _ := service.GetHisDoctorAdviceInfo(id)
  8507. c.ServeSuccessJSON(map[string]interface{}{
  8508. "advice": advice,
  8509. })
  8510. return
  8511. }
  8512. func (c *HisApiController) GetHisMonthChargePatientList() {
  8513. record_date := c.GetString("record_date")
  8514. start_time := c.GetString("start_time")
  8515. end_time := c.GetString("end_time")
  8516. timeLayout := "2006-01-02"
  8517. loc, _ := time.LoadLocation("Local")
  8518. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8519. if err != nil {
  8520. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8521. return
  8522. }
  8523. if err != nil {
  8524. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8525. return
  8526. }
  8527. recordDateTime := theTime.Unix()
  8528. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8529. if err != nil {
  8530. }
  8531. startRecordDateTime := startTime.Unix()
  8532. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8533. if err != nil {
  8534. }
  8535. endRecordDateTime := endTime.Unix()
  8536. adminInfo := c.GetAdminUserInfo()
  8537. var tempMonthChargePatients []*service.MonthChargePatients
  8538. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  8539. for _, item := range tempPatients {
  8540. //过滤没有处方的
  8541. if len(item.HisPrescription) == 0 {
  8542. tempMonthChargePatients = append(tempMonthChargePatients, item)
  8543. }
  8544. }
  8545. c.ServeSuccessJSON(map[string]interface{}{
  8546. "list": tempMonthChargePatients,
  8547. })
  8548. }