his_api_controller.go 366KB

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