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