his_api_controller.go 500KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "math/rand"
  6. "reflect"
  7. "strconv"
  8. "strings"
  9. "syscall"
  10. "time"
  11. "unsafe"
  12. "XT_New/enums"
  13. "XT_New/models"
  14. "XT_New/service"
  15. "XT_New/utils"
  16. "github.com/astaxie/beego"
  17. "github.com/jinzhu/gorm"
  18. "github.com/mozillazg/go-pinyin"
  19. "github.com/shopspring/decimal"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. //beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  82. beego.Router("/api/monthcharge/list", &HisApiController{}, "get:GetHisMonthChargePatientList")
  83. beego.Router("/api/test/get", &HisApiController{}, "get:GetTestOrder")
  84. beego.Router("/api/batch/settleaccount", &HisApiController{}, "get:GetBatchSettleAccounts")
  85. beego.Router("/api/monthhispatient", &HisApiController{}, "get:GetMonthHisPatient")
  86. beego.Router("/api/changeorderdesc", &HisApiController{}, "get:ChangeOrderDesc")
  87. beego.Router("/api/getfapiaonumber", &HisApiController{}, "get:GetFaPiaoNumber")
  88. beego.Router("/api/associationprescription", &HisApiController{}, "get:AssociationHisPrescription")
  89. beego.Router("/api/checkhispatient", &HisApiController{}, "get:CheckHisPatient")
  90. beego.Router("/api/hisorder/listtwo", &HisApiController{}, "get:GetHisOrderListTwo")
  91. }
  92. func (c *HisApiController) CheckHisPatient() {
  93. record_date := c.GetString("record_date")
  94. patient_id, _ := c.GetInt64("patient_id")
  95. timeLayout := "2006-01-02"
  96. loc, _ := time.LoadLocation("Local")
  97. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  98. if err != nil {
  99. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  100. return
  101. }
  102. recordDateTime := theTime.Unix()
  103. adminInfo := c.GetAdminUserInfo()
  104. patients, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  105. if len(patients) > 1 {
  106. ps, _ := service.GetHisPrescriptionByHisPatientID(recordDateTime, adminInfo.CurrentOrgId, patient_id)
  107. if len(ps) > 0 && len(ps[0].VMHisPrescription) > 0 {
  108. c.ServeSuccessJSON(map[string]interface{}{
  109. "status": 1,
  110. "msg": "关联",
  111. "ps": ps,
  112. "his_patient_id": patients[len(patients)-1].ID,
  113. "patient_id": patients[len(patients)-1].PatientId,
  114. })
  115. } else {
  116. c.ServeSuccessJSON(map[string]interface{}{
  117. "status": 0,
  118. "msg": "无需关联",
  119. })
  120. }
  121. } else {
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "status": 0,
  124. "msg": "无需关联",
  125. })
  126. return
  127. }
  128. }
  129. func (c *HisApiController) AssociationHisPrescription() {
  130. record_date := c.GetString("record_date")
  131. his_patient_id, _ := c.GetInt64("his_patient_id")
  132. patient_id, _ := c.GetInt64("patient_id")
  133. p_ids := c.GetString("p_ids")
  134. p_ids_arr := strings.Split(p_ids, ",")
  135. timeLayout := "2006-01-02"
  136. loc, _ := time.LoadLocation("Local")
  137. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  138. if err != nil {
  139. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  140. return
  141. }
  142. recordDateTime := theTime.Unix()
  143. his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  144. if his_patient_id == 0 || his_patient.ID == 0 {
  145. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  146. return
  147. }
  148. err = service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  149. if err == nil {
  150. c.ServeSuccessJSON(map[string]interface{}{
  151. "msg": "关联处方成功",
  152. })
  153. return
  154. } else {
  155. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  156. return
  157. }
  158. }
  159. //func (c *HisApiController) AssociationHisPrescription() {
  160. // record_date, _ := c.GetInt64("record_date")
  161. // his_patient_id, _ := c.GetInt64("his_patient_id")
  162. // patient_id, _ := c.GetInt64("patient_id")
  163. // p_ids := c.GetString("p_ids")
  164. // p_ids_arr := strings.Split(p_ids, ",")
  165. // his_patient, _ := service.GetHisPatientByIdThree(his_patient_id)
  166. // if his_patient_id == 0 || his_patient.ID == 0 {
  167. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  168. // return
  169. // }
  170. // err := service.UpdateHisPrescriptionHisIDByPID(his_patient_id, patient_id, record_date, c.GetAdminUserInfo().CurrentOrgId, p_ids_arr)
  171. // if err == nil {
  172. // c.ServeSuccessJSON(map[string]interface{}{
  173. // "msg": "关联处方成功",
  174. // })
  175. // return
  176. // } else {
  177. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  178. // return
  179. // }
  180. //}
  181. func (c *HisApiController) GetFaPiaoNumber() {
  182. max_order, _ := service.GetLastHisOrderTwo(c.GetAdminUserInfo().CurrentOrgId)
  183. count, _ := strconv.ParseInt(max_order.FaPiaoNumber, 10, 64)
  184. fmt.Println(count)
  185. var zero string
  186. number := count + 1
  187. if number >= 1000 {
  188. zero = "0000" + strconv.FormatInt(number, 10)
  189. } else if number >= 10000 {
  190. zero = "000" + strconv.FormatInt(number, 10)
  191. } else if number >= 100000 {
  192. zero = "00" + strconv.FormatInt(number, 10)
  193. } else if number >= 1000000 {
  194. zero = "0" + strconv.FormatInt(number, 10)
  195. } else {
  196. zero = strconv.FormatInt(number, 10)
  197. }
  198. c.ServeSuccessJSON(map[string]interface{}{
  199. "fapiao_number": zero,
  200. })
  201. return
  202. }
  203. func (c *HisApiController) ChangeOrderDesc() {
  204. id, _ := c.GetInt64("id")
  205. desc := c.GetString("desc")
  206. change_type := c.GetString("change_type")
  207. order, _ := service.GetHisOrderByID(id)
  208. if order.ID == 0 {
  209. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  210. return
  211. }
  212. switch change_type {
  213. case "oth_desc":
  214. order.OthDesc = desc
  215. break
  216. case "cash_pay":
  217. order.CashPay = desc
  218. break
  219. case "jifen_pay":
  220. order.JifenPay = desc
  221. break
  222. case "band_card_pay":
  223. order.BandCardPay = desc
  224. break
  225. case "ali_pay":
  226. order.AliPay = desc
  227. break
  228. case "wechat_pay":
  229. order.WechatPay = desc
  230. break
  231. case "fa_piao_number":
  232. order.FaPiaoNumber = desc
  233. break
  234. case "fa_piao_code":
  235. order.FaPiaoCode = desc
  236. break
  237. }
  238. err := service.SaveHisOrder(&order)
  239. if err == nil {
  240. c.ServeSuccessJSON(map[string]interface{}{
  241. "msg": "修改成功",
  242. })
  243. return
  244. } else {
  245. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  246. return
  247. }
  248. }
  249. func (c *HisApiController) GetMonthHisPatient() {
  250. record_date := c.GetString("record_date")
  251. //order_status, _ := c.GetInt64("type")
  252. timeLayout := "2006-01-02"
  253. loc, _ := time.LoadLocation("Local")
  254. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  255. if err != nil {
  256. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  257. return
  258. }
  259. recordDateTime := theTime.Unix()
  260. adminInfo := c.GetAdminUserInfo()
  261. var tempPatients []service.NewTempPatients
  262. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  263. // 获取当前时间
  264. now := time.Now()
  265. // 获取本月的第一天
  266. firstDay := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location())
  267. // 获取下个月的第一天
  268. nextMonth := firstDay.AddDate(0, 1, 0)
  269. // 获取本月的最后一天
  270. lastDay := nextMonth.Add(-time.Nanosecond)
  271. tempPatients, _ = service.GetMonthNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, firstDay.Unix(), lastDay.Unix())
  272. chargePatients, _ := service.GetChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  273. var patients []service.NewTempPatients
  274. var patients_two []service.NewTempPatients
  275. if c.GetAdminUserInfo().CurrentOrgId == 10206 {
  276. for _, item := range tempPatients {
  277. //过滤掉没挂号的和没开处方的
  278. if len(item.HisPrescription) > 0 {
  279. patients = append(patients, item)
  280. patients_two = append(patients_two, item)
  281. }
  282. ////过滤掉没挂号的
  283. //if len(item.HisPatient) > 0 {
  284. //}
  285. }
  286. } else {
  287. for _, item := range tempPatients {
  288. //过滤掉没挂号的和没开处方的
  289. if len(item.HisPatient) > 0 && len(item.HisPrescription) > 0 {
  290. patients = append(patients, item)
  291. }
  292. ////过滤掉没挂号的
  293. //if len(item.HisPatient) > 0 {
  294. // patients_two = append(patients_two, item)
  295. //}
  296. }
  297. }
  298. c.ServeSuccessJSON(map[string]interface{}{
  299. "list": patients,
  300. "list_two": patients_two,
  301. "chargePatients": chargePatients,
  302. })
  303. }
  304. func (c *HisApiController) GetBatchSettleAccounts() {
  305. order_ids := c.GetString("order_ids")
  306. admin_user_id, _ := c.GetInt64("admin_user_id")
  307. adminUser := c.GetAdminUserInfo()
  308. orders := strings.Split(order_ids, ",")
  309. var newOrders []models.Orders
  310. for _, item := range orders {
  311. order, _ := service.GetHisOrderByIDTenOne(item)
  312. his, _ := service.GetHisPatientByNumber(order.MdtrtId)
  313. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  314. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  315. orderInfos = append(orderInfos, orderInfos_two...)
  316. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  317. //diagnosisConfig, _ := service.FindDiagnoseById(his.Diagnosis)
  318. var diagnosis_ids []string
  319. if his.ID > 0 {
  320. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  321. } else {
  322. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  323. }
  324. patient, _ := service.GetPatientByIDTenTwo(adminUser.CurrentOrgId, order.PatientId)
  325. var dia_config []*models.HisXtDiagnoseConfig
  326. var name string
  327. for _, item := range diagnosis_ids {
  328. id, _ := strconv.ParseInt(item, 10, 64)
  329. diagnosisConfig, _ := service.FindDiagnoseById(id)
  330. dia_config = append(dia_config, diagnosisConfig)
  331. if len(name) == 0 {
  332. name = diagnosisConfig.ClassName
  333. } else {
  334. name = name + "," + diagnosisConfig.ClassName
  335. }
  336. }
  337. var bedCostTotal float64 = 0 //床位总费
  338. var bedCostSelfTotal float64 = 0 //床位自费
  339. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  340. var bedSelfTotal float64 = 0 //床位部分项目自费
  341. var bedInscpTotal float64 = 0 //床位部分项目自费
  342. var operationCostTotal float64 = 0 //手术费
  343. var operationCostSelfTotal float64 = 0 //手术费
  344. var operationCostPartSelfTotal float64 = 0 //手术费
  345. var operationSelfTotal float64 = 0 //床位部分项目自费
  346. var operationInscpTotal float64 = 0 //床位部分项目自费
  347. var otherCostTotal float64 = 0 //其他费用
  348. var otherCostSelfTotal float64 = 0 //其他费用
  349. var otherCostPartSelfTotal float64 = 0 //其他费用
  350. var otherSelfTotal float64 = 0 //床位部分项目自费
  351. var otherInscpTotal float64 = 0 //床位部分项目自费
  352. var materialCostTotal float64 = 0 //材料费
  353. var materialCostSelfTotal float64 = 0 //材料费
  354. var materialCostPartSelfTotal float64 = 0 //材料费
  355. var materialSelfTotal float64 = 0 //床位部分项目自费
  356. var materialInscpTotal float64 = 0 //床位部分项目自费
  357. var westernMedicineCostTotal float64 = 0 //西药费
  358. var westernMedicineCostSelfTotal float64 = 0 //西药费
  359. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  360. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  361. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  362. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  363. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  364. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  365. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  366. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  367. var checkCostTotal float64 = 0 //检查费
  368. var checkCostSelfTotal float64 = 0 //检查费
  369. var checkCostPartSelfTotal float64 = 0 //检查费
  370. var checkSelfTotal float64 = 0 //床位部分项目自费
  371. var checkInscpTotal float64 = 0 //床位部分项目自费
  372. var laboratoryCostTotal float64 = 0 //化验费
  373. var laboratoryCostSelfTotal float64 = 0 //化验费
  374. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  375. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  376. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  377. var treatCostTotal float64 = 0 //治疗费用
  378. var treatCostSelfTotal float64 = 0 //治疗费用
  379. var treatCostPartSelfTotal float64 = 0 //治疗费用
  380. var treatSelfTotal float64 = 0 //床位部分项目自费
  381. var treatInscpTotal float64 = 0 //床位部分项目自费
  382. decimal.DivisionPrecision = 2
  383. for _, item := range orderInfos {
  384. if item.MedChrgitmType == "01" { //床位费
  385. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  386. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  387. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  388. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  389. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  390. }
  391. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  392. if item.MedChrgitmType == "03" { //检查费
  393. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  394. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  395. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  396. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  397. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  398. }
  399. } else {
  400. if item.MedChrgitmType == "03" { //检查费
  401. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  402. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  403. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  404. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  405. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  406. }
  407. }
  408. if item.MedChrgitmType == "04" { //化验费
  409. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  410. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  411. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  412. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  413. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  414. }
  415. if item.MedChrgitmType == "05" { //治疗费
  416. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  417. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  418. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  419. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  420. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  421. }
  422. if item.MedChrgitmType == "06" { //手术费
  423. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  424. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  425. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  426. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  427. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  428. }
  429. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  430. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  431. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  432. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  433. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  434. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  435. }
  436. if item.MedChrgitmType == "09" { //西药费
  437. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  438. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  439. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  440. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  441. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  442. }
  443. if item.MedChrgitmType == "11" { //中成费
  444. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  445. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  446. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  447. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  448. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  449. }
  450. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  451. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  452. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  453. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  454. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  455. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  456. }
  457. }
  458. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  459. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  460. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  461. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  462. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  463. var doctor_name string
  464. if roles.ID == 0 {
  465. doctor_name = "管理员"
  466. } else {
  467. doctor_name = roles.UserName
  468. }
  469. yiliao_leibie := ""
  470. switch order.MedType {
  471. case "11":
  472. yiliao_leibie = "普通门诊"
  473. break
  474. case "12":
  475. yiliao_leibie = "门诊挂号"
  476. break
  477. case "13":
  478. yiliao_leibie = "急诊"
  479. break
  480. case "14":
  481. yiliao_leibie = "门诊特殊病"
  482. break
  483. case "15":
  484. yiliao_leibie = "门诊统筹"
  485. break
  486. case "16":
  487. yiliao_leibie = "门诊慢性病"
  488. break
  489. case "21":
  490. yiliao_leibie = "普通住院"
  491. break
  492. }
  493. var newOrder models.Orders
  494. newOrder.Diagnosis = name
  495. newOrder.OrderInfos = orderInfos
  496. newOrder.Number = order.MdtrtId
  497. newOrder.Date = order.SettleAccountsDate
  498. newOrder.ChargeAdmin = charge_admin
  499. newOrder.PrintorAdmin = printor_admin
  500. newOrder.Order = order
  501. newOrder.BedCostTotal = bedCostTotal
  502. newOrder.BedCostSelfTotal = bedCostSelfTotal
  503. newOrder.BedCostPartSelfTotal = bedCostPartSelfTotal
  504. newOrder.BedSelfTotal = bedSelfTotal
  505. newOrder.BedInscpTotal = bedInscpTotal
  506. newOrder.OperationCostTotal = operationCostTotal
  507. newOrder.OperationCostSelfTotal = operationCostSelfTotal
  508. newOrder.OperationCostPartSelfTotal = operationCostPartSelfTotal
  509. newOrder.OperationSelfTotal = operationSelfTotal
  510. newOrder.OperationInscpTotal = operationInscpTotal
  511. newOrder.OtherCostTotal = otherCostTotal
  512. newOrder.OtherCostSelfTotal = otherCostSelfTotal
  513. newOrder.OtherCostPartSelfTotal = otherCostPartSelfTotal
  514. newOrder.OtherSelfTotal = otherSelfTotal
  515. newOrder.OtherInscpTotal = otherInscpTotal
  516. newOrder.MaterialCostTotal = materialCostTotal
  517. newOrder.MaterialCostSelfTotal = materialCostSelfTotal
  518. newOrder.MaterialCostPartSelfTotal = materialCostPartSelfTotal
  519. newOrder.MaterialSelfTotal = materialSelfTotal
  520. newOrder.MaterialInscpTotal = materialInscpTotal
  521. newOrder.WesternMedicineCostTotal = westernMedicineCostTotal
  522. newOrder.WesternMedicineCostSelfTotal = westernMedicineCostSelfTotal
  523. newOrder.WesternMedicineCostPartSelfTotal = westernMedicineCostPartSelfTotal
  524. newOrder.WesternMedicineSelfTotal = westernMedicineSelfTotal
  525. newOrder.WesternMedicineInscpTotal = westernMedicineInscpTotal
  526. newOrder.ChineseTraditionalMedicineCostTotal = chineseTraditionalMedicineCostTotal
  527. newOrder.ChineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostSelfTotal
  528. newOrder.ChineseTraditionalMedicineCostPartSelfTotal = chineseTraditionalMedicineCostPartSelfTotal
  529. newOrder.ChineseTraditionalSelfTotal = chineseTraditionalSelfTotal
  530. newOrder.ChineseTraditionalInscpTotal = chineseTraditionalInscpTotal
  531. newOrder.CheckCostTotal = checkCostTotal
  532. newOrder.CheckCostSelfTotal = checkCostSelfTotal
  533. newOrder.CheckCostPartSelfTotal = checkCostPartSelfTotal
  534. newOrder.CheckSelfTotal = checkSelfTotal
  535. newOrder.CheckInscpTotal = checkInscpTotal
  536. newOrder.LaboratoryCostTotal = laboratoryCostTotal
  537. newOrder.LaboratoryCostSelfTotal = laboratoryCostSelfTotal
  538. newOrder.LaboratoryCostPartSelfTotal = laboratoryCostPartSelfTotal
  539. newOrder.LaboratorySelfTotal = laboratorySelfTotal
  540. newOrder.LaboratoryInscpTotal = laboratoryInscpTotal
  541. newOrder.TreatCostTotal = treatCostTotal
  542. newOrder.TreatCostSelfTotal = treatCostSelfTotal
  543. newOrder.TreatCostPartSelfTotal = treatCostPartSelfTotal
  544. newOrder.TreatSelfTotal = treatSelfTotal
  545. newOrder.TreatInscpTotal = treatInscpTotal
  546. newOrder.DoctorInfo = doctor_info
  547. newOrder.DoctorName = doctor_name
  548. newOrder.HealthCardNo = order.PsnNo
  549. newOrder.YiliaoLeibie = yiliao_leibie
  550. newOrder.Patient = patient
  551. newOrder.OrgName = miConfig.OrgName
  552. newOrder.OrgCode = miConfig.Code
  553. newOrder.OrderNumber = order.Number
  554. newOrder.HisPatient = his
  555. newOrder.DiaConfig = dia_config
  556. newOrders = append(newOrders, newOrder)
  557. }
  558. c.ServeSuccessJSON(map[string]interface{}{
  559. "orders": newOrders,
  560. })
  561. }
  562. func (c *HisApiController) GetTestOrder() {
  563. order_id, _ := c.GetInt64("order_id")
  564. admin_user_id, _ := c.GetInt64("admin_user_id")
  565. adminUser := c.GetAdminUserInfo()
  566. order, _ := service.GetHisOrderByID(order_id)
  567. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  568. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  569. orderInfos = append(orderInfos, orderInfos_two...)
  570. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  571. patient, _ := service.GetPatientByIDTwo(adminUser.CurrentOrgId, order.PatientId)
  572. var dia_config []*models.HisXtDiagnoseConfig
  573. var name string
  574. var bedCostTotal float64 = 0 //床位总费
  575. var bedCostSelfTotal float64 = 0 //床位自费
  576. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  577. var bedSelfTotal float64 = 0 //床位部分项目自费
  578. var bedInscpTotal float64 = 0 //床位部分项目自费
  579. var operationCostTotal float64 = 0 //手术费
  580. var operationCostSelfTotal float64 = 0 //手术费
  581. var operationCostPartSelfTotal float64 = 0 //手术费
  582. var operationSelfTotal float64 = 0 //床位部分项目自费
  583. var operationInscpTotal float64 = 0 //床位部分项目自费
  584. var otherCostTotal float64 = 0 //其他费用
  585. var otherCostSelfTotal float64 = 0 //其他费用
  586. var otherCostPartSelfTotal float64 = 0 //其他费用
  587. var otherSelfTotal float64 = 0 //床位部分项目自费
  588. var otherInscpTotal float64 = 0 //床位部分项目自费
  589. var materialCostTotal float64 = 0 //材料费
  590. var materialCostSelfTotal float64 = 0 //材料费
  591. var materialCostPartSelfTotal float64 = 0 //材料费
  592. var materialSelfTotal float64 = 0 //床位部分项目自费
  593. var materialInscpTotal float64 = 0 //床位部分项目自费
  594. var westernMedicineCostTotal float64 = 0 //西药费
  595. var westernMedicineCostSelfTotal float64 = 0 //西药费
  596. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  597. var westernMedicineSelfTotal float64 = 0 //床位部分项目自费
  598. var westernMedicineInscpTotal float64 = 0 //床位部分项目自费
  599. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  600. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  601. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  602. var chineseTraditionalSelfTotal float64 = 0 //床位部分项目自费
  603. var chineseTraditionalInscpTotal float64 = 0 //床位部分项目自费
  604. var checkCostTotal float64 = 0 //检查费
  605. var checkCostSelfTotal float64 = 0 //检查费
  606. var checkCostPartSelfTotal float64 = 0 //检查费
  607. var checkSelfTotal float64 = 0 //床位部分项目自费
  608. var checkInscpTotal float64 = 0 //床位部分项目自费
  609. var laboratoryCostTotal float64 = 0 //化验费
  610. var laboratoryCostSelfTotal float64 = 0 //化验费
  611. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  612. var laboratorySelfTotal float64 = 0 //床位部分项目自费
  613. var laboratoryInscpTotal float64 = 0 //床位部分项目自费
  614. var treatCostTotal float64 = 0 //治疗费用
  615. var treatCostSelfTotal float64 = 0 //治疗费用
  616. var treatCostPartSelfTotal float64 = 0 //治疗费用
  617. var treatSelfTotal float64 = 0 //床位部分项目自费
  618. var treatInscpTotal float64 = 0 //床位部分项目自费
  619. decimal.DivisionPrecision = 2
  620. for _, item := range orderInfos {
  621. if item.MedChrgitmType == "01" { //床位费
  622. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  623. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  624. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  625. bedSelfTotal, _ = decimal.NewFromFloat(bedSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  626. bedInscpTotal, _ = decimal.NewFromFloat(bedInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  627. }
  628. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  629. if item.MedChrgitmType == "03" { //检查费
  630. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  631. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  632. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  633. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  634. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  635. }
  636. } else {
  637. if item.MedChrgitmType == "03" { //检查费
  638. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  639. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  640. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  641. checkSelfTotal, _ = decimal.NewFromFloat(checkSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  642. checkInscpTotal, _ = decimal.NewFromFloat(checkInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  643. }
  644. }
  645. if item.MedChrgitmType == "04" { //化验费
  646. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  647. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  648. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  649. laboratorySelfTotal, _ = decimal.NewFromFloat(laboratorySelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  650. laboratoryInscpTotal, _ = decimal.NewFromFloat(laboratoryInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  651. }
  652. if item.MedChrgitmType == "05" { //治疗费
  653. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  654. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  655. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  656. treatSelfTotal, _ = decimal.NewFromFloat(treatSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  657. treatInscpTotal, _ = decimal.NewFromFloat(treatInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  658. }
  659. if item.MedChrgitmType == "06" { //手术费
  660. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  661. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  662. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  663. operationSelfTotal, _ = decimal.NewFromFloat(operationSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  664. operationInscpTotal, _ = decimal.NewFromFloat(operationInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  665. }
  666. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  668. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  669. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  670. materialSelfTotal, _ = decimal.NewFromFloat(materialSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  671. materialInscpTotal, _ = decimal.NewFromFloat(materialInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  672. }
  673. if item.MedChrgitmType == "09" { //西药费
  674. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  675. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  676. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  677. westernMedicineSelfTotal, _ = decimal.NewFromFloat(westernMedicineSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  678. westernMedicineInscpTotal, _ = decimal.NewFromFloat(westernMedicineInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  679. }
  680. if item.MedChrgitmType == "11" { //中成费
  681. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  682. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  683. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  684. chineseTraditionalSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  685. chineseTraditionalInscpTotal, _ = decimal.NewFromFloat(chineseTraditionalInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  686. }
  687. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  688. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  689. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  690. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  691. otherSelfTotal, _ = decimal.NewFromFloat(otherSelfTotal).Add(decimal.NewFromFloat(item.FulamtOwnpayAmt)).Float64()
  692. otherInscpTotal, _ = decimal.NewFromFloat(otherInscpTotal).Add(decimal.NewFromFloat(item.InscpScpAmt)).Float64()
  693. }
  694. }
  695. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  696. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  697. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  698. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, his_hospital.Doctor)
  699. roles, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  700. var doctor_name string
  701. if roles.ID == 0 {
  702. doctor_name = "管理员"
  703. } else {
  704. doctor_name = roles.UserName
  705. }
  706. yiliao_leibie := ""
  707. switch order.MedType {
  708. case "11":
  709. yiliao_leibie = "普通门诊"
  710. break
  711. case "12":
  712. yiliao_leibie = "门诊挂号"
  713. break
  714. case "13":
  715. yiliao_leibie = "急诊"
  716. break
  717. case "14":
  718. yiliao_leibie = "门诊特殊病"
  719. break
  720. case "15":
  721. yiliao_leibie = "门诊统筹"
  722. break
  723. case "16":
  724. yiliao_leibie = "门诊慢性病"
  725. break
  726. case "21":
  727. yiliao_leibie = "普通住院"
  728. break
  729. }
  730. c.ServeSuccessJSON(map[string]interface{}{
  731. "diagnosis": name,
  732. "order_infos": orderInfos,
  733. "number": order.MdtrtId,
  734. "date": order.SettleAccountsDate,
  735. "charge_admin": charge_admin,
  736. "printor_admin": printor_admin,
  737. "info": order,
  738. "order": order,
  739. "bedCostTotal": bedCostTotal,
  740. "bedCostSelfTotal": bedCostSelfTotal,
  741. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  742. "bedSelfTotal": bedSelfTotal,
  743. "bedInscpTotal": bedInscpTotal,
  744. "operationCostTotal": operationCostTotal,
  745. "operationCostSelfTotal": operationCostSelfTotal,
  746. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  747. "operationSelfTotal": operationSelfTotal,
  748. "operationInscpTotal": operationInscpTotal,
  749. "otherCostTotal": otherCostTotal,
  750. "otherCostSelfTotal": otherCostSelfTotal,
  751. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  752. "otherSelfTotal": otherSelfTotal,
  753. "otherInscpTotal": otherInscpTotal,
  754. "materialCostTotal": materialCostTotal,
  755. "materialCostSelfTotal": materialCostSelfTotal,
  756. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  757. "materialSelfTotal": materialSelfTotal,
  758. "materialInscpTotal": materialInscpTotal,
  759. "westernMedicineCostTotal": westernMedicineCostTotal,
  760. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  761. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  762. "westernMedicineSelfTotal": westernMedicineSelfTotal,
  763. "westernMedicineInscpTotal": westernMedicineInscpTotal,
  764. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  765. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  766. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  767. "chineseTraditionalSelfTotal": chineseTraditionalSelfTotal,
  768. "chineseTraditionalInscpTotal": chineseTraditionalInscpTotal,
  769. "checkCostTotal": checkCostTotal,
  770. "checkCostSelfTotal": checkCostSelfTotal,
  771. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  772. "checkSelfTotal": checkSelfTotal,
  773. "checkInscpTotal": checkInscpTotal,
  774. "laboratoryCostTotal": laboratoryCostTotal,
  775. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  776. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  777. "laboratorySelfTotal": laboratorySelfTotal,
  778. "laboratoryInscpTotal": laboratoryInscpTotal,
  779. "treatCostTotal": treatCostTotal,
  780. "treatCostSelfTotal": treatCostSelfTotal,
  781. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  782. "treatSelfTotal": treatSelfTotal,
  783. "treatInscpTotal": treatInscpTotal,
  784. "doctor_info": doctor_info,
  785. "doctor_name": doctor_name,
  786. "health_card_no": order.PsnNo,
  787. "yiliao_leibie": yiliao_leibie,
  788. "patient": patient,
  789. "org_name": miConfig.OrgName,
  790. "org_code": miConfig.Code,
  791. "order_number": order.Number,
  792. "his_hospital": his_hospital,
  793. "dia_config": dia_config,
  794. })
  795. }
  796. type CustomFundPay struct {
  797. FundPayType string `json:"fund_pay_type"`
  798. FundPayamt float64 `json:"fund_payamt"`
  799. InscpScpAmt float64 `json:"inscp_scp_amt"`
  800. }
  801. func (c *PublicApiController) GetBaiLinExportData() {
  802. data := service.GetBaiLinOrderData()
  803. fmt.Println(len(data))
  804. var new_data []*models.NewCustomHisOrder
  805. for _, item := range data {
  806. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  807. new_data = append(new_data, item)
  808. }
  809. }
  810. fmt.Println(len(new_data))
  811. c.ServeSuccessJSON(map[string]interface{}{
  812. "list": new_data,
  813. })
  814. }
  815. func (c *HisApiController) GetHisUnChargePatientList() {
  816. record_date := c.GetString("record_date")
  817. sch_type, _ := c.GetInt64("sch_type")
  818. timeLayout := "2006-01-02"
  819. loc, _ := time.LoadLocation("Local")
  820. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  821. if err != nil {
  822. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  823. return
  824. }
  825. recordDateTime := theTime.Unix()
  826. adminInfo := c.GetAdminUserInfo()
  827. var tempPatients []*service.NewTempPatients
  828. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  829. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  830. var patients []*service.NewTempPatients
  831. var patients_two []*service.NewTempPatients
  832. for _, item := range tempPatients {
  833. //过滤掉没挂号的和没开处方的
  834. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  835. patients = append(patients, item)
  836. }
  837. //过滤掉没挂号的
  838. if len(item.HisPatient) > 0 {
  839. patients_two = append(patients_two, item)
  840. }
  841. }
  842. c.ServeSuccessJSON(map[string]interface{}{
  843. "list": patients,
  844. "list_two": patients_two,
  845. })
  846. }
  847. func (c *HisApiController) GetPrivateExpensesOrder() {
  848. //id, _ := c.GetInt64("id")
  849. //record_time := c.GetString("record_time")
  850. order_id, _ := c.GetInt64("order_id")
  851. admin_user_id, _ := c.GetInt64("admin_user_id")
  852. //timeLayout := "2006-01-02"
  853. //loc, _ := time.LoadLocation("Local")
  854. //
  855. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  856. //if err != nil {
  857. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  858. // return
  859. //}
  860. //recordDateTime := theTime.Unix()
  861. adminUser := c.GetAdminUserInfo()
  862. order, _ := service.GetHisOrderByID(order_id)
  863. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  864. his_hospital, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  865. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  866. miConfig, _ := service.FindMedicalInsuranceInfo(adminUser.CurrentOrgId)
  867. //var config []*models.HisXtDiagnoseConfig
  868. var name string
  869. if order.PType == 1 {
  870. diagnosis_ids := strings.Split(his_hospital.Diagnosis, ",")
  871. for _, item := range diagnosis_ids {
  872. id, _ := strconv.ParseInt(item, 10, 64)
  873. diagnosisConfig, _ := service.FindDiagnoseById(id)
  874. if len(name) == 0 {
  875. name = diagnosisConfig.ClassName
  876. } else {
  877. name = name + "," + diagnosisConfig.ClassName
  878. }
  879. }
  880. } else {
  881. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  882. for _, item := range diagnosis_ids {
  883. id, _ := strconv.ParseInt(item, 10, 64)
  884. diagnosisConfig, _ := service.FindDiagnoseById(id)
  885. if len(name) == 0 {
  886. name = diagnosisConfig.ClassName
  887. } else {
  888. name = name + "," + diagnosisConfig.ClassName
  889. }
  890. }
  891. }
  892. var bedCostTotal float64 = 0 //床位总费
  893. //var bedCostSelfTotal float64 = 0 //床位自费
  894. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  895. var operationCostTotal float64 = 0 //手术费
  896. //var operationCostSelfTotal float64 = 0 //手术费
  897. var operationCostPartSelfTotal float64 = 0 //手术费
  898. var otherCostTotal float64 = 0 //其他费用
  899. //var otherCostSelfTotal float64 = 0 //其他费用
  900. var otherCostPartSelfTotal float64 = 0 //其他费用
  901. var materialCostTotal float64 = 0 //材料费
  902. //var materialCostSelfTotal float64 = 0 //材料费
  903. var materialCostPartSelfTotal float64 = 0 //材料费
  904. var westernMedicineCostTotal float64 = 0 //西药费
  905. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  906. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  907. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  908. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  909. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  910. var checkCostTotal float64 = 0 //检查费
  911. //var checkCostSelfTotal float64 = 0 //检查费
  912. var checkCostPartSelfTotal float64 = 0 //检查费
  913. var laboratoryCostTotal float64 = 0 //化验费
  914. //var laboratoryCostSelfTotal float64 = 0 //化验费
  915. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  916. var treatCostTotal float64 = 0 //治疗费用
  917. //var treatCostSelfTotal float64 = 0 //治疗费用
  918. var treatCostPartSelfTotal float64 = 0 //治疗费用
  919. var zhenChaCostTotal float64 = 0 //其他费用
  920. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  921. decimal.DivisionPrecision = 2
  922. for _, item := range orderInfos {
  923. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  924. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  925. item.MedChrgitmType = "09"
  926. }
  927. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  928. if item.HisPrescriptionProject.Type == 2 {
  929. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  930. fmt.Println("CostClassify")
  931. fmt.Println(item.HisPrescriptionProject.VMHisProject.CostClassify)
  932. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  933. case 0:
  934. item.MedChrgitmType = "0"
  935. break
  936. case 1:
  937. item.MedChrgitmType = "14"
  938. break
  939. case 2:
  940. item.MedChrgitmType = "05"
  941. break
  942. case 3:
  943. item.MedChrgitmType = "03"
  944. break
  945. case 4:
  946. item.MedChrgitmType = "03"
  947. break
  948. case 5:
  949. item.MedChrgitmType = "08"
  950. break
  951. case 6:
  952. item.MedChrgitmType = "14"
  953. break
  954. case 7:
  955. item.MedChrgitmType = "14"
  956. break
  957. case 8:
  958. item.MedChrgitmType = "03"
  959. break
  960. case 9:
  961. item.MedChrgitmType = "14"
  962. break
  963. case 10:
  964. item.MedChrgitmType = "14"
  965. break
  966. case 11:
  967. item.MedChrgitmType = "06"
  968. break
  969. case 12:
  970. item.MedChrgitmType = "12"
  971. break
  972. case 13:
  973. item.MedChrgitmType = "01"
  974. break
  975. case 14:
  976. item.MedChrgitmType = "04"
  977. break
  978. case 15:
  979. item.MedChrgitmType = "14"
  980. break
  981. }
  982. } else {
  983. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  984. case 1:
  985. item.MedChrgitmType = "14"
  986. break
  987. case 2:
  988. item.MedChrgitmType = "05"
  989. break
  990. case 3:
  991. item.MedChrgitmType = "04"
  992. break
  993. case 4:
  994. item.MedChrgitmType = "14"
  995. break
  996. case 5:
  997. item.MedChrgitmType = "08"
  998. break
  999. case 6:
  1000. item.MedChrgitmType = "14"
  1001. break
  1002. case 7:
  1003. item.MedChrgitmType = "14"
  1004. break
  1005. case 8:
  1006. item.MedChrgitmType = "03"
  1007. break
  1008. case 9:
  1009. item.MedChrgitmType = "14"
  1010. break
  1011. default:
  1012. item.MedChrgitmType = "14"
  1013. break
  1014. }
  1015. }
  1016. } else if item.HisPrescriptionProject.Type == 3 {
  1017. item.MedChrgitmType = "08"
  1018. }
  1019. }
  1020. }
  1021. if order.IsMedicineInsurance != 1 {
  1022. order.PsnCashPay = order.MedfeeSumamt
  1023. }
  1024. for _, item := range orderInfos {
  1025. if item.MedChrgitmType == "01" { //床位费
  1026. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1027. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1028. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1029. }
  1030. if item.MedChrgitmType == "02" { //诊察费
  1031. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1032. //zhenChaCostSelfTotal = zhenChaCostTotal
  1033. }
  1034. if item.MedChrgitmType == "03" { //检查费
  1035. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1036. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1037. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1038. }
  1039. if item.MedChrgitmType == "02" { //检查费
  1040. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1041. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1042. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1043. }
  1044. if item.MedChrgitmType == "04" { //化验费
  1045. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1046. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1047. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1048. }
  1049. if item.MedChrgitmType == "05" { //治疗费
  1050. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1051. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1052. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1053. }
  1054. if item.MedChrgitmType == "06" { //手术费
  1055. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1056. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1057. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1058. }
  1059. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  1060. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1061. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1062. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1063. }
  1064. if item.MedChrgitmType == "09" { //西药费
  1065. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1066. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1067. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1068. }
  1069. if item.MedChrgitmType == "11" { //中成费
  1070. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1071. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1072. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1073. }
  1074. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  1075. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  1076. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  1077. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  1078. }
  1079. }
  1080. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  1081. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  1082. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  1083. var dia_config []*models.HisXtDiagnoseConfig
  1084. var diagnosis_ids []string
  1085. if his.ID > 0 {
  1086. diagnosis_ids = strings.Split(his.Diagnosis, ",")
  1087. } else {
  1088. diagnosis_ids = strings.Split(his_hospital.Diagnosis, ",")
  1089. }
  1090. for _, item := range diagnosis_ids {
  1091. id, _ := strconv.ParseInt(item, 10, 64)
  1092. diagnosisConfig, _ := service.FindDiagnoseById(id)
  1093. dia_config = append(dia_config, diagnosisConfig)
  1094. }
  1095. var rf []CustomFundPay
  1096. json.Unmarshal([]byte(order.SetlDetail), &rf)
  1097. patient, _ := service.GetFaPiaoPatientByID(order.UserOrgId, order.PatientId)
  1098. c.ServeSuccessJSON(map[string]interface{}{
  1099. "patient": patient,
  1100. "order_infos": orderInfos,
  1101. "diagnosis": name,
  1102. "bedCostTotal": bedCostTotal,
  1103. "bedCostSelfTotal": bedCostTotal,
  1104. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  1105. "operationCostTotal": operationCostTotal,
  1106. "operationCostSelfTotal": operationCostTotal,
  1107. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  1108. "otherCostTotal": otherCostTotal,
  1109. "otherCostSelfTotal": otherCostTotal,
  1110. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  1111. "materialCostTotal": materialCostTotal,
  1112. "materialCostSelfTotal": materialCostTotal,
  1113. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  1114. "westernMedicineCostTotal": westernMedicineCostTotal,
  1115. "westernMedicineCostSelfTotal": westernMedicineCostTotal,
  1116. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  1117. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  1118. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostTotal,
  1119. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  1120. "checkCostTotal": checkCostTotal,
  1121. "checkCostSelfTotal": checkCostTotal,
  1122. "zhenChaCostTotal": zhenChaCostTotal,
  1123. "zhenChaCostSelfTotal": zhenChaCostTotal,
  1124. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  1125. "laboratoryCostTotal": laboratoryCostTotal,
  1126. "laboratoryCostSelfTotal": laboratoryCostTotal,
  1127. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  1128. "treatCostTotal": treatCostTotal,
  1129. "treatCostSelfTotal": treatCostTotal,
  1130. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  1131. "charge_admin": charge_admin,
  1132. "printor_admin": printor_admin,
  1133. "org_name": org.OrgName,
  1134. "org_code": miConfig.Code,
  1135. "name": patient.Name,
  1136. "number": order.MdtrtId,
  1137. "date": order.SettleAccountsDate,
  1138. "info": order,
  1139. "new_order": order,
  1140. "his_hospital": his_hospital,
  1141. "his": his,
  1142. "funds": rf,
  1143. "dia_config": dia_config,
  1144. })
  1145. }
  1146. func (c *HisApiController) RefudDetail() {
  1147. order_id, _ := c.GetInt64("order_id")
  1148. order, _ := service.GetHisOrderByID(order_id)
  1149. adminUser := c.GetAdminUserInfo()
  1150. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  1151. c.ServeSuccessJSON(map[string]interface{}{
  1152. "msg": "撤销成功",
  1153. })
  1154. }
  1155. func (c *HisApiController) Sscard() {
  1156. //r := CardInit()
  1157. //if r == 0 {
  1158. // GetBaseInfo()
  1159. //}
  1160. //c.ServeSuccessJSON(map[string]interface{}{
  1161. // "list": "11",
  1162. //})
  1163. }
  1164. func GetBaseInfo() error {
  1165. //handle := syscall.MustLoadDLL("SSCard.dll")
  1166. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  1167. //
  1168. //str := make([]byte, 256)
  1169. //str1 := make([]byte, 256)
  1170. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  1171. //if ferr != nil {
  1172. // fmt.Println("ReadCardBas 报错", ferr.Error())
  1173. // return ferr
  1174. //}
  1175. //
  1176. //fmt.Println(string(str))
  1177. //
  1178. //fmt.Println(r)
  1179. return nil
  1180. }
  1181. func CardInit() int {
  1182. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  1183. //add := DllTestDef.MustFindProc("Init")
  1184. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  1185. //if err != nil {
  1186. // fmt.Println("SSCard的运算结果为:", ret)
  1187. //}
  1188. //result := int(ret)
  1189. return 0
  1190. }
  1191. func IntPtr(n int) uintptr {
  1192. return uintptr(n)
  1193. }
  1194. func StrPtr(s string) uintptr {
  1195. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  1196. }
  1197. func (c *HisApiController) GetHisPatientList() {
  1198. //types, _ := c.GetInt64("type", 0)
  1199. record_date := c.GetString("record_date")
  1200. sch_type, _ := c.GetInt64("sch_type")
  1201. timeLayout := "2006-01-02"
  1202. loc, _ := time.LoadLocation("Local")
  1203. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1204. if err != nil {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. recordDateTime := theTime.Unix()
  1209. adminInfo := c.GetAdminUserInfo()
  1210. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  1211. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime, sch_type)
  1212. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  1213. //获取当前用户的信息
  1214. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  1215. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1216. //获取所有科室信息
  1217. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1218. c.ServeSuccessJSON(map[string]interface{}{
  1219. "list": patients,
  1220. "list_two": patients_two,
  1221. "info": adminUserInfo,
  1222. "doctors": doctors,
  1223. "department": department,
  1224. })
  1225. }
  1226. type CustomTemplate struct {
  1227. ID int64 `gorm:"column:id" json:"id" form:"id"`
  1228. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  1229. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  1230. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  1231. Status int64 `gorm:"column:status" json:"status" form:"status"`
  1232. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  1233. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  1234. Type int64 `gorm:"column:type" json:"type" form:"type"`
  1235. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  1236. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  1237. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  1238. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  1239. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  1240. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  1241. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  1242. }
  1243. func (c *HisApiController) GetHisPatientInfo() {
  1244. patient_id, _ := c.GetInt64("patient_id")
  1245. his_patient_id, _ := c.GetInt64("his_patient_id")
  1246. record_date := c.GetString("record_date")
  1247. number := c.GetString("number")
  1248. //start_time := c.GetString("start_time")
  1249. //end_time := c.GetString("end_time")
  1250. p_type, _ := c.GetInt64("p_type")
  1251. timeLayout := "2006-01-02"
  1252. loc, _ := time.LoadLocation("Local")
  1253. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1254. if err != nil {
  1255. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1256. return
  1257. }
  1258. recordDateTime := theTime.Unix()
  1259. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  1260. //if err != nil {
  1261. //
  1262. //}
  1263. //startRecordDateTime := startTime.Unix()
  1264. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  1265. //if err != nil {
  1266. //
  1267. //}
  1268. //endRecordDateTime := endTime.Unix()
  1269. admin := c.GetAdminUserInfo()
  1270. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1271. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  1272. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  1273. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  1274. var prescriptions []*models.HisPrescription
  1275. var last_prescriptions []*models.HisPrescription
  1276. var sch_prescriptions []CustomTemplate
  1277. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1278. if p_type == 1 { //住院
  1279. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1280. for _, item := range prescriptions {
  1281. for _, subItem := range item.HisDoctorAdviceInfo {
  1282. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1283. if info.RetailPrice > 0 {
  1284. subItem.Drug.MinPrice = info.RetailPrice
  1285. }
  1286. }
  1287. }
  1288. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1289. } else { //门诊
  1290. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  1291. for _, item := range prescriptions {
  1292. for _, subItem := range item.HisDoctorAdviceInfo {
  1293. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1294. if info.RetailPrice > 0 {
  1295. subItem.Drug.MinPrice = info.RetailPrice
  1296. }
  1297. }
  1298. }
  1299. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  1300. }
  1301. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  1302. if sch.ID > 0 {
  1303. var week string
  1304. t := time.Now()
  1305. switch t.Weekday().String() {
  1306. case "Monday":
  1307. week = "周一"
  1308. break
  1309. case "Tuesday":
  1310. week = "周二"
  1311. break
  1312. case "Wednesday":
  1313. week = "周三"
  1314. break
  1315. case "Thursday":
  1316. week = "周四"
  1317. break
  1318. case "Friday":
  1319. week = "周五"
  1320. break
  1321. case "Saturday":
  1322. week = "周六"
  1323. break
  1324. case "Sunday":
  1325. week = "周日"
  1326. break
  1327. }
  1328. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  1329. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  1330. //根据推送频率组装新的数组
  1331. for _, item := range temp_sch_prescriptions {
  1332. var cus CustomTemplate
  1333. cus.ID = item.ID
  1334. cus.UserOrgId = item.UserOrgId
  1335. cus.PatientId = item.PatientId
  1336. cus.MedType = item.MedType
  1337. cus.RecordDate = item.RecordDate
  1338. cus.Type = item.Type
  1339. cus.PType = item.PType
  1340. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1341. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  1342. if subItem.FrequencyType == 1 { //每次必推
  1343. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1344. }
  1345. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  1346. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1347. }
  1348. if subItem.FrequencyType == 2 { //按照天数频率
  1349. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1350. now := p.Unix()
  1351. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1352. dayStr2 := "-" + dayStr
  1353. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1354. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1355. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  1356. if len(advices) == 0 {
  1357. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  1358. }
  1359. }
  1360. }
  1361. }
  1362. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1363. if subItem.Type == 2 {
  1364. if subItem.XtHisProject.MedicalStatus != 1 {
  1365. if subItem.FrequencyType == 1 {
  1366. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1367. }
  1368. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1369. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1370. }
  1371. if subItem.FrequencyType == 2 {
  1372. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1373. now := p.Unix()
  1374. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1375. dayStr2 := "-" + dayStr
  1376. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1377. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1378. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1379. if len(projects) == 0 {
  1380. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1381. }
  1382. }
  1383. }
  1384. } else if subItem.Type == 3 {
  1385. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  1386. if subItem.FrequencyType == 1 {
  1387. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1388. }
  1389. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  1390. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1391. }
  1392. if subItem.FrequencyType == 2 {
  1393. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  1394. now := p.Unix()
  1395. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  1396. dayStr2 := "-" + dayStr
  1397. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  1398. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  1399. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  1400. if len(projects) == 0 {
  1401. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  1402. }
  1403. }
  1404. }
  1405. }
  1406. }
  1407. sch_prescriptions = append(sch_prescriptions, cus)
  1408. }
  1409. for _, item := range sch_prescriptions {
  1410. if len(item.HisPrescriptionProjectTemplate) == 0 {
  1411. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  1412. }
  1413. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  1414. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  1415. }
  1416. }
  1417. }
  1418. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  1419. if config.ID > 0 && config.IsOpen == 1 {
  1420. for _, item := range sch_prescriptions {
  1421. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  1422. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  1423. if info.RetailPrice > 0 {
  1424. subItem.Drug.MinPrice = info.RetailPrice
  1425. if admin.CurrentOrgId != 10598 {
  1426. service.UpdatePrescriptionAdvice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice, subItem.PatientId)
  1427. service.UpdateBaseMinPrice(subItem.DrugId, admin.CurrentOrgId, info.RetailPrice)
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. if config.ID > 0 && config.IsOpen == 1 {
  1434. for _, item := range sch_prescriptions {
  1435. for _, subItem := range item.HisPrescriptionProjectTemplate {
  1436. if subItem.Type == 3 {
  1437. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  1438. if info.Price > 0 {
  1439. subItem.GoodInfo.PackingPrice = info.Price
  1440. if admin.CurrentOrgId != 10598 {
  1441. service.UpdatePrescriptionProject(subItem.ProjectId, admin.CurrentOrgId, info.Price, subItem.PatientId)
  1442. service.UpdateGood(subItem.ProjectId, admin.CurrentOrgId, info.Price)
  1443. }
  1444. }
  1445. }
  1446. }
  1447. }
  1448. }
  1449. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  1450. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  1451. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  1452. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1453. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  1454. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  1455. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  1456. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  1457. //获取所有科室信息
  1458. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  1459. c.ServeSuccessJSON(map[string]interface{}{
  1460. "his_info": his_patient_info,
  1461. "xt_info": xt_patient_info,
  1462. "prescription": prescriptions,
  1463. "case_history": case_history,
  1464. "info": patientPrescriptionInfo,
  1465. //"month_prescriptions": monthPrescriptions,
  1466. "order": order,
  1467. "doctors": doctors,
  1468. "department": department,
  1469. "sch_prescriptions": sch_prescriptions,
  1470. "last_prescriptions": last_prescriptions,
  1471. "schedule": sch,
  1472. "count": count,
  1473. "drugStockConfig": drugStockConfig,
  1474. "last_info": lastPatientPrescriptionInfo,
  1475. })
  1476. return
  1477. }
  1478. func (c *HisApiController) GetHisPrescriptionConfig() {
  1479. adminInfo := c.GetAdminUserInfo()
  1480. //获取医嘱模版
  1481. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  1482. houseConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1483. if adminInfo.CurrentOrgId == 9675 || adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10215 {
  1484. //获取所有基础药
  1485. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1486. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1487. if config.ID > 0 && config.IsOpen == 1 {
  1488. for _, item := range drugs {
  1489. var index = 0
  1490. for _, subItem := range item.OtherDrugWarehouseInfo {
  1491. if index == 0 {
  1492. index = index + 1
  1493. if subItem.RetailPrice > 0 {
  1494. item.MinPrice = subItem.RetailPrice
  1495. }
  1496. }
  1497. }
  1498. }
  1499. }
  1500. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1501. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1502. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1503. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1504. //获取所有科室信息
  1505. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1506. //获取诊断信息
  1507. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1508. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1509. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1510. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1511. //获取是否开启保存耗材出库的开关
  1512. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1513. c.ServeSuccessJSON(map[string]interface{}{
  1514. "drugs": drugs,
  1515. "advices_template": advices,
  1516. "drugways": drugways,
  1517. "efs": efs,
  1518. "doctors": doctors,
  1519. "department": department,
  1520. "sick": sick,
  1521. "additions": additions,
  1522. "diagnose": diagnose,
  1523. "manufacturers": manufacturers,
  1524. "goodOutOpen": goodOutOpen,
  1525. "patientDiagnose": patientDiagnose,
  1526. })
  1527. }
  1528. if adminInfo.CurrentOrgId != 9675 && adminInfo.CurrentOrgId != 9671 && adminInfo.CurrentOrgId != 10215 {
  1529. //获取所有基础药
  1530. drugs, _ := service.GetAllDrugLibListSix(adminInfo.CurrentOrgId, houseConfig.DrugStorehouseOut)
  1531. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  1532. if config.ID > 0 && config.IsOpen == 1 {
  1533. for _, item := range drugs {
  1534. var index = 0
  1535. for _, subItem := range item.OtherDrugWarehouseInfo {
  1536. if index == 0 {
  1537. index = index + 1
  1538. if subItem.RetailPrice > 0 {
  1539. item.MinPrice = subItem.RetailPrice
  1540. }
  1541. }
  1542. }
  1543. }
  1544. }
  1545. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  1546. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  1547. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  1548. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  1549. //获取所有科室信息
  1550. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  1551. //获取诊断信息
  1552. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  1553. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  1554. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  1555. //获取是否开启保存耗材出库的开关
  1556. goodOutOpen, _ := service.GetGoodOutOpenConfigOne(adminInfo.CurrentOrgId)
  1557. patientDiagnose, _ := service.FindPatientDianose(adminInfo.CurrentOrgId)
  1558. c.ServeSuccessJSON(map[string]interface{}{
  1559. "drugs": drugs,
  1560. "advices_template": advices,
  1561. "drugways": drugways,
  1562. "efs": efs,
  1563. "doctors": doctors,
  1564. "department": department,
  1565. "sick": sick,
  1566. "additions": additions,
  1567. "diagnose": diagnose,
  1568. "manufacturers": manufacturers,
  1569. "goodOutOpen": goodOutOpen,
  1570. "patientDiagnose": patientDiagnose,
  1571. })
  1572. }
  1573. }
  1574. func (c *HisApiController) CreateHisPrescription() {
  1575. record_date := c.GetString("record_date")
  1576. patient_id, _ := c.GetInt64("patient_id")
  1577. reg_type, _ := c.GetInt64("reg_type")
  1578. diagnose := c.GetString("diagnose")
  1579. sick_type, _ := c.GetInt64("sick_type")
  1580. sick_history := c.GetString("sick_history")
  1581. doctor_id, _ := c.GetInt64("doctor", 0)
  1582. department, _ := c.GetInt64("department", 0)
  1583. his_patient_id, _ := c.GetInt64("his_patient_id")
  1584. p_type, _ := c.GetInt64("p_type")
  1585. patient_diagnose := c.GetString("patient_diagnose")
  1586. dataBody := make(map[string]interface{}, 0)
  1587. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1588. if err != nil {
  1589. utils.ErrorLog(err.Error())
  1590. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1591. return
  1592. }
  1593. //edit, src := GetCompareData(dataBody)
  1594. //drugResult := ComparePrescriptions(src.adviceList, edit.adviceList)
  1595. //goodResult := CompareGoodPrescriptions(src.projectList, edit.projectList)
  1596. //fmt.Println(drugResult)
  1597. //fmt.Println(goodResult)
  1598. timeLayout := "2006-01-02"
  1599. loc, _ := time.LoadLocation("Local")
  1600. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1601. if err != nil {
  1602. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1603. return
  1604. }
  1605. adminInfo := c.GetAdminUserInfo()
  1606. recordDateTime := theTime.Unix()
  1607. //查询默认出库仓库库存
  1608. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  1609. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1610. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  1611. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  1612. if len(lists) == 1 {
  1613. his_patient_id = lists[0].ID
  1614. }
  1615. }
  1616. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  1617. //自动出库的开关开启
  1618. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1619. //自动出库
  1620. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1621. //耗材保存处方出库
  1622. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1623. settleConfig, _ := service.FindeDrugSettleConfigById(c.GetAdminUserInfo().CurrentOrgId)
  1624. //已发药和已收费限制逻辑
  1625. isMidicine := false
  1626. isCharge := false
  1627. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1628. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1629. if len(prescriptions) > 0 {
  1630. for _, item := range prescriptions {
  1631. items := item.(map[string]interface{})
  1632. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1633. utils.ErrorLog("id")
  1634. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1635. return
  1636. }
  1637. id := int64(items["id"].(float64))
  1638. if id > 0 {
  1639. new_prescription, err := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1640. if err != nil {
  1641. if new_prescription.OrderStatus == 4 {
  1642. isCharge = true
  1643. }
  1644. }
  1645. }
  1646. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1647. advices := items["advices"].([]interface{})
  1648. if len(advices) > 0 {
  1649. for _, advice := range advices {
  1650. var adviceId int64
  1651. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1652. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1653. }
  1654. if adviceId > 0 {
  1655. his_advice_info, err := service.GetHisDoctorAdviceInfo(adviceId)
  1656. if err == nil {
  1657. if his_advice_info.IsMedicine == 1 {
  1658. isMidicine = true
  1659. }
  1660. }
  1661. }
  1662. }
  1663. }
  1664. }
  1665. }
  1666. }
  1667. }
  1668. if isMidicine == true {
  1669. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMedicineWrong)
  1670. return
  1671. }
  1672. if isCharge == true {
  1673. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeChargeWrong)
  1674. return
  1675. }
  1676. // 开始主事务
  1677. db := service.XTWriteDB()
  1678. tx := db.Begin()
  1679. // 在函数结束时处理事务回滚
  1680. defer func() {
  1681. if r := recover(); r != nil {
  1682. tx.Rollback()
  1683. }
  1684. }()
  1685. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  1686. //药品发药出库
  1687. if pharmacyConfig.IsOpen == 1 {
  1688. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1689. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1690. if len(prescriptions) > 0 {
  1691. for _, item := range prescriptions {
  1692. items := item.(map[string]interface{})
  1693. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1694. advices := items["advices"].([]interface{})
  1695. if len(advices) > 0 {
  1696. for _, advice := range advices {
  1697. var drug_id int64
  1698. var prescribing_number float64
  1699. var prescribingNumberUnit string
  1700. var adviceId int64
  1701. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1702. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1703. }
  1704. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1705. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1706. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1707. }
  1708. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1709. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1710. }
  1711. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1712. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1713. }
  1714. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1715. if drug.ID == 0 {
  1716. tx.Rollback()
  1717. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1718. return
  1719. }
  1720. //查询药品的所有库存
  1721. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1722. var total_count int64
  1723. for _, it := range list {
  1724. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1725. }
  1726. totals := strconv.FormatInt(total_count, 10)
  1727. //查询该药品是否存在开药记录
  1728. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1729. //新增处方盘点库存是否充足
  1730. if advicelist.ID == 0 {
  1731. all_count, _ := strconv.ParseFloat(totals, 64)
  1732. if prescribingNumberUnit == drug.MinUnit {
  1733. if drug.IsUse != 1 {
  1734. if drug.IsProject == 0 || drug.IsProject == 2 {
  1735. if all_count == 0 {
  1736. tx.Rollback()
  1737. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1738. return
  1739. }
  1740. if prescribing_number > all_count {
  1741. tx.Rollback()
  1742. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1743. return
  1744. }
  1745. }
  1746. }
  1747. }
  1748. if prescribingNumberUnit == drug.MaxUnit {
  1749. num := prescribing_number * float64(drug.MinNumber)
  1750. if drug.IsUse != 1 {
  1751. if drug.IsProject == 0 || drug.IsProject == 2 {
  1752. if all_count == 0 {
  1753. tx.Rollback()
  1754. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1755. return
  1756. }
  1757. if num > all_count {
  1758. tx.Rollback()
  1759. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1760. return
  1761. }
  1762. }
  1763. }
  1764. }
  1765. }
  1766. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1767. //不使用保存处方出库
  1768. if drugOutConfig.IsOpen != 1 {
  1769. //修改处方
  1770. for _, advice := range advices {
  1771. var drug_id int64
  1772. var prescribing_number float64
  1773. var prescribingNumberUnit string
  1774. var prescribingNumber string
  1775. var adviceId int64
  1776. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1777. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1778. }
  1779. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1780. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1781. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1782. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1783. }
  1784. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1785. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1786. }
  1787. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1788. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1789. }
  1790. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1791. if drug.ID == 0 {
  1792. tx.Rollback()
  1793. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1794. return
  1795. }
  1796. //查询药品的所有库存
  1797. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1798. var total_count int64
  1799. for _, it := range list {
  1800. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1801. }
  1802. totals := strconv.FormatInt(total_count, 10)
  1803. //查询该药品是否存在开药记录
  1804. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1805. //新增处方
  1806. if advicelist.ID == 0 {
  1807. all_count, _ := strconv.ParseFloat(totals, 64)
  1808. if prescribingNumberUnit == drug.MinUnit {
  1809. if drug.IsUse != 1 {
  1810. if drug.IsProject == 0 || drug.IsProject == 2 {
  1811. if all_count == 0 {
  1812. tx.Rollback()
  1813. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1814. return
  1815. }
  1816. if prescribing_number > all_count {
  1817. tx.Rollback()
  1818. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1819. return
  1820. }
  1821. }
  1822. }
  1823. } else {
  1824. if prescribingNumberUnit == drug.MaxUnit {
  1825. num := prescribing_number * float64(drug.MinNumber)
  1826. if drug.IsUse != 1 {
  1827. if drug.IsProject == 0 || drug.IsProject == 2 {
  1828. if all_count == 0 {
  1829. tx.Rollback()
  1830. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1831. return
  1832. }
  1833. if num > all_count {
  1834. tx.Rollback()
  1835. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1836. return
  1837. }
  1838. }
  1839. }
  1840. }
  1841. }
  1842. }
  1843. //修改处方
  1844. if advicelist.ID > 0 {
  1845. var device_number int64
  1846. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1847. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1848. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1849. device_number = prescribingNumberInt * drug.MinNumber
  1850. }
  1851. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1852. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1853. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1854. device_number = prescribingNumberInt
  1855. }
  1856. var number_count int64
  1857. if prescribingNumberUnit == drug.MaxUnit {
  1858. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1859. number_count = prescribingNumberInt * drug.MinNumber
  1860. }
  1861. if prescribingNumberUnit == drug.MinUnit {
  1862. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1863. number_count = prescribingNumberInt
  1864. }
  1865. //如果修改的数量大于之前修改的数量
  1866. if (number_count - device_number) > 0 {
  1867. //如果修改的差数量 大于库存数量
  1868. if drug.IsUse != 1 {
  1869. if (number_count - device_number) > total_count {
  1870. tx.Rollback()
  1871. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1872. return
  1873. }
  1874. }
  1875. }
  1876. }
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. }
  1884. }
  1885. }
  1886. //已发药和已收费限制逻辑
  1887. if drugStockConfig.IsOpen == 1 || settleConfig.IsOpen == 1 {
  1888. //校验库存总量
  1889. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1890. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1891. if len(prescriptions) > 0 {
  1892. for _, item := range prescriptions {
  1893. items := item.(map[string]interface{})
  1894. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1895. advices := items["advices"].([]interface{})
  1896. if len(advices) > 0 {
  1897. for _, advice := range advices {
  1898. var drug_id int64
  1899. var prescribing_number float64
  1900. var prescribingNumberUnit string
  1901. var adviceId int64
  1902. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1903. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1904. }
  1905. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1906. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1907. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1908. }
  1909. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1910. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1911. }
  1912. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1913. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1914. }
  1915. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1916. if drug.ID == 0 {
  1917. tx.Rollback()
  1918. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1919. return
  1920. }
  1921. //查询药品的所有库存
  1922. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1923. var total_count int64
  1924. for _, it := range list {
  1925. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1926. }
  1927. totals := strconv.FormatInt(total_count, 10)
  1928. //查询该药品是否存在开药记录
  1929. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1930. //查询最新批次库存
  1931. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1932. var batch_number_count int64
  1933. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1934. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1935. //新增处方
  1936. if advicelist.ID == 0 {
  1937. all_count, _ := strconv.ParseFloat(totals, 64)
  1938. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1939. if prescribingNumberUnit == drug.MinUnit {
  1940. if drug.IsUse != 1 {
  1941. if drug.IsProject == 0 || drug.IsProject == 2 {
  1942. if all_count == 0 {
  1943. tx.Rollback()
  1944. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1945. return
  1946. }
  1947. if prescribing_number > all_count {
  1948. tx.Rollback()
  1949. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1950. return
  1951. }
  1952. }
  1953. if adminInfo.CurrentOrgId == 10215 {
  1954. if prescribing_number > batch_number_all_count {
  1955. tx.Rollback()
  1956. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1957. return
  1958. }
  1959. }
  1960. }
  1961. }
  1962. if prescribingNumberUnit == drug.MaxUnit {
  1963. num := prescribing_number * float64(drug.MinNumber)
  1964. if drug.IsUse != 1 {
  1965. if drug.IsProject == 0 || drug.IsProject == 2 {
  1966. if all_count == 0 {
  1967. tx.Rollback()
  1968. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1969. return
  1970. }
  1971. if num > all_count {
  1972. tx.Rollback()
  1973. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1974. return
  1975. }
  1976. }
  1977. if adminInfo.CurrentOrgId == 10215 {
  1978. if num > batch_number_all_count {
  1979. tx.Rollback()
  1980. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1981. return
  1982. }
  1983. }
  1984. }
  1985. }
  1986. }
  1987. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1988. if drugOutConfig.IsOpen != 1 {
  1989. //修改处方
  1990. for _, advice := range advices {
  1991. var drug_id int64
  1992. var prescribing_number float64
  1993. var prescribingNumberUnit string
  1994. var prescribingNumber string
  1995. var adviceId int64
  1996. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1997. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1998. }
  1999. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2000. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2001. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2002. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2003. }
  2004. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2005. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2006. }
  2007. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2008. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2009. }
  2010. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2011. if drug.ID == 0 {
  2012. tx.Rollback()
  2013. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2014. return
  2015. }
  2016. //查询药品的所有库存
  2017. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2018. var total_count int64
  2019. for _, it := range list {
  2020. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2021. }
  2022. totals := strconv.FormatInt(total_count, 10)
  2023. //查询该药品是否存在开药记录
  2024. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2025. //新增处方
  2026. if advicelist.ID == 0 {
  2027. //查询最新批次库存
  2028. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2029. var batch_number_count int64
  2030. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2031. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2032. all_count, _ := strconv.ParseFloat(totals, 64)
  2033. if prescribingNumberUnit == drug.MinUnit {
  2034. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2035. if drug.IsUse != 1 {
  2036. if drug.IsProject == 0 || drug.IsProject == 2 {
  2037. if all_count == 0 {
  2038. tx.Rollback()
  2039. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2040. return
  2041. }
  2042. if prescribing_number > all_count {
  2043. tx.Rollback()
  2044. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2045. return
  2046. }
  2047. }
  2048. if adminInfo.CurrentOrgId == 10215 {
  2049. if prescribing_number > batch_number_all_count {
  2050. tx.Rollback()
  2051. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2052. return
  2053. }
  2054. }
  2055. }
  2056. } else {
  2057. if prescribingNumberUnit == drug.MaxUnit {
  2058. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2059. num := prescribing_number * float64(drug.MinNumber)
  2060. if drug.IsUse != 1 {
  2061. if drug.IsProject == 0 || drug.IsProject == 2 {
  2062. if all_count == 0 {
  2063. tx.Rollback()
  2064. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2065. return
  2066. }
  2067. if num > all_count {
  2068. tx.Rollback()
  2069. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2070. return
  2071. }
  2072. }
  2073. if adminInfo.CurrentOrgId == 10215 {
  2074. if prescribing_number > batch_number_all_count {
  2075. tx.Rollback()
  2076. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2077. return
  2078. }
  2079. }
  2080. }
  2081. }
  2082. }
  2083. }
  2084. //修改处方
  2085. if advicelist.ID > 0 {
  2086. //查询最新批次库存
  2087. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2088. var batch_number_count int64
  2089. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2090. var device_number int64
  2091. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2092. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2093. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2094. device_number = prescribingNumberInt * drug.MinNumber
  2095. }
  2096. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2097. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2098. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2099. device_number = prescribingNumberInt
  2100. }
  2101. var number_count int64
  2102. if prescribingNumberUnit == drug.MaxUnit {
  2103. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2104. number_count = prescribingNumberInt * drug.MinNumber
  2105. }
  2106. if prescribingNumberUnit == drug.MinUnit {
  2107. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2108. number_count = prescribingNumberInt
  2109. }
  2110. //如果修改的数量大于之前修改的数量
  2111. if (number_count - device_number) > 0 {
  2112. //如果修改的差数量 大于库存数量
  2113. if drug.IsUse != 1 {
  2114. if drug.IsProject == 0 || drug.IsProject == 2 {
  2115. if total_count == 0 {
  2116. tx.Rollback()
  2117. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2118. return
  2119. }
  2120. if (number_count - device_number) > total_count {
  2121. tx.Rollback()
  2122. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2123. return
  2124. }
  2125. if (number_count - device_number) > batch_number_count {
  2126. tx.Rollback()
  2127. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2128. return
  2129. }
  2130. }
  2131. if adminInfo.CurrentOrgId == 10215 {
  2132. // 查询该药品最后一次出库记录
  2133. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2134. var out_count int64
  2135. var in_count int64
  2136. var stock_max_number int64
  2137. var stock_min_number int64
  2138. for _, it := range outInfo {
  2139. if it.CountUnit == drug.MaxUnit {
  2140. it.Count = it.Count * drug.MinNumber
  2141. }
  2142. out_count += it.Count
  2143. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2144. stock_max_number = warehouseInfoList.StockMaxNumber
  2145. stock_min_number = warehouseInfoList.StockMinNumber
  2146. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2147. }
  2148. if out_count > 0 {
  2149. if (number_count - device_number) > in_count {
  2150. tx.Rollback()
  2151. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2152. return
  2153. }
  2154. }
  2155. // 未出库
  2156. if out_count == 0 {
  2157. var sum_in_count int64
  2158. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2159. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2160. fmt.Println("sum_in_count", sum_in_count)
  2161. //如果修改的数量大于有库存的第一个批次
  2162. if number_count > sum_in_count {
  2163. tx.Rollback()
  2164. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2165. return
  2166. }
  2167. }
  2168. }
  2169. }
  2170. }
  2171. pharmacyConfig, _ := service.FindPharmacyConfig(adminInfo.CurrentOrgId)
  2172. if pharmacyConfig.IsOpen != 1 {
  2173. if device_number != number_count {
  2174. // 查询该药品最后一次出库记录
  2175. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  2176. //回退库存
  2177. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2178. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  2179. }
  2180. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2181. var stock_max_number int64
  2182. var stock_min_number int64
  2183. if number_count >= drug.MinNumber {
  2184. stock_max_number = device_number / drug.MinNumber
  2185. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  2186. stock_min_number = device_number % drug.MinNumber
  2187. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  2188. } else {
  2189. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  2190. }
  2191. }
  2192. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  2193. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  2194. }
  2195. //删除记录
  2196. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  2197. //查询默认仓库剩余多少库存
  2198. var sum_count int64
  2199. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  2200. for _, its := range stockInfo {
  2201. if its.MaxUnit == drug.MaxUnit {
  2202. its.StockMaxNumber = its.StockMaxNumber * drug.MinNumber
  2203. }
  2204. sum_count += its.StockMaxNumber + its.StockMinNumber
  2205. }
  2206. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  2207. }
  2208. }
  2209. }
  2210. }
  2211. }
  2212. //保存处方开药
  2213. if drugOutConfig.IsOpen == 1 {
  2214. //修改处方
  2215. for _, advice := range advices {
  2216. var drug_id int64
  2217. var prescribing_number float64
  2218. var prescribingNumberUnit string
  2219. var prescribingNumber string
  2220. var adviceId int64
  2221. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  2222. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  2223. }
  2224. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  2225. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  2226. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  2227. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  2228. }
  2229. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  2230. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  2231. }
  2232. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  2233. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  2234. }
  2235. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  2236. if drug.ID == 0 {
  2237. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2238. return
  2239. }
  2240. //查询药品的所有库存
  2241. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  2242. var total_count int64
  2243. for _, it := range list {
  2244. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  2245. }
  2246. totals := strconv.FormatInt(total_count, 10)
  2247. //查询该药品是否存在开药记录
  2248. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  2249. //新增处方
  2250. if advicelist.ID == 0 {
  2251. //查询最新批次库存
  2252. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2253. var batch_number_count int64
  2254. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2255. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  2256. all_count, _ := strconv.ParseFloat(totals, 64)
  2257. if prescribingNumberUnit == drug.MinUnit {
  2258. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2259. if drug.IsUse != 1 {
  2260. if drug.IsProject == 0 || drug.IsProject == 2 {
  2261. if all_count == 0 {
  2262. tx.Rollback()
  2263. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2264. return
  2265. }
  2266. if prescribing_number > all_count {
  2267. tx.Rollback()
  2268. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2269. return
  2270. }
  2271. }
  2272. if adminInfo.CurrentOrgId == 10215 {
  2273. if prescribing_number > batch_number_all_count {
  2274. tx.Rollback()
  2275. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2276. return
  2277. }
  2278. }
  2279. }
  2280. } else {
  2281. if prescribingNumberUnit == drug.MaxUnit {
  2282. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  2283. num := prescribing_number * float64(drug.MinNumber)
  2284. if drug.IsUse != 1 {
  2285. if drug.IsProject == 0 || drug.IsProject == 2 {
  2286. if all_count == 0 {
  2287. tx.Rollback()
  2288. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2289. return
  2290. }
  2291. if num > all_count {
  2292. tx.Rollback()
  2293. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2294. return
  2295. }
  2296. }
  2297. if adminInfo.CurrentOrgId == 10215 {
  2298. if prescribing_number > batch_number_all_count {
  2299. tx.Rollback()
  2300. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2301. return
  2302. }
  2303. }
  2304. }
  2305. }
  2306. }
  2307. }
  2308. //修改处方
  2309. if advicelist.ID > 0 {
  2310. //查询最新批次库存
  2311. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2312. var batch_number_count int64
  2313. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  2314. var device_number int64
  2315. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  2316. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2317. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2318. device_number = prescribingNumberInt * drug.MinNumber
  2319. }
  2320. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  2321. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  2322. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  2323. device_number = prescribingNumberInt
  2324. }
  2325. var number_count int64
  2326. if prescribingNumberUnit == drug.MaxUnit {
  2327. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2328. number_count = prescribingNumberInt * drug.MinNumber
  2329. }
  2330. if prescribingNumberUnit == drug.MinUnit {
  2331. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  2332. number_count = prescribingNumberInt
  2333. }
  2334. fmt.Println("number_count--------------", number_count)
  2335. fmt.Println("device_number--------------", device_number)
  2336. fmt.Println("batch_number_count", batch_number_count)
  2337. //如果修改的数量大于之前修改的数量
  2338. if (number_count - device_number) > 0 {
  2339. //如果修改的差数量 大于库存数量
  2340. if drug.IsUse != 1 {
  2341. if drug.IsProject == 0 || drug.IsProject == 2 {
  2342. if total_count == 0 {
  2343. tx.Rollback()
  2344. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2345. return
  2346. }
  2347. if (number_count - device_number) > total_count {
  2348. tx.Rollback()
  2349. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  2350. return
  2351. }
  2352. }
  2353. if adminInfo.CurrentOrgId == 10215 {
  2354. if (number_count - device_number) > batch_number_count {
  2355. tx.Rollback()
  2356. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  2357. return
  2358. }
  2359. }
  2360. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  2361. //查询历史出库数据总批次
  2362. // 查询该药品最后一次出库记录
  2363. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  2364. var out_count int64
  2365. var in_count int64
  2366. var stock_max_number int64
  2367. var stock_min_number int64
  2368. for _, it := range outInfo {
  2369. if it.CountUnit == drug.MaxUnit {
  2370. it.Count = it.Count * drug.MinNumber
  2371. }
  2372. out_count += it.Count
  2373. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  2374. stock_max_number = warehouseInfoList.StockMaxNumber
  2375. stock_min_number = warehouseInfoList.StockMinNumber
  2376. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  2377. }
  2378. if out_count > 0 {
  2379. if (number_count - device_number) > in_count {
  2380. tx.Rollback()
  2381. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  2382. return
  2383. }
  2384. }
  2385. // 未出库
  2386. if out_count == 0 {
  2387. var sum_in_count int64
  2388. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  2389. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  2390. if sum_in_count == 0 {
  2391. tx.Rollback()
  2392. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2393. return
  2394. }
  2395. //如果修改的数量大于有库存的第一个批次
  2396. if number_count > sum_in_count {
  2397. tx.Rollback()
  2398. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  2399. return
  2400. }
  2401. }
  2402. }
  2403. }
  2404. }
  2405. }
  2406. }
  2407. }
  2408. }
  2409. }
  2410. }
  2411. }
  2412. }
  2413. }
  2414. }
  2415. //校验耗材库存
  2416. if goodOutConfig.IsOpen == 1 {
  2417. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2418. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2419. if len(prescriptions) > 0 {
  2420. for _, item := range prescriptions {
  2421. items := item.(map[string]interface{})
  2422. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2423. projects := items["project"].([]interface{})
  2424. if len(projects) > 0 {
  2425. for _, project := range projects {
  2426. var project_id int64
  2427. var project_type int64
  2428. var totals float64
  2429. var project_name string
  2430. var parsetotal int64
  2431. var id int64
  2432. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2433. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2434. }
  2435. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2436. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2437. }
  2438. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2439. total, _ := project.(map[string]interface{})["total"].(string)
  2440. totals, _ = strconv.ParseFloat(total, 64)
  2441. }
  2442. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2443. project_name = project.(map[string]interface{})["project_name"].(string)
  2444. }
  2445. if project_type == 3 {
  2446. //查找该耗材的出库记录
  2447. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2448. if len(goodWarehouseInfo) == 0 {
  2449. //查询耗材库存
  2450. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2451. var stock_count int64
  2452. for _, it := range list {
  2453. stock_count += it.StockCount
  2454. }
  2455. stock_counts := strconv.FormatInt(stock_count, 10)
  2456. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2457. if stock_total_count == 0 {
  2458. tx.Rollback()
  2459. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2460. return
  2461. }
  2462. if totals > stock_total_count {
  2463. tx.Rollback()
  2464. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2465. return
  2466. }
  2467. }
  2468. if len(goodWarehouseInfo) > 0 {
  2469. //查询该患者耗材的历史数据
  2470. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2471. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2472. //数量发生改变
  2473. if parsetotal != count {
  2474. //如果现在的数量大于历史数量,就要看库存是否足够
  2475. if parsetotal > count {
  2476. //查询耗材所有库存
  2477. list, _ := service.GetGoodWarehouseInfoSevenTen(project_id, storeConfig.StorehouseOutInfo)
  2478. var stock_count int64
  2479. for _, it := range list {
  2480. stock_count += it.StockCount
  2481. }
  2482. //库存不足
  2483. if stock_count == 0 {
  2484. tx.Rollback()
  2485. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2486. return
  2487. }
  2488. if (parsetotal - count) > stock_count {
  2489. tx.Rollback()
  2490. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2491. return
  2492. }
  2493. }
  2494. }
  2495. }
  2496. }
  2497. }
  2498. }
  2499. }
  2500. }
  2501. }
  2502. }
  2503. }
  2504. //不使用耗材保存处方出库
  2505. if goodOutConfig.IsOpen != 1 {
  2506. if stockConfig.IsOpen == 1 {
  2507. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2508. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2509. if len(prescriptions) > 0 {
  2510. for _, item := range prescriptions {
  2511. items := item.(map[string]interface{})
  2512. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2513. projects := items["project"].([]interface{})
  2514. if len(projects) > 0 {
  2515. for _, project := range projects {
  2516. var project_id int64
  2517. var project_type int64
  2518. var totals float64
  2519. var project_name string
  2520. var parsetotal int64
  2521. var id int64
  2522. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  2523. id = int64(project.(map[string]interface{})["id"].(float64))
  2524. }
  2525. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  2526. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  2527. }
  2528. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  2529. project_type = int64(project.(map[string]interface{})["type"].(float64))
  2530. }
  2531. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  2532. total, _ := project.(map[string]interface{})["total"].(string)
  2533. totals, _ = strconv.ParseFloat(total, 64)
  2534. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  2535. }
  2536. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  2537. project_name = project.(map[string]interface{})["project_name"].(string)
  2538. }
  2539. if project_type == 3 {
  2540. //查找该耗材的出库记录
  2541. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  2542. //没有出库记录
  2543. if len(goodWarehouseInfo) == 0 {
  2544. //查询耗材库存
  2545. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  2546. var stock_count int64
  2547. for _, it := range list {
  2548. stock_count += it.StockCount
  2549. }
  2550. stock_counts := strconv.FormatInt(stock_count, 10)
  2551. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  2552. if stock_total_count == 0 {
  2553. tx.Rollback()
  2554. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2555. return
  2556. }
  2557. if totals > stock_total_count {
  2558. tx.Rollback()
  2559. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  2560. return
  2561. }
  2562. //查找今日该患者已经出库的所有耗材
  2563. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2564. for _, item := range goodList {
  2565. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2566. var flush_count int64
  2567. for _, it := range goodListSix {
  2568. flush_count += it.StockCount
  2569. }
  2570. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2571. creater := adminInfo.AdminUser.Id
  2572. if errs != nil {
  2573. goodErrcode := models.XtGoodErrcode{
  2574. UserOrgId: item.OrgId,
  2575. Errcode: "手动出库更新剩余出库失败",
  2576. GoodId: item.GoodId,
  2577. Status: 1,
  2578. Ctime: time.Now().Unix(),
  2579. Mtime: 0,
  2580. Count: 0,
  2581. StockCount: 0,
  2582. Creater: creater,
  2583. BatchNumberId: 0,
  2584. WarehouseOutId: 0,
  2585. }
  2586. service.CreateGoodErrcode(goodErrcode)
  2587. }
  2588. }
  2589. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2590. }
  2591. //有出库记录
  2592. if len(goodWarehouseInfo) > 0 {
  2593. //查询该患者耗材的历史数据
  2594. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  2595. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  2596. //数量发生改变
  2597. if parsetotal != count {
  2598. //查找今日该患者已经出库的所有耗材
  2599. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  2600. for _, item := range goodList {
  2601. goodListSix, _ := service.GetSumGoodList(item.OrgId, item.StorehouseId, item.GoodId)
  2602. var flush_count int64
  2603. for _, it := range goodListSix {
  2604. flush_count += it.StockCount
  2605. }
  2606. errs := service.UpdateSumGood(item.OrgId, item.StorehouseId, item.GoodId, flush_count)
  2607. //减少出库数量
  2608. creater := adminInfo.AdminUser.Id
  2609. if errs != nil {
  2610. goodErrcode := models.XtGoodErrcode{
  2611. UserOrgId: item.OrgId,
  2612. Errcode: "手动出库更新剩余出库失败",
  2613. GoodId: item.GoodId,
  2614. Status: 1,
  2615. Ctime: time.Now().Unix(),
  2616. Mtime: 0,
  2617. Count: 0,
  2618. StockCount: 0,
  2619. Creater: creater,
  2620. BatchNumberId: 0,
  2621. WarehouseOutId: 0,
  2622. }
  2623. service.CreateGoodErrcode(goodErrcode)
  2624. }
  2625. //查询默认仓库
  2626. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  2627. var total_count int64
  2628. for _, it := range stockList {
  2629. total_count += it.StockCount
  2630. }
  2631. //基础库插入数据
  2632. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  2633. }
  2634. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  2635. }
  2636. }
  2637. }
  2638. }
  2639. }
  2640. }
  2641. }
  2642. }
  2643. }
  2644. }
  2645. }
  2646. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  2647. var hpInfo models.HisPrescriptionInfo
  2648. if info.ID == 0 {
  2649. var randNum int
  2650. randNum = rand.Intn(10000) + 1000
  2651. timestamp := time.Now().Unix()
  2652. tempTime := time.Unix(timestamp, 0)
  2653. timeFormat := tempTime.Format("20060102150405")
  2654. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  2655. hpInfo = models.HisPrescriptionInfo{
  2656. HisPatientId: his_patient_id,
  2657. UserOrgId: adminInfo.CurrentOrgId,
  2658. RecordDate: theTime.Unix(),
  2659. PatientId: patient_id,
  2660. Status: 1,
  2661. Ctime: time.Now().Unix(),
  2662. Mtime: time.Now().Unix(),
  2663. Creator: adminInfo.AdminUser.Id,
  2664. Modifier: adminInfo.AdminUser.Id,
  2665. Diagnosis: diagnose,
  2666. SickHistory: sick_history,
  2667. Departments: department,
  2668. RegisterType: reg_type,
  2669. PrescriptionNumber: p_number,
  2670. PrescriptionStatus: 1,
  2671. Doctor: role.UserName,
  2672. DoctorId: doctor_id,
  2673. SickType: sick_type,
  2674. PType: p_type,
  2675. PatientDiagnosis: patient_diagnose,
  2676. }
  2677. service.SavePatientPrescriptionInfo(hpInfo)
  2678. //创建步骤表
  2679. finish := models.XtDialysisFinish{
  2680. IsFinish: 1,
  2681. UserOrgId: adminInfo.CurrentOrgId,
  2682. Status: 1,
  2683. Ctime: time.Now().Unix(),
  2684. Mtime: 0,
  2685. Module: 4,
  2686. RecordDate: theTime.Unix(),
  2687. Sourse: 1,
  2688. PatientId: patient_id,
  2689. }
  2690. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, theTime.Unix(), 4, patient_id)
  2691. if dialysisFinish.ID == 0 {
  2692. service.CreateDialysisFinish(finish)
  2693. }
  2694. redis := service.RedisClient()
  2695. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2696. redis.Set(key, "", time.Second)
  2697. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2698. redis.Set(keyOne, "", time.Second)
  2699. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2700. redis.Set(keySeven, "", time.Second)
  2701. defer redis.Close()
  2702. } else {
  2703. hpInfo = models.HisPrescriptionInfo{
  2704. ID: info.ID,
  2705. UserOrgId: adminInfo.CurrentOrgId,
  2706. RecordDate: info.RecordDate,
  2707. PatientId: info.PatientId,
  2708. Status: 1,
  2709. Ctime: info.Ctime,
  2710. Mtime: time.Now().Unix(),
  2711. Creator: info.Creator,
  2712. Modifier: adminInfo.AdminUser.Id,
  2713. Diagnosis: diagnose,
  2714. SickHistory: sick_history,
  2715. Departments: department,
  2716. RegisterType: reg_type,
  2717. PrescriptionNumber: info.PrescriptionNumber,
  2718. Doctor: role.UserName,
  2719. PrescriptionStatus: info.PrescriptionStatus,
  2720. DoctorId: doctor_id,
  2721. SickType: sick_type,
  2722. PType: info.PType,
  2723. HisPatientId: info.HisPatientId,
  2724. PatientDiagnosis: patient_diagnose,
  2725. }
  2726. service.SavePatientPrescriptionInfo(hpInfo)
  2727. //创建步骤表
  2728. finish := models.XtDialysisFinish{
  2729. IsFinish: 1,
  2730. UserOrgId: adminInfo.CurrentOrgId,
  2731. Status: 1,
  2732. Ctime: time.Now().Unix(),
  2733. Mtime: 0,
  2734. Module: 4,
  2735. RecordDate: info.RecordDate,
  2736. Sourse: 1,
  2737. PatientId: info.PatientId,
  2738. }
  2739. dialysisFinish, _ := service.GetDialysisFinish(adminInfo.CurrentOrgId, info.RecordDate, 4, info.PatientId)
  2740. if dialysisFinish.ID == 0 {
  2741. service.CreateDialysisFinish(finish)
  2742. }
  2743. redis := service.RedisClient()
  2744. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2745. redis.Set(key, "", time.Second)
  2746. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2747. redis.Set(keyOne, "", time.Second)
  2748. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2749. redis.Set(keySeven, "", time.Second)
  2750. defer redis.Close()
  2751. }
  2752. //定义切片
  2753. var adviceList []models.HisDoctorAdviceInfo
  2754. var projectList []models.HisPrescriptionProject
  2755. if adminInfo.CurrentOrgId == 10489 || adminInfo.CurrentOrgId == 10510 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 10478 || adminInfo.CurrentOrgId == 10318 || adminInfo.CurrentOrgId == 10480 {
  2756. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  2757. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  2758. var tempPrescription *models.HisPrescription
  2759. if len(prescriptions) > 0 {
  2760. for _, item := range prescriptions {
  2761. // 开始外部循环的事务
  2762. tx := db.Begin()
  2763. // 在函数结束时处理事务回滚
  2764. defer func() {
  2765. if r := recover(); r != nil {
  2766. tx.Rollback()
  2767. }
  2768. }()
  2769. items := item.(map[string]interface{})
  2770. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  2771. utils.ErrorLog("id")
  2772. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2773. return
  2774. }
  2775. id := int64(items["id"].(float64))
  2776. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  2777. tempPrescription = &new_prescription
  2778. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  2779. utils.ErrorLog("type")
  2780. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2781. return
  2782. }
  2783. types := int64(items["type"].(float64))
  2784. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  2785. utils.ErrorLog("med_type")
  2786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2787. return
  2788. }
  2789. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  2790. if med_type == "0" {
  2791. med_type = "14"
  2792. }
  2793. //if order_status == 0 {
  2794. // order_status = 1
  2795. //}
  2796. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  2797. utils.ErrorLog("pre_time")
  2798. }
  2799. preTime, _ := items["pre_time"].(string)
  2800. fmt.Println("preTime", preTime)
  2801. timeLayout := "2006-01-02"
  2802. loc, _ := time.LoadLocation("Local")
  2803. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  2804. result := strings.Split(preTime, " ")
  2805. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  2806. if err != nil {
  2807. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2808. return
  2809. }
  2810. pTime := theTime2.Unix()
  2811. ctime := time.Now().Unix()
  2812. if tempPrescription.ID == 0 {
  2813. prescription := &models.HisPrescription{
  2814. ID: 0,
  2815. PatientId: patient_id,
  2816. UserOrgId: adminInfo.CurrentOrgId,
  2817. RecordDate: recordDateTime,
  2818. Ctime: ctime,
  2819. Mtime: ctime,
  2820. Type: types,
  2821. Modifier: adminInfo.AdminUser.Id,
  2822. Creator: adminInfo.AdminUser.Id,
  2823. Status: 1,
  2824. Doctor: role.UserName,
  2825. HisPatientId: his_patient_id,
  2826. OrderStatus: 1,
  2827. BatchNumber: "",
  2828. PrescriptionNumber: hpInfo.PrescriptionNumber,
  2829. PreTime: pTime,
  2830. PType: p_type,
  2831. MedType: med_type,
  2832. }
  2833. tempPrescription = prescription
  2834. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2835. redis := service.RedisClient()
  2836. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2837. redis.Set(key, "", time.Second)
  2838. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2839. redis.Set(keyOne, "", time.Second)
  2840. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2841. redis.Set(keySeven, "", time.Second)
  2842. defer redis.Close()
  2843. } else {
  2844. tempPrescription.ID = id
  2845. tempPrescription.Type = types
  2846. tempPrescription.Modifier = adminInfo.AdminUser.Id
  2847. tempPrescription.Mtime = time.Now().Unix()
  2848. tempPrescription.Doctor = role.UserName
  2849. //tempPrescription.OrderStatus = order_status
  2850. tempPrescription.PreTime = pTime
  2851. tempPrescription.MedType = med_type
  2852. service.SaveHisPrescriptionOne(tx, tempPrescription)
  2853. redis := service.RedisClient()
  2854. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2855. redis.Set(key, "", time.Second)
  2856. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2857. redis.Set(keyOne, "", time.Second)
  2858. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2859. redis.Set(keySeven, "", time.Second)
  2860. defer redis.Close()
  2861. }
  2862. //service.SaveHisPrescription(prescription)
  2863. //更改患者挂号状态
  2864. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  2865. fmt.Println("更改失败", err2)
  2866. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2867. advices := items["advices"].([]interface{})
  2868. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2869. groupNo := int64(0)
  2870. ctime := time.Now().Unix()
  2871. mtime := ctime
  2872. if len(advices) > 0 {
  2873. for _, advice := range advices {
  2874. tx := db.Begin()
  2875. // 在函数结束时处理事务回滚
  2876. defer func() {
  2877. if r := recover(); r != nil {
  2878. tx.Rollback()
  2879. }
  2880. }()
  2881. var s models.HisDoctorAdviceInfo
  2882. s.PrescriptionId = tempPrescription.ID
  2883. s.AdviceType = 2
  2884. s.AdviceDoctor = doctor_id
  2885. s.StopState = 2
  2886. s.ExecutionState = 2
  2887. s.AdviceDate = theTime3.Unix()
  2888. s.Status = 1
  2889. s.UserOrgId = adminInfo.CurrentOrgId
  2890. s.RecordDate = theTime3.Unix()
  2891. s.StartTime = tempPrescription.PreTime
  2892. s.Groupno = groupNo
  2893. s.CreatedTime = ctime
  2894. s.UpdatedTime = mtime
  2895. s.PatientId = patient_id
  2896. s.HisPatientId = his_patient_id
  2897. s.StartTime = pTime
  2898. s.IsSettle = 2
  2899. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  2900. if errcode > 0 {
  2901. c.ServeFailJSONWithSGJErrorCode(errcode)
  2902. return
  2903. }
  2904. s.StartTime = pTime
  2905. var total_count int64 //处方总库存
  2906. //查询改药品信息
  2907. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  2908. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  2909. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  2910. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  2911. total_count += prescribingNumberSeven * medical.MinNumber
  2912. }
  2913. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  2914. total_count += prescribingNumberSeven
  2915. }
  2916. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  2917. total_count += prescribingNumberSeven
  2918. }
  2919. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  2920. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  2921. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  2922. if s.Price != lastWarehouse.RetailPrice {
  2923. s.Price = lastWarehouse.RetailPrice
  2924. }
  2925. if s.Price == 0 {
  2926. if lastWarehouse.ID == 0 {
  2927. lastWarehouseTwo, _ := service.FindLastDrugWarehousingInfoByIDTwo(s.DrugId, storeConfig.DrugStorehouseOut)
  2928. s.Price = lastWarehouseTwo.RetailPrice
  2929. }
  2930. }
  2931. }
  2932. //查询保存处方出库开关是否打开
  2933. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  2934. if drugOutConfig.IsOpen == 1 {
  2935. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, s.DrugId)
  2936. // 查询该药品最后一次出库记录
  2937. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(s.DrugId, patient_id, recordDateTime, s.ID)
  2938. if len(druginfo) > 0 {
  2939. //回退库存
  2940. for _, it := range druginfo {
  2941. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  2942. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2943. }
  2944. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  2945. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2946. }
  2947. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  2948. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  2949. }
  2950. }
  2951. //删除记录
  2952. service.DeleteNewDrugAutoWarehouseSeven(s.DrugId, patient_id, recordDateTime, s.ID)
  2953. }
  2954. service.CreateHisDoctorAdviceOne(&s, tx)
  2955. advicelast, _ := service.GetLastHisAdvicesList(s.PatientId, s.AdviceDate, s.UserOrgId, tx)
  2956. //出库
  2957. if drug.IsUse == 2 {
  2958. creater := adminInfo.AdminUser.Id
  2959. newadviceInfo := &models.HisDoctorAdviceInfo{
  2960. ID: advicelast.ID,
  2961. UserOrgId: s.UserOrgId,
  2962. PatientId: s.PatientId,
  2963. HisPatientId: s.HisPatientId,
  2964. AdviceType: s.AdviceType,
  2965. AdviceDate: s.AdviceDate,
  2966. StartTime: s.StartTime,
  2967. AdviceName: s.AdviceName,
  2968. AdviceDesc: s.AdviceDesc,
  2969. ReminderDate: s.ReminderDate,
  2970. SingleDose: s.SingleDose,
  2971. SingleDoseUnit: s.SingleDoseUnit,
  2972. PrescribingNumber: s.PrescribingNumber,
  2973. PrescribingNumberUnit: s.PrescribingNumberUnit,
  2974. DeliveryWay: s.DeliveryWay,
  2975. ExecutionFrequency: s.ExecutionFrequency,
  2976. AdviceDoctor: s.AdviceDoctor,
  2977. Status: s.Status,
  2978. CreatedTime: s.CreatedTime,
  2979. UpdatedTime: s.UpdatedTime,
  2980. AdviceAffirm: s.AdviceAffirm,
  2981. Remark: s.Remark,
  2982. StopTime: s.StopTime,
  2983. StopReason: s.StopReason,
  2984. StopDoctor: s.StopDoctor,
  2985. StopState: s.StopState,
  2986. ParentId: s.ParentId,
  2987. ExecutionTime: s.ExecutionTime,
  2988. ExecutionStaff: s.ExecutionStaff,
  2989. ExecutionState: s.ExecutionState,
  2990. Checker: s.Checker,
  2991. RecordDate: s.RecordDate,
  2992. DialysisOrderId: s.DialysisOrderId,
  2993. CheckTime: s.CheckTime,
  2994. CheckState: s.CheckState,
  2995. DrugSpec: s.DrugSpec,
  2996. DrugSpecUnit: s.DrugSpecUnit,
  2997. Groupno: s.Groupno,
  2998. RemindType: s.RemindType,
  2999. FrequencyType: s.FrequencyType,
  3000. DayCount: s.DayCount,
  3001. WeekDay: s.WeekDay,
  3002. TemplateId: s.TemplateId,
  3003. Modifier: s.Modifier,
  3004. DrugId: s.DrugId,
  3005. Price: s.Price,
  3006. PrescriptionId: s.PrescriptionId,
  3007. MedListCodg: s.MedListCodg,
  3008. FeedetlSn: s.FeedetlSn,
  3009. Day: s.DayCount,
  3010. ChildDoctorAdvice: nil,
  3011. Drug: models.Drug{},
  3012. Diagnosis: s.Diagnosis,
  3013. Way: s.Way,
  3014. HospApprFlag: s.HospApprFlag,
  3015. LmtUsedFlag: s.LmtUsedFlag,
  3016. HisOrderInfo: models.HisOrderInfo{},
  3017. IsMedicine: s.IsMedicine,
  3018. ExecutionFrequencyId: s.ExecutionFrequencyId,
  3019. Child: nil,
  3020. IsSettle: s.IsSettle,
  3021. IsMobile: s.IsMobile,
  3022. IsSelfDrug: s.IsSelfDrug,
  3023. DrugWayCount: s.DrugWayCount,
  3024. }
  3025. service.NewHisDrugsDelivery(s.UserOrgId, creater, newadviceInfo, tx)
  3026. }
  3027. //更新字典里面的库存
  3028. stockInfo, _ := service.GetNewDrugAllStockInfo(storeConfig.DrugStorehouseOut, s.UserOrgId, s.DrugId, tx)
  3029. var sum_count int64
  3030. for _, its := range stockInfo {
  3031. baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3032. if its.MaxUnit == baseDrug.MaxUnit {
  3033. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3034. }
  3035. sum_count += its.StockMaxNumber + its.StockMinNumber
  3036. }
  3037. //更新基础库存
  3038. service.UpdateNewBaseDrugSumTwo(s.DrugId, sum_count, s.UserOrgId, tx)
  3039. //剩余库存
  3040. service.UpdateNewDrugStockCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, sum_count, tx)
  3041. over, _ := service.FindNewOverCount(s.DrugId, s.UserOrgId, storeConfig.DrugStorehouseOut, tx)
  3042. service.UpdateNewActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount, tx)
  3043. }
  3044. //记录日志
  3045. byterequest, _ := json.Marshal(s)
  3046. adviceLog := models.XtDoctorAdviceLog{
  3047. UserOrgId: s.UserOrgId,
  3048. PatientId: s.PatientId,
  3049. AdminUserId: adminInfo.AdminUser.Id,
  3050. Module: 1,
  3051. ErrLog: string(byterequest),
  3052. Status: 1,
  3053. Ctime: time.Now().Unix(),
  3054. Mtime: 0,
  3055. Source: "电脑端新建his医嘱",
  3056. RecordDate: s.AdviceDate,
  3057. }
  3058. service.CreateDoctorAdviceLog(adviceLog)
  3059. //存储切片中
  3060. adviceList = append(adviceList, s)
  3061. redis := service.RedisClient()
  3062. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3063. redis.Set(key, "", time.Second)
  3064. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3065. redis.Set(keyOne, "", time.Second)
  3066. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3067. redis.Set(keySeven, "", time.Second)
  3068. var randNum int
  3069. randNum = rand.Intn(10000) + 1000
  3070. timestamp := time.Now().Unix()
  3071. tempTime := time.Unix(timestamp, 0)
  3072. timeFormat := tempTime.Format("20060102150405")
  3073. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3074. service.CreateHisDoctorAdviceOne(&s, tx)
  3075. //list, _ := service.GetHisToday(s.PatientId, s.AdviceDate, s.UserOrgId, s.DrugId, tx)
  3076. //var count_total int64
  3077. //var count_one int64
  3078. //for _, its := range list {
  3079. // baseDrug, _ := service.GetNewBaseDrugMedical(its.DrugId, tx)
  3080. // if its.PrescribingNumberUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  3081. // prescribingNumberTenty := strconv.FormatFloat(its.PrescribingNumber, 'f', -1, 64)
  3082. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3083. // count_total += prescribingNumberSevenTy * baseDrug.MinNumber
  3084. // }
  3085. //
  3086. // if its.PrescribingNumberUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  3087. // prescribingNumberTenty := strconv.FormatFloat(its.PrescribingNumber, 'f', -1, 64)
  3088. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3089. // count_total += prescribingNumberSevenTy
  3090. // }
  3091. //
  3092. // if its.PrescribingNumberUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
  3093. // prescribingNumberTenty := strconv.FormatFloat(its.PrescribingNumber, 'f', -1, 64)
  3094. // prescribingNumberSevenTy, _ := strconv.ParseInt(prescribingNumberTenty, 10, 64)
  3095. // count_total += prescribingNumberSevenTy
  3096. // }
  3097. //
  3098. // drugAuto, _ := service.GetLastDrugAuto(its.ID, its.DrugId, its.AdviceDate, its.PatientId,its.UserOrgId, tx)
  3099. //
  3100. // if drugAuto.CountUnit == baseDrug.MaxUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  3101. //
  3102. // count_one = drugAuto.Count * baseDrug.MinNumber
  3103. // }
  3104. //
  3105. // if drugAuto.CountUnit == baseDrug.MinUnit && baseDrug.MaxUnit != baseDrug.MinUnit {
  3106. //
  3107. // count_one = drugAuto.Count
  3108. // }
  3109. //
  3110. // if drugAuto.CountUnit == baseDrug.MaxUnit && baseDrug.MaxUnit == baseDrug.MinUnit {
  3111. //
  3112. // count_one = drugAuto.Count
  3113. // }
  3114. // fmt.Println("count_one==================", count_one)
  3115. // fmt.Println("count_total==================", count_total)
  3116. // if count_total != count_one {
  3117. //
  3118. // service.UpdateTodayHis(its.DrugId, its.AdviceDate, its.PatientId, its.UserOrgId, baseDrug.MinUnit, count_total, its.ID, tx)
  3119. // }
  3120. //
  3121. //}
  3122. tx.Commit()
  3123. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3124. redis.Set(keySix, "", time.Second)
  3125. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3126. redis.Set(keyFive, "", time.Second)
  3127. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3128. redis.Set(keyEight, "", time.Second)
  3129. defer redis.Close()
  3130. }
  3131. }
  3132. }
  3133. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3134. projects := items["project"].([]interface{})
  3135. if len(projects) > 0 {
  3136. for _, project := range projects {
  3137. tx := db.Begin()
  3138. // 在函数结束时处理事务回滚
  3139. defer func() {
  3140. if r := recover(); r != nil {
  3141. tx.Rollback()
  3142. }
  3143. }()
  3144. var p models.HisPrescriptionProject
  3145. p.PrescriptionId = tempPrescription.ID
  3146. p.Ctime = time.Now().Unix()
  3147. p.Mtime = time.Now().Unix()
  3148. p.PatientId = patient_id
  3149. p.RecordDate = theTime3.Unix()
  3150. p.Doctor = doctor_id
  3151. p.UserOrgId = adminInfo.CurrentOrgId
  3152. p.HisPatientId = his_patient_id
  3153. p.Status = 1
  3154. p.StartTime = pTime
  3155. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3156. if errcode > 0 {
  3157. c.ServeFailJSONWithSGJErrorCode(errcode)
  3158. return
  3159. }
  3160. if p.ID == 0 {
  3161. p.IsOut = 2
  3162. }
  3163. if p.ID > 0 {
  3164. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3165. p.IsOut = projectDetail.IsOut
  3166. }
  3167. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3168. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3169. if p.Type == 3 {
  3170. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3171. if p.Price != lastWarehouse.PackingPrice {
  3172. p.Price = lastWarehouse.PackingPrice
  3173. }
  3174. if p.Unit == "" {
  3175. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3176. p.Unit = goodInfoOne.PackingUnit
  3177. }
  3178. }
  3179. }
  3180. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3181. //
  3182. // if p.Type == 3 {
  3183. // //查询该耗材是否停用
  3184. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3185. // //表示该耗材已经停用,不能保存
  3186. // if goodInfoSeven.ID == 0 {
  3187. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3188. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3189. // return
  3190. // }
  3191. // }
  3192. //
  3193. //}
  3194. service.CreateNewHisProjectTwo(&p, tx)
  3195. var randNum int
  3196. randNum = rand.Intn(10000) + 1000
  3197. timestamp := time.Now().Unix()
  3198. tempTime := time.Unix(timestamp, 0)
  3199. timeFormat := tempTime.Format("20060102150405")
  3200. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3201. service.CreateNewHisProjectTwo(&p, tx)
  3202. //查询保存耗材出库开关是否打开
  3203. if goodOutConfig.IsOpen == 1 {
  3204. //耗材出库
  3205. if p.Type == 3 {
  3206. lastHisProject, _ := service.GetLastHisProject(p.PatientId, p.UserOrgId, p.RecordDate, tx, p.ProjectId)
  3207. //查询历史出库数据
  3208. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3209. var out_count_five int64
  3210. for _, item := range flowGood {
  3211. out_count_five += item.Count
  3212. }
  3213. parseIntCount, _ := strconv.ParseInt(p.Count, 10, 64)
  3214. //如果当前处方的出库数量和已经出库的数量不一致,需要进行退库或者出库
  3215. if out_count_five != parseIntCount {
  3216. //查询耗材最后一次出库记录
  3217. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(p.ProjectId, patient_id, recordDateTime, lastHisProject.ID)
  3218. //查询默认出库仓库库存
  3219. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3220. if len(wareOut) > 0 {
  3221. for _, it := range wareOut {
  3222. //回退库存
  3223. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3224. //删除出库记录
  3225. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3226. }
  3227. }
  3228. timeStr := time.Now().Format("2006-01-02")
  3229. timeArr := strings.Split(timeStr, "-")
  3230. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3231. total = total + 1
  3232. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3233. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3234. number = number + total
  3235. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3236. operation_time := time.Now().Unix()
  3237. creater := c.GetAdminUserInfo().AdminUser.Id
  3238. recordDateStr := time.Now().Format("2006-01-02")
  3239. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3240. nowtime := recordDate.Unix()
  3241. warehouseOut := models.WarehouseOut{
  3242. WarehouseOutOrderNumber: warehousing_out_order,
  3243. OperationTime: operation_time,
  3244. OrgId: adminInfo.CurrentOrgId,
  3245. Creater: creater,
  3246. Ctime: time.Now().Unix(),
  3247. Status: 1,
  3248. WarehouseOutTime: nowtime,
  3249. Type: 1,
  3250. StorehouseId: storeConfig.StorehouseOutInfo,
  3251. IsCheck: 1,
  3252. IsSys: 1,
  3253. }
  3254. //查询是否生成出库单
  3255. out, _ := service.FindNewPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3256. if out.ID == 0 {
  3257. service.AddNewSigleWarehouseOut(&warehouseOut, tx)
  3258. }
  3259. lastOut, _ := service.FindNewLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime, tx)
  3260. goodObj, _ := service.GetNewGoodInformationByGoodIdThirty(p.ProjectId, tx)
  3261. houseConfig, _ := service.GetNewAllStoreHouseConfig(p.UserOrgId, tx)
  3262. dialyPrepareOne := models.DialysisBeforePrepare{
  3263. GoodTypeId: goodObj.GoodTypeId,
  3264. GoodId: p.ProjectId,
  3265. PatientId: p.PatientId,
  3266. RecordDate: p.RecordDate,
  3267. UserOrgId: adminInfo.CurrentOrgId,
  3268. Count: parseIntCount,
  3269. Ctime: time.Now().Unix(),
  3270. Creater: creater,
  3271. Status: 1,
  3272. StorehouseId: houseConfig.StorehouseOutInfo,
  3273. ProjectId: lastHisProject.ID,
  3274. }
  3275. //判断是否是零用耗材(非零用)
  3276. if goodObj.IsUse == 2 || goodObj.IsUse == 0 {
  3277. //查询历史出库数据
  3278. flowGood, _ := service.GetNewStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3279. var out_count int64
  3280. for _, item := range flowGood {
  3281. out_count += item.Count
  3282. }
  3283. //如果历史数和当前数据不想等才进行退库出库
  3284. if out_count != parseIntCount {
  3285. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3286. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3287. detail := models.AutomaticReduceDetail{
  3288. WarehouseOutId: 0,
  3289. WarehouseOutOrderNumber: "",
  3290. PatientId: p.PatientId,
  3291. Ctime: time.Now().Unix(),
  3292. Mtime: 0,
  3293. Status: 1,
  3294. RecordTime: p.RecordDate,
  3295. OrgId: p.UserOrgId,
  3296. GoodId: p.ProjectId,
  3297. GoodTypeId: 0,
  3298. Count: parseIntCount,
  3299. Type: 0,
  3300. ProjectId: lastHisProject.ID,
  3301. StorehouseId: 0,
  3302. }
  3303. service.CreateNewAutoDetail(detail, tx)
  3304. //查询剩余库存
  3305. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3306. var sum_count int64
  3307. for _, item := range goodList {
  3308. sum_count += item.StockCount
  3309. }
  3310. //更新剩余库存
  3311. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3312. //耗材
  3313. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3314. }
  3315. //判断是否是零用耗材(零用但是是出库耗材)
  3316. if goodObj.IsUse == 1 && goodObj.IsWarehouse == 1 {
  3317. //查询历史出库数据
  3318. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID)
  3319. var out_count int64
  3320. for _, item := range flowGood {
  3321. out_count += item.Count
  3322. }
  3323. //如果历史数和当前数据不想等才进行退库出库
  3324. if out_count != parseIntCount {
  3325. service.ConsumableNewPrescriptionDelivery(adminInfo.CurrentOrgId, p.PatientId, p.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount, tx)
  3326. service.UpdateNewAutomaticReduce(p.PatientId, p.RecordDate, p.ProjectId, lastHisProject.ID, tx)
  3327. detail := models.AutomaticReduceDetail{
  3328. WarehouseOutId: 0,
  3329. WarehouseOutOrderNumber: "",
  3330. PatientId: p.PatientId,
  3331. Ctime: time.Now().Unix(),
  3332. Mtime: 0,
  3333. Status: 1,
  3334. RecordTime: p.RecordDate,
  3335. OrgId: p.UserOrgId,
  3336. GoodId: p.ProjectId,
  3337. GoodTypeId: 0,
  3338. Count: parseIntCount,
  3339. Type: 0,
  3340. ProjectId: p.ID,
  3341. StorehouseId: 0,
  3342. }
  3343. service.CreateNewAutoDetail(detail, tx)
  3344. //查询剩余库存
  3345. goodList, _ := service.GetNewAllGoodSumCount(p.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, tx)
  3346. var sum_count int64
  3347. for _, item := range goodList {
  3348. sum_count += item.StockCount
  3349. }
  3350. //更新剩余库存
  3351. service.UpdateNewGoodFlushCount(houseConfig.StorehouseOutInfo, p.ProjectId, adminInfo.CurrentOrgId, sum_count, tx)
  3352. //耗材
  3353. service.UpdateNewGoodSumCountSeven(sum_count, p.ProjectId, adminInfo.CurrentOrgId, tx)
  3354. }
  3355. }
  3356. }
  3357. }
  3358. //记录日志
  3359. byterequest, _ := json.Marshal(p)
  3360. adviceLog := models.XtDoctorAdviceLog{
  3361. UserOrgId: p.UserOrgId,
  3362. PatientId: p.PatientId,
  3363. AdminUserId: adminInfo.AdminUser.Id,
  3364. Module: 1,
  3365. ErrLog: string(byterequest),
  3366. Status: 1,
  3367. Ctime: time.Now().Unix(),
  3368. Mtime: 0,
  3369. Source: "电脑端新建his项目",
  3370. RecordDate: p.RecordDate,
  3371. }
  3372. service.CreateDoctorAdviceLog(adviceLog)
  3373. projectList = append(projectList, p)
  3374. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3375. //新增或者编辑项目,修改对应的标签数据
  3376. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3377. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3378. var label models.HisLabelPrintInfo
  3379. project, _ := service.GetProjectDetail(p.ProjectId)
  3380. if project.CostClassify == 3 { //类别为检验检查
  3381. if p.TeamId > 0 { //检验检查组套
  3382. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3383. if tempLabel.ID == 0 {
  3384. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3385. label.Number = tempPrescription.PrescriptionNumber
  3386. label.ProjectId = project.ID
  3387. label.Status = 1
  3388. label.IsPrint = 2
  3389. label.DoctorId = info.DoctorId
  3390. label.UserOrgId = p.UserOrgId
  3391. label.PatientId = patient_id
  3392. label.RecordDate = recordDateTime
  3393. label.Ctime = time.Now().Unix()
  3394. label.Mtime = time.Now().Unix()
  3395. label.ItemId = p.TeamId
  3396. label.FeedetlSn = p.FeedetlSn
  3397. label.PProjectId = p.ID
  3398. label.ProjectName = team.ProjectTeam
  3399. label.PatientName = patient.Name
  3400. service.CreateNewHisLabelRecord(&label, tx)
  3401. }
  3402. } else { //单条检验检查项目
  3403. label.Number = tempPrescription.PrescriptionNumber
  3404. label.ProjectId = project.ID
  3405. label.Status = 1
  3406. label.DoctorId = info.DoctorId
  3407. label.UserOrgId = p.UserOrgId
  3408. label.PatientId = patient_id
  3409. label.RecordDate = recordDateTime
  3410. label.IsPrint = 2
  3411. label.Ctime = time.Now().Unix()
  3412. label.Mtime = time.Now().Unix()
  3413. label.FeedetlSn = p.FeedetlSn
  3414. label.PProjectId = p.ID
  3415. label.ItemId = p.TeamId
  3416. label.ProjectName = project.ProjectName
  3417. label.PatientName = patient.Name
  3418. service.CreateNewHisLabelRecord(&label, tx)
  3419. }
  3420. }
  3421. }
  3422. }
  3423. }
  3424. }
  3425. tx.Commit()
  3426. }
  3427. }
  3428. }
  3429. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3430. // addition := items["addition"].([]interface{})
  3431. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3432. // ctime := time.Now().Unix()
  3433. // mtime := ctime
  3434. // if len(addition) > 0 {
  3435. // for _, item := range addition {
  3436. // var s models.HisAdditionalCharge
  3437. // s.PrescriptionId = tempPrescription.ID
  3438. // s.Status = 1
  3439. // s.UserOrgId = adminInfo.CurrentOrgId
  3440. // s.RecordDate = recordDateTime
  3441. // s.CreatedTime = ctime
  3442. // s.UpdatedTime = mtime
  3443. // s.PatientId = patient_id
  3444. // s.HisPatientId = his_patient_id
  3445. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3446. // if errcode > 0 {
  3447. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3448. // return
  3449. // }
  3450. // service.CreateAdditionalCharge(&s)
  3451. // var randNum int
  3452. // randNum = rand.Intn(10000) + 1000
  3453. // timestamp := time.Now().Unix()
  3454. // tempTime := time.Unix(timestamp, 0)
  3455. // timeFormat := tempTime.Format("20060102150405")
  3456. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3457. // service.CreateAdditionalCharge(&s)
  3458. //
  3459. // }
  3460. // }
  3461. //}
  3462. }
  3463. }
  3464. }
  3465. tx.Commit()
  3466. if err == nil {
  3467. c.ServeSuccessJSON(map[string]interface{}{
  3468. "msg": "保存成功",
  3469. })
  3470. return
  3471. } else {
  3472. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  3473. return
  3474. }
  3475. } else {
  3476. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  3477. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  3478. var tempPrescription *models.HisPrescription
  3479. if len(prescriptions) > 0 {
  3480. for _, item := range prescriptions {
  3481. items := item.(map[string]interface{})
  3482. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  3483. utils.ErrorLog("id")
  3484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3485. return
  3486. }
  3487. id := int64(items["id"].(float64))
  3488. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  3489. tempPrescription = &new_prescription
  3490. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  3491. utils.ErrorLog("type")
  3492. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3493. return
  3494. }
  3495. types := int64(items["type"].(float64))
  3496. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  3497. utils.ErrorLog("med_type")
  3498. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3499. return
  3500. }
  3501. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  3502. if med_type == "0" {
  3503. med_type = "14"
  3504. }
  3505. //if order_status == 0 {
  3506. // order_status = 1
  3507. //}
  3508. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  3509. utils.ErrorLog("pre_time")
  3510. }
  3511. preTime, _ := items["pre_time"].(string)
  3512. timeLayout := "2006-01-02"
  3513. loc, _ := time.LoadLocation("Local")
  3514. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  3515. result := strings.Split(preTime, " ")
  3516. theTime3, _ := time.ParseInLocation(timeLayout, result[0], loc)
  3517. if err != nil {
  3518. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3519. return
  3520. }
  3521. pTime := theTime2.Unix()
  3522. ctime := time.Now().Unix()
  3523. if tempPrescription.ID == 0 {
  3524. prescription := &models.HisPrescription{
  3525. ID: 0,
  3526. PatientId: patient_id,
  3527. UserOrgId: adminInfo.CurrentOrgId,
  3528. RecordDate: recordDateTime,
  3529. Ctime: ctime,
  3530. Mtime: ctime,
  3531. Type: types,
  3532. Modifier: adminInfo.AdminUser.Id,
  3533. Creator: adminInfo.AdminUser.Id,
  3534. Status: 1,
  3535. Doctor: role.UserName,
  3536. HisPatientId: his_patient_id,
  3537. OrderStatus: 1,
  3538. BatchNumber: "",
  3539. PrescriptionNumber: hpInfo.PrescriptionNumber,
  3540. PreTime: pTime,
  3541. PType: p_type,
  3542. MedType: med_type,
  3543. }
  3544. tempPrescription = prescription
  3545. service.SaveHisPrescription(tempPrescription)
  3546. redis := service.RedisClient()
  3547. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3548. redis.Set(key, "", time.Second)
  3549. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3550. redis.Set(keyOne, "", time.Second)
  3551. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3552. redis.Set(keySeven, "", time.Second)
  3553. defer redis.Close()
  3554. } else {
  3555. tempPrescription.ID = id
  3556. tempPrescription.Type = types
  3557. tempPrescription.Modifier = adminInfo.AdminUser.Id
  3558. tempPrescription.Mtime = time.Now().Unix()
  3559. tempPrescription.Doctor = role.UserName
  3560. //tempPrescription.OrderStatus = order_status
  3561. tempPrescription.PreTime = pTime
  3562. tempPrescription.MedType = med_type
  3563. service.SaveHisPrescription(tempPrescription)
  3564. redis := service.RedisClient()
  3565. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3566. redis.Set(key, "", time.Second)
  3567. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3568. redis.Set(keyOne, "", time.Second)
  3569. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3570. redis.Set(keySeven, "", time.Second)
  3571. defer redis.Close()
  3572. }
  3573. //service.SaveHisPrescription(prescription)
  3574. //更改患者挂号状态
  3575. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3576. fmt.Println("更改失败", err2)
  3577. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  3578. advices := items["advices"].([]interface{})
  3579. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3580. groupNo := int64(0)
  3581. ctime := time.Now().Unix()
  3582. mtime := ctime
  3583. if len(advices) > 0 {
  3584. for _, advice := range advices {
  3585. var s models.HisDoctorAdviceInfo
  3586. s.PrescriptionId = tempPrescription.ID
  3587. s.AdviceType = 2
  3588. s.AdviceDoctor = doctor_id
  3589. s.StopState = 2
  3590. s.ExecutionState = 2
  3591. s.AdviceDate = theTime3.Unix()
  3592. s.Status = 1
  3593. s.UserOrgId = adminInfo.CurrentOrgId
  3594. s.RecordDate = theTime3.Unix()
  3595. s.StartTime = tempPrescription.PreTime
  3596. s.Groupno = groupNo
  3597. s.CreatedTime = ctime
  3598. s.UpdatedTime = mtime
  3599. s.PatientId = patient_id
  3600. s.HisPatientId = his_patient_id
  3601. s.StartTime = pTime
  3602. s.IsSettle = 2
  3603. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  3604. if errcode > 0 {
  3605. c.ServeFailJSONWithSGJErrorCode(errcode)
  3606. return
  3607. }
  3608. s.StartTime = pTime
  3609. var total_count int64 //处方总库存
  3610. //查询改药品信息
  3611. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  3612. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  3613. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  3614. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  3615. total_count += prescribingNumberSeven * medical.MinNumber
  3616. }
  3617. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  3618. total_count += prescribingNumberSeven
  3619. }
  3620. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  3621. total_count += prescribingNumberSeven
  3622. }
  3623. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3624. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3625. lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  3626. if s.Price != lastWarehouse.RetailPrice {
  3627. s.Price = lastWarehouse.RetailPrice
  3628. }
  3629. if s.Price == 0 {
  3630. s.Price = lastWarehouse.RetailPrice
  3631. }
  3632. }
  3633. service.CreateHisDoctorAdvice(&s)
  3634. //记录日志
  3635. byterequest, _ := json.Marshal(s)
  3636. adviceLog := models.XtDoctorAdviceLog{
  3637. UserOrgId: s.UserOrgId,
  3638. PatientId: s.PatientId,
  3639. AdminUserId: adminInfo.AdminUser.Id,
  3640. Module: 1,
  3641. ErrLog: string(byterequest),
  3642. Status: 1,
  3643. Ctime: time.Now().Unix(),
  3644. Mtime: 0,
  3645. Source: "电脑端新建his医嘱",
  3646. RecordDate: s.AdviceDate,
  3647. }
  3648. service.CreateDoctorAdviceLog(adviceLog)
  3649. //存储切片中
  3650. adviceList = append(adviceList, s)
  3651. redis := service.RedisClient()
  3652. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3653. redis.Set(key, "", time.Second)
  3654. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3655. redis.Set(keyOne, "", time.Second)
  3656. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3657. redis.Set(keySeven, "", time.Second)
  3658. var randNum int
  3659. randNum = rand.Intn(10000) + 1000
  3660. timestamp := time.Now().Unix()
  3661. tempTime := time.Unix(timestamp, 0)
  3662. timeFormat := tempTime.Format("20060102150405")
  3663. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  3664. service.CreateHisDoctorAdvice(&s)
  3665. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  3666. redis.Set(keySix, "", time.Second)
  3667. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  3668. redis.Set(keyFive, "", time.Second)
  3669. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  3670. redis.Set(keyEight, "", time.Second)
  3671. defer redis.Close()
  3672. }
  3673. }
  3674. }
  3675. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  3676. projects := items["project"].([]interface{})
  3677. if len(projects) > 0 {
  3678. for _, project := range projects {
  3679. var p models.HisPrescriptionProject
  3680. p.PrescriptionId = tempPrescription.ID
  3681. p.Ctime = time.Now().Unix()
  3682. p.Mtime = time.Now().Unix()
  3683. p.PatientId = patient_id
  3684. p.RecordDate = theTime3.Unix()
  3685. p.Doctor = doctor_id
  3686. p.UserOrgId = adminInfo.CurrentOrgId
  3687. p.HisPatientId = his_patient_id
  3688. p.Status = 1
  3689. p.StartTime = pTime
  3690. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  3691. if errcode > 0 {
  3692. c.ServeFailJSONWithSGJErrorCode(errcode)
  3693. return
  3694. }
  3695. if p.ID == 0 {
  3696. p.IsOut = 2
  3697. }
  3698. if p.ID > 0 {
  3699. projectDetail, _ := service.GetHisPrescriptonProjectById(p.ID)
  3700. p.IsOut = projectDetail.IsOut
  3701. }
  3702. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  3703. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3704. if p.Type == 3 {
  3705. lastWarehouse, _ := service.FindFirstWarehousingInfoByStockThree(p.ProjectId, storeConfig.DrugStorehouseOut)
  3706. if p.Price != lastWarehouse.PackingPrice {
  3707. p.Price = lastWarehouse.PackingPrice
  3708. }
  3709. if p.Unit == "" {
  3710. goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3711. p.Unit = goodInfoOne.PackingUnit
  3712. }
  3713. }
  3714. }
  3715. //if adminInfo.CurrentOrgId == 9671 || adminInfo.CurrentOrgId == 10265 {
  3716. //
  3717. // if p.Type == 3 {
  3718. // //查询该耗材是否停用
  3719. // goodInfoSeven, _ := service.GetGoodByIdIsStop(p.ProjectId, adminInfo.CurrentOrgId)
  3720. // //表示该耗材已经停用,不能保存
  3721. // if goodInfoSeven.ID == 0 {
  3722. // goodInfoOne, _ := service.GetGoodInformationByGoodIdOne(p.ProjectId)
  3723. // c.ServeDynamicFailJsonSend(goodInfoOne.GoodName + "耗材已经停用,保存失败!")
  3724. // return
  3725. // }
  3726. // }
  3727. //
  3728. //}
  3729. service.CreateHisProjectTwo(&p)
  3730. //记录日志
  3731. byterequest, _ := json.Marshal(p)
  3732. adviceLog := models.XtDoctorAdviceLog{
  3733. UserOrgId: p.UserOrgId,
  3734. PatientId: p.PatientId,
  3735. AdminUserId: adminInfo.AdminUser.Id,
  3736. Module: 1,
  3737. ErrLog: string(byterequest),
  3738. Status: 1,
  3739. Ctime: time.Now().Unix(),
  3740. Mtime: 0,
  3741. Source: "电脑端新建his项目",
  3742. RecordDate: p.RecordDate,
  3743. }
  3744. service.CreateDoctorAdviceLog(adviceLog)
  3745. projectList = append(projectList, p)
  3746. var randNum int
  3747. randNum = rand.Intn(10000) + 1000
  3748. timestamp := time.Now().Unix()
  3749. tempTime := time.Unix(timestamp, 0)
  3750. timeFormat := tempTime.Format("20060102150405")
  3751. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  3752. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  3753. //新增或者编辑项目,修改对应的标签数据
  3754. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  3755. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  3756. var label models.HisLabelPrintInfo
  3757. project, _ := service.GetProjectDetail(p.ProjectId)
  3758. if project.CostClassify == 3 { //类别为检验检查
  3759. if p.TeamId > 0 { //检验检查组套
  3760. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  3761. if tempLabel.ID == 0 {
  3762. team, _ := service.GetProjectTeamDetail(p.TeamId)
  3763. label.Number = tempPrescription.PrescriptionNumber
  3764. label.ProjectId = project.ID
  3765. label.Status = 1
  3766. label.IsPrint = 2
  3767. label.DoctorId = info.DoctorId
  3768. label.UserOrgId = p.UserOrgId
  3769. label.PatientId = patient_id
  3770. label.RecordDate = recordDateTime
  3771. label.Ctime = time.Now().Unix()
  3772. label.Mtime = time.Now().Unix()
  3773. label.ItemId = p.TeamId
  3774. label.FeedetlSn = p.FeedetlSn
  3775. label.PProjectId = p.ID
  3776. label.ProjectName = team.ProjectTeam
  3777. label.PatientName = patient.Name
  3778. service.CreateHisLabelRecord(&label)
  3779. }
  3780. } else { //单条检验检查项目
  3781. label.Number = tempPrescription.PrescriptionNumber
  3782. label.ProjectId = project.ID
  3783. label.Status = 1
  3784. label.DoctorId = info.DoctorId
  3785. label.UserOrgId = p.UserOrgId
  3786. label.PatientId = patient_id
  3787. label.RecordDate = recordDateTime
  3788. label.IsPrint = 2
  3789. label.Ctime = time.Now().Unix()
  3790. label.Mtime = time.Now().Unix()
  3791. label.FeedetlSn = p.FeedetlSn
  3792. label.PProjectId = p.ID
  3793. label.ItemId = p.TeamId
  3794. label.ProjectName = project.ProjectName
  3795. label.PatientName = patient.Name
  3796. service.CreateHisLabelRecord(&label)
  3797. }
  3798. }
  3799. }
  3800. }
  3801. service.SaveHisProjectTwo(&p)
  3802. }
  3803. }
  3804. }
  3805. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  3806. // addition := items["addition"].([]interface{})
  3807. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  3808. // ctime := time.Now().Unix()
  3809. // mtime := ctime
  3810. // if len(addition) > 0 {
  3811. // for _, item := range addition {
  3812. // var s models.HisAdditionalCharge
  3813. // s.PrescriptionId = tempPrescription.ID
  3814. // s.Status = 1
  3815. // s.UserOrgId = adminInfo.CurrentOrgId
  3816. // s.RecordDate = recordDateTime
  3817. // s.CreatedTime = ctime
  3818. // s.UpdatedTime = mtime
  3819. // s.PatientId = patient_id
  3820. // s.HisPatientId = his_patient_id
  3821. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  3822. // if errcode > 0 {
  3823. // c.ServeFailJSONWithSGJErrorCode(errcode)
  3824. // return
  3825. // }
  3826. // service.CreateAdditionalCharge(&s)
  3827. // var randNum int
  3828. // randNum = rand.Intn(10000) + 1000
  3829. // timestamp := time.Now().Unix()
  3830. // tempTime := time.Unix(timestamp, 0)
  3831. // timeFormat := tempTime.Format("20060102150405")
  3832. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  3833. // service.CreateAdditionalCharge(&s)
  3834. //
  3835. // }
  3836. // }
  3837. //}
  3838. }
  3839. }
  3840. //查询今日该患者开的药品处方
  3841. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3842. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  3843. //药品出库
  3844. if drugOutConfig.IsOpen == 1 {
  3845. for _, item := range hisdoctorlist {
  3846. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  3847. // 查询该药品最后一次出库记录
  3848. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  3849. if len(druginfo) > 0 {
  3850. //回退库存
  3851. for _, it := range druginfo {
  3852. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  3853. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3854. }
  3855. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  3856. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3857. }
  3858. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  3859. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  3860. }
  3861. }
  3862. }
  3863. //删除记录
  3864. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  3865. //查询最后一次数据
  3866. if drugOutConfig.IsOpen == 1 {
  3867. //出库
  3868. if drug.IsUse == 2 {
  3869. creater := adminInfo.AdminUser.Id
  3870. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  3871. }
  3872. //更新字典里面的库存
  3873. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  3874. var sum_count int64
  3875. for _, its := range stockInfo {
  3876. baseDrug, _ := service.GetBaseDrugMedical(its.DrugId)
  3877. if its.MaxUnit == baseDrug.MaxUnit {
  3878. its.StockMaxNumber = its.StockMaxNumber * baseDrug.MinNumber
  3879. }
  3880. sum_count += its.StockMaxNumber + its.StockMinNumber
  3881. }
  3882. //更新基础库存
  3883. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  3884. //剩余库存
  3885. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut, sum_count)
  3886. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeConfig.DrugStorehouseOut)
  3887. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  3888. }
  3889. }
  3890. }
  3891. //耗材保存处方出库
  3892. if goodOutConfig.IsOpen == 1 {
  3893. //查询今日耗材出库数量
  3894. hisgoodlist, _ := service.GetHisGoodList(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  3895. for _, item := range hisgoodlist {
  3896. //查询历史出库数据
  3897. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3898. var out_count_five int64
  3899. for _, item := range flowGood {
  3900. out_count_five += item.Count
  3901. }
  3902. parseIntCount, _ := strconv.ParseInt(item.Count, 10, 64)
  3903. if out_count_five != parseIntCount {
  3904. //查询耗材最后一次出库记录
  3905. wareOut, _ := service.GetLastGoodWarehouseOutInfoByProjectId(item.ProjectId, patient_id, recordDateTime, item.ID)
  3906. //查询默认出库仓库库存
  3907. storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  3908. if len(wareOut) > 0 {
  3909. for _, it := range wareOut {
  3910. //回退库存
  3911. service.ModifyGoodWarehouseInfo(it.GoodId, it.WarehouseInfotId, it.OrgId, it.Count)
  3912. //删除出库记录
  3913. service.DeleteGoodWarehouseOutInfo(it.GoodId, it.SysRecordTime, it.OrgId, it.ProjectId)
  3914. }
  3915. }
  3916. timeStr := time.Now().Format("2006-01-02")
  3917. timeArr := strings.Split(timeStr, "-")
  3918. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  3919. total = total + 1
  3920. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  3921. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  3922. number = number + total
  3923. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  3924. operation_time := time.Now().Unix()
  3925. creater := c.GetAdminUserInfo().AdminUser.Id
  3926. recordDateStr := time.Now().Format("2006-01-02")
  3927. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  3928. nowtime := recordDate.Unix()
  3929. warehouseOut := models.WarehouseOut{
  3930. WarehouseOutOrderNumber: warehousing_out_order,
  3931. OperationTime: operation_time,
  3932. OrgId: adminInfo.CurrentOrgId,
  3933. Creater: creater,
  3934. Ctime: time.Now().Unix(),
  3935. Status: 1,
  3936. WarehouseOutTime: nowtime,
  3937. Type: 1,
  3938. StorehouseId: storeConfig.StorehouseOutInfo,
  3939. IsCheck: 1,
  3940. IsSys: 1,
  3941. }
  3942. //查询是否生成出库单
  3943. out, _ := service.FindPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3944. if out.ID == 0 {
  3945. service.AddSigleWarehouseOut(&warehouseOut)
  3946. }
  3947. lastOut, _ := service.FindLastPrescriptionWarehouseOut(adminInfo.CurrentOrgId, nowtime)
  3948. goodObj, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3949. houseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  3950. dialyPrepareOne := models.DialysisBeforePrepare{
  3951. GoodTypeId: goodObj.GoodTypeId,
  3952. GoodId: item.ProjectId,
  3953. PatientId: item.PatientId,
  3954. RecordDate: item.RecordDate,
  3955. UserOrgId: adminInfo.CurrentOrgId,
  3956. Count: parseIntCount,
  3957. Ctime: time.Now().Unix(),
  3958. Creater: creater,
  3959. Status: 1,
  3960. StorehouseId: houseConfig.StorehouseOutInfo,
  3961. ProjectId: item.ID,
  3962. }
  3963. goodinfo, _ := service.GetGoodInformationByGoodIdThirty(item.ProjectId)
  3964. if goodinfo.IsUser == 2 || goodinfo.IsUser == 0 {
  3965. //查询历史出库数据
  3966. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3967. var out_count int64
  3968. for _, item := range flowGood {
  3969. out_count += item.Count
  3970. }
  3971. //如果历史数和当前数据不想等才进行退库出库
  3972. if out_count != parseIntCount {
  3973. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  3974. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  3975. detail := models.AutomaticReduceDetail{
  3976. WarehouseOutId: 0,
  3977. WarehouseOutOrderNumber: "",
  3978. PatientId: item.PatientId,
  3979. Ctime: time.Now().Unix(),
  3980. Mtime: 0,
  3981. Status: 1,
  3982. RecordTime: item.RecordDate,
  3983. OrgId: item.UserOrgId,
  3984. GoodId: item.ProjectId,
  3985. GoodTypeId: 0,
  3986. Count: parseIntCount,
  3987. Type: 0,
  3988. ProjectId: item.ID,
  3989. StorehouseId: 0,
  3990. }
  3991. service.CreateAutoDetail(detail)
  3992. //查询剩余库存
  3993. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  3994. var sum_count int64
  3995. for _, item := range goodList {
  3996. sum_count += item.StockCount
  3997. }
  3998. //更新剩余库存
  3999. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4000. //耗材
  4001. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4002. }
  4003. }
  4004. if goodinfo.IsUser == 1 && goodinfo.IsWarehouse == 1 {
  4005. //查询历史出库数据
  4006. flowGood, _ := service.GetStockFlowIsBatchNumberSeventy(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4007. var out_count int64
  4008. for _, item := range flowGood {
  4009. out_count += item.Count
  4010. }
  4011. //如果历史数和当前数据不想等才进行退库出库
  4012. if out_count != parseIntCount {
  4013. service.ConsumablePrescriptionDelivery(adminInfo.CurrentOrgId, item.PatientId, item.RecordDate, &dialyPrepareOne, &lastOut, creater, parseIntCount)
  4014. service.UpdateAutomaticReduce(item.PatientId, item.RecordDate, item.ProjectId, item.ID)
  4015. detail := models.AutomaticReduceDetail{
  4016. WarehouseOutId: 0,
  4017. WarehouseOutOrderNumber: "",
  4018. PatientId: item.PatientId,
  4019. Ctime: time.Now().Unix(),
  4020. Mtime: 0,
  4021. Status: 1,
  4022. RecordTime: item.RecordDate,
  4023. OrgId: item.UserOrgId,
  4024. GoodId: item.ProjectId,
  4025. GoodTypeId: 0,
  4026. Count: parseIntCount,
  4027. Type: 0,
  4028. ProjectId: item.ID,
  4029. StorehouseId: 0,
  4030. }
  4031. service.CreateAutoDetail(detail)
  4032. //查询剩余库存
  4033. goodList, _ := service.GetAllGoodSumCount(item.ProjectId, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo)
  4034. var sum_count int64
  4035. for _, item := range goodList {
  4036. sum_count += item.StockCount
  4037. }
  4038. //更新剩余库存
  4039. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.ProjectId, adminInfo.CurrentOrgId, sum_count)
  4040. //耗材
  4041. service.UpdateGoodSumCountSeven(sum_count, item.ProjectId, adminInfo.CurrentOrgId)
  4042. }
  4043. }
  4044. }
  4045. }
  4046. }
  4047. }
  4048. tx.Commit()
  4049. if err == nil {
  4050. c.ServeSuccessJSON(map[string]interface{}{
  4051. "msg": "保存成功",
  4052. })
  4053. return
  4054. } else {
  4055. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4056. return
  4057. }
  4058. }
  4059. }
  4060. //func (c *HisApiController) EditHisPrescription() {
  4061. // record_date := c.GetString("record_date")
  4062. // patient_id, _ := c.GetInt64("patient_id")
  4063. // reg_type, _ := c.GetInt64("reg_type")
  4064. // //diagnose, _ := c.GetInt64("diagnose", 0)
  4065. // diagnose := c.GetString("diagnose")
  4066. // sick_type, _ := c.GetInt64("sick_type")
  4067. // sick_history := c.GetString("sick_history")
  4068. // doctor_id, _ := c.GetInt64("doctor", 0)
  4069. // department, _ := c.GetInt64("department", 0)
  4070. // his_patient_id, _ := c.GetInt64("his_patient_id")
  4071. // p_type, _ := c.GetInt64("p_type")
  4072. //
  4073. // dataBody := make(map[string]interface{}, 0)
  4074. // err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4075. // if err != nil {
  4076. // utils.ErrorLog(err.Error())
  4077. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4078. // return
  4079. // }
  4080. //
  4081. // timeLayout := "2006-01-02"
  4082. // loc, _ := time.LoadLocation("Local")
  4083. // theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4084. // if err != nil {
  4085. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4086. // return
  4087. // }
  4088. // adminInfo := c.GetAdminUserInfo()
  4089. // recordDateTime := theTime.Unix()
  4090. //
  4091. // role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  4092. //
  4093. // info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4094. // var hpInfo models.HisPrescriptionInfo
  4095. // if info.ID == 0 {
  4096. // var randNum int
  4097. // randNum = rand.Intn(10000) + 1000
  4098. // timestamp := time.Now().Unix()
  4099. // tempTime := time.Unix(timestamp, 0)
  4100. // timeFormat := tempTime.Format("20060102150405")
  4101. // p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4102. //
  4103. // hpInfo = models.HisPrescriptionInfo{
  4104. // UserOrgId: adminInfo.CurrentOrgId,
  4105. // RecordDate: theTime.Unix(),
  4106. // PatientId: patient_id,
  4107. // Status: 1,
  4108. // Ctime: time.Now().Unix(),
  4109. // Mtime: time.Now().Unix(),
  4110. // Creator: adminInfo.AdminUser.Id,
  4111. // Modifier: adminInfo.AdminUser.Id,
  4112. // Diagnosis: diagnose,
  4113. // SickHistory: sick_history,
  4114. // Departments: department,
  4115. // RegisterType: reg_type,
  4116. // PrescriptionNumber: p_number,
  4117. // PrescriptionStatus: 1,
  4118. // Doctor: role.UserName,
  4119. // DoctorId: doctor_id,
  4120. // SickType: sick_type,
  4121. // PType: p_type,
  4122. // }
  4123. // service.SavePatientPrescriptionInfo(hpInfo)
  4124. //
  4125. // } else {
  4126. // hpInfo = models.HisPrescriptionInfo{
  4127. // ID: info.ID,
  4128. // UserOrgId: adminInfo.CurrentOrgId,
  4129. // RecordDate: info.RecordDate,
  4130. // PatientId: info.PatientId,
  4131. // Status: 1,
  4132. // Ctime: info.Ctime,
  4133. // Mtime: time.Now().Unix(),
  4134. // Creator: info.Creator,
  4135. // Modifier: adminInfo.AdminUser.Id,
  4136. // Diagnosis: diagnose,
  4137. // SickHistory: sick_history,
  4138. // Departments: department,
  4139. // RegisterType: reg_type,
  4140. // PrescriptionNumber: info.PrescriptionNumber,
  4141. // Doctor: role.UserName,
  4142. // PrescriptionStatus: info.PrescriptionStatus,
  4143. // DoctorId: doctor_id,
  4144. // SickType: sick_type,
  4145. // PType: info.PType,
  4146. // }
  4147. // service.SavePatientPrescriptionInfo(hpInfo)
  4148. // }
  4149. //
  4150. // if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  4151. // prescriptions, _ := dataBody["prescriptions"].([]interface{})
  4152. //
  4153. // if len(prescriptions) > 0 {
  4154. // for _, item := range prescriptions {
  4155. // items := item.(map[string]interface{})
  4156. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  4157. // utils.ErrorLog("id")
  4158. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4159. // return
  4160. // }
  4161. // id := int64(items["id"].(float64))
  4162. //
  4163. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  4164. // utils.ErrorLog("type")
  4165. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4166. // return
  4167. // }
  4168. // types := int64(items["type"].(float64))
  4169. //
  4170. // if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  4171. // utils.ErrorLog("med_type")
  4172. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4173. // return
  4174. // }
  4175. // med_type := strconv.Itoa(int(items["med_type"].(float64)))
  4176. //
  4177. // historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  4178. //
  4179. // ctime := time.Now().Unix()
  4180. //
  4181. // prescription := &models.HisPrescription{
  4182. // ID: id,
  4183. // PatientId: patient_id,
  4184. // UserOrgId: adminInfo.CurrentOrgId,
  4185. // RecordDate: recordDateTime,
  4186. // Ctime: ctime,
  4187. // Mtime: ctime,
  4188. // Type: types,
  4189. // Modifier: adminInfo.AdminUser.Id,
  4190. // Creator: adminInfo.AdminUser.Id,
  4191. // Status: 1,
  4192. // Doctor: role.UserName,
  4193. // HisPatientId: his_patient_id,
  4194. // OrderStatus: 1,
  4195. // BatchNumber: "",
  4196. // PrescriptionNumber: hpInfo.PrescriptionNumber,
  4197. // PType: hpInfo.PType,
  4198. // MedType: med_type,
  4199. // }
  4200. //
  4201. // if historyPrescription.ID > 0 {
  4202. // prescription.PreTime = historyPrescription.PreTime
  4203. //
  4204. // }
  4205. //
  4206. // service.SaveHisPrescription(prescription)
  4207. //
  4208. // if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  4209. // advices := items["advices"].([]interface{})
  4210. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4211. // groupNo := int64(0)
  4212. // ctime := time.Now().Unix()
  4213. // mtime := ctime
  4214. // if len(advices) > 0 {
  4215. // for _, advice := range advices {
  4216. // var s models.HisDoctorAdviceInfo
  4217. // s.PrescriptionId = prescription.ID
  4218. // s.AdviceType = 2
  4219. // s.AdviceDoctor = adminInfo.AdminUser.Id
  4220. // s.StopState = 2
  4221. // s.ExecutionState = 2
  4222. // s.AdviceDate = recordDateTime
  4223. // s.Status = 1
  4224. // s.UserOrgId = adminInfo.CurrentOrgId
  4225. // s.RecordDate = recordDateTime
  4226. // s.StartTime = prescription.PreTime
  4227. // s.Groupno = groupNo
  4228. // s.CreatedTime = ctime
  4229. // s.UpdatedTime = mtime
  4230. // s.PatientId = patient_id
  4231. // s.HisPatientId = his_patient_id
  4232. // errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  4233. // if errcode > 0 {
  4234. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4235. // return
  4236. // }
  4237. //
  4238. // if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 3877 {
  4239. // storeConfig, _ := service.GetAllStoreHouseConfig(adminInfo.CurrentOrgId)
  4240. // lastWarehouse, _ := service.FindLastDrugWarehousingInfoByID(s.DrugId, storeConfig.DrugStorehouseOut)
  4241. // if s.Price == 0 {
  4242. // s.Price = lastWarehouse.RetailPrice
  4243. // }
  4244. // }
  4245. //
  4246. // service.CreateHisDoctorAdvice(&s)
  4247. // //记录日志
  4248. // byterequest, _ := json.Marshal(s)
  4249. // adviceLog := models.XtDoctorAdviceLog{
  4250. // UserOrgId: s.UserOrgId,
  4251. // PatientId: s.PatientId,
  4252. // AdminUserId: adminInfo.AdminUser.Id,
  4253. // Module: 1,
  4254. // ErrLog: string(byterequest),
  4255. // Status: 1,
  4256. // Ctime: time.Now().Unix(),
  4257. // Mtime: 0,
  4258. // Source: "电脑端his医嘱修改",
  4259. // RecordDate: s.AdviceDate,
  4260. // }
  4261. // service.CreateDoctorAdviceLog(adviceLog)
  4262. // redis := service.RedisClient()
  4263. // key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  4264. // redis.Set(key, "", time.Second)
  4265. // keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  4266. // fmt.Println("keyOne", keyOne)
  4267. // redis.Set(keyOne, "", time.Second)
  4268. // keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  4269. // redis.Set(keySeven, "", time.Second)
  4270. // redis.Close()
  4271. //
  4272. // }
  4273. // }
  4274. // }
  4275. // if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  4276. // projects := items["project"].([]interface{})
  4277. // if len(projects) > 0 {
  4278. // for _, project := range projects {
  4279. // var p models.HisPrescriptionProject
  4280. // p.PrescriptionId = prescription.ID
  4281. // p.Ctime = time.Now().Unix()
  4282. // p.Mtime = time.Now().Unix()
  4283. // p.PatientId = patient_id
  4284. // p.RecordDate = recordDateTime
  4285. // p.UserOrgId = adminInfo.CurrentOrgId
  4286. // p.HisPatientId = his_patient_id
  4287. // p.Status = 1
  4288. // errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  4289. // if errcode > 0 {
  4290. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4291. // return
  4292. // }
  4293. // service.CreateHisProjectTwo(&p)
  4294. //
  4295. // //记录日志
  4296. // byterequest, _ := json.Marshal(p)
  4297. // adviceLog := models.XtDoctorAdviceLog{
  4298. // UserOrgId: p.UserOrgId,
  4299. // PatientId: p.PatientId,
  4300. // AdminUserId: adminInfo.AdminUser.Id,
  4301. // Module: 1,
  4302. // ErrLog: string(byterequest),
  4303. // Status: 1,
  4304. // Ctime: time.Now().Unix(),
  4305. // Mtime: 0,
  4306. // Source: "电脑端his项目修改",
  4307. // RecordDate: p.RecordDate,
  4308. // }
  4309. // service.CreateDoctorAdviceLog(adviceLog)
  4310. // }
  4311. // }
  4312. // }
  4313. // if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  4314. // addition := items["addition"].([]interface{})
  4315. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  4316. // ctime := time.Now().Unix()
  4317. // mtime := ctime
  4318. // if len(addition) > 0 {
  4319. // for _, item := range addition {
  4320. // var s models.HisAdditionalCharge
  4321. // s.PrescriptionId = prescription.ID
  4322. // s.Status = 1
  4323. // s.UserOrgId = adminInfo.CurrentOrgId
  4324. // s.RecordDate = recordDateTime
  4325. // s.CreatedTime = ctime
  4326. // s.UpdatedTime = mtime
  4327. // s.PatientId = patient_id
  4328. // s.HisPatientId = his_patient_id
  4329. // errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  4330. // if errcode > 0 {
  4331. // c.ServeFailJSONWithSGJErrorCode(errcode)
  4332. // return
  4333. // }
  4334. // service.CreateAdditionalCharge(&s)
  4335. // }
  4336. // }
  4337. // }
  4338. //
  4339. // }
  4340. // }
  4341. // }
  4342. // if err == nil {
  4343. // c.ServeSuccessJSON(map[string]interface{}{
  4344. // "msg": "保存成功",
  4345. // })
  4346. // return
  4347. //
  4348. // } else {
  4349. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4350. // return
  4351. // }
  4352. //}
  4353. func (c *HisApiController) DeletePrescription() {
  4354. prescription_id, _ := c.GetInt64("id")
  4355. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  4356. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  4357. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4358. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4359. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4360. //耗材保存处方出库
  4361. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4362. //已收费和已发药限制逻辑
  4363. isCharge := false
  4364. isMedicine := false
  4365. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4366. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4367. for _, item := range new_prescriptions {
  4368. if item.IsMedicine == 1 {
  4369. isMedicine = true
  4370. }
  4371. }
  4372. for _, item := range new_prescriptions {
  4373. if item.OrderStatus == 4 {
  4374. isCharge = true
  4375. }
  4376. }
  4377. if p_err != nil {
  4378. if new_prescription.ID > 0 {
  4379. if new_prescription.OrderStatus == 2 {
  4380. isCharge = true
  4381. }
  4382. }
  4383. }
  4384. for _, item := range advices {
  4385. if item.IsMedicine == 1 {
  4386. isMedicine = true
  4387. }
  4388. }
  4389. if isCharge {
  4390. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4391. return
  4392. }
  4393. if isMedicine {
  4394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4395. return
  4396. }
  4397. //已收费和已发药限制逻辑
  4398. if len(projects) > 0 {
  4399. for _, item := range projects {
  4400. service.DeletePrintInfo(item.ID) //删除打印信息
  4401. if goodOutConfig.IsOpen != 1 {
  4402. if stockConfig.IsOpen == 1 {
  4403. if item.Type == 3 && item.IsOut == 1 {
  4404. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4405. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4406. good.Total = good.Total + f_count
  4407. service.UpdateGoodInfo(&good)
  4408. operation_time := time.Now().Unix()
  4409. creater := c.GetAdminUserInfo().AdminUser.Id
  4410. //创建退库单
  4411. timeStr := time.Now().Format("2006-01-02")
  4412. timeArr := strings.Split(timeStr, "-")
  4413. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4414. total = total + 1
  4415. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4416. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4417. cancelStock := models.CancelStock{
  4418. OrderNumber: orderNumber,
  4419. OperaTime: operation_time,
  4420. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4421. Creater: creater,
  4422. Ctime: time.Now().Unix(),
  4423. Status: 1,
  4424. ReturnTime: item.RecordDate,
  4425. Type: 1,
  4426. StorehouseId: houseConfig.StorehouseOutInfo,
  4427. IsCheck: 1,
  4428. }
  4429. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4430. if msgerrkonde == gorm.ErrRecordNotFound {
  4431. service.AddSigleCancelStock(&cancelStock)
  4432. }
  4433. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4434. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4435. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4436. //查询该耗材是否出库
  4437. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4438. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4439. deaerler, _ := service.GetDealerById(info.Dealer)
  4440. var total_count int64
  4441. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4442. total_count += count
  4443. if info.ID > 0 {
  4444. if info.Count >= total_count {
  4445. //回退库存
  4446. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4447. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4448. var flush_count int64
  4449. for _, it := range goodList {
  4450. flush_count += it.StockCount
  4451. }
  4452. cancelStockInfo := models.CancelStockInfo{
  4453. GoodId: item.ProjectId,
  4454. CancelStockId: cancel.ID,
  4455. GoodTypeId: good.GoodTypeId,
  4456. Count: prescribingNumber,
  4457. Price: info.Price,
  4458. Total: 0,
  4459. ProductDate: info.ProductDate,
  4460. ExpiryDate: info.ExpiryDate,
  4461. Ctime: time.Now().Unix(),
  4462. Status: 1,
  4463. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4464. OrderNumber: cancel.OrderNumber,
  4465. Type: 0,
  4466. Dealer: deaerler.DealerName,
  4467. Manufacturer: manufacturer.ManufacturerName,
  4468. Number: info.Number,
  4469. RegisterAccount: "",
  4470. Remark: "",
  4471. WarehouseInfoId: info.WarehouseInfotId,
  4472. PatientId: info.PatientId,
  4473. RecordDate: info.SysRecordTime,
  4474. StorehouseId: houseConfig.StorehouseOutInfo,
  4475. IsCheck: 1,
  4476. }
  4477. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4478. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4479. flow := models.VmStockFlow{
  4480. WarehousingId: info.WarehouseInfotId,
  4481. GoodId: item.ProjectId,
  4482. Number: info.Number,
  4483. LicenseNumber: info.LicenseNumber,
  4484. Count: prescribingNumber,
  4485. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4486. PatientId: item.PatientId,
  4487. SystemTime: info.SysRecordTime,
  4488. ConsumableType: 7,
  4489. IsSys: 0,
  4490. WarehousingOrder: "",
  4491. WarehouseOutId: info.WarehouseOutId,
  4492. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4493. IsEdit: 0,
  4494. CancelStockId: cancel.ID,
  4495. CancelOrderNumber: cancel.OrderNumber,
  4496. Manufacturer: manufacturer.ID,
  4497. Dealer: 0,
  4498. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4499. UpdateCreator: 0,
  4500. Status: 1,
  4501. Ctime: time.Now().Unix(),
  4502. Mtime: 0,
  4503. Price: info.Price,
  4504. WarehousingDetailId: info.WarehouseInfotId,
  4505. WarehouseOutDetailId: info.ID,
  4506. CancelOutDetailId: cancelInfo.ID,
  4507. ProductDate: info.ProductDate,
  4508. ExpireDate: info.ExpiryDate,
  4509. StorehouseId: houseConfig.StorehouseOutInfo,
  4510. OverCount: flush_count,
  4511. }
  4512. service.CreateStockFlowOne(flow)
  4513. //退库数量增加
  4514. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4515. //出库数量减少
  4516. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4517. }
  4518. if info.Count < total_count {
  4519. //回退库存
  4520. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, item.ProjectId)
  4521. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4522. var flush_count int64
  4523. for _, it := range goodList {
  4524. flush_count += it.StockCount
  4525. }
  4526. cancelStockInfo := models.CancelStockInfo{
  4527. GoodId: item.ProjectId,
  4528. CancelStockId: cancel.ID,
  4529. GoodTypeId: good.GoodTypeId,
  4530. Count: info.Count,
  4531. Price: info.Price,
  4532. Total: 0,
  4533. ProductDate: info.ProductDate,
  4534. ExpiryDate: info.ExpiryDate,
  4535. Ctime: time.Now().Unix(),
  4536. Status: 1,
  4537. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4538. OrderNumber: cancel.OrderNumber,
  4539. Type: 0,
  4540. Dealer: deaerler.DealerName,
  4541. Manufacturer: manufacturer.ManufacturerName,
  4542. Number: info.Number,
  4543. RegisterAccount: "",
  4544. Remark: "",
  4545. WarehouseInfoId: info.WarehouseInfotId,
  4546. PatientId: info.PatientId,
  4547. RecordDate: info.SysRecordTime,
  4548. StorehouseId: houseConfig.StorehouseOutInfo,
  4549. IsCheck: 1,
  4550. }
  4551. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4552. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4553. flow := models.VmStockFlow{
  4554. WarehousingId: info.WarehouseInfotId,
  4555. GoodId: item.ProjectId,
  4556. Number: info.Number,
  4557. LicenseNumber: info.LicenseNumber,
  4558. Count: info.Count,
  4559. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4560. PatientId: item.PatientId,
  4561. SystemTime: info.SysRecordTime,
  4562. ConsumableType: 7,
  4563. IsSys: 0,
  4564. WarehousingOrder: "",
  4565. WarehouseOutId: info.WarehouseOutId,
  4566. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4567. IsEdit: 0,
  4568. CancelStockId: cancel.ID,
  4569. CancelOrderNumber: cancel.OrderNumber,
  4570. Manufacturer: manufacturer.ID,
  4571. Dealer: 0,
  4572. Creator: c.GetAdminUserInfo().CurrentOrgId,
  4573. UpdateCreator: 0,
  4574. Status: 1,
  4575. Ctime: time.Now().Unix(),
  4576. Mtime: 0,
  4577. Price: info.Price,
  4578. WarehousingDetailId: info.WarehouseInfotId,
  4579. WarehouseOutDetailId: info.ID,
  4580. CancelOutDetailId: cancelInfo.ID,
  4581. ProductDate: info.ProductDate,
  4582. ExpireDate: info.ExpiryDate,
  4583. StorehouseId: houseConfig.StorehouseOutInfo,
  4584. OverCount: flush_count,
  4585. }
  4586. service.CreateStockFlowOne(flow)
  4587. //退库数量增加
  4588. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  4589. //出库数量减少
  4590. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, info.Count)
  4591. }
  4592. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4593. var flush_count int64
  4594. for _, it := range goodList {
  4595. flush_count += it.StockCount
  4596. }
  4597. //查询已出库数量
  4598. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4599. if prescribingNumber < dialysisInfo.Count {
  4600. //改变数量
  4601. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4602. }
  4603. if prescribingNumber >= dialysisInfo.Count {
  4604. //删除出库表
  4605. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4606. }
  4607. //更新库存
  4608. service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count)
  4609. //更新基础库库存
  4610. service.UpdateGoodInfoSumCountSix(item.ProjectId, flush_count, c.GetAdminUserInfo().CurrentOrgId)
  4611. }
  4612. }
  4613. }
  4614. }
  4615. //保存耗材出库
  4616. if goodOutConfig.IsOpen == 1 {
  4617. if item.Type == 3 {
  4618. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  4619. f_count, _ := strconv.ParseFloat(item.Count, 64)
  4620. good.Total = good.Total + f_count
  4621. service.UpdateGoodInfo(&good)
  4622. operation_time := time.Now().Unix()
  4623. creater := c.GetAdminUserInfo().AdminUser.Id
  4624. //创建退库单
  4625. timeStr := time.Now().Format("2006-01-02")
  4626. timeArr := strings.Split(timeStr, "-")
  4627. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  4628. total = total + 1
  4629. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  4630. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  4631. cancelStock := models.CancelStock{
  4632. OrderNumber: orderNumber,
  4633. OperaTime: operation_time,
  4634. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4635. Creater: creater,
  4636. Ctime: time.Now().Unix(),
  4637. Status: 1,
  4638. ReturnTime: item.RecordDate,
  4639. Type: 1,
  4640. StorehouseId: houseConfig.StorehouseOutInfo,
  4641. IsCheck: 1,
  4642. }
  4643. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  4644. if msgerrkonde == gorm.ErrRecordNotFound {
  4645. service.AddSigleCancelStock(&cancelStock)
  4646. }
  4647. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  4648. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  4649. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  4650. //查询该耗材是否出库
  4651. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  4652. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  4653. deaerler, _ := service.GetDealerById(info.Dealer)
  4654. var total_count int64
  4655. count, _ := strconv.ParseInt(item.Count, 10, 64)
  4656. total_count += count
  4657. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4658. var flush_count int64
  4659. for _, it := range goodList {
  4660. flush_count += it.StockCount
  4661. }
  4662. fmt.Println("历史出库数据", info.Count)
  4663. fmt.Println("出库数量", total_count)
  4664. if info.ID > 0 {
  4665. cancelStockInfo := models.CancelStockInfo{
  4666. GoodId: item.ProjectId,
  4667. CancelStockId: cancel.ID,
  4668. GoodTypeId: good.GoodTypeId,
  4669. Count: prescribingNumber,
  4670. Price: info.Price,
  4671. Total: 0,
  4672. ProductDate: info.ProductDate,
  4673. ExpiryDate: info.ExpiryDate,
  4674. Ctime: time.Now().Unix(),
  4675. Status: 1,
  4676. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  4677. OrderNumber: cancel.OrderNumber,
  4678. Type: 0,
  4679. Dealer: deaerler.DealerName,
  4680. Manufacturer: manufacturer.ManufacturerName,
  4681. Number: info.Number,
  4682. RegisterAccount: "",
  4683. Remark: "",
  4684. WarehouseInfoId: info.WarehouseInfotId,
  4685. PatientId: info.PatientId,
  4686. RecordDate: info.SysRecordTime,
  4687. StorehouseId: houseConfig.StorehouseOutInfo,
  4688. IsCheck: 1,
  4689. }
  4690. service.CreateCancelStockInfoOne(&cancelStockInfo)
  4691. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  4692. //查询出库数量
  4693. list, _ := service.GetWarehouseOutInfoByProjectIdList(item.ID, c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, item.PatientId, info.SysRecordTime)
  4694. //出库数据 大于 退库数量
  4695. if len(list) > 0 {
  4696. for _, it := range list {
  4697. //回退库存
  4698. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  4699. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4700. var flush_count_one int64
  4701. for _, it := range goodList {
  4702. flush_count_one += it.StockCount
  4703. }
  4704. //查询该批次是否有退库数据
  4705. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.SysRecordTime)
  4706. creater := c.GetAdminUserInfo().AdminUser.Id
  4707. flow := models.VmStockFlow{
  4708. WarehousingId: it.WarehouseInfotId,
  4709. GoodId: it.GoodId,
  4710. Number: it.Number,
  4711. LicenseNumber: it.LicenseNumber,
  4712. Count: it.Count,
  4713. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4714. PatientId: it.PatientId,
  4715. SystemTime: it.SysRecordTime,
  4716. ConsumableType: 7,
  4717. IsSys: 0,
  4718. WarehousingOrder: "",
  4719. WarehouseOutId: it.WarehouseOutId,
  4720. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  4721. IsEdit: 0,
  4722. CancelStockId: cancel.ID,
  4723. CancelOrderNumber: cancel.OrderNumber,
  4724. Manufacturer: manufacturer.ID,
  4725. Dealer: 0,
  4726. Creator: creater,
  4727. UpdateCreator: 0,
  4728. Status: 1,
  4729. Ctime: time.Now().Unix(),
  4730. Mtime: 0,
  4731. Price: it.Price,
  4732. WarehousingDetailId: it.WarehouseInfotId,
  4733. WarehouseOutDetailId: it.ID,
  4734. CancelOutDetailId: cancelInfo.ID,
  4735. ProductDate: it.ProductDate,
  4736. ExpireDate: it.ExpiryDate,
  4737. StorehouseId: houseConfig.StorehouseOutInfo,
  4738. OverCount: flush_count_one,
  4739. }
  4740. service.CreateStockFlowOne(flow)
  4741. //if flow.ID > 0 {
  4742. // service.AddCountFlowOne(it.WarehouseInfotId, it.GoodId, c.GetAdminUserInfo().CurrentOrgId, it.PatientId, it.Count, it.SysRecordTime, flush_count_one)
  4743. //}
  4744. }
  4745. }
  4746. //flow := models.VmStockFlow{
  4747. // WarehousingId: info.WarehouseInfotId,
  4748. // GoodId: item.ProjectId,
  4749. // Number: info.Number,
  4750. // LicenseNumber: info.LicenseNumber,
  4751. // Count: prescribingNumber,
  4752. // UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4753. // PatientId: item.PatientId,
  4754. // SystemTime: info.SysRecordTime,
  4755. // ConsumableType: 7,
  4756. // IsSys: 0,
  4757. // WarehousingOrder: "",
  4758. // WarehouseOutId: info.WarehouseOutId,
  4759. // WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  4760. // IsEdit: 0,
  4761. // CancelStockId: cancel.ID,
  4762. // CancelOrderNumber: cancel.OrderNumber,
  4763. // Manufacturer: manufacturer.ID,
  4764. // Dealer: 0,
  4765. // Creator: c.GetAdminUserInfo().CurrentOrgId,
  4766. // UpdateCreator: 0,
  4767. // Status: 1,
  4768. // Ctime: time.Now().Unix(),
  4769. // Mtime: 0,
  4770. // Price: info.Price,
  4771. // WarehousingDetailId: info.WarehouseInfotId,
  4772. // WarehouseOutDetailId: info.ID,
  4773. // CancelOutDetailId: cancelInfo.ID,
  4774. // ProductDate: info.ProductDate,
  4775. // ExpireDate: info.ExpiryDate,
  4776. // StorehouseId: houseConfig.StorehouseOutInfo,
  4777. // OverCount: flush_count,
  4778. //}
  4779. //service.CreateStockFlowOne(flow)
  4780. //退库数量增加
  4781. service.UpdateSumAddCancelCount(c.GetAdminUserInfo().CurrentOrgId, item.ProjectId, houseConfig.StorehouseOutInfo, total_count)
  4782. //出库数量减少
  4783. service.UpdateSumCount(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, total_count)
  4784. //查询已出库数量
  4785. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  4786. if prescribingNumber < dialysisInfo.Count {
  4787. //改变数量
  4788. service.UpdateAutoGood(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID, prescribingNumber)
  4789. }
  4790. if prescribingNumber >= dialysisInfo.Count {
  4791. //删除出库表
  4792. service.DeleteAutoRedeceDetailTwenty(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId, item.ID)
  4793. }
  4794. goodList, _ := service.GetSumGoodList(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId)
  4795. var flush_count_one int64
  4796. for _, it := range goodList {
  4797. flush_count_one += it.StockCount
  4798. }
  4799. //更新库存
  4800. msgerrkonde := service.UpdateSumGood(c.GetAdminUserInfo().CurrentOrgId, houseConfig.StorehouseOutInfo, item.ProjectId, flush_count_one)
  4801. fmt.Println("msgerrkonde23332323", msgerrkonde)
  4802. //更新基础库库存
  4803. service.UpdateGoodInfoReduceSumCount(item.ProjectId, flush_count_one, c.GetAdminUserInfo().CurrentOrgId)
  4804. }
  4805. }
  4806. }
  4807. }
  4808. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4809. fmt.Println(err)
  4810. }
  4811. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  4812. fmt.Println(err)
  4813. if len(advices) > 0 {
  4814. for _, item := range advices {
  4815. redis := service.RedisClient()
  4816. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  4817. redis.Set(keyFive, "", time.Second)
  4818. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  4819. redis.Set(keyOne, "", time.Second)
  4820. redis.Close()
  4821. }
  4822. }
  4823. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4824. if len(advices) > 0 {
  4825. for _, item := range advices {
  4826. creater := c.GetAdminUserInfo().AdminUser.Id
  4827. service.DrugAutoAddCancelInfo(item, creater)
  4828. }
  4829. }
  4830. } else {
  4831. if drugOutConfig.IsOpen == 1 {
  4832. if len(advices) > 0 {
  4833. for _, item := range advices {
  4834. creater := c.GetAdminUserInfo().AdminUser.Id
  4835. service.DrugAutoAddCancelInfo(item, creater)
  4836. }
  4837. }
  4838. } else {
  4839. if len(advices) > 0 {
  4840. for _, item := range advices {
  4841. creater := c.GetAdminUserInfo().AdminUser.Id
  4842. service.DrugAutoAddCancelInfo(item, creater)
  4843. }
  4844. }
  4845. }
  4846. }
  4847. c.ServeSuccessJSON(map[string]interface{}{
  4848. "msg": "删除成功",
  4849. })
  4850. return
  4851. }
  4852. func (c *HisApiController) DeleteDoctorAdvice() {
  4853. id, _ := c.GetInt64("id")
  4854. advice, _ := service.GetHisDoctorAdvicesById(id)
  4855. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4856. drugOutConfig, _ := service.FindDrugOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4857. //已收费和已发药的限制逻辑
  4858. isCharge := false
  4859. isMedicine := false
  4860. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4861. //获取今天该患者所有处方,判断是否发药或者收费
  4862. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4863. for _, item := range new_prescriptions {
  4864. if item.IsMedicine == 1 {
  4865. isMedicine = true
  4866. }
  4867. }
  4868. for _, item := range new_prescriptions {
  4869. if item.OrderStatus == 4 {
  4870. isCharge = true
  4871. }
  4872. }
  4873. if isMedicine {
  4874. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4875. return
  4876. }
  4877. if isCharge {
  4878. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4879. return
  4880. }
  4881. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  4882. for _, item := range advices {
  4883. if item.IsMedicine == 1 {
  4884. isMedicine = true
  4885. }
  4886. }
  4887. if isMedicine {
  4888. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  4889. return
  4890. }
  4891. if new_prescription.ID > 0 {
  4892. if new_prescription.OrderStatus == 2 {
  4893. isCharge = true
  4894. }
  4895. }
  4896. if isCharge {
  4897. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4898. return
  4899. }
  4900. //已收费和已发药的限制逻辑
  4901. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  4902. redis := service.RedisClient()
  4903. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  4904. redis.Set(keyFive, "", time.Second)
  4905. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  4906. redis.Set(keyOne, "", time.Second)
  4907. defer redis.Close()
  4908. if err == nil {
  4909. if c.GetAdminUserInfo().CurrentOrgId == 10387 {
  4910. //查询是否在处方中出库
  4911. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4912. if openConfig.IsOpen != 1 {
  4913. //判断该医嘱是否执行了
  4914. if advice.ExecutionState == 1 {
  4915. creater := c.GetAdminUserInfo().AdminUser.Id
  4916. service.DrugAutoAddCancelInfo(&advice, creater)
  4917. }
  4918. }
  4919. //开启保存处方扣减功能
  4920. if openConfig.IsOpen == 1 {
  4921. creater := c.GetAdminUserInfo().AdminUser.Id
  4922. service.DrugAutoAddCancelInfo(&advice, creater)
  4923. }
  4924. } else {
  4925. if drugOutConfig.IsOpen == 1 {
  4926. //查询是否在处方中出库
  4927. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  4928. if openConfig.IsOpen != 1 {
  4929. //判断该医嘱是否执行了
  4930. if advice.ExecutionState == 1 {
  4931. creater := c.GetAdminUserInfo().AdminUser.Id
  4932. service.DrugAutoAddCancelInfo(&advice, creater)
  4933. }
  4934. }
  4935. //开启保存处方扣减功能
  4936. if openConfig.IsOpen == 1 {
  4937. creater := c.GetAdminUserInfo().AdminUser.Id
  4938. service.DrugAutoAddCancelInfo(&advice, creater)
  4939. }
  4940. } else {
  4941. //判断该医嘱是否执行了
  4942. if advice.ExecutionState == 1 {
  4943. creater := c.GetAdminUserInfo().AdminUser.Id
  4944. service.DrugAutoAddCancelInfo(&advice, creater)
  4945. }
  4946. }
  4947. }
  4948. c.ServeSuccessJSON(map[string]interface{}{
  4949. "msg": "删除成功",
  4950. })
  4951. return
  4952. } else {
  4953. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4954. return
  4955. }
  4956. }
  4957. func (c *HisApiController) DeleteProject() {
  4958. id, _ := c.GetInt64("id")
  4959. adminInfo := c.GetAdminUserInfo()
  4960. project, _ := service.GetHisProjectByID(id)
  4961. // var consumable models.DialysisBeforePrepare
  4962. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  4963. //耗材保存处方出库
  4964. goodOutConfig, _ := service.FindGoodOutConfigById(c.GetAdminUserInfo().CurrentOrgId)
  4965. isCharge := false
  4966. isMedicine := false
  4967. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  4968. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  4969. for _, item := range new_prescriptions {
  4970. if item.IsMedicine == 1 {
  4971. isMedicine = true
  4972. }
  4973. }
  4974. for _, item := range new_prescriptions {
  4975. if item.OrderStatus == 4 {
  4976. isCharge = true
  4977. }
  4978. }
  4979. if isMedicine {
  4980. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  4981. return
  4982. }
  4983. if isCharge {
  4984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  4985. return
  4986. }
  4987. if new_prescription.ID > 0 {
  4988. if new_prescription.OrderStatus == 2 {
  4989. isCharge = true
  4990. }
  4991. }
  4992. if isCharge {
  4993. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  4994. return
  4995. }
  4996. service.DeletePrintInfo(id)
  4997. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  4998. label.Status = 0
  4999. service.CreateHisLabelRecordTwo(&label)
  5000. fmt.Println(goodOutConfig.IsOpen)
  5001. if goodOutConfig.IsOpen != 1 {
  5002. if stockConfig.IsOpen == 1 {
  5003. if project.Type == 2 {
  5004. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5005. fmt.Println(err)
  5006. }
  5007. if project.Type == 3 && project.IsOut == 1 {
  5008. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5009. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5010. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5011. operation_time := time.Now().Unix()
  5012. creater := adminInfo.AdminUser.Id
  5013. //创建退库单
  5014. timeStr := time.Now().Format("2006-01-02")
  5015. timeArr := strings.Split(timeStr, "-")
  5016. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5017. total = total + 1
  5018. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5019. cancelStock := models.CancelStock{
  5020. OrderNumber: orderNumber,
  5021. OperaTime: operation_time,
  5022. OrgId: adminInfo.CurrentOrgId,
  5023. Creater: creater,
  5024. Ctime: time.Now().Unix(),
  5025. Status: 1,
  5026. ReturnTime: project.RecordDate,
  5027. Type: 1,
  5028. StorehouseId: houseConfig.StorehouseOutInfo,
  5029. IsCheck: 1,
  5030. }
  5031. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5032. if msgerrkonde == gorm.ErrRecordNotFound {
  5033. service.AddSigleCancelStock(&cancelStock)
  5034. }
  5035. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5036. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5037. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5038. //查询是否有出库
  5039. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5040. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5041. deaerler, _ := service.GetDealerById(info.Dealer)
  5042. if info.ID > 0 {
  5043. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5044. if info.Count >= prescribingNumber {
  5045. cancelStockInfo := models.CancelStockInfo{
  5046. GoodId: project.ProjectId,
  5047. CancelStockId: cancel.ID,
  5048. GoodTypeId: good.GoodTypeId,
  5049. Count: prescribingNumber,
  5050. Price: info.Price,
  5051. Total: 0,
  5052. ProductDate: info.ProductDate,
  5053. ExpiryDate: info.ExpiryDate,
  5054. Ctime: time.Now().Unix(),
  5055. Status: 1,
  5056. OrgId: adminInfo.CurrentOrgId,
  5057. OrderNumber: cancel.OrderNumber,
  5058. Type: 0,
  5059. Dealer: deaerler.DealerName,
  5060. Manufacturer: manufacturer.ManufacturerName,
  5061. Number: info.Number,
  5062. RegisterAccount: "",
  5063. Remark: "",
  5064. WarehouseInfoId: info.WarehouseInfotId,
  5065. PatientId: info.PatientId,
  5066. RecordDate: info.SysRecordTime,
  5067. StorehouseId: houseConfig.StorehouseOutInfo,
  5068. IsCheck: 1,
  5069. }
  5070. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5071. //回退库存
  5072. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, prescribingNumber, info.PatientId, info.SysRecordTime, project.ProjectId)
  5073. //退库数量增加
  5074. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5075. //出库数量减少
  5076. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5077. }
  5078. if info.Count < prescribingNumber {
  5079. cancelStockInfo := models.CancelStockInfo{
  5080. GoodId: project.ProjectId,
  5081. CancelStockId: cancel.ID,
  5082. GoodTypeId: good.GoodTypeId,
  5083. Count: info.Count,
  5084. Price: info.Price,
  5085. Total: 0,
  5086. ProductDate: info.ProductDate,
  5087. ExpiryDate: info.ExpiryDate,
  5088. Ctime: time.Now().Unix(),
  5089. Status: 1,
  5090. OrgId: adminInfo.CurrentOrgId,
  5091. OrderNumber: cancel.OrderNumber,
  5092. Type: 0,
  5093. Dealer: deaerler.DealerName,
  5094. Manufacturer: manufacturer.ManufacturerName,
  5095. Number: info.Number,
  5096. RegisterAccount: "",
  5097. Remark: "",
  5098. WarehouseInfoId: info.WarehouseInfotId,
  5099. PatientId: info.PatientId,
  5100. RecordDate: info.SysRecordTime,
  5101. StorehouseId: houseConfig.StorehouseOutInfo,
  5102. IsCheck: 1,
  5103. }
  5104. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5105. //回退库存
  5106. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5107. //退库数量增加
  5108. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, info.Count)
  5109. //出库数量减少
  5110. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, info.Count)
  5111. }
  5112. //查询剩余库存
  5113. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5114. var over_count int64
  5115. for _, it := range goodList {
  5116. over_count += it.StockCount
  5117. }
  5118. //出库数据 大于 退库数量
  5119. if info.Count >= prescribingNumber {
  5120. flow := models.VmStockFlow{
  5121. WarehousingId: info.WarehouseInfotId,
  5122. GoodId: project.ProjectId,
  5123. Number: info.Number,
  5124. LicenseNumber: info.LicenseNumber,
  5125. Count: prescribingNumber,
  5126. UserOrgId: adminInfo.CurrentOrgId,
  5127. PatientId: project.PatientId,
  5128. SystemTime: info.SysRecordTime,
  5129. ConsumableType: 7,
  5130. IsSys: 0,
  5131. WarehousingOrder: "",
  5132. WarehouseOutId: info.WarehouseOutId,
  5133. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5134. IsEdit: 0,
  5135. CancelStockId: cancel.ID,
  5136. CancelOrderNumber: cancel.OrderNumber,
  5137. Manufacturer: manufacturer.ID,
  5138. Dealer: 0,
  5139. Creator: adminInfo.AdminUser.Id,
  5140. UpdateCreator: 0,
  5141. Status: 1,
  5142. Ctime: time.Now().Unix(),
  5143. Mtime: 0,
  5144. Price: info.Price,
  5145. WarehousingDetailId: info.WarehouseInfotId,
  5146. WarehouseOutDetailId: info.ID,
  5147. CancelOutDetailId: cancelInfo.ID,
  5148. ProductDate: info.ProductDate,
  5149. ExpireDate: info.ExpiryDate,
  5150. StorehouseId: houseConfig.StorehouseOutInfo,
  5151. OverCount: over_count,
  5152. }
  5153. service.CreateStockFlowOne(flow)
  5154. }
  5155. //出库数据小于退库数据
  5156. if info.Count < prescribingNumber {
  5157. flow := models.VmStockFlow{
  5158. WarehousingId: info.WarehouseInfotId,
  5159. GoodId: project.ProjectId,
  5160. Number: info.Number,
  5161. LicenseNumber: info.LicenseNumber,
  5162. Count: info.Count,
  5163. UserOrgId: adminInfo.CurrentOrgId,
  5164. PatientId: project.PatientId,
  5165. SystemTime: info.SysRecordTime,
  5166. ConsumableType: 7,
  5167. IsSys: 0,
  5168. WarehousingOrder: "",
  5169. WarehouseOutId: info.WarehouseOutId,
  5170. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  5171. IsEdit: 0,
  5172. CancelStockId: cancel.ID,
  5173. CancelOrderNumber: cancel.OrderNumber,
  5174. Manufacturer: manufacturer.ID,
  5175. Dealer: 0,
  5176. Creator: adminInfo.AdminUser.Id,
  5177. UpdateCreator: 0,
  5178. Status: 1,
  5179. Ctime: time.Now().Unix(),
  5180. Mtime: 0,
  5181. Price: info.Price,
  5182. WarehousingDetailId: info.WarehouseInfotId,
  5183. WarehouseOutDetailId: info.ID,
  5184. CancelOutDetailId: cancelInfo.ID,
  5185. ProductDate: info.ProductDate,
  5186. ExpireDate: info.ExpiryDate,
  5187. StorehouseId: houseConfig.StorehouseOutInfo,
  5188. OverCount: over_count,
  5189. }
  5190. service.CreateStockFlowOne(flow)
  5191. }
  5192. //查询已出库数量
  5193. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5194. fmt.Println("aiwohonguo --------------------", prescribingNumber)
  5195. fmt.Println("aiwohonguo --------------------", dialysisInfo.Count)
  5196. if prescribingNumber < dialysisInfo.Count {
  5197. //改变数量
  5198. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5199. }
  5200. if prescribingNumber >= dialysisInfo.Count {
  5201. //删除出库表
  5202. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5203. }
  5204. //更新剩余库存
  5205. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5206. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5207. var total_count_one int64
  5208. for _, it := range stockList {
  5209. total_count_one += it.StockCount
  5210. }
  5211. //基础库插入数据
  5212. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5213. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5214. var flush_count int64
  5215. for _, it := range goodListOne {
  5216. flush_count += it.StockCount
  5217. }
  5218. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5219. if errs != nil {
  5220. goodErrcode := models.XtGoodErrcode{
  5221. UserOrgId: project.UserOrgId,
  5222. Errcode: "手动出库更新剩余出库失败",
  5223. GoodId: project.ProjectId,
  5224. Status: 1,
  5225. Ctime: time.Now().Unix(),
  5226. Mtime: 0,
  5227. Count: 0,
  5228. StockCount: 0,
  5229. Creater: creater,
  5230. BatchNumberId: 0,
  5231. WarehouseOutId: 0,
  5232. }
  5233. service.CreateGoodErrcode(goodErrcode)
  5234. }
  5235. }
  5236. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5237. fmt.Println(err)
  5238. } else {
  5239. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5240. fmt.Println(err)
  5241. }
  5242. } else {
  5243. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5244. fmt.Println(err)
  5245. }
  5246. }
  5247. //保存处方出库
  5248. if goodOutConfig.IsOpen == 1 {
  5249. if project.Type == 3 {
  5250. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  5251. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  5252. f_count, _ := strconv.ParseFloat(project.Count, 64)
  5253. operation_time := time.Now().Unix()
  5254. creater := adminInfo.AdminUser.Id
  5255. //创建退库单
  5256. timeStr := time.Now().Format("2006-01-02")
  5257. timeArr := strings.Split(timeStr, "-")
  5258. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  5259. total = total + 1
  5260. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5261. cancelStock := models.CancelStock{
  5262. OrderNumber: orderNumber,
  5263. OperaTime: operation_time,
  5264. OrgId: adminInfo.CurrentOrgId,
  5265. Creater: creater,
  5266. Ctime: time.Now().Unix(),
  5267. Status: 1,
  5268. ReturnTime: project.RecordDate,
  5269. Type: 1,
  5270. StorehouseId: houseConfig.StorehouseOutInfo,
  5271. IsCheck: 1,
  5272. }
  5273. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  5274. if msgerrkonde == gorm.ErrRecordNotFound {
  5275. service.AddSigleCancelStock(&cancelStock)
  5276. }
  5277. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  5278. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  5279. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5280. //获取出库数据
  5281. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  5282. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  5283. deaerler, _ := service.GetDealerById(info.Dealer)
  5284. if info.ID > 0 {
  5285. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  5286. if info.Count >= prescribingNumber {
  5287. cancelStockInfo := models.CancelStockInfo{
  5288. GoodId: project.ProjectId,
  5289. CancelStockId: cancel.ID,
  5290. GoodTypeId: good.GoodTypeId,
  5291. Count: prescribingNumber,
  5292. Price: info.Price,
  5293. Total: 0,
  5294. ProductDate: info.ProductDate,
  5295. ExpiryDate: info.ExpiryDate,
  5296. Ctime: time.Now().Unix(),
  5297. Status: 1,
  5298. OrgId: adminInfo.CurrentOrgId,
  5299. OrderNumber: cancel.OrderNumber,
  5300. Type: 0,
  5301. Dealer: deaerler.DealerName,
  5302. Manufacturer: manufacturer.ManufacturerName,
  5303. Number: info.Number,
  5304. RegisterAccount: "",
  5305. Remark: "",
  5306. WarehouseInfoId: info.WarehouseInfotId,
  5307. PatientId: info.PatientId,
  5308. RecordDate: info.SysRecordTime,
  5309. StorehouseId: houseConfig.StorehouseOutInfo,
  5310. IsCheck: 1,
  5311. }
  5312. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5313. //退库数量增加
  5314. //service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, prescribingNumber)
  5315. //出库数量减少
  5316. //service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, prescribingNumber)
  5317. }
  5318. if info.Count < prescribingNumber {
  5319. cancelStockInfo := models.CancelStockInfo{
  5320. GoodId: project.ProjectId,
  5321. CancelStockId: cancel.ID,
  5322. GoodTypeId: good.GoodTypeId,
  5323. Count: prescribingNumber,
  5324. Price: info.Price,
  5325. Total: 0,
  5326. ProductDate: info.ProductDate,
  5327. ExpiryDate: info.ExpiryDate,
  5328. Ctime: time.Now().Unix(),
  5329. Status: 1,
  5330. OrgId: adminInfo.CurrentOrgId,
  5331. OrderNumber: cancel.OrderNumber,
  5332. Type: 0,
  5333. Dealer: deaerler.DealerName,
  5334. Manufacturer: manufacturer.ManufacturerName,
  5335. Number: info.Number,
  5336. RegisterAccount: "",
  5337. Remark: "",
  5338. WarehouseInfoId: info.WarehouseInfotId,
  5339. PatientId: info.PatientId,
  5340. RecordDate: info.SysRecordTime,
  5341. StorehouseId: houseConfig.StorehouseOutInfo,
  5342. IsCheck: 1,
  5343. }
  5344. service.CreateCancelStockInfoOne(&cancelStockInfo)
  5345. //回退库存
  5346. //service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, info.Count, info.PatientId, info.SysRecordTime, project.ProjectId)
  5347. }
  5348. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5349. var over_count int64
  5350. for _, it := range goodList {
  5351. over_count += it.StockCount
  5352. }
  5353. //查询出库数量
  5354. list, _ := service.GetWarehouseOutInfoByProjectIdList(id, adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, project.PatientId, info.SysRecordTime)
  5355. //出库数据 大于 退库数量
  5356. if len(list) > 0 {
  5357. for _, it := range list {
  5358. //回退库存
  5359. service.UpDateWarehouseInfoByStockDelete(it.WarehouseInfotId, it.Count, it.PatientId, it.SysRecordTime, it.ProjectId)
  5360. //退库数量增加
  5361. service.UpdateSumAddCancelCount(adminInfo.CurrentOrgId, project.ProjectId, houseConfig.StorehouseOutInfo, it.Count)
  5362. //出库数量减少
  5363. service.UpdateSumCount(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, it.Count)
  5364. goodList, _ := service.GetSumGoodList(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5365. var over_count_one int64
  5366. for _, it := range goodList {
  5367. over_count_one += it.StockCount
  5368. }
  5369. //查询该批次是否有退库数据
  5370. //flow, _ := service.GetWarehouseStockFlow(it.WarehouseInfotId, it.GoodId, adminInfo.CurrentOrgId, it.PatientId, it.SysRecordTime)
  5371. flow := models.VmStockFlow{
  5372. WarehousingId: it.WarehouseInfotId,
  5373. GoodId: it.GoodId,
  5374. Number: it.Number,
  5375. LicenseNumber: it.LicenseNumber,
  5376. Count: it.Count,
  5377. UserOrgId: adminInfo.CurrentOrgId,
  5378. PatientId: it.PatientId,
  5379. SystemTime: it.SysRecordTime,
  5380. ConsumableType: 7,
  5381. IsSys: 0,
  5382. WarehousingOrder: "",
  5383. WarehouseOutId: it.WarehouseOutId,
  5384. WarehouseOutOrderNumber: it.WarehouseOutOrderNumber,
  5385. IsEdit: 0,
  5386. CancelStockId: cancel.ID,
  5387. CancelOrderNumber: cancel.OrderNumber,
  5388. Manufacturer: manufacturer.ID,
  5389. Dealer: 0,
  5390. Creator: adminInfo.AdminUser.Id,
  5391. UpdateCreator: 0,
  5392. Status: 1,
  5393. Ctime: time.Now().Unix(),
  5394. Mtime: 0,
  5395. Price: it.Price,
  5396. WarehousingDetailId: it.WarehouseInfotId,
  5397. WarehouseOutDetailId: it.ID,
  5398. CancelOutDetailId: cancelInfo.ID,
  5399. ProductDate: it.ProductDate,
  5400. ExpireDate: it.ExpiryDate,
  5401. StorehouseId: houseConfig.StorehouseOutInfo,
  5402. OverCount: over_count_one,
  5403. }
  5404. service.CreateStockFlowOne(flow)
  5405. }
  5406. }
  5407. //查询已出库数量
  5408. dialysisInfo, _ := service.GetGoodDialysisOutInfoSix(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  5409. if prescribingNumber < dialysisInfo.Count {
  5410. //改变数量
  5411. service.UpdateAutoGood(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id, prescribingNumber)
  5412. }
  5413. if prescribingNumber >= dialysisInfo.Count {
  5414. //删除出库表
  5415. service.DeleteAutoRedeceDetailTwenty(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId, id)
  5416. }
  5417. //更新剩余库存
  5418. service.UpdateSumGood(adminInfo.CurrentOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, over_count)
  5419. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  5420. var total_count_one int64
  5421. for _, it := range stockList {
  5422. total_count_one += it.StockCount
  5423. }
  5424. //基础库插入数据
  5425. service.UpdateGoodInfoSumCountSix(project.ProjectId, total_count_one, project.UserOrgId)
  5426. goodListOne, _ := service.GetSumGoodList(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId)
  5427. var flush_count int64
  5428. for _, it := range goodListOne {
  5429. flush_count += it.StockCount
  5430. }
  5431. errs := service.UpdateSumGood(project.UserOrgId, houseConfig.StorehouseOutInfo, project.ProjectId, flush_count)
  5432. if errs != nil {
  5433. goodErrcode := models.XtGoodErrcode{
  5434. UserOrgId: project.UserOrgId,
  5435. Errcode: "手动出库更新剩余出库失败",
  5436. GoodId: project.ProjectId,
  5437. Status: 1,
  5438. Ctime: time.Now().Unix(),
  5439. Mtime: 0,
  5440. Count: 0,
  5441. StockCount: 0,
  5442. Creater: creater,
  5443. BatchNumberId: 0,
  5444. WarehouseOutId: 0,
  5445. }
  5446. service.CreateGoodErrcode(goodErrcode)
  5447. }
  5448. }
  5449. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5450. fmt.Println(err)
  5451. } else {
  5452. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  5453. fmt.Println(err)
  5454. }
  5455. }
  5456. c.ServeSuccessJSON(map[string]interface{}{
  5457. "msg": "删除成功",
  5458. })
  5459. return
  5460. }
  5461. func (c *HisApiController) CreateHisAdditionalCharge() {
  5462. his_patient_id, _ := c.GetInt64("his_patient_id")
  5463. patient_id, _ := c.GetInt64("patient_id")
  5464. record_date := c.GetString("record_date")
  5465. timeLayout := "2006-01-02"
  5466. loc, _ := time.LoadLocation("Local")
  5467. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5468. if err != nil {
  5469. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5470. return
  5471. }
  5472. adminInfo := c.GetAdminUserInfo()
  5473. recordDateTime := theTime.Unix()
  5474. dataBody := make(map[string]interface{}, 0)
  5475. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5476. if err != nil {
  5477. utils.ErrorLog(err.Error())
  5478. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5479. return
  5480. }
  5481. var additions []*models.HisAdditionalCharge
  5482. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  5483. additions, _ := dataBody["addition"].([]interface{})
  5484. if len(additions) > 0 {
  5485. for _, item := range additions {
  5486. items := item.(map[string]interface{})
  5487. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  5488. utils.ErrorLog("item_id")
  5489. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5490. return
  5491. }
  5492. item_id := int64(items["item_id"].(float64))
  5493. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  5494. utils.ErrorLog("item_name")
  5495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5496. return
  5497. }
  5498. item_name := items["item_name"].(string)
  5499. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  5500. utils.ErrorLog("price")
  5501. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5502. return
  5503. }
  5504. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  5505. ctime := time.Now().Unix()
  5506. additional := &models.HisAdditionalCharge{
  5507. PatientId: patient_id,
  5508. HisPatientId: his_patient_id,
  5509. UserOrgId: adminInfo.CurrentOrgId,
  5510. RecordDate: recordDateTime,
  5511. CreatedTime: ctime,
  5512. UpdatedTime: ctime,
  5513. Modifier: adminInfo.AdminUser.Id,
  5514. Creator: adminInfo.AdminUser.Id,
  5515. Price: price,
  5516. ItemName: item_name,
  5517. ItemId: item_id,
  5518. Status: 1,
  5519. }
  5520. additions = append(additions, additional)
  5521. }
  5522. }
  5523. }
  5524. for _, item := range additions {
  5525. service.CreateAddtionalCharge(item)
  5526. }
  5527. c.ServeSuccessJSON(map[string]interface{}{
  5528. "msg": "创建成功",
  5529. })
  5530. }
  5531. func (c *HisApiController) CreateHisPatientCaseHistory() {
  5532. blood_fat := c.GetString("blood_fat")
  5533. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  5534. blood_sugar := c.GetString("blood_sugar")
  5535. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  5536. chief_conplaint := c.GetString("chief_conplaint")
  5537. dbp := c.GetString("dbp")
  5538. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  5539. delivery_way, _ := c.GetInt64("delivery_way")
  5540. diagnostic := c.GetString("diagnostic")
  5541. family_history := c.GetString("family_history")
  5542. height := c.GetString("height")
  5543. history_of_present_illness := c.GetString("history_of_present_illness")
  5544. is_infect, _ := c.GetInt64("is_infect")
  5545. past_history := c.GetString("past_history")
  5546. patient_id, _ := c.GetInt64("patient_id")
  5547. his_patient_id, _ := c.GetInt64("his_patient_id")
  5548. personal_history := c.GetString("personal_history")
  5549. pulse := c.GetString("pulse")
  5550. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  5551. sbp := c.GetString("sbp")
  5552. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  5553. heightfloat, _ := strconv.ParseFloat(height, 64)
  5554. sicktype := c.GetString("sick_type")
  5555. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  5556. symptom := c.GetString("symptom")
  5557. sick_date := c.GetString("sick_date")
  5558. temperatures := c.GetString("temperature")
  5559. temperature, _ := strconv.ParseFloat(temperatures, 64)
  5560. record_date := c.GetString("record_date")
  5561. breathing := c.GetString("breathing")
  5562. doctor_advice := c.GetString("doctor_advice")
  5563. remark := c.GetString("remark")
  5564. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  5565. sick, _ := c.GetInt64("sick")
  5566. diagnose, _ := c.GetInt64("diagnose")
  5567. //id, _ := c.GetInt64("id")
  5568. timeLayout := "2006-01-02"
  5569. loc, _ := time.LoadLocation("Local")
  5570. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5571. allergic_history := c.GetString("allergic_history")
  5572. if err != nil {
  5573. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5574. return
  5575. }
  5576. recordDateTime := theTime.Unix()
  5577. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  5578. if err != nil {
  5579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5580. return
  5581. }
  5582. sickTimes := sickTime.Unix()
  5583. ctime := time.Now().Unix()
  5584. primary_disease := c.GetString("primary_disease")
  5585. confirm_failure_date := c.GetString("confirm_failure_date")
  5586. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  5587. drug_allergy_history := c.GetString("drug_allergy_history")
  5588. physical_examination := c.GetString("physical_examination")
  5589. special_inspection := c.GetString("special_inspection")
  5590. lab_apparatus := c.GetString("lab_apparatus")
  5591. caseHistory := models.HisPatientCaseHistory{
  5592. HisPatientId: his_patient_id,
  5593. PatientId: patient_id,
  5594. Temperature: temperature,
  5595. BloodSugar: bloodsugarfloat,
  5596. Pulse: pulsefloat,
  5597. Sbp: sbpfloat,
  5598. Dbp: dbpfloat,
  5599. Height: heightfloat,
  5600. BloodFat: bloodfatfloat,
  5601. SickType: sick_type,
  5602. Symptom: symptom,
  5603. SickDate: sickTimes,
  5604. IsInfect: is_infect,
  5605. HistoryOfPresentIllness: history_of_present_illness,
  5606. PastHistory: past_history,
  5607. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  5608. ChiefConplaint: chief_conplaint,
  5609. PersonalHistory: personal_history,
  5610. FamilyHistory: family_history,
  5611. Diagnostic: diagnostic,
  5612. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5613. Status: 1,
  5614. Ctime: ctime,
  5615. Mtime: ctime,
  5616. RecordDate: recordDateTime,
  5617. DeliveryWay: delivery_way,
  5618. Breathing: breathingfloat,
  5619. DoctorAdvice: doctor_advice,
  5620. Remark: remark,
  5621. Sick: sick,
  5622. Diagnose: diagnose,
  5623. AllergicHistory: allergic_history,
  5624. PrimaryDisease: primary_disease,
  5625. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  5626. DrugAllergyHistory: drug_allergy_history,
  5627. PhysicalExamination: physical_examination,
  5628. SpecialInspection: special_inspection,
  5629. LabApparatus: lab_apparatus,
  5630. }
  5631. //查询该患者是否有病历
  5632. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  5633. if errcodes == gorm.ErrRecordNotFound {
  5634. err = service.SaveHisPatientCaseHistory(&caseHistory)
  5635. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5636. if err != nil {
  5637. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5638. return
  5639. }
  5640. c.ServeSuccessJSON(map[string]interface{}{
  5641. "caseHistory": caseHistory,
  5642. "historyInfo": historyInfo,
  5643. })
  5644. return
  5645. } else if errcodes == nil {
  5646. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  5647. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  5648. if err != nil {
  5649. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5650. return
  5651. }
  5652. c.ServeSuccessJSON(map[string]interface{}{
  5653. "caseHistory": caseHistory,
  5654. "historyInfo": historyInfo,
  5655. })
  5656. }
  5657. //查询该患者是否有病历
  5658. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  5659. //if errcode == gorm.ErrRecordNotFound {
  5660. // err = service.SaveHisPatientCaseHistory(caseHistory)
  5661. // if err != nil {
  5662. // c.ServeSuccessJSON(map[string]interface{}{
  5663. // "msg": "保存成功",
  5664. // })
  5665. // }
  5666. //} else if errcode == nil {
  5667. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5668. // return
  5669. //}
  5670. }
  5671. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  5672. patient_id, _ := c.GetInt64("patient_id", 0)
  5673. adminUser := c.GetAdminUserInfo()
  5674. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  5675. c.ServeSuccessJSON(map[string]interface{}{
  5676. "list": caseHistorys,
  5677. })
  5678. }
  5679. func (c *HisApiController) GetHisPatientCaseHistory() {
  5680. record_date, _ := c.GetInt64("record_date", 0)
  5681. patient_id, _ := c.GetInt64("patient_id", 0)
  5682. admin := c.GetAdminUserInfo()
  5683. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  5684. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  5685. c.ServeSuccessJSON(map[string]interface{}{
  5686. "info": info,
  5687. "case_history": case_history,
  5688. })
  5689. }
  5690. func (c *HisApiController) CreateCaseHistoryTemplate() {
  5691. template_name := c.GetString("template_name")
  5692. template_remark := c.GetString("template_remark")
  5693. doctor := c.GetAdminUserInfo().AdminUser.Id
  5694. diagnostic := c.GetString("diagnostic")
  5695. chief_conplaint := c.GetString("chief_conplain")
  5696. history_of_present_illness := c.GetString("history_of_present_illness")
  5697. past_history := c.GetString("past_history")
  5698. personal_history := c.GetString("personal_history")
  5699. family_history := c.GetString("family_history")
  5700. user_name := c.GetString("user_name")
  5701. doctor_advice := c.GetString("doctor_advice")
  5702. remark := c.GetString("remark")
  5703. //record_date := c.GetString("record_date")
  5704. //fmt.Println("record_date--------",record_date)
  5705. //timeLayout := "2006-01-02"
  5706. //loc, _ := time.LoadLocation("Local")
  5707. //
  5708. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5709. //if err != nil {
  5710. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5711. // return
  5712. //}
  5713. //recordDateTime := theTime.Unix()
  5714. ctime := time.Now().Unix()
  5715. template := models.HisCaseHistoryTemplate{
  5716. HistoryOfPresentIllness: history_of_present_illness,
  5717. PastHistory: past_history,
  5718. ChiefConplaint: chief_conplaint,
  5719. PersonalHistory: personal_history,
  5720. FamilyHistory: family_history,
  5721. Diagnostic: diagnostic,
  5722. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5723. Status: 1,
  5724. Ctime: ctime,
  5725. Mtime: ctime,
  5726. RecordDate: time.Now().Unix(),
  5727. TemplateName: template_name,
  5728. TemplateRemark: template_remark,
  5729. Creator: doctor,
  5730. Modifier: doctor,
  5731. UserName: user_name,
  5732. DoctorAdvice: doctor_advice,
  5733. Remark: remark,
  5734. }
  5735. err := service.SaveHisPatientCaseHistoryTemplate(template)
  5736. if err == nil {
  5737. c.ServeSuccessJSON(map[string]interface{}{
  5738. "msg": "保存成功",
  5739. })
  5740. } else {
  5741. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5742. return
  5743. }
  5744. }
  5745. func (c *HisApiController) GetCaseHistoryTemplate() {
  5746. timeLayout := "2006-01-02"
  5747. loc, _ := time.LoadLocation("Local")
  5748. keyword := c.GetString("keyword")
  5749. start_time := c.GetString("start_time")
  5750. end_time := c.GetString("end_time")
  5751. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5752. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5753. admin := c.GetAdminUserInfo()
  5754. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  5755. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  5756. c.ServeSuccessJSON(map[string]interface{}{
  5757. "template": template,
  5758. //"history": history,
  5759. })
  5760. }
  5761. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  5762. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  5763. utils.ErrorLog("drug_name")
  5764. return enums.ErrorCodeParamWrong
  5765. }
  5766. adviceName, _ := json["drug_name"].(string)
  5767. if len(adviceName) == 0 {
  5768. utils.ErrorLog("len(advice_name) == 0")
  5769. return enums.ErrorCodeParamWrong
  5770. }
  5771. advice.AdviceName = adviceName
  5772. adviceDesc, _ := json["advice_desc"].(string)
  5773. advice.AdviceDesc = adviceDesc
  5774. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  5775. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  5776. advice.DrugSpec = drugSpec
  5777. }
  5778. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5779. remark, _ := json["remark"].(string)
  5780. advice.Remark = remark
  5781. }
  5782. if json["id"] == nil {
  5783. advice.DrugId = 0
  5784. } else {
  5785. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5786. drug_id := int64(json["id"].(float64))
  5787. advice.DrugId = drug_id
  5788. }
  5789. }
  5790. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  5791. advice_id := int64(json["advice_id"].(float64))
  5792. advice.ID = advice_id
  5793. if advice.ID > 0 {
  5794. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  5795. if err == nil {
  5796. if hisAdvice.ID > 0 {
  5797. advice.ExecutionTime = hisAdvice.ExecutionTime
  5798. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  5799. advice.ExecutionState = hisAdvice.ExecutionState
  5800. advice.CheckTime = hisAdvice.CheckTime
  5801. advice.Checker = hisAdvice.Checker
  5802. advice.CheckState = hisAdvice.CheckState
  5803. advice.StartTime = hisAdvice.StartTime
  5804. advice.FeedetlSn = hisAdvice.FeedetlSn
  5805. }
  5806. }
  5807. }
  5808. }
  5809. //
  5810. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  5811. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  5812. // advice.ExecutionTime = execution_time
  5813. //}
  5814. //
  5815. //
  5816. //
  5817. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  5818. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  5819. // advice.ExecutionStaff = execution_staff
  5820. //}
  5821. //
  5822. //
  5823. //
  5824. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  5825. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  5826. // advice.ExecutionState = execution_state
  5827. //}
  5828. //
  5829. //
  5830. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  5831. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  5832. // advice.CheckTime = check_time
  5833. //}
  5834. //
  5835. //
  5836. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  5837. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  5838. // advice.CheckState = check_state
  5839. //}
  5840. //
  5841. //
  5842. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  5843. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  5844. // advice.Checker = checker
  5845. //}
  5846. //
  5847. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  5848. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  5849. // advice.StartTime = start_time
  5850. //}
  5851. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  5852. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  5853. advice.IsSelfDrug = is_self_drug
  5854. }
  5855. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  5856. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  5857. drug_way_count, _ := json["drug_way_count"].(string)
  5858. advice.DrugWayCount = drug_way_count
  5859. }
  5860. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  5861. drugSpecUnit, _ := json["min_unit"].(string)
  5862. advice.DrugSpecUnit = drugSpecUnit
  5863. }
  5864. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5865. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  5866. advice.SingleDose = singleDose
  5867. }
  5868. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  5869. singleDoseUnit, _ := json["single_dose_unit"].(string)
  5870. advice.SingleDoseUnit = singleDoseUnit
  5871. }
  5872. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  5873. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  5874. advice.PrescribingNumber = prescribingNumber
  5875. }
  5876. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  5877. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  5878. advice.PrescribingNumberUnit = prescribingNumberUnit
  5879. }
  5880. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5881. deliveryWay, _ := json["delivery_way"].(string)
  5882. advice.DeliveryWay = deliveryWay
  5883. }
  5884. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5885. executionFrequency, _ := json["execution_frequency"].(string)
  5886. advice.ExecutionFrequency = executionFrequency
  5887. }
  5888. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  5889. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  5890. advice.Price = price
  5891. }
  5892. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  5893. med_list_codg, _ := json["medical_insurance_number"].(string)
  5894. advice.MedListCodg = med_list_codg
  5895. }
  5896. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  5897. day := int64(json["day"].(float64))
  5898. advice.Day = day
  5899. }
  5900. return 0
  5901. }
  5902. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  5903. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5904. id := int64(json["id"].(float64))
  5905. project.ID = id
  5906. historyProject, _ := service.GetHisProjectByID(id)
  5907. project.FeedetlSn = historyProject.FeedetlSn
  5908. }
  5909. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  5910. project_id := int64(json["project_id"].(float64))
  5911. project.ProjectId = project_id
  5912. }
  5913. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5914. // price := int64(json["price"].(float64))
  5915. // formatInt_price := strconv.FormatInt(price, 10)
  5916. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5917. // project.Price = float_price
  5918. // }
  5919. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5920. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5921. project.Price = price
  5922. }
  5923. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  5924. total, _ := json["total"].(string)
  5925. project.Count = total
  5926. }
  5927. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  5928. medical_code, _ := json["medical_code"].(string)
  5929. project.MedListCodg = medical_code
  5930. }
  5931. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  5932. single_dose, _ := json["single_dose"].(string)
  5933. project.SingleDose = single_dose
  5934. }
  5935. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  5936. delivery_way, _ := json["delivery_way"].(string)
  5937. project.DeliveryWay = delivery_way
  5938. }
  5939. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  5940. execution_frequency, _ := json["execution_frequency"].(string)
  5941. project.ExecutionFrequency = execution_frequency
  5942. }
  5943. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  5944. remark, _ := json["remark"].(string)
  5945. project.Remark = remark
  5946. }
  5947. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  5948. day, _ := json["number_days"].(string)
  5949. project.Day = day
  5950. }
  5951. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  5952. unit, _ := json["unit"].(string)
  5953. project.Unit = unit
  5954. }
  5955. return 0
  5956. }
  5957. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  5958. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  5959. id := int64(json["id"].(float64))
  5960. historyAddtions, _ := service.GetHisAdditionByID(id)
  5961. additionalCharge.ID = id
  5962. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  5963. }
  5964. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  5965. item_id := int64(json["item_id"].(float64))
  5966. additionalCharge.ItemId = item_id
  5967. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  5968. if config.ID > 0 {
  5969. if len(config.Code) > 0 {
  5970. additionalCharge.MedListCodg = config.Code
  5971. }
  5972. }
  5973. }
  5974. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5975. // price := int64(json["price"].(float64))
  5976. // formatInt_price := strconv.FormatInt(price, 10)
  5977. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5978. // additionalCharge.Price = float_price
  5979. // }
  5980. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  5981. // price := int64(json["price"].(float64))
  5982. // formatInt_price := strconv.FormatInt(price, 10)
  5983. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  5984. // additionalCharge.Price = float_price
  5985. //}
  5986. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  5987. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  5988. additionalCharge.Price = price
  5989. }
  5990. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  5991. count, _ := json["count"].(string)
  5992. counts, _ := strconv.ParseInt(count, 10, 64)
  5993. additionalCharge.Count = counts
  5994. }
  5995. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  5996. item_name, _ := json["item_name"].(string)
  5997. additionalCharge.ItemName = item_name
  5998. }
  5999. return 0
  6000. }
  6001. func SetAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6002. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6003. utils.ErrorLog("drug_name")
  6004. return enums.ErrorCodeParamWrong
  6005. }
  6006. adviceName, _ := json["drug_name"].(string)
  6007. if len(adviceName) == 0 {
  6008. utils.ErrorLog("len(advice_name) == 0")
  6009. return enums.ErrorCodeParamWrong
  6010. }
  6011. advice.AdviceName = adviceName
  6012. adviceDesc, _ := json["advice_desc"].(string)
  6013. advice.AdviceDesc = adviceDesc
  6014. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6015. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6016. advice.DrugSpec = drugSpec
  6017. }
  6018. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6019. remark, _ := json["remark"].(string)
  6020. advice.Remark = remark
  6021. }
  6022. if json["id"] == nil {
  6023. advice.DrugId = 0
  6024. } else {
  6025. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6026. drug_id := int64(json["id"].(float64))
  6027. advice.DrugId = drug_id
  6028. }
  6029. }
  6030. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6031. groupno := int64(json["groupno"].(float64))
  6032. advice.Groupno = groupno
  6033. }
  6034. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6035. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6036. advice.IsSelfDrug = is_self_drug
  6037. }
  6038. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6039. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6040. drug_way_count, _ := json["drug_way_count"].(string)
  6041. advice.DrugWayCount = drug_way_count
  6042. }
  6043. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6044. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6045. advice.HospApprFlag = hosp_appr_flag
  6046. }
  6047. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6048. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6049. advice.PrescribingNumber = prescribingNumber
  6050. }
  6051. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6052. // frequency_type := int64(json["frequency_type"].(float64))
  6053. // advice.FrequencyType = frequency_type
  6054. //}
  6055. //
  6056. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6057. // day_count := int64(json["day_count"].(float64))
  6058. // advice.DayCount = day_count
  6059. //}
  6060. //
  6061. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6062. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6063. // week_day, _ := json["week_day"].(string)
  6064. // advice.WeekDay = week_day
  6065. //}
  6066. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6067. drugSpecUnit, _ := json["min_unit"].(string)
  6068. advice.DrugSpecUnit = drugSpecUnit
  6069. }
  6070. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6071. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6072. advice.SingleDose = singleDose
  6073. }
  6074. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6075. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6076. advice.SingleDoseUnit = singleDoseUnit
  6077. }
  6078. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6079. deliveryWay, _ := json["delivery_way"].(string)
  6080. advice.DeliveryWay = deliveryWay
  6081. }
  6082. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6083. executionFrequency, _ := json["execution_frequency"].(string)
  6084. advice.ExecutionFrequency = executionFrequency
  6085. }
  6086. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6087. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6088. advice.Price = price
  6089. }
  6090. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6091. med_list_codg, _ := json["medical_insurance_number"].(string)
  6092. advice.MedListCodg = med_list_codg
  6093. }
  6094. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6095. day := int64(json["day"].(float64))
  6096. advice.Day = day
  6097. }
  6098. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6099. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6100. advice.PrescribingNumberUnit = prescribingNumberUnit
  6101. }
  6102. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6103. advice_id := int64(json["advice_id"].(float64))
  6104. advice.ID = advice_id
  6105. if advice.ID > 0 {
  6106. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6107. if err == nil {
  6108. if hisAdvice.ID > 0 {
  6109. advice.ExecutionTime = hisAdvice.ExecutionTime
  6110. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6111. advice.ExecutionState = hisAdvice.ExecutionState
  6112. advice.CheckTime = hisAdvice.CheckTime
  6113. advice.Checker = hisAdvice.Checker
  6114. advice.CheckState = hisAdvice.CheckState
  6115. advice.StartTime = hisAdvice.StartTime
  6116. advice.HospApprFlag = hisAdvice.HospApprFlag
  6117. advice.IsMedicine = hisAdvice.IsMedicine
  6118. if hisAdvice.UserOrgId == 10028 {
  6119. 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 {
  6120. advice.ExecutionTime = 0
  6121. advice.ExecutionStaff = 0
  6122. advice.ExecutionState = 2
  6123. advice.CheckTime = 0
  6124. advice.Checker = 0
  6125. advice.CheckState = 2
  6126. }
  6127. } else {
  6128. 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 {
  6129. advice.ExecutionTime = 0
  6130. advice.ExecutionStaff = 0
  6131. advice.ExecutionState = 2
  6132. advice.CheckTime = 0
  6133. advice.Checker = 0
  6134. advice.CheckState = 2
  6135. }
  6136. }
  6137. //advice.Groupno = hisAdvice.Groupno
  6138. }
  6139. }
  6140. }
  6141. }
  6142. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6143. //
  6144. //if drugStockConfig.IsOpen == 1 {
  6145. //
  6146. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6147. // if advice.ID == 0 { //医嘱不存在
  6148. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6149. // drug.Total = drug.Total - advice.PrescribingNumber
  6150. // service.UpdateBaseDrugLib(&drug)
  6151. //
  6152. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6153. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6154. // drug.Total = drug.Total - num
  6155. // service.UpdateBaseDrugLib(&drug)
  6156. // }
  6157. //
  6158. // } else if advice.ID > 0 { //医嘱存在
  6159. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6160. // var num float64
  6161. //
  6162. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6163. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6164. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6165. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6166. // drug.Total = drug.Total + num
  6167. // service.UpdateBaseDrugLib(&drug)
  6168. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6169. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6170. // drug.Total = drug.Total - num
  6171. // service.UpdateBaseDrugLib(&drug)
  6172. // }
  6173. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6174. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6175. // if num2 > advice.PrescribingNumber {
  6176. // num = num2 - advice.PrescribingNumber
  6177. // drug.Total = drug.Total + num
  6178. // service.UpdateBaseDrugLib(&drug)
  6179. // } else if num2 < advice.PrescribingNumber {
  6180. // num = advice.PrescribingNumber - num2
  6181. // drug.Total = drug.Total - num
  6182. // service.UpdateBaseDrugLib(&drug)
  6183. // }
  6184. //
  6185. // }
  6186. //
  6187. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6188. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6189. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6190. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6191. // if num1 > num2 {
  6192. // num = num1 - num2
  6193. // drug.Total = drug.Total + num
  6194. // service.UpdateBaseDrugLib(&drug)
  6195. // } else if num1 < num2 {
  6196. // num = num2 - num1
  6197. // drug.Total = drug.Total - num
  6198. // service.UpdateBaseDrugLib(&drug)
  6199. // }
  6200. //
  6201. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6202. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6203. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6204. // if hisAdvice.PrescribingNumber > num2 {
  6205. // num = hisAdvice.PrescribingNumber - num2
  6206. // drug.Total = drug.Total + num
  6207. // service.UpdateBaseDrugLib(&drug)
  6208. // } else if num2 < advice.PrescribingNumber {
  6209. // num = num2 - hisAdvice.PrescribingNumber
  6210. // drug.Total = drug.Total - num
  6211. // service.UpdateBaseDrugLib(&drug)
  6212. // }
  6213. //
  6214. // }
  6215. // }
  6216. // }
  6217. //}
  6218. //
  6219. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6220. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6221. // advice.ExecutionTime = execution_time
  6222. //}
  6223. //
  6224. //
  6225. //
  6226. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6227. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6228. // advice.ExecutionStaff = execution_staff
  6229. //}
  6230. //
  6231. //
  6232. //
  6233. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6234. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6235. // advice.ExecutionState = execution_state
  6236. //}
  6237. //
  6238. //
  6239. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6240. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6241. // advice.CheckTime = check_time
  6242. //}
  6243. //
  6244. //
  6245. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6246. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6247. // advice.CheckState = check_state
  6248. //}
  6249. //
  6250. //
  6251. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6252. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6253. // advice.Checker = checker
  6254. //}
  6255. //
  6256. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6257. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6258. // advice.StartTime = start_time
  6259. //}
  6260. return 0
  6261. }
  6262. func SetProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6263. project.ExecutionStaff = 0
  6264. project.ExecutionState = 2
  6265. project.ExecutionTime = 0
  6266. project.Checker = 0
  6267. project.CheckState = 2
  6268. project.CheckTime = 0
  6269. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6270. id := int64(json["id"].(float64))
  6271. project.ID = id
  6272. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6273. project.ExecutionStaff = temp_project.ExecutionStaff
  6274. project.ExecutionState = temp_project.ExecutionState
  6275. project.ExecutionTime = temp_project.ExecutionTime
  6276. project.Checker = temp_project.Checker
  6277. project.CheckState = temp_project.CheckState
  6278. project.CheckTime = temp_project.CheckTime
  6279. project.TeamId = temp_project.TeamId
  6280. }
  6281. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6282. types := int64(json["type"].(float64))
  6283. project.Type = types
  6284. }
  6285. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6286. project_id := int64(json["project_id"].(float64))
  6287. project.ProjectId = project_id
  6288. }
  6289. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6290. team_id := int64(json["team_id"].(float64))
  6291. project.TeamId = team_id
  6292. }
  6293. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6294. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6295. project.Price = price
  6296. }
  6297. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6298. total, _ := json["total"].(string)
  6299. //totals, _ := strconv.ParseInt(total, 10, 64)
  6300. project.Count = total
  6301. }
  6302. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6303. medical_code, _ := json["medical_code"].(string)
  6304. project.MedListCodg = medical_code
  6305. }
  6306. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6307. single_dose, _ := json["single_dose"].(string)
  6308. project.SingleDose = single_dose
  6309. }
  6310. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6311. delivery_way, _ := json["delivery_way"].(string)
  6312. project.DeliveryWay = delivery_way
  6313. }
  6314. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6315. execution_frequency, _ := json["execution_frequency"].(string)
  6316. project.ExecutionFrequency = execution_frequency
  6317. }
  6318. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6319. remark, _ := json["remark"].(string)
  6320. project.Remark = remark
  6321. }
  6322. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6323. day, _ := json["number_days"].(string)
  6324. project.Day = day
  6325. }
  6326. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6327. unit, _ := json["unit"].(string)
  6328. project.Unit = unit
  6329. }
  6330. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6331. // frequency_type := int64(json["frequency_type"].(float64))
  6332. // project.FrequencyType = frequency_type
  6333. //}
  6334. //
  6335. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6336. // day_count := int64(json["day_count"].(float64))
  6337. // project.DayCount = day_count
  6338. //}
  6339. //
  6340. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6341. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6342. // week_day, _ := json["week_day"].(string)
  6343. // project.WeekDay = week_day
  6344. //}
  6345. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6346. //
  6347. //if project.ID == 0 {
  6348. // if stockConfig.IsOpen == 1 {
  6349. // if project.Type == 3 {
  6350. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6351. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6352. // good.Total = good.Total - f_count
  6353. // service.UpdateGoodInfo(&good)
  6354. // }
  6355. // }
  6356. //
  6357. //} else {
  6358. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6359. //
  6360. // if stockConfig.IsOpen == 1 {
  6361. // if project.Type == 3 {
  6362. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6363. // if project.Count < temp_project.Count {
  6364. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6365. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6366. //
  6367. // other_count := f_count_two - f_count_one
  6368. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6369. // good.Total = good.Total + other_count_two
  6370. // service.UpdateGoodInfo(&good)
  6371. // } else if project.Count > temp_project.Count {
  6372. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6373. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6374. //
  6375. // other_count := f_count_one - f_count_two
  6376. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6377. // good.Total = good.Total - other_count_two
  6378. // service.UpdateGoodInfo(&good)
  6379. // }
  6380. //
  6381. // }
  6382. // }
  6383. //
  6384. //}
  6385. return 0
  6386. }
  6387. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  6388. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6389. utils.ErrorLog("drug_name")
  6390. return enums.ErrorCodeParamWrong
  6391. }
  6392. adviceName, _ := json["drug_name"].(string)
  6393. if len(adviceName) == 0 {
  6394. utils.ErrorLog("len(advice_name) == 0")
  6395. return enums.ErrorCodeParamWrong
  6396. }
  6397. advice.AdviceName = adviceName
  6398. adviceDesc, _ := json["advice_desc"].(string)
  6399. advice.AdviceDesc = adviceDesc
  6400. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6401. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6402. advice.DrugSpec = drugSpec
  6403. }
  6404. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6405. remark, _ := json["remark"].(string)
  6406. advice.Remark = remark
  6407. }
  6408. if json["id"] == nil {
  6409. advice.DrugId = 0
  6410. } else {
  6411. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6412. drug_id := int64(json["id"].(float64))
  6413. advice.DrugId = drug_id
  6414. }
  6415. }
  6416. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6417. groupno := int64(json["groupno"].(float64))
  6418. advice.Groupno = groupno
  6419. }
  6420. if json["is_self_drug"] != nil && reflect.TypeOf(json["is_self_drug"]).String() == "string" {
  6421. is_self_drug, _ := strconv.ParseInt(json["is_self_drug"].(string), 10, 64)
  6422. advice.IsSelfDrug = is_self_drug
  6423. }
  6424. if json["drug_way_count"] != nil && reflect.TypeOf(json["drug_way_count"]).String() == "string" {
  6425. //drug_way_count, _ := strconv.ParseInt(json["drug_way_count"].(string), 10, 64)
  6426. drug_way_count, _ := json["drug_way_count"].(string)
  6427. advice.DrugWayCount = drug_way_count
  6428. }
  6429. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  6430. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  6431. advice.HospApprFlag = hosp_appr_flag
  6432. }
  6433. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6434. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6435. advice.PrescribingNumber = prescribingNumber
  6436. }
  6437. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6438. // frequency_type := int64(json["frequency_type"].(float64))
  6439. // advice.FrequencyType = frequency_type
  6440. //}
  6441. //
  6442. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6443. // day_count := int64(json["day_count"].(float64))
  6444. // advice.DayCount = day_count
  6445. //}
  6446. //
  6447. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6448. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6449. // week_day, _ := json["week_day"].(string)
  6450. // advice.WeekDay = week_day
  6451. //}
  6452. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6453. drugSpecUnit, _ := json["min_unit"].(string)
  6454. advice.DrugSpecUnit = drugSpecUnit
  6455. }
  6456. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6457. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6458. advice.SingleDose = singleDose
  6459. }
  6460. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6461. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6462. advice.SingleDoseUnit = singleDoseUnit
  6463. }
  6464. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6465. deliveryWay, _ := json["delivery_way"].(string)
  6466. advice.DeliveryWay = deliveryWay
  6467. }
  6468. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6469. executionFrequency, _ := json["execution_frequency"].(string)
  6470. advice.ExecutionFrequency = executionFrequency
  6471. }
  6472. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6473. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6474. advice.Price = price
  6475. }
  6476. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6477. med_list_codg, _ := json["medical_insurance_number"].(string)
  6478. advice.MedListCodg = med_list_codg
  6479. }
  6480. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6481. day := int64(json["day"].(float64))
  6482. advice.Day = day
  6483. }
  6484. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6485. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6486. advice.PrescribingNumberUnit = prescribingNumberUnit
  6487. }
  6488. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  6489. advice_id := int64(json["advice_id"].(float64))
  6490. advice.ID = advice_id
  6491. if advice.ID > 0 {
  6492. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  6493. if err == nil {
  6494. if hisAdvice.ID > 0 {
  6495. advice.ExecutionTime = hisAdvice.ExecutionTime
  6496. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  6497. advice.ExecutionState = hisAdvice.ExecutionState
  6498. advice.CheckTime = hisAdvice.CheckTime
  6499. advice.Checker = hisAdvice.Checker
  6500. advice.CheckState = hisAdvice.CheckState
  6501. advice.StartTime = hisAdvice.StartTime
  6502. advice.HospApprFlag = hisAdvice.HospApprFlag
  6503. advice.IsMedicine = hisAdvice.IsMedicine
  6504. if hisAdvice.UserOrgId == 10028 {
  6505. 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 {
  6506. advice.ExecutionTime = 0
  6507. advice.ExecutionStaff = 0
  6508. advice.ExecutionState = 2
  6509. advice.CheckTime = 0
  6510. advice.Checker = 0
  6511. advice.CheckState = 2
  6512. }
  6513. } else {
  6514. 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 {
  6515. advice.ExecutionTime = 0
  6516. advice.ExecutionStaff = 0
  6517. advice.ExecutionState = 2
  6518. advice.CheckTime = 0
  6519. advice.Checker = 0
  6520. advice.CheckState = 2
  6521. }
  6522. }
  6523. //advice.Groupno = hisAdvice.Groupno
  6524. }
  6525. }
  6526. }
  6527. }
  6528. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  6529. //
  6530. //if drugStockConfig.IsOpen == 1 {
  6531. //
  6532. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6533. // if advice.ID == 0 { //医嘱不存在
  6534. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  6535. // drug.Total = drug.Total - advice.PrescribingNumber
  6536. // service.UpdateBaseDrugLib(&drug)
  6537. //
  6538. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  6539. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  6540. // drug.Total = drug.Total - num
  6541. // service.UpdateBaseDrugLib(&drug)
  6542. // }
  6543. //
  6544. // } else if advice.ID > 0 { //医嘱存在
  6545. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  6546. // var num float64
  6547. //
  6548. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  6549. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  6550. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  6551. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  6552. // drug.Total = drug.Total + num
  6553. // service.UpdateBaseDrugLib(&drug)
  6554. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  6555. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  6556. // drug.Total = drug.Total - num
  6557. // service.UpdateBaseDrugLib(&drug)
  6558. // }
  6559. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  6560. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6561. // if num2 > advice.PrescribingNumber {
  6562. // num = num2 - advice.PrescribingNumber
  6563. // drug.Total = drug.Total + num
  6564. // service.UpdateBaseDrugLib(&drug)
  6565. // } else if num2 < advice.PrescribingNumber {
  6566. // num = advice.PrescribingNumber - num2
  6567. // drug.Total = drug.Total - num
  6568. // service.UpdateBaseDrugLib(&drug)
  6569. // }
  6570. //
  6571. // }
  6572. //
  6573. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  6574. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  6575. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  6576. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6577. // if num1 > num2 {
  6578. // num = num1 - num2
  6579. // drug.Total = drug.Total + num
  6580. // service.UpdateBaseDrugLib(&drug)
  6581. // } else if num1 < num2 {
  6582. // num = num2 - num1
  6583. // drug.Total = drug.Total - num
  6584. // service.UpdateBaseDrugLib(&drug)
  6585. // }
  6586. //
  6587. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  6588. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  6589. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  6590. // if hisAdvice.PrescribingNumber > num2 {
  6591. // num = hisAdvice.PrescribingNumber - num2
  6592. // drug.Total = drug.Total + num
  6593. // service.UpdateBaseDrugLib(&drug)
  6594. // } else if num2 < advice.PrescribingNumber {
  6595. // num = num2 - hisAdvice.PrescribingNumber
  6596. // drug.Total = drug.Total - num
  6597. // service.UpdateBaseDrugLib(&drug)
  6598. // }
  6599. //
  6600. // }
  6601. // }
  6602. // }
  6603. //}
  6604. //
  6605. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  6606. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  6607. // advice.ExecutionTime = execution_time
  6608. //}
  6609. //
  6610. //
  6611. //
  6612. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  6613. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  6614. // advice.ExecutionStaff = execution_staff
  6615. //}
  6616. //
  6617. //
  6618. //
  6619. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  6620. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  6621. // advice.ExecutionState = execution_state
  6622. //}
  6623. //
  6624. //
  6625. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  6626. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  6627. // advice.CheckTime = check_time
  6628. //}
  6629. //
  6630. //
  6631. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  6632. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  6633. // advice.CheckState = check_state
  6634. //}
  6635. //
  6636. //
  6637. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  6638. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  6639. // advice.Checker = checker
  6640. //}
  6641. //
  6642. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  6643. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  6644. // advice.StartTime = start_time
  6645. //}
  6646. return 0
  6647. }
  6648. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  6649. project.ExecutionStaff = 0
  6650. project.ExecutionState = 2
  6651. project.ExecutionTime = 0
  6652. project.Checker = 0
  6653. project.CheckState = 2
  6654. project.CheckTime = 0
  6655. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6656. id := int64(json["id"].(float64))
  6657. project.ID = id
  6658. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  6659. project.ExecutionStaff = temp_project.ExecutionStaff
  6660. project.ExecutionState = temp_project.ExecutionState
  6661. project.ExecutionTime = temp_project.ExecutionTime
  6662. project.Checker = temp_project.Checker
  6663. project.CheckState = temp_project.CheckState
  6664. project.CheckTime = temp_project.CheckTime
  6665. project.TeamId = temp_project.TeamId
  6666. }
  6667. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6668. types := int64(json["type"].(float64))
  6669. project.Type = types
  6670. }
  6671. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6672. project_id := int64(json["project_id"].(float64))
  6673. project.ProjectId = project_id
  6674. }
  6675. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  6676. team_id := int64(json["team_id"].(float64))
  6677. project.TeamId = team_id
  6678. }
  6679. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6680. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6681. project.Price = price
  6682. }
  6683. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6684. total, _ := json["total"].(string)
  6685. //totals, _ := strconv.ParseInt(total, 10, 64)
  6686. project.Count = total
  6687. }
  6688. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6689. medical_code, _ := json["medical_code"].(string)
  6690. project.MedListCodg = medical_code
  6691. }
  6692. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6693. single_dose, _ := json["single_dose"].(string)
  6694. project.SingleDose = single_dose
  6695. }
  6696. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6697. delivery_way, _ := json["delivery_way"].(string)
  6698. project.DeliveryWay = delivery_way
  6699. }
  6700. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6701. execution_frequency, _ := json["execution_frequency"].(string)
  6702. project.ExecutionFrequency = execution_frequency
  6703. }
  6704. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6705. remark, _ := json["remark"].(string)
  6706. project.Remark = remark
  6707. }
  6708. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6709. day, _ := json["number_days"].(string)
  6710. project.Day = day
  6711. }
  6712. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6713. unit, _ := json["unit"].(string)
  6714. project.Unit = unit
  6715. }
  6716. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  6717. // frequency_type := int64(json["frequency_type"].(float64))
  6718. // project.FrequencyType = frequency_type
  6719. //}
  6720. //
  6721. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  6722. // day_count := int64(json["day_count"].(float64))
  6723. // project.DayCount = day_count
  6724. //}
  6725. //
  6726. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  6727. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  6728. // week_day, _ := json["week_day"].(string)
  6729. // project.WeekDay = week_day
  6730. //}
  6731. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  6732. //
  6733. //if project.ID == 0 {
  6734. // if stockConfig.IsOpen == 1 {
  6735. // if project.Type == 3 {
  6736. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6737. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  6738. // good.Total = good.Total - f_count
  6739. // service.UpdateGoodInfo(&good)
  6740. // }
  6741. // }
  6742. //
  6743. //} else {
  6744. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  6745. //
  6746. // if stockConfig.IsOpen == 1 {
  6747. // if project.Type == 3 {
  6748. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  6749. // if project.Count < temp_project.Count {
  6750. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6751. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6752. //
  6753. // other_count := f_count_two - f_count_one
  6754. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6755. // good.Total = good.Total + other_count_two
  6756. // service.UpdateGoodInfo(&good)
  6757. // } else if project.Count > temp_project.Count {
  6758. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  6759. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  6760. //
  6761. // other_count := f_count_one - f_count_two
  6762. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  6763. // good.Total = good.Total - other_count_two
  6764. // service.UpdateGoodInfo(&good)
  6765. // }
  6766. //
  6767. // }
  6768. // }
  6769. //
  6770. //}
  6771. return 0
  6772. }
  6773. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  6774. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6775. id := int64(json["id"].(float64))
  6776. additionalCharge.ID = id
  6777. }
  6778. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  6779. item_id := int64(json["item_id"].(float64))
  6780. additionalCharge.ItemId = item_id
  6781. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  6782. if config.ID > 0 {
  6783. if len(config.Code) > 0 {
  6784. additionalCharge.MedListCodg = config.Code
  6785. }
  6786. }
  6787. }
  6788. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6789. // price := int64(json["price"].(float64))
  6790. // formatInt_price := strconv.FormatInt(price, 10)
  6791. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6792. // additionalCharge.Price = float_price
  6793. // }
  6794. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  6795. // price := int64(json["price"].(float64))
  6796. // formatInt_price := strconv.FormatInt(price, 10)
  6797. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  6798. // additionalCharge.Price = float_price
  6799. //}
  6800. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6801. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6802. additionalCharge.Price = price
  6803. }
  6804. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  6805. count, _ := json["count"].(string)
  6806. counts, _ := strconv.ParseInt(count, 10, 64)
  6807. additionalCharge.Count = counts
  6808. }
  6809. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  6810. item_name, _ := json["item_name"].(string)
  6811. additionalCharge.ItemName = item_name
  6812. }
  6813. return 0
  6814. }
  6815. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  6816. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  6817. utils.ErrorLog("drug_name")
  6818. return enums.ErrorCodeParamWrong
  6819. }
  6820. adviceName, _ := json["drug_name"].(string)
  6821. if len(adviceName) == 0 {
  6822. utils.ErrorLog("len(advice_name) == 0")
  6823. return enums.ErrorCodeParamWrong
  6824. }
  6825. advice.AdviceName = adviceName
  6826. adviceDesc, _ := json["advice_desc"].(string)
  6827. advice.AdviceDesc = adviceDesc
  6828. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  6829. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  6830. advice.DrugSpec = drugSpec
  6831. }
  6832. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6833. remark, _ := json["remark"].(string)
  6834. advice.Remark = remark
  6835. }
  6836. if json["id"] == nil {
  6837. advice.DrugId = 0
  6838. } else {
  6839. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  6840. drug_id := int64(json["id"].(float64))
  6841. advice.DrugId = drug_id
  6842. }
  6843. }
  6844. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  6845. groupno := int64(json["groupno"].(float64))
  6846. advice.Groupno = groupno
  6847. }
  6848. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  6849. drugSpecUnit, _ := json["min_unit"].(string)
  6850. advice.DrugSpecUnit = drugSpecUnit
  6851. }
  6852. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6853. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  6854. advice.SingleDose = singleDose
  6855. }
  6856. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  6857. singleDoseUnit, _ := json["single_dose_unit"].(string)
  6858. advice.SingleDoseUnit = singleDoseUnit
  6859. }
  6860. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  6861. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  6862. advice.PrescribingNumber = prescribingNumber
  6863. }
  6864. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  6865. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  6866. advice.PrescribingNumberUnit = prescribingNumberUnit
  6867. }
  6868. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6869. deliveryWay, _ := json["delivery_way"].(string)
  6870. advice.DeliveryWay = deliveryWay
  6871. }
  6872. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6873. executionFrequency, _ := json["execution_frequency"].(string)
  6874. advice.ExecutionFrequency = executionFrequency
  6875. }
  6876. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  6877. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  6878. advice.Price = price
  6879. }
  6880. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  6881. med_list_codg, _ := json["medical_insurance_number"].(string)
  6882. advice.MedListCodg = med_list_codg
  6883. }
  6884. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  6885. day := int64(json["day"].(float64))
  6886. advice.Day = day
  6887. }
  6888. advice.FrequencyType = 1
  6889. return 0
  6890. }
  6891. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  6892. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  6893. types := int64(json["type"].(float64))
  6894. project.Type = types
  6895. }
  6896. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  6897. project_id := int64(json["project_id"].(float64))
  6898. project.ProjectId = project_id
  6899. }
  6900. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  6901. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  6902. project.Price = price
  6903. }
  6904. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  6905. total, _ := json["total"].(string)
  6906. //totals, _ := strconv.ParseInt(total, 10, 64)
  6907. project.Count = total
  6908. }
  6909. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  6910. medical_code, _ := json["medical_code"].(string)
  6911. project.MedListCodg = medical_code
  6912. }
  6913. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  6914. single_dose, _ := json["single_dose"].(string)
  6915. project.SingleDose = single_dose
  6916. }
  6917. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  6918. delivery_way, _ := json["delivery_way"].(string)
  6919. project.DeliveryWay = delivery_way
  6920. }
  6921. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  6922. execution_frequency, _ := json["execution_frequency"].(string)
  6923. project.ExecutionFrequency = execution_frequency
  6924. }
  6925. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  6926. remark, _ := json["remark"].(string)
  6927. project.Remark = remark
  6928. }
  6929. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  6930. day, _ := json["number_days"].(string)
  6931. project.Day = day
  6932. }
  6933. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  6934. unit, _ := json["unit"].(string)
  6935. project.Unit = unit
  6936. }
  6937. project.FrequencyType = 1
  6938. return 0
  6939. }
  6940. func (c *HisApiController) GetHisOrderListTwo() {
  6941. start_time := c.GetString("start_time")
  6942. end_time := c.GetString("end_time")
  6943. timeLayout := "2006-01-02"
  6944. loc, _ := time.LoadLocation("Local")
  6945. var startTime int64
  6946. if len(start_time) > 0 {
  6947. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6948. if err != nil {
  6949. //fmt.Println(err)
  6950. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6951. return
  6952. }
  6953. startTime = theTime.Unix()
  6954. }
  6955. var endTime int64
  6956. if len(end_time) > 0 {
  6957. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6958. if err != nil {
  6959. utils.ErrorLog(err.Error())
  6960. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6961. return
  6962. }
  6963. endTime = theTime.Unix()
  6964. }
  6965. adminUser := c.GetAdminUserInfo()
  6966. org_id := adminUser.CurrentOrgId
  6967. order, err := service.GetNewHisOrderListTwo(org_id, startTime, endTime)
  6968. if err == nil {
  6969. c.ServeSuccessJSON(map[string]interface{}{
  6970. "order2": order,
  6971. })
  6972. } else {
  6973. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  6974. return
  6975. }
  6976. }
  6977. func (c *HisApiController) GetHisOrderList() {
  6978. page, _ := c.GetInt64("page", -1)
  6979. limit, _ := c.GetInt64("limit", -1)
  6980. start_time := c.GetString("start_time")
  6981. end_time := c.GetString("end_time")
  6982. types, _ := c.GetInt64("type", 0)
  6983. keywords := c.GetString("keywords")
  6984. p_type, _ := c.GetInt64("p_type", 0)
  6985. sort_type, _ := c.GetInt64("sort_type", 0)
  6986. charge_type, _ := c.GetInt64("charge_type", 0)
  6987. sch_type, _ := c.GetInt64("sch_type", 0)
  6988. zone_type, _ := c.GetInt64("zone_type", 0)
  6989. med_type, _ := c.GetInt64("med_type", 0)
  6990. timeLayout := "2006-01-02"
  6991. loc, _ := time.LoadLocation("Local")
  6992. var startTime int64
  6993. if len(start_time) > 0 {
  6994. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6995. if err != nil {
  6996. //fmt.Println(err)
  6997. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6998. return
  6999. }
  7000. startTime = theTime.Unix()
  7001. }
  7002. var endTime int64
  7003. if len(end_time) > 0 {
  7004. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7005. if err != nil {
  7006. utils.ErrorLog(err.Error())
  7007. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7008. return
  7009. }
  7010. endTime = theTime.Unix()
  7011. }
  7012. adminUser := c.GetAdminUserInfo()
  7013. org_id := adminUser.CurrentOrgId
  7014. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type, sch_type, zone_type, med_type)
  7015. for _, item := range order {
  7016. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  7017. item.DoctorName = info.Doctor
  7018. item.DepartmentName = info.XtHisDepartment.Name
  7019. }
  7020. if err == nil {
  7021. c.ServeSuccessJSON(map[string]interface{}{
  7022. "order": order,
  7023. "total": total,
  7024. })
  7025. } else {
  7026. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7027. return
  7028. }
  7029. }
  7030. func (c *HisApiController) GetHisOrder() {
  7031. patient_id, _ := c.GetInt64("patient_id", 0)
  7032. number := c.GetString("number")
  7033. adminInfo := c.GetAdminUserInfo()
  7034. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  7035. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  7036. if err == nil {
  7037. c.ServeSuccessJSON(map[string]interface{}{
  7038. "order": order,
  7039. "prescription": prescriptions,
  7040. })
  7041. } else {
  7042. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7043. return
  7044. }
  7045. }
  7046. func (c *HisApiController) GetHisPrescriptionList() {
  7047. record_date := c.GetString("record_date")
  7048. keywords := c.GetString("keywords")
  7049. page, _ := c.GetInt64("page")
  7050. limit, _ := c.GetInt64("limit")
  7051. sch_type, _ := c.GetInt64("sch_type")
  7052. timeLayout := "2006-01-02"
  7053. loc, _ := time.LoadLocation("Local")
  7054. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7055. if err != nil {
  7056. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7057. return
  7058. }
  7059. recordDateTime := theTime.Unix()
  7060. adminInfo := c.GetAdminUserInfo()
  7061. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit, sch_type)
  7062. //adminInfo := c.GetAdminUserInfo()
  7063. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  7064. //fmt.Println(prescriptionOrder)
  7065. if err == nil {
  7066. c.ServeSuccessJSON(map[string]interface{}{
  7067. "order": prescriptionOrder,
  7068. "total": total,
  7069. })
  7070. } else {
  7071. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7072. return
  7073. }
  7074. }
  7075. func (c *HisApiController) GetHisPrescriptionInfo() {
  7076. id, _ := c.GetInt64("id")
  7077. adminInfo := c.GetAdminUserInfo()
  7078. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  7079. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  7080. if err == nil {
  7081. c.ServeSuccessJSON(map[string]interface{}{
  7082. "order": prescriptionOrder,
  7083. "prescription": prescription,
  7084. })
  7085. } else {
  7086. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  7087. return
  7088. }
  7089. }
  7090. func (c *HisApiController) GetMedicalInsuranceConfig() {
  7091. adminUser := c.GetAdminUserInfo()
  7092. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  7093. c.ServeSuccessJSON(map[string]interface{}{
  7094. "config": config,
  7095. })
  7096. }
  7097. type ResultTwo struct {
  7098. ErrMsg interface{} `json:"err_msg"`
  7099. InfRefmsgid string `json:"inf_refmsgid"`
  7100. Infcode int64 `json:"infcode"`
  7101. Output struct {
  7102. Baseinfo struct {
  7103. Age float64 `json:"age"`
  7104. Brdy string `json:"brdy"`
  7105. Certno string `json:"certno"`
  7106. Gend string `json:"gend"`
  7107. Naty string `json:"naty"`
  7108. PsnCertType string `json:"psn_cert_type"`
  7109. PsnName string `json:"psn_name"`
  7110. PsnNo string `json:"psn_no"`
  7111. } `json:"baseinfo"`
  7112. Idetinfo []interface{} `json:"idetinfo"`
  7113. Iinfo []struct {
  7114. Balc float64 `json:"balc"`
  7115. CvlservFlag string `json:"cvlserv_flag"`
  7116. EmpName string `json:"emp_name"`
  7117. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  7118. Insutype string `json:"insutype"`
  7119. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  7120. PausInsuDate interface{} `json:"paus_insu_date"`
  7121. PsnInsuDate string `json:"psn_insu_date"`
  7122. PsnInsuStas string `json:"psn_insu_stas"`
  7123. PsnType string `json:"psn_type"`
  7124. } `json:"insuinfo"`
  7125. } `json:"output"`
  7126. RefmsgTime string `json:"refmsg_time"`
  7127. RespondTime string `json:"respond_time"`
  7128. Signtype interface{} `json:"signtype"`
  7129. WarnInfo interface{} `json:"warn_info"`
  7130. }
  7131. type ResultThree struct {
  7132. Cainfo interface{} `json:"cainfo"`
  7133. ErrMsg interface{} `json:"err_msg"`
  7134. InfRefmsgid string `json:"inf_refmsgid"`
  7135. Infcode int64 `json:"infcode"`
  7136. Output struct {
  7137. Data struct {
  7138. IptOtpNo string `json:"ipt_otp_no"`
  7139. MdtrtID string `json:"mdtrt_id"`
  7140. PsnNo string `json:"psn_no"`
  7141. } `json:"data"`
  7142. } `json:"output"`
  7143. RefmsgTime string `json:"refmsg_time"`
  7144. RespondTime string `json:"respond_time"`
  7145. Signtype interface{} `json:"signtype"`
  7146. WarnMsg interface{} `json:"warn_msg"`
  7147. }
  7148. type ResultFour struct {
  7149. Cainfo string `json:"cainfo"`
  7150. ErrMsg string `json:"err_msg"`
  7151. InfRefmsgid string `json:"inf_refmsgid"`
  7152. Infcode int64 `json:"infcode"`
  7153. Output struct {
  7154. Result []struct {
  7155. BasMednFlag string `json:"bas_medn_flag"`
  7156. ChldMedcFlag string `json:"chld_medc_flag"`
  7157. ChrgitmLv string `json:"chrgitm_lv"`
  7158. Cnt float64 `json:"cnt"`
  7159. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  7160. DrtReimFlag string `json:"drt_reim_flag"`
  7161. FeedetlSn string `json:"feedetl_sn"`
  7162. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7163. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  7164. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7165. ListSpItemFlag string `json:"list_sp_item_flag"`
  7166. LmtUsedFlag string `json:"lmt_used_flag"`
  7167. MedChrgitmType string `json:"med_chrgitm_type"`
  7168. Memo string `json:"memo"`
  7169. OverlmtAmt float64 `json:"overlmt_amt"`
  7170. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7171. Pric float64 `json:"pric"`
  7172. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  7173. SelfpayProp float64 `json:"selfpay_prop"`
  7174. } `json:"result"`
  7175. } `json:"output"`
  7176. RefmsgTime string `json:"refmsg_time"`
  7177. RespondTime string `json:"respond_time"`
  7178. Signtype string `json:"signtype"`
  7179. WarnMsg string `json:"warn_msg"`
  7180. }
  7181. type ResultFive struct {
  7182. Insutype string `json:"insutype"`
  7183. }
  7184. type ResultSix struct {
  7185. Cainfo interface{} `json:"cainfo"`
  7186. ErrMsg interface{} `json:"err_msg"`
  7187. InfRefmsgid string `json:"inf_refmsgid"`
  7188. Infcode int64 `json:"infcode"`
  7189. Output struct {
  7190. } `json:"output"`
  7191. RefmsgTime string `json:"refmsg_time"`
  7192. RespondTime string `json:"respond_time"`
  7193. Signtype interface{} `json:"signtype"`
  7194. WarnMsg interface{} `json:"warn_msg"`
  7195. }
  7196. type ResultSeven struct {
  7197. Cainfo string `json:"cainfo"`
  7198. ErrMsg string `json:"err_msg"`
  7199. InfRefmsgid string `json:"inf_refmsgid"`
  7200. Infcode int64 `json:"infcode"`
  7201. Output struct {
  7202. Setldetail []interface{} `json:"setldetail"`
  7203. Setlinfo struct {
  7204. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7205. AcctPay float64 `json:"acct_pay"`
  7206. ActPayDedc float64 `json:"act_pay_dedc"`
  7207. Age float64 `json:"age"`
  7208. Balc float64 `json:"balc"`
  7209. Brdy string `json:"brdy"`
  7210. Certno string `json:"certno"`
  7211. ClrOptins string `json:"clr_optins"`
  7212. ClrType string `json:"clr_type"`
  7213. ClrWay string `json:"clr_way"`
  7214. CvlservFlag string `json:"cvlserv_flag"`
  7215. CvlservPay float64 `json:"cvlserv_pay"`
  7216. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7217. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7218. Gend string `json:"gend"`
  7219. HifesPay float64 `json:"hifes_pay"`
  7220. HifmiPay float64 `json:"hifmi_pay"`
  7221. HifobPay float64 `json:"hifob_pay"`
  7222. HifpPay float64 `json:"hifp_pay"`
  7223. HospPartAmt float64 `json:"hosp_part_amt"`
  7224. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7225. Insutype string `json:"insutype"`
  7226. MafPay float64 `json:"maf_pay"`
  7227. MdtrtCertType string `json:"mdtrt_cert_type"`
  7228. MdtrtID string `json:"mdtrt_id"`
  7229. MedType string `json:"med_type"`
  7230. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7231. MedinsSetlID string `json:"medins_setl_id"`
  7232. Naty string `json:"naty"`
  7233. OthPay float64 `json:"oth_pay"`
  7234. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7235. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7236. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7237. PsnCashPay float64 `json:"psn_cash_pay"`
  7238. PsnCertType string `json:"psn_cert_type"`
  7239. PsnName string `json:"psn_name"`
  7240. PsnNo string `json:"psn_no"`
  7241. PsnPartAmt float64 `json:"psn_part_amt"`
  7242. PsnType string `json:"psn_type"`
  7243. SetlID string `json:"setl_id"`
  7244. SetlTime string `json:"setl_time"`
  7245. } `json:"setlinfo"`
  7246. } `json:"output"`
  7247. RefmsgTime string `json:"refmsg_time"`
  7248. RespondTime string `json:"respond_time"`
  7249. Signtype interface{} `json:"signtype"`
  7250. WarnMsg interface{} `json:"warn_msg"`
  7251. }
  7252. type ResultEight struct {
  7253. Cainfo string `json:"cainfo"`
  7254. ErrMsg string `json:"err_msg"`
  7255. InfRefmsgid string `json:"inf_refmsgid"`
  7256. Infcode int64 `json:"infcode"`
  7257. Output struct {
  7258. Stmtinfo struct {
  7259. SetlOptins string `json:"setl_optins"`
  7260. StmtRslt string `json:"stmt_rslt"`
  7261. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  7262. } `json:"stmtinfo"`
  7263. } `json:"output"`
  7264. RefmsgTime string `json:"refmsg_time"`
  7265. RespondTime string `json:"respond_time"`
  7266. Signtype interface{} `json:"signtype"`
  7267. WarnMsg interface{} `json:"warn_msg"`
  7268. }
  7269. type ResultNine struct {
  7270. Cainfo string `json:"cainfo"`
  7271. ErrMsg string `json:"err_msg"`
  7272. InfRefmsgid string `json:"inf_refmsgid"`
  7273. Infcode int64 `json:"infcode"`
  7274. Output struct {
  7275. FileQuryNo string `json:"file_qury_no"`
  7276. } `json:"output"`
  7277. RefmsgTime string `json:"refmsg_time"`
  7278. RespondTime string `json:"respond_time"`
  7279. Signtype interface{} `json:"signtype"`
  7280. WarnMsg interface{} `json:"warn_msg"`
  7281. }
  7282. type ResultTen struct {
  7283. Cainfo string `json:"cainfo"`
  7284. ErrMsg string `json:"err_msg"`
  7285. InfRefmsgid string `json:"inf_refmsgid"`
  7286. Infcode int64 `json:"infcode"`
  7287. Output struct {
  7288. DldEndtime string `json:"dld_endtime"`
  7289. FileQuryNo string `json:"file_qury_no"`
  7290. Filename string `json:"filename"`
  7291. } `json:"output"`
  7292. RefmsgTime string `json:"refmsg_time"`
  7293. RespondTime string `json:"respond_time"`
  7294. Signtype interface{} `json:"signtype"`
  7295. WarnMsg interface{} `json:"warn_msg"`
  7296. }
  7297. type ResultEleven struct {
  7298. Cainfo string `json:"cainfo"`
  7299. ErrMsg string `json:"err_msg"`
  7300. InfRefmsgid string `json:"inf_refmsgid"`
  7301. Infcode int64 `json:"infcode"`
  7302. Output struct {
  7303. Setlinfo struct {
  7304. FixmedinsName string `json:"fixmedins_name"`
  7305. FixmedinsCode string `json:"fixmedins_code"`
  7306. PsnNo string `json:"psn_no"`
  7307. PsnName string `json:"psn_name"`
  7308. HifobPay float64 `json:"hifob_pay"`
  7309. Gend string `json:"gend"`
  7310. Brdy string `json:"brdy"`
  7311. PsnCertType string `json:"psn_cert_type"`
  7312. PsnType string `json:"psn_type"`
  7313. EmpName string `json:"emp_name"`
  7314. Certno string `json:"certno"`
  7315. Insutype string `json:"insutype"`
  7316. MedfeeSumamt float64 `json:"medfee_sumamt"`
  7317. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  7318. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  7319. PreselfpayAmt float64 `json:"preselfpay_amt"`
  7320. InscpScpAmt float64 `json:"inscp_scp_amt"`
  7321. ActPayDedc float64 `json:"act_pay_dedc"`
  7322. HifpPay float64 `json:"hifp_pay"`
  7323. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  7324. CvlservPay float64 `json:"cvlserv_pay"`
  7325. HifesPay float64 `json:"hifes_pay"`
  7326. HifmiPay float64 `json:"hifmi_pay"`
  7327. MafPay float64 `json:"maf_pay"`
  7328. OthPay float64 `json:"oth_pay"`
  7329. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  7330. PsnPay float64 `json:"psn_pay"`
  7331. AcctPay float64 `json:"acct_pay"`
  7332. CashPayamt float64 `json:"cash_payamt"`
  7333. Balc float64 `json:"balc"`
  7334. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  7335. MedinsSetlId string `json:"medins_setl_id"`
  7336. RefdSetlFlag string `json:"refd_setl_flag"`
  7337. SetlTime string `json:"setl_time"`
  7338. MedType string `json:"med_type"`
  7339. } `json:"setlinfo"`
  7340. } `json:"output"`
  7341. RefmsgTime string `json:"refmsg_time"`
  7342. RespondTime string `json:"respond_time"`
  7343. Signtype interface{} `json:"signtype"`
  7344. WarnMsg interface{} `json:"warn_msg"`
  7345. }
  7346. type Custom struct {
  7347. DetItemFeeSumamt string
  7348. Cut string
  7349. FeedetlSn string
  7350. Price string
  7351. MedListCodg string
  7352. Type int64
  7353. AdviceId int64
  7354. ProjectId int64
  7355. ItemId int64
  7356. }
  7357. // 获取个人信息----挂号-----上传就诊信息
  7358. func (c *HisApiController) GetRegisterInfo() {
  7359. id, _ := c.GetInt64("id")
  7360. record_time := c.GetString("record_time")
  7361. settlementValue, _ := c.GetInt64("settlement_value")
  7362. medical_insurance_card := c.GetString("medical_insurance_card")
  7363. name := c.GetString("name")
  7364. id_card_type, _ := c.GetInt64("id_card_type")
  7365. certificates, _ := c.GetInt64("certificates")
  7366. medical_care, _ := c.GetInt64("medical_care")
  7367. birthday := c.GetString("birthday")
  7368. age, _ := c.GetInt64("age")
  7369. id_card := c.GetString("id_card")
  7370. register_type, _ := c.GetInt64("register")
  7371. doctor, _ := c.GetInt64("doctor")
  7372. department, _ := c.GetInt64("department")
  7373. gender, _ := c.GetInt64("sex")
  7374. phone := c.GetString("phone")
  7375. registration_fee, _ := c.GetFloat("registration_fee")
  7376. medical_expenses, _ := c.GetFloat("medical_expenses")
  7377. social_type, _ := c.GetInt64("social_type")
  7378. //diagnosis_id, _ := c.GetInt64("diagnosis")
  7379. diagnosis_ids := c.GetString("diagnosis")
  7380. sick_type, _ := c.GetInt64("sick_type")
  7381. reg_type := c.GetString("p_type")
  7382. timeLayout := "2006-01-02"
  7383. loc, _ := time.LoadLocation("Local")
  7384. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  7385. birthUnix := birthdays.Unix()
  7386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7387. if err != nil {
  7388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7389. return
  7390. }
  7391. recordDateTime := theTime.Unix()
  7392. adminInfo := c.GetAdminUserInfo()
  7393. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  7394. if tempPatient.ID == 0 {
  7395. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  7396. return
  7397. }
  7398. var patient service.Patients
  7399. if id == 0 {
  7400. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  7401. } else {
  7402. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  7403. }
  7404. if patient.ID == 0 {
  7405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  7406. return
  7407. }
  7408. if len(patient.IdCardNo) == 0 {
  7409. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  7410. return
  7411. }
  7412. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7413. if len(his) >= 1 {
  7414. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  7415. if len(his) >= 1 && order.ID == 0 {
  7416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  7417. return
  7418. }
  7419. }
  7420. timeStr := time.Now().Format("2006-01-02 15:04:05")
  7421. fmt.Println(timeStr)
  7422. timeArr := strings.Split(timeStr, " ")
  7423. fmt.Println(timeArr)
  7424. timeArrTwo := strings.Split(timeArr[0], "-")
  7425. timeArrThree := strings.Split(timeArr[1], ":")
  7426. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  7427. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  7428. if len(lists) == 0 {
  7429. var hisPatient models.XtHisPatient
  7430. hisPatient = models.XtHisPatient{
  7431. Name: name,
  7432. Age: age,
  7433. Gender: gender,
  7434. Birthday: birthUnix,
  7435. Phone: phone,
  7436. MedicalTreatmentType: medical_care,
  7437. IdType: certificates,
  7438. IdCardNo: id_card,
  7439. BalanceAccountsType: settlementValue,
  7440. SocialType: social_type,
  7441. MedicalInsuranceNumber: medical_insurance_card,
  7442. RegisterType: register_type,
  7443. RegisterCost: registration_fee,
  7444. TreatmentCost: medical_expenses,
  7445. AdminUserId: adminInfo.AdminUser.Id,
  7446. UserOrgId: adminInfo.CurrentOrgId,
  7447. Status: 1,
  7448. RecordDate: recordDateTime,
  7449. IsReturn: 1,
  7450. PatientId: patient.ID,
  7451. Ctime: time.Now().Unix(),
  7452. Mtime: time.Now().Unix(),
  7453. Number: str,
  7454. IdCardType: id_card_type,
  7455. Departments: department,
  7456. Doctor: doctor,
  7457. PType: reg_type,
  7458. Diagnosis: diagnosis_ids,
  7459. SickType: sick_type,
  7460. }
  7461. service.CreateHisPatient(&hisPatient)
  7462. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7463. c.ServeSuccessJSON(map[string]interface{}{
  7464. "his_info": hisPatient,
  7465. })
  7466. } else {
  7467. //chrgBchno := rand.Intn(1000000) + 10000
  7468. var hisPatient models.XtHisPatient
  7469. hisPatient = models.XtHisPatient{
  7470. Name: name,
  7471. Age: age,
  7472. Gender: gender,
  7473. Birthday: birthUnix,
  7474. Phone: phone,
  7475. MedicalTreatmentType: medical_care,
  7476. IdType: certificates,
  7477. IdCardNo: id_card,
  7478. BalanceAccountsType: settlementValue,
  7479. SocialType: social_type,
  7480. MedicalInsuranceNumber: medical_insurance_card,
  7481. RegisterType: register_type,
  7482. RegisterCost: registration_fee,
  7483. TreatmentCost: medical_expenses,
  7484. AdminUserId: adminInfo.AdminUser.Id,
  7485. UserOrgId: adminInfo.CurrentOrgId,
  7486. Status: 1,
  7487. RecordDate: recordDateTime,
  7488. IsReturn: 1,
  7489. PatientId: patient.ID,
  7490. Ctime: time.Now().Unix(),
  7491. Mtime: time.Now().Unix(),
  7492. Number: str,
  7493. IdCardType: id_card_type,
  7494. Departments: department,
  7495. Doctor: doctor,
  7496. PType: reg_type,
  7497. Diagnosis: diagnosis_ids,
  7498. SickType: sick_type,
  7499. }
  7500. service.CreateHisPatient(&hisPatient)
  7501. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  7502. c.ServeSuccessJSON(map[string]interface{}{
  7503. "his_info": hisPatient,
  7504. })
  7505. }
  7506. }
  7507. // 上传明细----结算
  7508. func (c *HisApiController) GetUploadInfo() {
  7509. id, _ := c.GetInt64("id")
  7510. record_time := c.GetString("record_time")
  7511. his_patient_id, _ := c.GetInt64("his_patient_id")
  7512. oth_desc := c.GetString("oth_desc")
  7513. pay_way, _ := c.GetInt64("pay_way")
  7514. pay_ways := c.GetString("pay_ways")
  7515. pay_price, _ := c.GetFloat("pay_price")
  7516. pay_card_no := c.GetString("pay_card_no")
  7517. discount_price, _ := c.GetFloat("discount_price")
  7518. preferential_price, _ := c.GetFloat("preferential_price")
  7519. reality_price, _ := c.GetFloat("reality_price")
  7520. found_price, _ := c.GetFloat("found_price")
  7521. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  7522. private_price, _ := c.GetFloat("private_price")
  7523. timeLayout := "2006-01-02"
  7524. loc, _ := time.LoadLocation("Local")
  7525. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  7526. fapiao_code := c.GetString("fapiao_code")
  7527. fapiao_number := c.GetString("fapiao_number")
  7528. diagnosis_id := c.GetString("diagnosis")
  7529. sick_type, _ := c.GetInt64("sick_type")
  7530. reg_type, _ := c.GetInt64("p_type")
  7531. order_id, _ := c.GetInt64("order_id")
  7532. cash_pay := c.GetString("cash_pay")
  7533. wechat_pay := c.GetString("wechat_pay")
  7534. ali_pay := c.GetString("ali_pay")
  7535. jifen_pay := c.GetString("jifen_pay")
  7536. band_card_pay := c.GetString("band_card_pay")
  7537. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  7538. tmp_decimal := c.GetString("tmp_decimal")
  7539. //last_order, _ := service.GetLastHisOrderThree(c.GetAdminUserInfo().CurrentOrgId)
  7540. var decimal float64 //本次使用的押金
  7541. var errmsg error
  7542. tx := service.XTWriteDB().Begin() //开了事务
  7543. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  7544. defer func() {
  7545. if errmsg != nil {
  7546. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  7547. tx.Rollback()
  7548. } else {
  7549. tx.Commit()
  7550. }
  7551. }()
  7552. fmt.Println("dec_way", dec_way)
  7553. if (dec_way == "true" && tmp_decimal == "0") || (dec_way == "true" && tmp_decimal == "") {
  7554. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  7555. return
  7556. }
  7557. if len(tmp_decimal) > 0 {
  7558. if tmp_decimal[0] == 45 {
  7559. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  7560. return
  7561. }
  7562. }
  7563. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  7564. fmt.Println(errs)
  7565. decimal = tt
  7566. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  7567. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  7568. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  7569. if err != nil {
  7570. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7571. return
  7572. }
  7573. recordDateTime := theTime.Unix()
  7574. adminUser := c.GetAdminUserInfo()
  7575. var prescriptions []*models.HisPrescription
  7576. var prescriptionsOne []*models.HisPrescription
  7577. var start_time int64
  7578. var end_time int64
  7579. ids_str := c.GetString("ids")
  7580. ids_arr := strings.Split(ids_str, ",")
  7581. if tempOrder.ID == 0 {
  7582. if settle_accounts_type == 1 { //日结
  7583. fmt.Println(reg_type)
  7584. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  7585. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  7586. prescriptionsOne, _ = service.GetPrescriptionByIdsTxOne(ids_arr, adminUser.CurrentOrgId, tx)
  7587. } else {
  7588. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7589. prescriptionsOne, _ = service.GetSettleHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7590. }
  7591. } else { //月结
  7592. start_time_str := c.GetString("start_time")
  7593. end_time_str := c.GetString("end_time")
  7594. timeLayout := "2006-01-02"
  7595. loc, _ := time.LoadLocation("Local")
  7596. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  7597. if err != nil {
  7598. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7599. return
  7600. }
  7601. recordStartTime := theStartTime.Unix()
  7602. start_time = recordStartTime
  7603. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  7604. if err != nil {
  7605. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7606. return
  7607. }
  7608. recordEndTime := theEndTime.Unix()
  7609. end_time = recordEndTime
  7610. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  7611. prescriptionsOne, _ = service.GetMonthHisPrescriptionTXOne(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  7612. }
  7613. var goods []*models.DialysisBeforePrepareGoods
  7614. var newGoods []*models.NewDialysisBeforePrepareGoods
  7615. var oldGoods []*models.OldDialysisBeforePrepareGoods
  7616. var infos []*models.HisDoctorAdviceInfo
  7617. var infoList []*models.HisDoctorAdviceInfo
  7618. var hisAdvice []*models.HisDoctorAdviceInfo
  7619. var newGoodOne []*models.NewDialysisBeforePrepareGoods
  7620. houseConfig, _ := service.GetAllStoreHouseConfig(adminUser.CurrentOrgId)
  7621. //判断库存不足
  7622. //结算出库开关
  7623. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  7624. if settConfig.IsOpen == 1 {
  7625. //判断库存的地方
  7626. for _, info := range prescriptions {
  7627. if info.Type == 1 {
  7628. infos = append(infos, info.HisDoctorAdviceInfo...)
  7629. }
  7630. if info.Type == 2 {
  7631. for _, sumItem := range info.HisPrescriptionProject {
  7632. if sumItem.Type == 3 {
  7633. var good models.DialysisBeforePrepareGoods
  7634. var newGood models.NewDialysisBeforePrepareGoods
  7635. good.GoodId = sumItem.GoodInfo.ID
  7636. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7637. count, _ := strconv.Atoi(sumItem.Count)
  7638. good.Count = int64(count)
  7639. good.StorehouseId = houseConfig.StorehouseOutInfo
  7640. good.ProjectId = sumItem.ID
  7641. goods = append(goods, &good)
  7642. newGood.GoodId = sumItem.GoodInfo.ID
  7643. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7644. count2, _ := strconv.Atoi(sumItem.Count)
  7645. newGood.Count = int64(count2)
  7646. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7647. newGood.ProjectId = sumItem.ID
  7648. newGoods = append(newGoods, &newGood)
  7649. }
  7650. }
  7651. }
  7652. }
  7653. for _, info := range prescriptionsOne {
  7654. if info.Type == 1 {
  7655. hisAdvice = append(hisAdvice, info.HisDoctorAdviceInfo...)
  7656. }
  7657. if info.Type == 2 {
  7658. for _, sumItem := range info.HisPrescriptionProject {
  7659. if sumItem.Type == 3 {
  7660. var newGood models.NewDialysisBeforePrepareGoods
  7661. newGood.GoodId = sumItem.GoodInfo.ID
  7662. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7663. count2, _ := strconv.Atoi(sumItem.Count)
  7664. newGood.Count = int64(count2)
  7665. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7666. newGood.ProjectId = sumItem.ID
  7667. newGoodOne = append(newGoodOne, &newGood)
  7668. }
  7669. }
  7670. }
  7671. }
  7672. //判断
  7673. for _, itemOne := range infos {
  7674. for _, itemTwo := range hisAdvice {
  7675. if itemOne.DrugId == itemTwo.DrugId {
  7676. itemTwo.Child = append(itemTwo.Child, itemOne)
  7677. }
  7678. }
  7679. }
  7680. for _, itemTwo := range hisAdvice {
  7681. medical, _ := service.GetBaseDrugMedical(itemTwo.DrugId)
  7682. var sum_out_count int64
  7683. for _, itemThree := range itemTwo.Child {
  7684. var prescribing_number int64
  7685. stringPrescribingNumber := strconv.FormatFloat(itemThree.PrescribingNumber, 'f', -1, 64)
  7686. parseIntPrescribingNumber, _ := strconv.ParseInt(stringPrescribingNumber, 10, 64)
  7687. if itemThree.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  7688. prescribing_number = parseIntPrescribingNumber * medical.MinNumber
  7689. }
  7690. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  7691. prescribing_number = parseIntPrescribingNumber
  7692. }
  7693. if itemThree.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit == medical.MinUnit {
  7694. prescribing_number = parseIntPrescribingNumber
  7695. }
  7696. sum_out_count += prescribing_number
  7697. }
  7698. drugStockOut, _ := service.GetDrugSumOutCountByDrugId(itemTwo.DrugId, adminUser.CurrentOrgId, houseConfig.DrugStorehouseOut)
  7699. if sum_out_count > drugStockOut.FlushCount {
  7700. c.ServeSuccessJSON(map[string]interface{}{
  7701. "msg": "2",
  7702. "drug": medical,
  7703. })
  7704. return
  7705. }
  7706. }
  7707. for _, itemOne := range newGoods {
  7708. for _, item := range newGoodOne {
  7709. if itemOne.GoodId == item.GoodId {
  7710. item.ChildNewDialysisBeforePrepareGoods = append(item.ChildNewDialysisBeforePrepareGoods, itemOne)
  7711. }
  7712. }
  7713. }
  7714. for _, item := range newGoodOne {
  7715. var sum_out_count_one int64
  7716. good, _ := service.GetGoodInformationByGoodIdOne(item.GoodId)
  7717. for _, itemOne := range item.ChildNewDialysisBeforePrepareGoods {
  7718. sum_out_count_one += itemOne.Count
  7719. }
  7720. list, _ := service.GetStockGoodList(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  7721. fmt.Println("sum_out_count_one", sum_out_count_one)
  7722. fmt.Println("list.FlushCount", list.FlushCount)
  7723. if sum_out_count_one > list.FlushCount {
  7724. c.ServeSuccessJSON(map[string]interface{}{
  7725. "msg": "3",
  7726. "good": good,
  7727. })
  7728. return
  7729. }
  7730. }
  7731. }
  7732. timestamp := time.Now().Unix()
  7733. tempTime := time.Unix(timestamp, 0)
  7734. timeFormat := tempTime.Format("20060102150405")
  7735. chrgBchno := rand.Intn(100000) + 10000
  7736. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  7737. strconv.FormatInt(his.PatientId, 10)
  7738. var ids []int64
  7739. for _, item := range prescriptions {
  7740. ids = append(ids, item.ID)
  7741. }
  7742. var total float64
  7743. for _, item := range prescriptions {
  7744. fmt.Println(item)
  7745. if item.Type == 1 { //药品
  7746. for _, subItem := range item.HisDoctorAdviceInfo {
  7747. total = total + (subItem.Price * subItem.PrescribingNumber)
  7748. }
  7749. }
  7750. if item.Type == 2 { //项目
  7751. for _, subItem := range item.HisPrescriptionProject {
  7752. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7753. total = total + (subItem.Price * cnt)
  7754. }
  7755. }
  7756. for _, subItem := range item.HisAdditionalCharge {
  7757. total = total + (subItem.Price * float64(subItem.Count))
  7758. }
  7759. }
  7760. if reg_type == 1111 || reg_type == 1112 {
  7761. reg_type = 11
  7762. }
  7763. tm := time.Unix(time.Now().Unix(), 0)
  7764. allTotal := fmt.Sprintf("%.4f", total)
  7765. totals, _ := strconv.ParseFloat(allTotal, 64)
  7766. order := &models.HisOrder{
  7767. UserOrgId: adminUser.CurrentOrgId,
  7768. HisPatientId: his.ID,
  7769. PatientId: id,
  7770. SettleAccountsDate: recordDateTime,
  7771. Ctime: time.Now().Unix(),
  7772. Mtime: time.Now().Unix(),
  7773. Status: 1,
  7774. OrderStatus: 2,
  7775. MdtrtId: his.Number,
  7776. Number: chrg_bchno,
  7777. MedfeeSumamt: totals,
  7778. PayWay: pay_way,
  7779. PayWays: pay_ways,
  7780. PayPrice: pay_price,
  7781. MedType: strconv.Itoa(int(reg_type)),
  7782. PayCardNo: pay_card_no,
  7783. DiscountPrice: discount_price,
  7784. PreferentialPrice: preferential_price,
  7785. RealityPrice: reality_price,
  7786. FoundPrice: found_price,
  7787. MedicalInsurancePrice: medical_insurance_price,
  7788. PrivatePrice: private_price,
  7789. SettleEndTime: end_time,
  7790. SettleStartTime: start_time,
  7791. PsnPartAmt: totals,
  7792. PsnCashPay: totals,
  7793. SettleType: settle_accounts_type,
  7794. FaPiaoCode: fapiao_code,
  7795. FaPiaoNumber: fapiao_number,
  7796. Diagnosis: diagnosis_id,
  7797. PType: 2,
  7798. SetlTime: tm.Format("2006-01-02 15:04:05"),
  7799. Decimal: decimal,
  7800. OthDesc: oth_desc,
  7801. CashPay: cash_pay,
  7802. WechatPay: wechat_pay,
  7803. AliPay: ali_pay,
  7804. JifenPay: jifen_pay,
  7805. BandCardPay: band_card_pay,
  7806. Creator: adminUser.AdminUser.Id,
  7807. }
  7808. err = service.CreateOrderTX(order, tx)
  7809. if err != nil {
  7810. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7811. return
  7812. }
  7813. var customs []*Custom
  7814. for _, item := range prescriptions {
  7815. if item.Type == 1 { //药品a
  7816. for _, subItem := range item.HisDoctorAdviceInfo {
  7817. cus := &Custom{
  7818. AdviceId: subItem.ID,
  7819. ProjectId: 0,
  7820. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  7821. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  7822. FeedetlSn: subItem.FeedetlSn,
  7823. Price: fmt.Sprintf("%.4f", subItem.Price),
  7824. MedListCodg: subItem.MedListCodg,
  7825. Type: 1,
  7826. }
  7827. customs = append(customs, cus)
  7828. }
  7829. }
  7830. if item.Type == 2 { //项目
  7831. for _, subItem := range item.HisPrescriptionProject {
  7832. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  7833. cus := &Custom{
  7834. AdviceId: 0,
  7835. ProjectId: subItem.ID,
  7836. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  7837. Cut: fmt.Sprintf("%.4f", cnt),
  7838. FeedetlSn: subItem.FeedetlSn,
  7839. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  7840. MedListCodg: subItem.MedListCodg,
  7841. Type: 2,
  7842. }
  7843. customs = append(customs, cus)
  7844. }
  7845. }
  7846. for _, item := range item.HisAdditionalCharge {
  7847. cus := &Custom{
  7848. ItemId: item.ID,
  7849. AdviceId: 0,
  7850. ProjectId: 0,
  7851. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  7852. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  7853. FeedetlSn: item.FeedetlSn,
  7854. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  7855. MedListCodg: item.XtHisAddtionConfig.Code,
  7856. Type: 3,
  7857. }
  7858. customs = append(customs, cus)
  7859. }
  7860. }
  7861. for _, item := range customs {
  7862. var advice_id int64 = 0
  7863. var project_id int64 = 0
  7864. var item_id int64 = 0
  7865. var types int64 = 0
  7866. if item.Type == 1 {
  7867. advice_id = item.AdviceId
  7868. project_id = 0
  7869. item_id = 0
  7870. } else if item.Type == 2 {
  7871. advice_id = 0
  7872. item_id = 0
  7873. project_id = item.ProjectId
  7874. } else if item.Type == 3 {
  7875. advice_id = 0
  7876. item_id = item.ItemId
  7877. project_id = 0
  7878. }
  7879. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  7880. cut, _ := strconv.ParseFloat(item.Cut, 32)
  7881. pric, _ := strconv.ParseFloat(item.Price, 32)
  7882. info := &models.HisOrderInfo{
  7883. OrderNumber: order.Number,
  7884. UploadDate: time.Now().Unix(),
  7885. AdviceId: advice_id,
  7886. DetItemFeeSumamt: detItemFeeSumamt,
  7887. Cnt: cut,
  7888. Pric: pric,
  7889. PatientId: id,
  7890. Status: 1,
  7891. Mtime: time.Now().Unix(),
  7892. Ctime: time.Now().Unix(),
  7893. UserOrgId: adminUser.CurrentOrgId,
  7894. HisPatientId: his.ID,
  7895. OrderId: order.ID,
  7896. ProjectId: project_id,
  7897. Type: types,
  7898. ItemId: item_id,
  7899. }
  7900. service.CreateOrderInfoTX(info, tx)
  7901. }
  7902. his.Diagnosis = diagnosis_id
  7903. his.SickType = sick_type
  7904. his.RegisterType = reg_type
  7905. his.MedicalTreatmentType = reg_type
  7906. service.UpdataHisPateintTX(&his, tx)
  7907. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  7908. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  7909. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  7910. //判断是否使用了押金
  7911. if dec_way == "true" {
  7912. tmpstring := strconv.FormatInt(order.ID, 10)
  7913. //扣押金
  7914. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  7915. order.Decimal = decimal
  7916. service.UpDateOrderTwo(order, tx)
  7917. if errmsg != nil {
  7918. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  7919. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  7920. return
  7921. }
  7922. }
  7923. if err == nil {
  7924. for _, info := range prescriptions {
  7925. if info.Type == 1 {
  7926. infoList = append(infoList, info.HisDoctorAdviceInfo...)
  7927. }
  7928. if info.Type == 2 {
  7929. for _, sumItem := range info.HisPrescriptionProject {
  7930. if sumItem.Type == 3 {
  7931. var good models.DialysisBeforePrepareGoods
  7932. var newGood models.NewDialysisBeforePrepareGoods
  7933. var oldGood models.OldDialysisBeforePrepareGoods
  7934. good.GoodId = sumItem.GoodInfo.ID
  7935. good.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7936. count, _ := strconv.Atoi(sumItem.Count)
  7937. good.Count = int64(count)
  7938. good.StorehouseId = houseConfig.StorehouseOutInfo
  7939. good.ProjectId = sumItem.ID
  7940. good.PatientId = sumItem.PatientId
  7941. goods = append(goods, &good)
  7942. newGood.GoodId = sumItem.GoodInfo.ID
  7943. newGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7944. count2, _ := strconv.Atoi(sumItem.Count)
  7945. newGood.Count = int64(count2)
  7946. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  7947. newGood.ProjectId = sumItem.ID
  7948. newGood.PatientId = sumItem.HisPatientId
  7949. newGoods = append(newGoods, &newGood)
  7950. oldGood.GoodId = sumItem.GoodInfo.ID
  7951. oldGood.GoodTypeId = sumItem.GoodInfo.GoodTypeId
  7952. count3, _ := strconv.Atoi(sumItem.Count)
  7953. oldGood.Count = int64(count3)
  7954. oldGood.StorehouseId = houseConfig.StorehouseOutInfo
  7955. oldGood.ProjectId = sumItem.ID
  7956. oldGood.RecordDate = sumItem.RecordDate
  7957. oldGood.PatientId = sumItem.HisPatientId
  7958. oldGoods = append(oldGoods, &oldGood)
  7959. }
  7960. }
  7961. }
  7962. }
  7963. if settConfig.IsOpen == 1 {
  7964. for _, item := range infoList {
  7965. medical, _ := service.GetBaseDrugMedical(item.DrugId)
  7966. if medical.IsUse == 2 {
  7967. //药品出库
  7968. service.HisSettleDrugsDelivery(item.UserOrgId, adminUser.AdminUser.Id, item, order.ID)
  7969. //查询默认仓库
  7970. storeHouseConfig, _ := service.GetAllStoreHouseConfig(item.UserOrgId)
  7971. //查询默认仓库剩余多少库存
  7972. var sum_count int64
  7973. stockInfo, _ := service.GetDrugAllStockInfo(storeHouseConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  7974. for _, its := range stockInfo {
  7975. if its.MaxUnit == medical.MaxUnit {
  7976. its.StockMaxNumber = its.StockMaxNumber * medical.MinNumber
  7977. }
  7978. sum_count += its.StockMaxNumber + its.StockMinNumber
  7979. }
  7980. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  7981. service.UpdateDrugStockCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut, sum_count)
  7982. over, _ := service.FindOverCount(item.DrugId, item.UserOrgId, storeHouseConfig.DrugStorehouseOut)
  7983. service.UpdateActOut(over.ID, over.SumInCount, over.FlushCount, over.SumCancelCount)
  7984. }
  7985. }
  7986. orgId := c.GetAdminUserInfo().CurrentOrgId
  7987. if len(oldGoods) > 0 {
  7988. timeStr := time.Now().Format("2006-01-02")
  7989. timeArr := strings.Split(timeStr, "-")
  7990. total, _ := service.FindAllWarehouseOut(orgId)
  7991. total = total + 1
  7992. warehousing_out_order := strconv.FormatInt(orgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  7993. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  7994. number = number + total
  7995. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  7996. operation_time := time.Now().Unix()
  7997. creater := c.GetAdminUserInfo().AdminUser.Id
  7998. //查询默认出库仓库库存
  7999. storeConfig, _ := service.GetAllStoreHouseConfig(orgId)
  8000. recordDateStr := time.Now().Format("2006-01-02")
  8001. recordDate, _ := utils.ParseTimeStringToTime("2006-01-02", recordDateStr)
  8002. nowtime := recordDate.Unix()
  8003. warehouseOut := models.WarehouseOut{
  8004. WarehouseOutOrderNumber: warehousing_out_order,
  8005. OperationTime: operation_time,
  8006. OrgId: orgId,
  8007. Creater: creater,
  8008. Ctime: time.Now().Unix(),
  8009. Status: 1,
  8010. WarehouseOutTime: nowtime,
  8011. Type: 1,
  8012. StorehouseId: storeConfig.StorehouseOutInfo,
  8013. IsCheck: 1,
  8014. OrderId: order.ID,
  8015. IsSys: 5,
  8016. }
  8017. //查询是否生成出库单
  8018. out, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8019. if out.ID == 0 {
  8020. service.AddSigleWarehouseOut(&warehouseOut)
  8021. }
  8022. lastOut, _ := service.FindAllSettleWarehouseOut(orgId, nowtime, 5)
  8023. for _, item := range oldGoods {
  8024. dialyPrepareOne := models.DialysisBeforePrepare{
  8025. GoodTypeId: item.GoodTypeId,
  8026. GoodId: item.GoodId,
  8027. PatientId: his.PatientId,
  8028. RecordDate: item.RecordDate,
  8029. UserOrgId: adminUser.CurrentOrgId,
  8030. Count: item.Count,
  8031. Ctime: time.Now().Unix(),
  8032. Creater: adminUser.AdminUser.Id,
  8033. CommdityCode: item.CommdityCode,
  8034. Status: 1,
  8035. StorehouseId: houseConfig.StorehouseOutInfo,
  8036. }
  8037. goodInfo, _ := service.GetGoodInformationByGoodIdThirty(item.GoodId)
  8038. //非零用
  8039. if goodInfo.IsUser == 2 || goodInfo.IsUser == 0 {
  8040. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8041. //查询剩余库存
  8042. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8043. var sum_count int64
  8044. for _, item := range goodList {
  8045. sum_count += item.StockCount
  8046. }
  8047. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8048. //耗材
  8049. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8050. }
  8051. if goodInfo.IsUser == 1 && goodInfo.IsWarehouse == 1 {
  8052. service.ConsumableSettleDelivery(adminUser.CurrentOrgId, his.PatientId, his.RecordDate, &dialyPrepareOne, &lastOut, adminUser.AdminUser.Id, order.ID)
  8053. //查询剩余库存
  8054. goodList, _ := service.GetAllGoodSumCount(item.GoodId, adminUser.CurrentOrgId, houseConfig.StorehouseOutInfo)
  8055. var sum_count int64
  8056. for _, item := range goodList {
  8057. sum_count += item.StockCount
  8058. }
  8059. service.UpdateGoodFlushCount(houseConfig.StorehouseOutInfo, item.GoodId, adminUser.CurrentOrgId, sum_count)
  8060. //耗材
  8061. service.UpdateGoodSumCountSeven(sum_count, item.GoodId, adminUser.CurrentOrgId)
  8062. }
  8063. }
  8064. }
  8065. }
  8066. c.ServeSuccessJSON(map[string]interface{}{
  8067. "msg": "结算成功",
  8068. })
  8069. }
  8070. }
  8071. }
  8072. // 退款
  8073. func (c *HisApiController) Refund() {
  8074. order_id, _ := c.GetInt64("order_id")
  8075. order, _ := service.GetHisOrderByID(order_id)
  8076. adminUser := c.GetAdminUserInfo()
  8077. orgid := c.GetAdminUserInfo().CurrentOrgId
  8078. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  8079. if err != nil {
  8080. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8081. return
  8082. }
  8083. tmp := strconv.FormatInt(order.ID, 10)
  8084. //当押金不为零时产生退费记录
  8085. if order.Decimal != 0 {
  8086. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  8087. if err != nil {
  8088. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8089. return
  8090. }
  8091. }
  8092. orders, _ := service.GetHisOrderDetailByNumberThree(order.Number, order.UserOrgId)
  8093. houseConfig, _ := service.GetAllStoreHouseConfig(order.UserOrgId)
  8094. var goods []*models.DialysisBeforePrepareGoods
  8095. var newGoods []*models.NewDialysisBeforePrepareGoods
  8096. var infos []*models.HisDoctorAdviceInfo
  8097. for _, info := range orders {
  8098. if info.AdviceId > 0 && info.ProjectId == 0 {
  8099. infos = append(infos, &info.HisDoctorAdviceInfo)
  8100. }
  8101. if info.ProjectId > 0 && info.AdviceId == 0 {
  8102. if info.HisPrescriptionProject.Type == 3 {
  8103. var good models.DialysisBeforePrepareGoods
  8104. var newGood models.NewDialysisBeforePrepareGoods
  8105. good.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8106. good.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8107. count, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8108. good.Count = int64(count)
  8109. good.StorehouseId = houseConfig.StorehouseOutInfo
  8110. good.ProjectId = info.HisPrescriptionProject.ID
  8111. good.PatientId = info.PatientId
  8112. good.OrderId = order_id
  8113. goods = append(goods, &good)
  8114. newGood.GoodId = info.HisPrescriptionProject.VMGoodInfo.ID
  8115. newGood.GoodTypeId = info.HisPrescriptionProject.VMGoodInfo.GoodTypeId
  8116. count2, _ := strconv.Atoi(info.HisPrescriptionProject.Count)
  8117. newGood.Count = int64(count2)
  8118. newGood.StorehouseId = houseConfig.StorehouseOutInfo
  8119. newGood.ProjectId = info.HisPrescriptionProject.ID
  8120. newGood.RecordDate = order.SettleAccountsDate
  8121. newGood.UserOrgId = order.UserOrgId
  8122. newGood.PatientId = info.PatientId
  8123. newGood.OrderId = order_id
  8124. newGoods = append(newGoods, &newGood)
  8125. }
  8126. }
  8127. }
  8128. settConfig, _ := service.GetSettleOpenConfigByOrgId(adminUser.CurrentOrgId)
  8129. if settConfig.IsOpen == 1 {
  8130. for _, item := range infos {
  8131. service.DrugAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8132. }
  8133. for _, item := range newGoods {
  8134. service.GoodAutoAddCancelInfo(item, adminUser.AdminUser.Id)
  8135. }
  8136. }
  8137. c.ServeSuccessJSON(map[string]interface{}{
  8138. "msg": "退费成功",
  8139. })
  8140. }
  8141. func (c *HisApiController) RefundNumber() {
  8142. his_patient_id, _ := c.GetInt64("id")
  8143. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8144. info.Status = 0
  8145. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  8146. if count > 0 {
  8147. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  8148. return
  8149. }
  8150. err := service.SaveHisPatient(info)
  8151. if err == nil {
  8152. c.ServeSuccessJSON(map[string]interface{}{
  8153. "msg": "退号成功",
  8154. })
  8155. } else {
  8156. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  8157. return
  8158. }
  8159. }
  8160. func (this *HisApiController) AdditionalCharge() {
  8161. dataBody := make(map[string]interface{}, 0)
  8162. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  8163. fmt.Println(err)
  8164. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  8165. patient_id := int64(dataBody["patient_id"].(float64))
  8166. medicineData, _ := dataBody["medicineData"].([]interface{})
  8167. adminUserInfo := this.GetAdminUserInfo()
  8168. orgId := adminUserInfo.CurrentOrgId
  8169. admin_user_id := adminUserInfo.AdminUser.Id
  8170. timeStr := time.Now().Format("2006-01-02")
  8171. timeLayout := "2006-01-02 15:04:05"
  8172. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  8173. timenow := timeStringToTime.Unix()
  8174. var additionalCharges []*models.HisAdditionalCharge
  8175. for _, item := range medicineData {
  8176. var randNum int
  8177. randNum = rand.Intn(10000) + 1000
  8178. timestamp := time.Now().Unix()
  8179. tempTime := time.Unix(timestamp, 0)
  8180. timeFormat := tempTime.Format("20060102150405")
  8181. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  8182. items := item.(map[string]interface{})
  8183. money := items["price"].(string)
  8184. item_id_str := items["item_id"].(string)
  8185. name := items["name"].(string)
  8186. id_str := items["id"].(string)
  8187. moneys, _ := strconv.ParseInt(money, 10, 64)
  8188. monStr := strconv.FormatInt(moneys, 10)
  8189. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  8190. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  8191. id, _ := strconv.ParseInt(id_str, 10, 64)
  8192. additionalCharge := &models.HisAdditionalCharge{
  8193. ID: id,
  8194. HisPatientId: his_patient_id,
  8195. UserOrgId: orgId,
  8196. PatientId: patient_id,
  8197. RecordDate: timenow,
  8198. Price: monneyStr,
  8199. Status: 1,
  8200. ItemName: name,
  8201. ItemId: item_id,
  8202. AdminUserId: admin_user_id,
  8203. CreatedTime: time.Now().Unix(),
  8204. OrderStatus: 0,
  8205. PrescriptionNumber: "",
  8206. BatchNumber: "",
  8207. FeedetlSn: p_number,
  8208. }
  8209. service.CreateAdditionalCharge(additionalCharge)
  8210. additionalCharges = append(additionalCharges, additionalCharge)
  8211. }
  8212. this.ServeSuccessJSON(map[string]interface{}{
  8213. "msg": "添加成功",
  8214. "additional_charges": additionalCharges,
  8215. })
  8216. }
  8217. func (this *HisApiController) DeleteAddition() {
  8218. id, _ := this.GetInt64("id")
  8219. //TODO 需要判断是否已经结算
  8220. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  8221. if err == nil {
  8222. this.ServeSuccessJSON(map[string]interface{}{
  8223. "msg": "删除成功",
  8224. })
  8225. return
  8226. } else {
  8227. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8228. return
  8229. }
  8230. }
  8231. func (this *HisApiController) GetAdminUsers() {
  8232. adminUser := this.GetAdminUserInfo()
  8233. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  8234. this.ServeSuccessJSON(map[string]interface{}{
  8235. "doctors": doctors,
  8236. })
  8237. }
  8238. func (this *HisApiController) GetLastOrNextHisPrescription() {
  8239. change_type, _ := this.GetInt64("type", 0)
  8240. record_date := this.GetString("record_time")
  8241. patient_id, _ := this.GetInt64("patient_id", 0)
  8242. p_type, _ := this.GetInt64("p_type", 0)
  8243. timeLayout := "2006-01-02"
  8244. loc, _ := time.LoadLocation("Local")
  8245. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  8246. record_time := theAdviceRecordTime.Unix()
  8247. adminUserInfo := this.GetAdminUserInfo()
  8248. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  8249. if err == nil {
  8250. if len(prescriptions) == 0 {
  8251. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  8252. return
  8253. } else {
  8254. this.ServeSuccessJSON(map[string]interface{}{
  8255. "prescriptions": prescriptions,
  8256. })
  8257. return
  8258. }
  8259. } else {
  8260. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8261. return
  8262. }
  8263. }
  8264. func (this *HisApiController) GetCallHisPrescription() {
  8265. patient_id, _ := this.GetInt64("patient_id", 0)
  8266. timeLayout := "2006-01-02"
  8267. loc, _ := time.LoadLocation("Local")
  8268. start_time := this.GetString("start_time")
  8269. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8270. end_time := this.GetString("end_time")
  8271. p_type, _ := this.GetInt64("p_type")
  8272. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8273. adminUserInfo := this.GetAdminUserInfo()
  8274. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  8275. if err == nil {
  8276. this.ServeSuccessJSON(map[string]interface{}{
  8277. "prescriptions": prescriptions,
  8278. })
  8279. return
  8280. } else {
  8281. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8282. return
  8283. }
  8284. }
  8285. func (this *HisApiController) GetHisDayPrescription() {
  8286. timeLayout := "2006-01-02"
  8287. loc, _ := time.LoadLocation("Local")
  8288. start_time := this.GetString("start_time")
  8289. patient_id, _ := this.GetInt64("patient_id", 0)
  8290. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8291. end_time := this.GetString("end_time")
  8292. p_type, _ := this.GetInt64("p_type")
  8293. order_status, _ := this.GetInt64("type")
  8294. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8295. adminUserInfo := this.GetAdminUserInfo()
  8296. var dayHisPrescription []*models.HisPrescription
  8297. var err error
  8298. if order_status == 1 || order_status == 0 {
  8299. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8300. } else if order_status == 2 {
  8301. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  8302. }
  8303. var settle_total float64
  8304. for _, item := range dayHisPrescription {
  8305. if len(item.HisPrescriptionProject) > 0 {
  8306. for _, subItem := range item.HisPrescriptionProject {
  8307. count, _ := strconv.ParseFloat(subItem.Count, 64)
  8308. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  8309. settle_total = settle_total + total
  8310. }
  8311. }
  8312. if len(item.HisDoctorAdviceInfo) > 0 {
  8313. for _, subItem := range item.HisDoctorAdviceInfo {
  8314. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  8315. settle_total = settle_total + total
  8316. }
  8317. }
  8318. }
  8319. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  8320. if err == nil {
  8321. this.ServeSuccessJSON(map[string]interface{}{
  8322. "day_prescription": dayHisPrescription,
  8323. "settle_total": settle_total,
  8324. })
  8325. return
  8326. } else {
  8327. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  8328. return
  8329. }
  8330. }
  8331. func (c *HisApiController) GetHisChargePatientList() {
  8332. record_date := c.GetString("record_date")
  8333. order_status, _ := c.GetInt64("type")
  8334. sch_type, _ := c.GetInt64("sch_type")
  8335. timeLayout := "2006-01-02"
  8336. loc, _ := time.LoadLocation("Local")
  8337. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8338. if err != nil {
  8339. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8340. return
  8341. }
  8342. recordDateTime := theTime.Unix()
  8343. adminInfo := c.GetAdminUserInfo()
  8344. var tempPatients []*service.NewTempPatients
  8345. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  8346. if c.GetAdminUserInfo().CurrentOrgId == 10206 { //针对用了坐标系统的机构
  8347. if order_status != 2 {
  8348. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8349. } else {
  8350. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8351. }
  8352. } else {
  8353. if order_status != 2 {
  8354. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8355. } else {
  8356. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  8357. }
  8358. }
  8359. var patients []*service.NewTempPatients
  8360. var patients_two []*service.NewTempPatients
  8361. for _, item := range tempPatients {
  8362. if c.GetAdminUserInfo().CurrentOrgId != 10206 {
  8363. //过滤掉没挂号的和没开处方的
  8364. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  8365. patients = append(patients, item)
  8366. }
  8367. //过滤掉没挂号的
  8368. if len(item.HisPatient) > 0 {
  8369. patients_two = append(patients_two, item)
  8370. }
  8371. } else {
  8372. if len(item.HisPrescription) > 0 {
  8373. patients = append(patients, item)
  8374. }
  8375. }
  8376. }
  8377. c.ServeSuccessJSON(map[string]interface{}{
  8378. "list": patients,
  8379. "list_two": patients_two,
  8380. })
  8381. }
  8382. func (c *HisApiController) GetHisUnRegisterPatientList() {
  8383. record_date := c.GetString("record_date")
  8384. timeLayout := "2006-01-02"
  8385. loc, _ := time.LoadLocation("Local")
  8386. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8387. if err != nil {
  8388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8389. return
  8390. }
  8391. recordDateTime := theTime.Unix()
  8392. adminUser := c.GetAdminUserInfo()
  8393. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  8394. var patients []*service.Patients
  8395. for _, item := range tempPatients {
  8396. if item.HisPatient.ID == 0 {
  8397. patients = append(patients, item)
  8398. }
  8399. }
  8400. c.ServeSuccessJSON(map[string]interface{}{
  8401. "list": patients,
  8402. //"list_two": patients_two,
  8403. })
  8404. }
  8405. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  8406. newArr = make([]*service.Patients, 0)
  8407. for i := 0; i < len(patient); i++ {
  8408. repeat := false
  8409. for j := i + 1; j < len(patient); j++ {
  8410. if patient[i].ID == patient[j].ID {
  8411. repeat = true
  8412. break
  8413. }
  8414. }
  8415. if !repeat {
  8416. newArr = append(newArr, patient[i])
  8417. }
  8418. }
  8419. return
  8420. }
  8421. func (c *HisApiController) GetHisChargePatientInfo() {
  8422. patient_id, _ := c.GetInt64("patient_id")
  8423. his_patient_id, _ := c.GetInt64("his_patient_id")
  8424. record_date := c.GetString("record_date")
  8425. //start_time := c.GetString("start_time")
  8426. //end_time := c.GetString("end_time")
  8427. order_status, _ := c.GetInt64("type", 0)
  8428. p_type, _ := c.GetInt64("p_type", 0)
  8429. order_id, _ := c.GetInt64("order_id", 0)
  8430. timeLayout := "2006-01-02"
  8431. loc, _ := time.LoadLocation("Local")
  8432. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  8433. if err != nil {
  8434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  8435. return
  8436. }
  8437. recordDateTime := theTime.Unix()
  8438. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8439. //if err != nil {
  8440. //
  8441. //}
  8442. //startRecordDateTime := startTime.Unix()
  8443. //
  8444. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8445. //if err != nil {
  8446. //
  8447. //}
  8448. //endRecordDateTime := endTime.Unix()
  8449. admin := c.GetAdminUserInfo()
  8450. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  8451. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  8452. var prescriptions []*models.HisPrescription
  8453. //var unChargeMonthPrescriptions []*models.HisPrescription
  8454. order, _ := service.GetHisOrderByID(order_id)
  8455. if order_status == 1 || order_status == 0 {
  8456. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  8457. } else if order_status == 2 {
  8458. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  8459. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  8460. }
  8461. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  8462. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  8463. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  8464. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  8465. //获取所有科室信息
  8466. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  8467. c.ServeSuccessJSON(map[string]interface{}{
  8468. "his_info": his_patient_info,
  8469. "xt_info": xt_patient_info,
  8470. "prescription": prescriptions,
  8471. "case_history": case_history,
  8472. "info": patientPrescriptionInfo,
  8473. "last_info": lastPatientPrescriptionInfo,
  8474. "order": order,
  8475. "doctors": doctors,
  8476. "department": department,
  8477. })
  8478. return
  8479. }
  8480. func (c *HisApiController) GetAllOrderDetail() {
  8481. order_id, _ := c.GetInt64("id", 0)
  8482. order, _ := service.GetHisOrderByID(order_id)
  8483. if order.ID == 0 {
  8484. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8485. return
  8486. }
  8487. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8488. org_id := c.GetAdminUserInfo().CurrentOrgId
  8489. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8490. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8491. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8492. c.ServeSuccessJSON(map[string]interface{}{
  8493. "order": order,
  8494. "order_info": order_info,
  8495. "patient": patient,
  8496. "admin_info": adminInfo,
  8497. "hospital_record": record,
  8498. })
  8499. return
  8500. }
  8501. func (c *HisApiController) GetAllOrderDetailCollect() {
  8502. order_id, _ := c.GetInt64("id", 0)
  8503. order, _ := service.GetHisOrderByID(order_id)
  8504. if order.ID == 0 {
  8505. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  8506. return
  8507. }
  8508. org_id := c.GetAdminUserInfo().CurrentOrgId
  8509. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  8510. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  8511. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  8512. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  8513. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  8514. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  8515. var bedCostTotal float64 = 0 //床位总费
  8516. //var bedCostSelfTotal float64 = 0 //床位自费
  8517. var operationCostTotal float64 = 0 //手术费
  8518. //var operationCostSelfTotal float64 = 0 //手术费
  8519. var otherCostTotal float64 = 0 //其他费用
  8520. //var otherCostSelfTotal float64 = 0 //其他费用
  8521. var materialCostTotal float64 = 0 //材料费
  8522. //var materialCostSelfTotal float64 = 0 //材料费
  8523. var westernMedicineCostTotal float64 = 0 //西药费
  8524. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  8525. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  8526. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  8527. var checkCostTotal float64 = 0 //检查费
  8528. //var checkCostSelfTotal float64 = 0 //检查费
  8529. var laboratoryCostTotal float64 = 0 //化验费
  8530. //var laboratoryCostSelfTotal float64 = 0 //化验费
  8531. var treatCostTotal float64 = 0 //治疗费用
  8532. //var treatCostSelfTotal float64 = 0 //治疗费用
  8533. var zhenChaCostTotal float64 = 0 //其他费用
  8534. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  8535. decimal.DivisionPrecision = 2
  8536. var BalanceAccountsType int64
  8537. if his.ID > 0 {
  8538. BalanceAccountsType = his.BalanceAccountsType
  8539. } else {
  8540. BalanceAccountsType = record.BalanceAccountsType
  8541. }
  8542. if BalanceAccountsType != 2 {
  8543. for _, item := range order_info {
  8544. if org_id == 10215 {
  8545. if item.MedChrgitmType == "01" { //床位费
  8546. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8547. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8548. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8549. }
  8550. if item.MedChrgitmType == "02" { //诊察费
  8551. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8552. //zhenChaCostSelfTotal = zhenChaCostTotal
  8553. }
  8554. if item.MedChrgitmType == "03" { //检查费
  8555. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8556. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8557. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8558. }
  8559. //if item.MedChrgitmType == "02" { //检查费
  8560. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8561. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8562. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8563. //}
  8564. if item.MedChrgitmType == "04" { //化验费
  8565. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8566. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8567. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8568. }
  8569. if item.MedChrgitmType == "05" { //治疗费
  8570. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8571. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8572. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8573. }
  8574. if item.MedChrgitmType == "06" { //手术费
  8575. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8576. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8577. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8578. }
  8579. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8580. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8581. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8582. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8583. }
  8584. if item.MedChrgitmType == "09" { //西药费
  8585. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8586. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8587. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8588. }
  8589. if item.MedChrgitmType == "11" { //中成费
  8590. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8591. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8592. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8593. }
  8594. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8595. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8596. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8597. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8598. }
  8599. } else if org_id == 10188 || org_id == 10217 {
  8600. if item.MedChrgitmType == "01" { //床位费
  8601. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8602. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8603. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8604. }
  8605. if item.MedChrgitmType == "02" { //诊察费
  8606. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8607. //zhenChaCostSelfTotal = zhenChaCostTotal
  8608. }
  8609. if item.MedChrgitmType == "03" { //检查费
  8610. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8611. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8612. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8613. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8614. }
  8615. //if item.MedChrgitmType == "02" { //检查费
  8616. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8617. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8618. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8619. //}
  8620. if item.MedChrgitmType == "04" { //化验费
  8621. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8622. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8623. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8624. }
  8625. if item.MedChrgitmType == "05" { //治疗费
  8626. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8627. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8628. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8629. }
  8630. if item.MedChrgitmType == "06" { //手术费
  8631. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8632. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8633. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8634. }
  8635. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8636. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8637. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8638. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8639. }
  8640. if item.MedChrgitmType == "09" { //西药费
  8641. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8642. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8643. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8644. }
  8645. if item.MedChrgitmType == "11" { //中成费
  8646. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8647. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8648. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8649. }
  8650. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8651. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8652. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8653. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8654. }
  8655. } else {
  8656. if item.MedChrgitmType == "01" { //床位费
  8657. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8658. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8659. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8660. }
  8661. //if item.MedChrgitmType == "02" { //诊察费
  8662. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8663. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8664. //}
  8665. if item.MedChrgitmType == "03" { //检查费
  8666. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8667. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8668. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8669. }
  8670. //if item.MedChrgitmType == "02" { //检查费
  8671. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8672. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8673. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8674. //}
  8675. if item.MedChrgitmType == "04" { //化验费
  8676. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8677. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8678. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8679. }
  8680. if item.MedChrgitmType == "05" { //治疗费
  8681. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8682. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8683. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8684. }
  8685. if item.MedChrgitmType == "06" { //手术费
  8686. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8687. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8688. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8689. }
  8690. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8691. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8692. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8693. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8694. }
  8695. if item.MedChrgitmType == "09" { //西药费
  8696. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8697. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8698. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8699. }
  8700. if item.MedChrgitmType == "11" { //中成费
  8701. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8702. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8703. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8704. }
  8705. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8706. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8707. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8708. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8709. }
  8710. }
  8711. }
  8712. c.ServeSuccessJSON(map[string]interface{}{
  8713. "order": order,
  8714. "order_info": order_info,
  8715. "patient": patient,
  8716. "admin_info": adminInfo,
  8717. "his_hospital": record,
  8718. "bedCostTotal": bedCostTotal,
  8719. "operationCostTotal": operationCostTotal,
  8720. "otherCostTotal": otherCostTotal,
  8721. "materialCostTotal": materialCostTotal,
  8722. "westernMedicineCostTotal": westernMedicineCostTotal,
  8723. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8724. "checkCostTotal": checkCostTotal,
  8725. "zhenChaCostTotal": zhenChaCostTotal,
  8726. "laboratoryCostTotal": laboratoryCostTotal,
  8727. "treatCostTotal": treatCostTotal,
  8728. })
  8729. } else {
  8730. for _, item := range order_info {
  8731. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  8732. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  8733. item.MedChrgitmType = "09"
  8734. }
  8735. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  8736. if item.HisPrescriptionProject.Type == 2 {
  8737. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  8738. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8739. case 0:
  8740. item.MedChrgitmType = "0"
  8741. break
  8742. case 1:
  8743. item.MedChrgitmType = "14"
  8744. break
  8745. case 2:
  8746. item.MedChrgitmType = "05"
  8747. break
  8748. case 3:
  8749. item.MedChrgitmType = "03"
  8750. break
  8751. case 4:
  8752. item.MedChrgitmType = "03"
  8753. break
  8754. case 5:
  8755. item.MedChrgitmType = "08"
  8756. break
  8757. case 6:
  8758. item.MedChrgitmType = "14"
  8759. break
  8760. case 7:
  8761. item.MedChrgitmType = "14"
  8762. break
  8763. case 8:
  8764. item.MedChrgitmType = "03"
  8765. break
  8766. case 9:
  8767. item.MedChrgitmType = "14"
  8768. break
  8769. case 10:
  8770. item.MedChrgitmType = "14"
  8771. break
  8772. case 11:
  8773. item.MedChrgitmType = "06"
  8774. break
  8775. case 12:
  8776. item.MedChrgitmType = "12"
  8777. break
  8778. case 13:
  8779. item.MedChrgitmType = "01"
  8780. break
  8781. case 14:
  8782. item.MedChrgitmType = "04"
  8783. break
  8784. case 15:
  8785. item.MedChrgitmType = "14"
  8786. break
  8787. }
  8788. } else {
  8789. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  8790. case 1:
  8791. item.MedChrgitmType = "14"
  8792. break
  8793. case 2:
  8794. item.MedChrgitmType = "05"
  8795. break
  8796. case 3:
  8797. item.MedChrgitmType = "04"
  8798. break
  8799. case 4:
  8800. item.MedChrgitmType = "14"
  8801. break
  8802. case 5:
  8803. item.MedChrgitmType = "08"
  8804. break
  8805. case 6:
  8806. item.MedChrgitmType = "14"
  8807. break
  8808. case 7:
  8809. item.MedChrgitmType = "14"
  8810. break
  8811. case 8:
  8812. item.MedChrgitmType = "03"
  8813. break
  8814. case 9:
  8815. item.MedChrgitmType = "14"
  8816. break
  8817. }
  8818. }
  8819. } else if item.HisPrescriptionProject.Type == 3 {
  8820. item.MedChrgitmType = "08"
  8821. }
  8822. }
  8823. }
  8824. for _, item := range order_info {
  8825. if org_id == 10215 {
  8826. if item.MedChrgitmType == "01" { //床位费
  8827. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8828. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8829. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8830. }
  8831. if item.MedChrgitmType == "02" { //诊察费
  8832. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8833. //zhenChaCostSelfTotal = zhenChaCostTotal
  8834. }
  8835. if item.MedChrgitmType == "03" { //检查费
  8836. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8837. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8838. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8839. }
  8840. //if item.MedChrgitmType == "02" { //检查费
  8841. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8842. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8843. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8844. //}
  8845. if item.MedChrgitmType == "04" { //化验费
  8846. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8847. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8848. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8849. }
  8850. if item.MedChrgitmType == "05" { //治疗费
  8851. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8852. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8853. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8854. }
  8855. if item.MedChrgitmType == "06" { //手术费
  8856. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8857. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8858. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8859. }
  8860. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8861. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8862. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8863. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8864. }
  8865. if item.MedChrgitmType == "09" { //西药费
  8866. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8867. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8868. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8869. }
  8870. if item.MedChrgitmType == "11" { //中成费
  8871. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8872. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8873. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8874. }
  8875. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  8876. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8877. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8878. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8879. }
  8880. } else {
  8881. if item.MedChrgitmType == "01" { //床位费
  8882. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8883. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8884. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8885. }
  8886. //if item.MedChrgitmType == "02" { //诊察费
  8887. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8888. // //zhenChaCostSelfTotal = zhenChaCostTotal
  8889. //}
  8890. if item.MedChrgitmType == "03" { //检查费
  8891. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8892. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8893. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8894. }
  8895. //if item.MedChrgitmType == "02" { //检查费
  8896. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8897. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8898. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8899. //}
  8900. if item.MedChrgitmType == "04" { //化验费
  8901. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8902. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8903. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8904. }
  8905. if item.MedChrgitmType == "05" { //治疗费
  8906. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8907. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8908. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8909. }
  8910. if item.MedChrgitmType == "06" { //手术费
  8911. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8912. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8913. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8914. }
  8915. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" { //材料费
  8916. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8917. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8918. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8919. }
  8920. if item.MedChrgitmType == "09" { //西药费
  8921. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8922. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8923. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8924. }
  8925. if item.MedChrgitmType == "11" { //中成费
  8926. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8927. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8928. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8929. }
  8930. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  8931. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  8932. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  8933. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  8934. }
  8935. }
  8936. }
  8937. c.ServeSuccessJSON(map[string]interface{}{
  8938. "order": order,
  8939. "order_info": order_info,
  8940. "patient": patient,
  8941. "admin_info": adminInfo,
  8942. "his_hospital": record,
  8943. "bedCostTotal": bedCostTotal,
  8944. "operationCostTotal": operationCostTotal,
  8945. "otherCostTotal": otherCostTotal,
  8946. "materialCostTotal": materialCostTotal,
  8947. "westernMedicineCostTotal": westernMedicineCostTotal,
  8948. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  8949. "checkCostTotal": checkCostTotal,
  8950. "zhenChaCostTotal": zhenChaCostTotal,
  8951. "laboratoryCostTotal": laboratoryCostTotal,
  8952. "treatCostTotal": treatCostTotal,
  8953. })
  8954. }
  8955. }
  8956. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  8957. page, _ := c.GetInt64("page")
  8958. limit, _ := c.GetInt64("limit")
  8959. keywords := c.GetString("keywords")
  8960. start_time := c.GetString("start_time")
  8961. end_time := c.GetString("end_time")
  8962. //clr_type := c.GetString("clr_type")
  8963. insutype := c.GetString("insutype")
  8964. timeLayout := "2006-01-02"
  8965. loc, _ := time.LoadLocation("Local")
  8966. var theStartTIme int64
  8967. if len(start_time) > 0 {
  8968. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  8969. theStartTIme = theTime.Unix()
  8970. }
  8971. var theEndtTIme int64
  8972. if len(end_time) > 0 {
  8973. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  8974. theEndtTIme = theTime.Unix()
  8975. }
  8976. if page <= 0 {
  8977. page = 1
  8978. }
  8979. if limit <= 0 {
  8980. limit = 10
  8981. }
  8982. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  8983. c.ServeSuccessJSON(map[string]interface{}{
  8984. "total": total,
  8985. "list": list,
  8986. })
  8987. return
  8988. }
  8989. func (c *HisApiController) GetPutOnRecordList() {
  8990. page, _ := c.GetInt64("page")
  8991. limit, _ := c.GetInt64("limit")
  8992. keywords := c.GetString("keywords")
  8993. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  8994. if page <= 0 {
  8995. page = 1
  8996. }
  8997. if limit <= 0 {
  8998. limit = 10
  8999. }
  9000. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  9001. c.ServeSuccessJSON(map[string]interface{}{
  9002. "total": total,
  9003. "list": list,
  9004. })
  9005. return
  9006. }
  9007. func (c *HisApiController) GetCompareData() {
  9008. start_time := c.GetString("start_time")
  9009. end_time := c.GetString("end_time")
  9010. insutype := c.GetString("insutype")
  9011. clr_type := c.GetString("clr_type")
  9012. timeLayout := "2006-01-02"
  9013. loc, _ := time.LoadLocation("Local")
  9014. var theStartTIme int64
  9015. if len(start_time) > 0 {
  9016. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9017. if err != nil {
  9018. theStartTIme = 0
  9019. }
  9020. theStartTIme = theTime.Unix()
  9021. }
  9022. var theEndtTIme int64
  9023. if len(end_time) > 0 {
  9024. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9025. if err != nil {
  9026. theEndtTIme = 0
  9027. }
  9028. theEndtTIme = theTime.Unix()
  9029. }
  9030. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  9031. fmt.Println(err)
  9032. if err == nil {
  9033. c.ServeSuccessJSON(map[string]interface{}{
  9034. "list": formData,
  9035. })
  9036. } else {
  9037. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  9038. return
  9039. }
  9040. }
  9041. func (c *HisApiController) GetFaPiaoData() {
  9042. order_id, _ := c.GetInt64("order_id")
  9043. patient_id, _ := c.GetInt64("patient_id")
  9044. //number := c.GetString("number")
  9045. adminUser := c.GetAdminUserInfo()
  9046. order, _ := service.GetHisOrderByID(order_id)
  9047. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9048. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9049. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9050. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9051. prescriptions, _ := service.GetHisPrescriptionByBatchNumber(adminUser.CurrentOrgId, order.Number)
  9052. doctor_info, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, prescriptions[0].Creator)
  9053. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9054. patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9055. var bedCostTotal float64 = 0 //床位总费
  9056. var bedCostSelfTotal float64 = 0 //床位自费
  9057. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9058. var operationCostTotal float64 = 0 //手术费
  9059. var operationCostSelfTotal float64 = 0 //手术费
  9060. var operationCostPartSelfTotal float64 = 0 //手术费
  9061. var otherCostTotal float64 = 0 //其他费用
  9062. var otherCostSelfTotal float64 = 0 //其他费用
  9063. var otherCostPartSelfTotal float64 = 0 //其他费用
  9064. var materialCostTotal float64 = 0 //材料费
  9065. var materialCostSelfTotal float64 = 0 //材料费
  9066. var materialCostPartSelfTotal float64 = 0 //材料费
  9067. var westernMedicineCostTotal float64 = 0 //西药费
  9068. var westernMedicineCostSelfTotal float64 = 0 //西药费
  9069. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9070. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9071. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9072. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9073. var checkCostTotal float64 = 0 //检查费
  9074. var checkCostSelfTotal float64 = 0 //检查费
  9075. var checkCostPartSelfTotal float64 = 0 //检查费
  9076. var hiliCostTotal float64 = 0 //护理费
  9077. var hiliCostSelfTotal float64 = 0 //护理费
  9078. var hiliCostPartSelfTotal float64 = 0 //护理费
  9079. var laboratoryCostTotal float64 = 0 //化验费
  9080. var laboratoryCostSelfTotal float64 = 0 //化验费
  9081. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9082. var treatCostTotal float64 = 0 //治疗费用
  9083. var treatCostSelfTotal float64 = 0 //治疗费用
  9084. var treatCostPartSelfTotal float64 = 0 //治疗费用
  9085. var zhenChaCostTotal float64 = 0 //其他费用
  9086. var zhenChaCostSelfTotal float64 = 0 //其他费用
  9087. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9088. decimal.DivisionPrecision = 2
  9089. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9090. var balanceAccountsType int64
  9091. if his.ID > 0 {
  9092. balanceAccountsType = his.BalanceAccountsType
  9093. } else {
  9094. balanceAccountsType = his_hospital_record.BalanceAccountsType
  9095. }
  9096. if balanceAccountsType == 2 {
  9097. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9098. for _, item := range orderInfos_two {
  9099. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9100. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9101. item.MedChrgitmType = "09"
  9102. }
  9103. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9104. if item.HisPrescriptionProject.Type == 2 {
  9105. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9106. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9107. case 0:
  9108. item.MedChrgitmType = "0"
  9109. break
  9110. case 1:
  9111. item.MedChrgitmType = "14"
  9112. break
  9113. case 2:
  9114. item.MedChrgitmType = "05"
  9115. break
  9116. case 3:
  9117. item.MedChrgitmType = "03"
  9118. break
  9119. case 4:
  9120. item.MedChrgitmType = "03"
  9121. break
  9122. case 5:
  9123. item.MedChrgitmType = "08"
  9124. break
  9125. case 6:
  9126. item.MedChrgitmType = "14"
  9127. break
  9128. case 7:
  9129. item.MedChrgitmType = "14"
  9130. break
  9131. case 8:
  9132. item.MedChrgitmType = "03"
  9133. break
  9134. case 9:
  9135. item.MedChrgitmType = "14"
  9136. break
  9137. case 10:
  9138. item.MedChrgitmType = "14"
  9139. break
  9140. case 11:
  9141. item.MedChrgitmType = "06"
  9142. break
  9143. case 12:
  9144. item.MedChrgitmType = "12"
  9145. break
  9146. case 13:
  9147. item.MedChrgitmType = "01"
  9148. break
  9149. case 14:
  9150. item.MedChrgitmType = "04"
  9151. break
  9152. case 15:
  9153. item.MedChrgitmType = "02"
  9154. break
  9155. }
  9156. } else {
  9157. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9158. case 1:
  9159. item.MedChrgitmType = "14"
  9160. break
  9161. case 2:
  9162. item.MedChrgitmType = "05"
  9163. break
  9164. case 3:
  9165. item.MedChrgitmType = "04"
  9166. break
  9167. case 4:
  9168. item.MedChrgitmType = "03"
  9169. break
  9170. case 5:
  9171. item.MedChrgitmType = "08"
  9172. break
  9173. case 6:
  9174. item.MedChrgitmType = "14"
  9175. break
  9176. case 7:
  9177. item.MedChrgitmType = "14"
  9178. break
  9179. case 8:
  9180. item.MedChrgitmType = "03"
  9181. break
  9182. case 9:
  9183. item.MedChrgitmType = "14"
  9184. break
  9185. }
  9186. }
  9187. } else if item.HisPrescriptionProject.Type == 3 {
  9188. item.MedChrgitmType = "08"
  9189. }
  9190. }
  9191. }
  9192. for _, item := range orderInfos_two {
  9193. fmt.Println(item.MedChrgitmType)
  9194. if item.MedChrgitmType == "07" { //床位费
  9195. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9196. hiliCostSelfTotal = hiliCostTotal
  9197. }
  9198. if item.MedChrgitmType == "01" { //床位费
  9199. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9200. bedCostSelfTotal = bedCostTotal
  9201. }
  9202. if item.MedChrgitmType == "02" { //诊察费
  9203. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9204. zhenChaCostSelfTotal = zhenChaCostTotal
  9205. }
  9206. if item.MedChrgitmType == "03" { //检查费
  9207. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9208. checkCostSelfTotal = checkCostTotal
  9209. }
  9210. if item.MedChrgitmType == "04" { //化验费
  9211. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9212. laboratoryCostSelfTotal = laboratoryCostTotal
  9213. }
  9214. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9215. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9216. treatCostSelfTotal = treatCostTotal
  9217. }
  9218. if item.MedChrgitmType == "06" { //手术费
  9219. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9220. operationCostSelfTotal = treatCostTotal
  9221. }
  9222. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "301" { //材料费
  9223. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9224. materialCostSelfTotal = materialCostTotal
  9225. }
  9226. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9227. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9228. westernMedicineCostSelfTotal = westernMedicineCostTotal
  9229. }
  9230. if item.MedChrgitmType == "11" { //中成费
  9231. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9232. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9233. }
  9234. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9235. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9236. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9237. otherCostSelfTotal = otherCostTotal
  9238. }
  9239. } else {
  9240. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9241. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9242. otherCostSelfTotal = otherCostTotal
  9243. }
  9244. }
  9245. }
  9246. } else {
  9247. for _, item := range orderInfos {
  9248. if item.MedChrgitmType == "01" { //床位费
  9249. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9250. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9251. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9252. }
  9253. if item.MedChrgitmType == "02" { //诊察费
  9254. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9255. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9256. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9257. }
  9258. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9259. if item.MedChrgitmType == "03" { //检查费
  9260. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9261. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9262. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9263. }
  9264. } else {
  9265. if item.MedChrgitmType == "03" { //检查费
  9266. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9267. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9268. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9269. }
  9270. }
  9271. if item.MedChrgitmType == "04" { //化验费
  9272. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9273. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9274. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9275. }
  9276. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "201" { //治疗费
  9277. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9278. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9279. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9280. }
  9281. if item.MedChrgitmType == "06" { //手术费
  9282. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9283. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9284. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9285. }
  9286. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" || item.MedChrgitmType == "301" { //材料费
  9287. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9288. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9289. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9290. }
  9291. if item.MedChrgitmType == "07" { //护理
  9292. hiliCostTotal, _ = decimal.NewFromFloat(hiliCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9293. hiliCostSelfTotal, _ = decimal.NewFromFloat(hiliCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9294. hiliCostPartSelfTotal, _ = decimal.NewFromFloat(hiliCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9295. }
  9296. if item.MedChrgitmType == "09" || item.MedChrgitmType == "101" { //西药费
  9297. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9298. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9299. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9300. }
  9301. if item.MedChrgitmType == "11" { //中成费
  9302. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9303. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9304. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9305. }
  9306. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9307. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9308. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9309. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9310. }
  9311. }
  9312. }
  9313. timeLayout := "2006-01-02"
  9314. loc, _ := time.LoadLocation("Local")
  9315. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9316. if err != nil {
  9317. }
  9318. startRecordDateTime := startTime.Unix()
  9319. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9320. if err != nil {
  9321. }
  9322. endRecordDateTime := endTime.Unix()
  9323. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9324. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9325. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9326. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  9327. c.ServeSuccessJSON(map[string]interface{}{
  9328. "charge_admin_name": charge_admin.UserName,
  9329. "order_number": order.Number, //业务流水号
  9330. "id_card_no": his.IdCardNo, //社会保障号
  9331. "patient": patient,
  9332. "department_name": department.Name, //科室
  9333. "number": his.Number, //门诊号
  9334. "date": order.SettleAccountsDate, //结算日期
  9335. "name": order.PsnName, //姓名
  9336. "gender": patient.Gender, //性别
  9337. "psn_cash_money": order.PsnCashPay, //个人支付
  9338. "pay_way": "门诊", //结算方式
  9339. "medfee_sumamt": order.MedfeeSumamt, //总费用
  9340. "admin_user_name": admin.UserName, //收款员
  9341. "order": order,
  9342. "order_info": orderInfos_two,
  9343. "his": his,
  9344. "bedCostTotal": bedCostTotal,
  9345. "bedCostSelfTotal": bedCostSelfTotal,
  9346. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9347. "operationCostTotal": operationCostTotal,
  9348. "operationCostSelfTotal": operationCostSelfTotal,
  9349. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9350. "otherCostTotal": otherCostTotal,
  9351. "otherCostSelfTotal": otherCostSelfTotal,
  9352. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9353. "materialCostTotal": materialCostTotal,
  9354. "materialCostSelfTotal": materialCostSelfTotal,
  9355. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9356. "westernMedicineCostTotal": westernMedicineCostTotal,
  9357. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9358. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9359. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9360. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9361. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9362. "checkCostTotal": checkCostTotal,
  9363. "checkCostSelfTotal": checkCostSelfTotal,
  9364. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9365. "laboratoryCostTotal": laboratoryCostTotal,
  9366. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9367. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9368. "treatCostTotal": treatCostTotal,
  9369. "treatCostSelfTotal": treatCostSelfTotal,
  9370. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9371. "zhenChaCostTotal": zhenChaCostTotal,
  9372. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9373. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9374. "his_hospital_record": his_hospital_record,
  9375. "pre_pay_money": pre_pay_money,
  9376. "refund_sum": sum,
  9377. "doctor_info": doctor_info,
  9378. "hiliCostTotal": hiliCostTotal,
  9379. "hiliCostSelfTotal": hiliCostSelfTotal,
  9380. "hiliCostPartSelfTotal": hiliCostPartSelfTotal,
  9381. })
  9382. }
  9383. //func (c *HisApiController) GetFaPiaoDatas() {
  9384. // order_ids := c.GetString("order_ids")
  9385. // patient_id, _ := c.GetInt64("patient_id")
  9386. // adminUser := c.GetAdminUserInfo()
  9387. //
  9388. // orders := strings.Split(order_ids, ",")
  9389. // patient, _ := service.GetFaPiaoPatientByID(adminUser.CurrentOrgId, patient_id)
  9390. //
  9391. // for _, item := range orders {
  9392. // order_id, _ := strconv.ParseInt(item, 10, 64)
  9393. // order, _ := service.GetHisOrderByID(order_id)
  9394. // orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  9395. // patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  9396. // department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  9397. // his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  9398. // his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  9399. //
  9400. // }
  9401. //
  9402. // var bedCostTotal float64 = 0 //床位总费
  9403. // var bedCostSelfTotal float64 = 0 //床位自费
  9404. // var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  9405. //
  9406. // var operationCostTotal float64 = 0 //手术费
  9407. // var operationCostSelfTotal float64 = 0 //手术费
  9408. // var operationCostPartSelfTotal float64 = 0 //手术费
  9409. //
  9410. // var otherCostTotal float64 = 0 //其他费用
  9411. // var otherCostSelfTotal float64 = 0 //其他费用
  9412. // var otherCostPartSelfTotal float64 = 0 //其他费用
  9413. //
  9414. // var materialCostTotal float64 = 0 //材料费
  9415. // var materialCostSelfTotal float64 = 0 //材料费
  9416. // var materialCostPartSelfTotal float64 = 0 //材料费
  9417. //
  9418. // var westernMedicineCostTotal float64 = 0 //西药费
  9419. // var westernMedicineCostSelfTotal float64 = 0 //西药费
  9420. // var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  9421. //
  9422. // var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  9423. // var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  9424. // var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  9425. //
  9426. // var checkCostTotal float64 = 0 //检查费
  9427. // var checkCostSelfTotal float64 = 0 //检查费
  9428. // var checkCostPartSelfTotal float64 = 0 //检查费
  9429. //
  9430. // var laboratoryCostTotal float64 = 0 //化验费
  9431. // var laboratoryCostSelfTotal float64 = 0 //化验费
  9432. // var laboratoryCostPartSelfTotal float64 = 0 //化验费
  9433. //
  9434. // var treatCostTotal float64 = 0 //治疗费用
  9435. // var treatCostSelfTotal float64 = 0 //治疗费用
  9436. // var treatCostPartSelfTotal float64 = 0 //治疗费用
  9437. //
  9438. // var zhenChaCostTotal float64 = 0 //其他费用
  9439. // var zhenChaCostSelfTotal float64 = 0 //其他费用
  9440. // var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  9441. //
  9442. // decimal.DivisionPrecision = 2
  9443. // orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9444. //
  9445. // var balanceAccountsType int64
  9446. // if his.ID > 0 {
  9447. // balanceAccountsType = his.BalanceAccountsType
  9448. // } else {
  9449. // balanceAccountsType = his_hospital_record.BalanceAccountsType
  9450. // }
  9451. // if balanceAccountsType == 2 {
  9452. // //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  9453. // for _, item := range orderInfos_two {
  9454. // item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  9455. // if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  9456. // item.MedChrgitmType = "09"
  9457. // }
  9458. //
  9459. // if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  9460. // if item.HisPrescriptionProject.Type == 2 {
  9461. // if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  9462. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9463. // case 0:
  9464. // item.MedChrgitmType = "0"
  9465. // break
  9466. // case 1:
  9467. // item.MedChrgitmType = "14"
  9468. // break
  9469. // case 2:
  9470. // item.MedChrgitmType = "05"
  9471. //
  9472. // break
  9473. // case 3:
  9474. // item.MedChrgitmType = "03"
  9475. //
  9476. // break
  9477. // case 4:
  9478. // item.MedChrgitmType = "03"
  9479. //
  9480. // break
  9481. // case 5:
  9482. // item.MedChrgitmType = "08"
  9483. //
  9484. // break
  9485. // case 6:
  9486. // item.MedChrgitmType = "14"
  9487. //
  9488. // break
  9489. // case 7:
  9490. // item.MedChrgitmType = "14"
  9491. //
  9492. // break
  9493. // case 8:
  9494. // item.MedChrgitmType = "03"
  9495. // break
  9496. // case 9:
  9497. // item.MedChrgitmType = "14"
  9498. // break
  9499. // case 10:
  9500. // item.MedChrgitmType = "14"
  9501. // break
  9502. // case 11:
  9503. // item.MedChrgitmType = "06"
  9504. // break
  9505. // case 12:
  9506. // item.MedChrgitmType = "12"
  9507. // break
  9508. // case 13:
  9509. // item.MedChrgitmType = "01"
  9510. // break
  9511. // case 14:
  9512. // item.MedChrgitmType = "04"
  9513. // break
  9514. // case 15:
  9515. // item.MedChrgitmType = "02"
  9516. // break
  9517. //
  9518. // }
  9519. //
  9520. // } else {
  9521. // switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  9522. //
  9523. // case 1:
  9524. // item.MedChrgitmType = "14"
  9525. // break
  9526. // case 2:
  9527. // item.MedChrgitmType = "05"
  9528. //
  9529. // break
  9530. // case 3:
  9531. // item.MedChrgitmType = "03"
  9532. //
  9533. // break
  9534. // case 4:
  9535. // item.MedChrgitmType = "03"
  9536. //
  9537. // break
  9538. // case 5:
  9539. // item.MedChrgitmType = "08"
  9540. //
  9541. // break
  9542. // case 6:
  9543. // item.MedChrgitmType = "14"
  9544. //
  9545. // break
  9546. // case 7:
  9547. // item.MedChrgitmType = "14"
  9548. //
  9549. // break
  9550. // case 8:
  9551. // item.MedChrgitmType = "03"
  9552. // break
  9553. // case 9:
  9554. // item.MedChrgitmType = "14"
  9555. // break
  9556. //
  9557. // }
  9558. //
  9559. // }
  9560. //
  9561. // } else if item.HisPrescriptionProject.Type == 3 {
  9562. // item.MedChrgitmType = "08"
  9563. // }
  9564. // }
  9565. // }
  9566. //
  9567. // for _, item := range orderInfos_two {
  9568. // fmt.Println(item.MedChrgitmType)
  9569. // if item.MedChrgitmType == "01" { //床位费
  9570. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9571. // bedCostSelfTotal = bedCostTotal
  9572. // }
  9573. //
  9574. // if item.MedChrgitmType == "02" { //诊察费
  9575. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9576. // zhenChaCostSelfTotal = zhenChaCostTotal
  9577. // }
  9578. //
  9579. // if item.MedChrgitmType == "03" { //检查费
  9580. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9581. // checkCostSelfTotal = checkCostTotal
  9582. // }
  9583. //
  9584. // if item.MedChrgitmType == "04" { //化验费
  9585. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9586. // laboratoryCostSelfTotal = laboratoryCostTotal
  9587. // }
  9588. //
  9589. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  9590. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9591. // treatCostSelfTotal = treatCostTotal
  9592. // }
  9593. //
  9594. // if item.MedChrgitmType == "06" { //手术费
  9595. // treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9596. // operationCostSelfTotal = treatCostTotal
  9597. // }
  9598. //
  9599. // if item.MedChrgitmType == "08" { //材料费
  9600. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9601. // materialCostSelfTotal = materialCostTotal
  9602. // }
  9603. //
  9604. // if item.MedChrgitmType == "09" { //西药费
  9605. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9606. // westernMedicineCostSelfTotal = westernMedicineCostTotal
  9607. // }
  9608. //
  9609. // if item.MedChrgitmType == "11" { //中成费
  9610. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9611. // chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  9612. // }
  9613. //
  9614. // if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  9615. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  9616. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9617. // otherCostSelfTotal = otherCostTotal
  9618. // }
  9619. // } else {
  9620. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9621. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9622. // otherCostSelfTotal = otherCostTotal
  9623. // }
  9624. //
  9625. // }
  9626. //
  9627. // }
  9628. //
  9629. // } else {
  9630. // for _, item := range orderInfos {
  9631. // if item.MedChrgitmType == "01" { //床位费
  9632. // bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9633. // bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9634. // bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9635. // }
  9636. //
  9637. // if item.MedChrgitmType == "02" { //诊察费
  9638. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9639. // zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9640. // zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9641. // }
  9642. //
  9643. // if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  9644. // if item.MedChrgitmType == "03" { //检查费
  9645. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9646. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9647. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9648. //
  9649. // }
  9650. // } else {
  9651. // if item.MedChrgitmType == "03" { //检查费
  9652. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9653. // checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9654. // checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9655. // }
  9656. //
  9657. // }
  9658. //
  9659. // if item.MedChrgitmType == "04" { //化验费
  9660. // laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9661. // laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9662. // laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9663. //
  9664. // }
  9665. //
  9666. // if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  9667. // treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9668. // treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9669. // treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9670. //
  9671. // }
  9672. //
  9673. // if item.MedChrgitmType == "06" { //手术费
  9674. // operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9675. // operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9676. // operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9677. // }
  9678. //
  9679. // if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  9680. // materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9681. // materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9682. // materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9683. // }
  9684. //
  9685. // if item.MedChrgitmType == "09" { //西药费
  9686. // westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9687. // westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9688. // westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9689. // }
  9690. //
  9691. // if item.MedChrgitmType == "11" { //中成费
  9692. // chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9693. // chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9694. // chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9695. // }
  9696. //
  9697. // if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  9698. // otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  9699. // otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  9700. // otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  9701. // }
  9702. //
  9703. // }
  9704. // }
  9705. // timeLayout := "2006-01-02"
  9706. // loc, _ := time.LoadLocation("Local")
  9707. // startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  9708. // if err != nil {
  9709. // }
  9710. // startRecordDateTime := startTime.Unix()
  9711. // endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  9712. // if err != nil {
  9713. // }
  9714. // endRecordDateTime := endTime.Unix()
  9715. // pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  9716. // sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  9717. // admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  9718. //
  9719. // c.ServeSuccessJSON(map[string]interface{}{
  9720. // "order_number": order.Number, //业务流水号
  9721. // "id_card_no": his.IdCardNo, //社会保障号
  9722. // "department_name": department.Name, //科室
  9723. // "number": his.Number, //门诊号
  9724. // "date": order.SettleAccountsDate, //结算日期
  9725. // "name": order.PsnName, //姓名
  9726. // "gender": patient.Gender, //性别
  9727. // "psn_cash_money": order.PsnCashPay, //个人支付
  9728. // "pay_way": "门诊", //结算方式
  9729. // "medfee_sumamt": order.MedfeeSumamt, //总费用
  9730. // "admin_user_name": admin.UserName, //收款员
  9731. // "order": order,
  9732. // "order_info": orderInfos_two,
  9733. // "his": his,
  9734. // "bedCostTotal": bedCostTotal,
  9735. // "bedCostSelfTotal": bedCostSelfTotal,
  9736. // "bedCostPartSelfTotal": bedCostPartSelfTotal,
  9737. // "operationCostTotal": operationCostTotal,
  9738. // "operationCostSelfTotal": operationCostSelfTotal,
  9739. // "operationCostPartSelfTotal": operationCostPartSelfTotal,
  9740. // "otherCostTotal": otherCostTotal,
  9741. // "otherCostSelfTotal": otherCostSelfTotal,
  9742. // "otherCostPartSelfTotal": otherCostPartSelfTotal,
  9743. // "materialCostTotal": materialCostTotal,
  9744. // "materialCostSelfTotal": materialCostSelfTotal,
  9745. // "materialCostPartSelfTotal": materialCostPartSelfTotal,
  9746. // "westernMedicineCostTotal": westernMedicineCostTotal,
  9747. // "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  9748. // "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  9749. // "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  9750. // "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  9751. // "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  9752. // "checkCostTotal": checkCostTotal,
  9753. // "checkCostSelfTotal": checkCostSelfTotal,
  9754. // "checkCostPartSelfTotal": checkCostPartSelfTotal,
  9755. // "laboratoryCostTotal": laboratoryCostTotal,
  9756. // "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  9757. // "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  9758. // "treatCostTotal": treatCostTotal,
  9759. // "treatCostSelfTotal": treatCostSelfTotal,
  9760. // "treatCostPartSelfTotal": treatCostPartSelfTotal,
  9761. // "zhenChaCostTotal": zhenChaCostTotal,
  9762. // "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  9763. // "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  9764. // "his_hospital_record": his_hospital_record,
  9765. // "pre_pay_money": pre_pay_money,
  9766. // "refund_sum": sum,
  9767. // })
  9768. //
  9769. //}
  9770. func (this *HisApiController) GetIncomeStatisticsData() {
  9771. start_time := this.GetString("start_time")
  9772. end_time := this.GetString("end_time")
  9773. key_words := this.GetString("key_words")
  9774. limit, _ := this.GetInt64("limit")
  9775. page, _ := this.GetInt64("page")
  9776. if page <= 0 {
  9777. page = 1
  9778. }
  9779. if limit <= 0 {
  9780. limit = 10
  9781. }
  9782. statistics_type, _ := this.GetInt64("statistics_type")
  9783. admin := this.GetAdminUserInfo()
  9784. timeLayout := "2006-01-02"
  9785. loc, _ := time.LoadLocation("Local")
  9786. var theStartTIme int64
  9787. if len(start_time) > 0 {
  9788. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  9789. if err != nil {
  9790. theStartTIme = 0
  9791. }
  9792. theStartTIme = theTime.Unix()
  9793. }
  9794. var theEndtTIme int64
  9795. if len(end_time) > 0 {
  9796. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  9797. if err != nil {
  9798. theEndtTIme = 0
  9799. }
  9800. theEndtTIme = theTime.Unix()
  9801. }
  9802. if statistics_type == 1 {
  9803. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9804. this.ServeSuccessJSON(map[string]interface{}{
  9805. "list": list,
  9806. "total": total,
  9807. })
  9808. } else {
  9809. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  9810. this.ServeSuccessJSON(map[string]interface{}{
  9811. "list": list,
  9812. "total": total,
  9813. })
  9814. }
  9815. }
  9816. func (c *HisApiController) PostProjectInformation() {
  9817. adminUser := c.GetAdminUserInfo()
  9818. orgId := adminUser.CurrentOrgId
  9819. dataBody := make(map[string]interface{}, 0)
  9820. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  9821. if err != nil {
  9822. utils.ErrorLog(err.Error())
  9823. return
  9824. }
  9825. utils.ErrorLog("%v", dataBody)
  9826. var projectList []*models.HisProject
  9827. var total_goods []interface{}
  9828. tempProjects := dataBody["projects"].([]interface{})
  9829. total_goods = tempProjects
  9830. for index, projectMap := range tempProjects {
  9831. projectM := projectMap.(map[string]interface{})
  9832. var project models.HisProject
  9833. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  9834. utils.ErrorLog("project_name")
  9835. return
  9836. }
  9837. project_name, _ := projectM["project_name"].(string)
  9838. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  9839. err_log := models.ExportErrLog{
  9840. LogType: 6,
  9841. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9842. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  9843. Status: 1,
  9844. CreateTime: time.Now().Unix(),
  9845. UpdateTime: time.Now().Unix(),
  9846. ExportTime: time.Now().Unix(),
  9847. }
  9848. service.CreateExportErrLog(&err_log)
  9849. continue
  9850. }
  9851. project.ProjectName = project_name
  9852. prices := projectM["price"].(string)
  9853. price, _ := strconv.ParseFloat(prices, 64)
  9854. if price <= 0 { //名字为空则生成一条导入错误日志
  9855. err_log := models.ExportErrLog{
  9856. LogType: 6,
  9857. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9858. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  9859. Status: 1,
  9860. CreateTime: time.Now().Unix(),
  9861. UpdateTime: time.Now().Unix(),
  9862. ExportTime: time.Now().Unix(),
  9863. }
  9864. service.CreateExportErrLog(&err_log)
  9865. continue
  9866. }
  9867. project.Price = price
  9868. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  9869. utils.ErrorLog("unit_id")
  9870. return
  9871. }
  9872. unit := projectM["unit"].(string)
  9873. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  9874. err_log := models.ExportErrLog{
  9875. LogType: 6,
  9876. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9877. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  9878. Status: 1,
  9879. CreateTime: time.Now().Unix(),
  9880. UpdateTime: time.Now().Unix(),
  9881. ExportTime: time.Now().Unix(),
  9882. }
  9883. service.CreateExportErrLog(&err_log)
  9884. continue
  9885. }
  9886. project.Unit = unit
  9887. cost_classify := projectM["cost_classify"].(string)
  9888. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  9889. err_log := models.ExportErrLog{
  9890. LogType: 6,
  9891. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9892. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9893. Status: 1,
  9894. CreateTime: time.Now().Unix(),
  9895. UpdateTime: time.Now().Unix(),
  9896. ExportTime: time.Now().Unix(),
  9897. }
  9898. service.CreateExportErrLog(&err_log)
  9899. continue
  9900. }
  9901. var costClassify = "费用类别"
  9902. var cost_classify_id int64
  9903. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  9904. if len(cost_classify) != 0 {
  9905. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  9906. if errcode == gorm.ErrRecordNotFound {
  9907. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  9908. dataconfig := models.DictDataconfig{
  9909. ParentId: costClassifyConfig.ID,
  9910. Module: "system",
  9911. OrgId: orgId,
  9912. Name: cost_classify,
  9913. FieldName: "",
  9914. Value: costConfig.Value + 1,
  9915. CreatedTime: "",
  9916. UpdatedTime: "",
  9917. CreateUserId: adminUser.AdminUser.Id,
  9918. Status: 1,
  9919. Remark: "",
  9920. DeleteIdSystem: 0,
  9921. Title: "",
  9922. Content: "",
  9923. Order: 0,
  9924. Code: "",
  9925. }
  9926. service.CreatedDicConfig(&dataconfig)
  9927. }
  9928. }
  9929. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  9930. for _, it := range costClassList {
  9931. if cost_classify == it.Name {
  9932. cost_classify_id = int64(it.Value)
  9933. }
  9934. }
  9935. project.CostClassify = cost_classify_id
  9936. executive_section := projectM["executive_section"].(string)
  9937. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  9938. err_log := models.ExportErrLog{
  9939. LogType: 6,
  9940. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9941. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  9942. Status: 1,
  9943. CreateTime: time.Now().Unix(),
  9944. UpdateTime: time.Now().Unix(),
  9945. ExportTime: time.Now().Unix(),
  9946. }
  9947. service.CreateExportErrLog(&err_log)
  9948. continue
  9949. }
  9950. if len(executive_section) != 0 {
  9951. //查找科室是否有内容
  9952. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  9953. if errcodedepart == gorm.ErrRecordNotFound {
  9954. department := models.XtHisDepartment{
  9955. Name: executive_section,
  9956. Status: 1,
  9957. UserOrgId: adminUser.CurrentOrgId,
  9958. CreatedTime: time.Now().Unix(),
  9959. }
  9960. service.CreateDePartment(&department)
  9961. }
  9962. }
  9963. var executive_section_id int64
  9964. departMentList, _ := service.GetAllDepartMent(orgId)
  9965. for _, it := range departMentList {
  9966. if executive_section == it.Name {
  9967. executive_section_id = it.ID
  9968. }
  9969. }
  9970. project.ExecutiveSection = executive_section_id
  9971. medical_coverage := projectM["medical_coverage"].(string)
  9972. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  9973. err_log := models.ExportErrLog{
  9974. LogType: 6,
  9975. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  9976. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  9977. Status: 1,
  9978. CreateTime: time.Now().Unix(),
  9979. UpdateTime: time.Now().Unix(),
  9980. ExportTime: time.Now().Unix(),
  9981. }
  9982. service.CreateExportErrLog(&err_log)
  9983. continue
  9984. }
  9985. var medicalCoverage = "医保等级"
  9986. var medical_coverage_id int64
  9987. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  9988. if len(medical_coverage) != 0 {
  9989. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  9990. if errormedicalcoverage == gorm.ErrRecordNotFound {
  9991. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  9992. dataconfig := models.DictDataconfig{
  9993. ParentId: medicalCoverageConfig.ID,
  9994. Module: "system",
  9995. OrgId: orgId,
  9996. Name: medical_coverage,
  9997. FieldName: "",
  9998. Value: medicalCoverageConfig.Value + 1,
  9999. CreatedTime: "",
  10000. UpdatedTime: "",
  10001. CreateUserId: adminUser.AdminUser.Id,
  10002. Status: 1,
  10003. Remark: "",
  10004. DeleteIdSystem: 0,
  10005. Title: "",
  10006. Content: "",
  10007. Order: 0,
  10008. Code: "",
  10009. }
  10010. service.CreatedDicConfig(&dataconfig)
  10011. }
  10012. }
  10013. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  10014. for _, it := range medicalCoverageList {
  10015. if medical_coverage == it.Name {
  10016. medical_coverage_id = int64(it.Value)
  10017. }
  10018. }
  10019. project.MedicalCoverage = medical_coverage_id
  10020. pinyin := projectM["pinyin"].(string)
  10021. project.Pinyin = pinyin
  10022. wubi := projectM["wubi"].(string)
  10023. project.Wubi = wubi
  10024. statistical_classification := projectM["statistical_classification"].(string)
  10025. var statisticalClassification = "统计分类"
  10026. var statistical_classification_id int64
  10027. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  10028. if len(statistical_classification) != 0 {
  10029. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  10030. if classificationerrcodes == gorm.ErrRecordNotFound {
  10031. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  10032. dataconfig := models.DictDataconfig{
  10033. ParentId: classiFication.ID,
  10034. Module: "system",
  10035. OrgId: orgId,
  10036. Name: statistical_classification,
  10037. FieldName: "",
  10038. Value: classiFicationConfig.Value + 1,
  10039. CreatedTime: "",
  10040. UpdatedTime: "",
  10041. CreateUserId: adminUser.AdminUser.Id,
  10042. Status: 1,
  10043. Remark: "",
  10044. DeleteIdSystem: 0,
  10045. Title: "",
  10046. Content: "",
  10047. Order: 0,
  10048. Code: "",
  10049. }
  10050. service.CreatedDicConfig(&dataconfig)
  10051. }
  10052. }
  10053. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  10054. for _, it := range classiFicationList {
  10055. if statistical_classification == it.Name {
  10056. statistical_classification_id = int64(it.Value)
  10057. }
  10058. }
  10059. project.StatisticalClassification = statistical_classification_id
  10060. disease_directory := int64(projectM["disease_directory"].(float64))
  10061. project.DiseaseDirectory = disease_directory
  10062. is_record := int64(projectM["is_record"].(float64))
  10063. project.IsRecord = is_record
  10064. medical_code := projectM["medical_code"].(string)
  10065. project.MedicalCode = medical_code
  10066. tube_color := projectM["tube_color"].(string)
  10067. var tubeColor = "试管颜色"
  10068. var tube_color_id int64
  10069. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  10070. if len(tube_color) != 0 {
  10071. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  10072. if errcodetube == gorm.ErrRecordNotFound {
  10073. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  10074. dataconfig := models.DictDataconfig{
  10075. ParentId: tubeColorConfig.ID,
  10076. Module: "system",
  10077. OrgId: orgId,
  10078. Name: tube_color,
  10079. FieldName: "",
  10080. Value: tubeConfig.Value + 1,
  10081. CreatedTime: "",
  10082. UpdatedTime: "",
  10083. CreateUserId: adminUser.AdminUser.Id,
  10084. Status: 1,
  10085. Remark: "",
  10086. DeleteIdSystem: 0,
  10087. Title: "",
  10088. Content: "",
  10089. Order: 0,
  10090. Code: "",
  10091. }
  10092. service.CreatedDicConfig(&dataconfig)
  10093. }
  10094. }
  10095. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  10096. for _, it := range tubeColorList {
  10097. if tube_color == it.Name {
  10098. tube_color_id = int64(it.Value)
  10099. }
  10100. }
  10101. project.TubeColor = tube_color_id
  10102. single_dose := projectM["single_dose"].(string)
  10103. project.SingleDose = single_dose
  10104. execution_frequency := projectM["execution_frequency"].(string)
  10105. project.ExecutionFrequency = execution_frequency
  10106. delivery_way := projectM["delivery_way"].(string)
  10107. project.DeliveryWay = delivery_way
  10108. number_days := projectM["number_days"].(string)
  10109. project.NumberDays = number_days
  10110. total := projectM["total"].(string)
  10111. project.Total = total
  10112. medical_status := int64(projectM["medical_status"].(float64))
  10113. project.MedicalStatus = medical_status
  10114. category := int64(projectM["category"].(float64))
  10115. project.Category = category
  10116. specail_project := int64(projectM["specail_project"].(float64))
  10117. project.SpecailProject = specail_project
  10118. social_security_directory_code := projectM["social_security_directory_code"].(string)
  10119. project.SocialSecurityDirectoryCode = social_security_directory_code
  10120. remark := projectM["remark"].(string)
  10121. project.Remark = remark
  10122. record_date := projectM["record_date"].(string)
  10123. timeLayout := "2006-01-02"
  10124. loc, _ := time.LoadLocation("Local")
  10125. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10126. project.RecordDate = theTime.Unix()
  10127. projectList = append(projectList, &project)
  10128. }
  10129. export_time := time.Now().Unix()
  10130. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  10131. if len(projectList) > 0 {
  10132. for _, item := range projectList {
  10133. hans := item.ProjectName // 要转换的汉字字符串
  10134. // 创建一个拼音转换器
  10135. p := pinyin.NewArgs()
  10136. // 将汉字转为拼音
  10137. pinyinSlice := pinyin.Pinyin(hans, p)
  10138. // 输出拼音
  10139. fmt.Println("Pinyin:", pinyinSlice)
  10140. // 获取首字母
  10141. firstLetter := ""
  10142. for _, py := range pinyinSlice {
  10143. if len(py) > 0 {
  10144. firstLetter += string(py[0][0])
  10145. }
  10146. }
  10147. item.FirstLetter = firstLetter
  10148. project := models.HisProject{
  10149. ProjectName: item.ProjectName,
  10150. Price: item.Price,
  10151. Unit: item.Unit,
  10152. CostClassify: item.CostClassify,
  10153. ExecutiveSection: item.ExecutiveSection,
  10154. MedicalCoverage: item.MedicalCoverage,
  10155. UserOrgId: orgId,
  10156. Status: 1,
  10157. CreatedTime: time.Now().Unix(),
  10158. Pinyin: item.Pinyin,
  10159. Wubi: item.Wubi,
  10160. StatisticalClassification: item.StatisticalClassification,
  10161. DiseaseDirectory: item.DiseaseDirectory,
  10162. IsRecord: item.IsRecord,
  10163. MedicalCode: item.MedicalCode,
  10164. TubeColor: item.TubeColor,
  10165. SingleDose: item.SingleDose,
  10166. DeliveryWay: item.DeliveryWay,
  10167. NumberDays: item.NumberDays,
  10168. Total: item.Total,
  10169. Category: item.Category,
  10170. MedicalStatus: item.MedicalStatus,
  10171. SpecailProject: item.SpecailProject,
  10172. RecordDate: item.RecordDate,
  10173. Remark: item.Remark,
  10174. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  10175. ExecutionFrequency: item.ExecutionFrequency,
  10176. FirstLetter: item.FirstLetter,
  10177. }
  10178. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  10179. if errcodeproject == gorm.ErrRecordNotFound {
  10180. service.CreateProjectInfomation(&project)
  10181. } else if errcodeproject == nil {
  10182. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  10183. }
  10184. log := models.ExportLog{
  10185. LogType: 6,
  10186. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10187. TotalNum: int64(len(total_goods)),
  10188. FailNum: int64(len(errLogs)),
  10189. SuccessNum: int64(len(projectList)),
  10190. CreateTime: time.Now().Unix(),
  10191. UpdateTime: time.Now().Unix(),
  10192. ExportTime: export_time,
  10193. Status: 1,
  10194. }
  10195. service.CreateExportLog(&log)
  10196. c.ServeSuccessJSON(map[string]interface{}{
  10197. "msg": "导入成功",
  10198. "total_num": len(total_goods),
  10199. "success_num": len(projectList),
  10200. "fail_num": int64(len(errLogs)),
  10201. })
  10202. }
  10203. } else {
  10204. log := models.ExportLog{
  10205. LogType: 6,
  10206. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10207. TotalNum: int64(len(total_goods)),
  10208. FailNum: int64(len(errLogs)),
  10209. SuccessNum: int64(len(projectList)),
  10210. CreateTime: time.Now().Unix(),
  10211. UpdateTime: time.Now().Unix(),
  10212. ExportTime: export_time,
  10213. Status: 1,
  10214. }
  10215. service.CreateExportLog(&log)
  10216. c.ServeSuccessJSON(map[string]interface{}{
  10217. "msg": "导入成功",
  10218. "total_num": len(total_goods),
  10219. "success_num": len(projectList),
  10220. "fail_num": int64(len(errLogs)),
  10221. })
  10222. }
  10223. }
  10224. //func (this *HisApiController) EditProjectInformation(){
  10225. //
  10226. // id, _ := this.GetInt64("id")
  10227. // project_team := this.GetString("project_team")
  10228. // price := this.GetString("price")
  10229. // price_float, _ := strconv.ParseFloat(price, 64)
  10230. // pinyin := this.GetString("pinyin")
  10231. // wubi := this.GetString("wubi")
  10232. // tube_color, _ := this.GetInt64("tube_color")
  10233. // team_type, _ := this.GetInt64("team_type")
  10234. // remark := this.GetString("remark")
  10235. // ids := this.GetString("ids")
  10236. // item_id := this.GetString("item_id")
  10237. // projectTeam := models.XtHisProjectTeam{
  10238. // ProjectTeam: project_team,
  10239. // Price: price_float,
  10240. // Pinyin: pinyin,
  10241. // Wubi: wubi,
  10242. // TubeColor: tube_color,
  10243. // TeamType: team_type,
  10244. // Remark: remark,
  10245. // ProjectId: ids,
  10246. // ItemId: item_id,
  10247. // }
  10248. //
  10249. //
  10250. // dataBody := make(map[string]interface{}, 0)
  10251. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  10252. // if err != nil {
  10253. // utils.ErrorLog(err.Error())
  10254. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10255. // return
  10256. // }
  10257. //
  10258. // err = service.UpdatedProjectTeam(id, &projectTeam)
  10259. //
  10260. //
  10261. // if err != nil {
  10262. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  10263. // return
  10264. // }
  10265. //
  10266. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  10267. // infos, _ := dataBody["info"].([]interface{})
  10268. // if len(infos) > 0 {
  10269. // var ids []string
  10270. //
  10271. // for _, item := range infos {
  10272. // items := item.(map[string]interface{})
  10273. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  10274. // utils.ErrorLog("id")
  10275. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10276. // return
  10277. // }
  10278. // id := int64(items["id"].(float64))
  10279. //
  10280. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10281. // utils.ErrorLog("type")
  10282. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10283. // return
  10284. // }
  10285. // types := int64(items["type"].(float64))
  10286. //
  10287. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  10288. // utils.ErrorLog("number")
  10289. // }
  10290. //
  10291. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  10292. //
  10293. // projectList := models.XtHisProjectList{
  10294. // Number: number,
  10295. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  10296. // ProjectId: id,
  10297. // Status: 1,
  10298. // CreatedTime: time.Now().Unix(),
  10299. // UpdatedTime: time.Now().Unix(),
  10300. // TeamId: projectTeam.ID,
  10301. // Type: types,
  10302. // }
  10303. // list := projectList
  10304. //
  10305. // service.CreateProjectList(&list)
  10306. //
  10307. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  10308. //
  10309. // }
  10310. // ids_str := strings.Join(ids, ",")
  10311. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  10312. // service.SaveProjectTeam(&projectTeam)
  10313. // this.ServeSuccessJSON(map[string]interface{}{
  10314. // "projectTeam": projectTeam,
  10315. // })
  10316. // }
  10317. // }
  10318. //}
  10319. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  10320. name := c.GetString("name")
  10321. mode_id, _ := c.GetInt64("mode", 0)
  10322. types, _ := c.GetInt64("type", 0)
  10323. patient_id, _ := c.GetInt64("patient_id", 0)
  10324. types = 1
  10325. adminInfo := c.GetAdminUserInfo()
  10326. template := &models.HisPrescriptionTemplate{
  10327. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  10328. PatientId: patient_id,
  10329. Type: types,
  10330. Status: 1,
  10331. Ctime: time.Now().Unix(),
  10332. Mtime: time.Now().Unix(),
  10333. Name: name,
  10334. Mode: mode_id,
  10335. }
  10336. dataBody := make(map[string]interface{}, 0)
  10337. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  10338. if err != nil {
  10339. utils.ErrorLog(err.Error())
  10340. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10341. return
  10342. }
  10343. template_one, _ := service.GetHisPrescriptionTemplateByModeId(mode_id, patient_id, c.GetAdminUserInfo().CurrentOrgId)
  10344. //如果已经存在记录则删除处方
  10345. if template_one.ID > 0 {
  10346. ps, _ := service.GetHisPrescriptionInfoTemplates(template_one.ID, template_one.UserOrgId)
  10347. var ids []int64
  10348. var org_id int64
  10349. for _, item := range ps {
  10350. org_id = c.GetAdminUserInfo().CurrentOrgId
  10351. ids = append(ids, item.ID)
  10352. }
  10353. err2 := service.BatchDelelteHisPrescriptionInfoTemplate(ids, org_id)
  10354. if err2 == nil {
  10355. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10356. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10357. if len(prescriptions) > 0 {
  10358. for _, item := range prescriptions {
  10359. items := item.(map[string]interface{})
  10360. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10361. utils.ErrorLog("type")
  10362. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10363. return
  10364. }
  10365. types := int64(items["type"].(float64))
  10366. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10367. utils.ErrorLog("med_type")
  10368. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10369. return
  10370. }
  10371. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10372. ctime := time.Now().Unix()
  10373. prescription := &models.HisPrescriptionInfoTemplate{
  10374. PatientId: patient_id,
  10375. UserOrgId: adminInfo.CurrentOrgId,
  10376. Ctime: ctime,
  10377. Mtime: ctime,
  10378. Type: types,
  10379. Modifier: adminInfo.AdminUser.Id,
  10380. Creator: adminInfo.AdminUser.Id,
  10381. Status: 1,
  10382. PTemplateId: template_one.ID,
  10383. MedType: med_type,
  10384. }
  10385. service.CreateHisPrescriptionInfoTemplate(prescription)
  10386. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10387. advices := items["advices"].([]interface{})
  10388. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10389. ctime := time.Now().Unix()
  10390. mtime := ctime
  10391. if len(advices) > 0 {
  10392. for _, advice := range advices {
  10393. var s models.HisPrescriptionAdviceTemplate
  10394. s.PrescriptionId = prescription.ID
  10395. s.AdviceType = 2
  10396. s.StopState = 2
  10397. s.ExecutionState = 2
  10398. s.Status = 1
  10399. s.UserOrgId = adminInfo.CurrentOrgId
  10400. s.CreatedTime = ctime
  10401. s.UpdatedTime = mtime
  10402. s.PatientId = patient_id
  10403. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10404. if errcode > 0 {
  10405. c.ServeFailJSONWithSGJErrorCode(errcode)
  10406. return
  10407. }
  10408. service.CreateHisPrescriptionAdviceTemplate(&s)
  10409. }
  10410. }
  10411. }
  10412. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10413. projects := items["project"].([]interface{})
  10414. if len(projects) > 0 {
  10415. for _, project := range projects {
  10416. var p models.HisPrescriptionProjectTemplate
  10417. p.PrescriptionId = prescription.ID
  10418. p.Ctime = time.Now().Unix()
  10419. p.Mtime = time.Now().Unix()
  10420. p.PatientId = patient_id
  10421. p.UserOrgId = adminInfo.CurrentOrgId
  10422. p.Status = 1
  10423. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10424. if errcode > 0 {
  10425. c.ServeFailJSONWithSGJErrorCode(errcode)
  10426. return
  10427. }
  10428. service.CreateHisPrescriptionProjectTemplate(&p)
  10429. }
  10430. }
  10431. }
  10432. }
  10433. c.ServeSuccessJSON(map[string]interface{}{
  10434. "msg": "创建成功",
  10435. })
  10436. }
  10437. }
  10438. } else {
  10439. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10440. return
  10441. }
  10442. } else {
  10443. err3 := service.CreateHisPrescriptionTemplate(template)
  10444. if err3 == nil {
  10445. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  10446. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  10447. if len(prescriptions) > 0 {
  10448. for _, item := range prescriptions {
  10449. items := item.(map[string]interface{})
  10450. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  10451. utils.ErrorLog("type")
  10452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10453. return
  10454. }
  10455. types := int64(items["type"].(float64))
  10456. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  10457. utils.ErrorLog("med_type")
  10458. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10459. return
  10460. }
  10461. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  10462. ctime := time.Now().Unix()
  10463. prescription := &models.HisPrescriptionInfoTemplate{
  10464. PatientId: patient_id,
  10465. UserOrgId: adminInfo.CurrentOrgId,
  10466. Ctime: ctime,
  10467. Mtime: ctime,
  10468. Type: types,
  10469. Modifier: adminInfo.AdminUser.Id,
  10470. Creator: adminInfo.AdminUser.Id,
  10471. Status: 1,
  10472. PTemplateId: template.ID,
  10473. MedType: med_type,
  10474. }
  10475. service.CreateHisPrescriptionInfoTemplate(prescription)
  10476. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  10477. advices := items["advices"].([]interface{})
  10478. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  10479. ctime := time.Now().Unix()
  10480. mtime := ctime
  10481. if len(advices) > 0 {
  10482. for _, advice := range advices {
  10483. var s models.HisPrescriptionAdviceTemplate
  10484. s.PrescriptionId = prescription.ID
  10485. s.AdviceType = 2
  10486. s.StopState = 2
  10487. s.ExecutionState = 2
  10488. s.Status = 1
  10489. s.UserOrgId = adminInfo.CurrentOrgId
  10490. s.CreatedTime = ctime
  10491. s.UpdatedTime = mtime
  10492. s.PatientId = patient_id
  10493. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  10494. if errcode > 0 {
  10495. c.ServeFailJSONWithSGJErrorCode(errcode)
  10496. return
  10497. }
  10498. service.CreateHisPrescriptionAdviceTemplate(&s)
  10499. }
  10500. }
  10501. }
  10502. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  10503. projects := items["project"].([]interface{})
  10504. if len(projects) > 0 {
  10505. for _, project := range projects {
  10506. var p models.HisPrescriptionProjectTemplate
  10507. p.PrescriptionId = prescription.ID
  10508. p.Ctime = time.Now().Unix()
  10509. p.Mtime = time.Now().Unix()
  10510. p.PatientId = patient_id
  10511. p.UserOrgId = adminInfo.CurrentOrgId
  10512. p.Status = 1
  10513. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  10514. if errcode > 0 {
  10515. c.ServeFailJSONWithSGJErrorCode(errcode)
  10516. return
  10517. }
  10518. service.CreateHisPrescriptionProjectTemplate(&p)
  10519. }
  10520. }
  10521. }
  10522. }
  10523. c.ServeSuccessJSON(map[string]interface{}{
  10524. "msg": "创建成功",
  10525. })
  10526. }
  10527. }
  10528. } else {
  10529. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10530. return
  10531. }
  10532. }
  10533. }
  10534. func (c *HisApiController) PreSettle() {
  10535. id, _ := c.GetInt64("id")
  10536. record_time := c.GetString("record_time")
  10537. his_patient_id, _ := c.GetInt64("his_patient_id")
  10538. timeLayout := "2006-01-02"
  10539. loc, _ := time.LoadLocation("Local")
  10540. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  10541. diagnosis_id := c.GetString("diagnosis")
  10542. sick_type, _ := c.GetInt64("sick_type")
  10543. reg_type, _ := c.GetInt64("p_type")
  10544. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10545. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  10546. if err != nil {
  10547. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10548. return
  10549. }
  10550. recordDateTime := theTime.Unix()
  10551. adminUser := c.GetAdminUserInfo()
  10552. var prescriptions []*models.HisPrescription
  10553. var start_time int64
  10554. var end_time int64
  10555. ids_str := c.GetString("ids")
  10556. ids_arr := strings.Split(ids_str, ",")
  10557. fmt.Println(reg_type)
  10558. if settle_accounts_type == 1 { //日结
  10559. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  10560. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  10561. } else {
  10562. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  10563. }
  10564. fmt.Println(prescriptions)
  10565. } else { //月结
  10566. start_time_str := c.GetString("start_time")
  10567. end_time_str := c.GetString("end_time")
  10568. timeLayout := "2006-01-02"
  10569. loc, _ := time.LoadLocation("Local")
  10570. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  10571. if err != nil {
  10572. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10573. return
  10574. }
  10575. recordStartTime := theStartTime.Unix()
  10576. start_time = recordStartTime
  10577. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  10578. if err != nil {
  10579. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10580. return
  10581. }
  10582. recordEndTime := theEndTime.Unix()
  10583. end_time = recordEndTime
  10584. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  10585. }
  10586. if reg_type == 1111 || reg_type == 1112 {
  10587. reg_type = 11
  10588. }
  10589. timestamp := time.Now().Unix()
  10590. tempTime := time.Unix(timestamp, 0)
  10591. timeFormat := tempTime.Format("20060102150405")
  10592. chrgBchno := rand.Intn(100000) + 10000
  10593. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  10594. strconv.FormatInt(his.PatientId, 10)
  10595. var ids []int64
  10596. for _, item := range prescriptions {
  10597. ids = append(ids, item.ID)
  10598. }
  10599. fmt.Println(ids)
  10600. var total float64
  10601. for _, item := range prescriptions {
  10602. fmt.Println(item)
  10603. if item.Type == 1 { //药品
  10604. for _, subItem := range item.HisDoctorAdviceInfo {
  10605. total = total + (subItem.Price * subItem.PrescribingNumber)
  10606. }
  10607. }
  10608. if item.Type == 2 { //项目
  10609. for _, subItem := range item.HisPrescriptionProject {
  10610. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10611. total = total + (subItem.Price * cnt)
  10612. }
  10613. }
  10614. for _, subItem := range item.HisAdditionalCharge {
  10615. total = total + (subItem.Price * float64(subItem.Count))
  10616. }
  10617. }
  10618. allTotal := fmt.Sprintf("%.2f", total)
  10619. totals, _ := strconv.ParseFloat(allTotal, 64)
  10620. order := &models.HisOrder{
  10621. UserOrgId: adminUser.CurrentOrgId,
  10622. HisPatientId: his.ID,
  10623. PatientId: id,
  10624. SettleAccountsDate: recordDateTime,
  10625. Ctime: time.Now().Unix(),
  10626. Mtime: time.Now().Unix(),
  10627. Status: 1,
  10628. OrderStatus: 1,
  10629. MdtrtId: his.Number,
  10630. Number: chrg_bchno,
  10631. MedfeeSumamt: totals,
  10632. SettleEndTime: end_time,
  10633. SettleStartTime: start_time,
  10634. SettleType: settle_accounts_type,
  10635. PsnPartAmt: totals,
  10636. PsnCashPay: totals,
  10637. PType: 2,
  10638. IsPre: 1,
  10639. MedType: strconv.Itoa(int(reg_type)),
  10640. Diagnosis: diagnosis_id,
  10641. }
  10642. err = service.CreateOrder(order)
  10643. if err != nil {
  10644. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  10645. return
  10646. }
  10647. var customs []*Custom
  10648. for _, item := range prescriptions {
  10649. fmt.Println(item.Type)
  10650. if item.Type == 1 { //药品
  10651. for _, subItem := range item.HisDoctorAdviceInfo {
  10652. cus := &Custom{
  10653. AdviceId: subItem.ID,
  10654. ProjectId: 0,
  10655. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  10656. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  10657. FeedetlSn: subItem.FeedetlSn,
  10658. Price: fmt.Sprintf("%.2f", subItem.Price),
  10659. MedListCodg: subItem.MedListCodg,
  10660. Type: 1,
  10661. }
  10662. customs = append(customs, cus)
  10663. }
  10664. }
  10665. if item.Type == 2 { //项目
  10666. for _, subItem := range item.HisPrescriptionProject {
  10667. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  10668. cus := &Custom{
  10669. AdviceId: 0,
  10670. ProjectId: subItem.ID,
  10671. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  10672. Cut: fmt.Sprintf("%.2f", cnt),
  10673. FeedetlSn: subItem.FeedetlSn,
  10674. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  10675. MedListCodg: subItem.MedListCodg,
  10676. Type: 2,
  10677. }
  10678. customs = append(customs, cus)
  10679. }
  10680. }
  10681. for _, item := range item.HisAdditionalCharge {
  10682. cus := &Custom{
  10683. ItemId: item.ID,
  10684. AdviceId: 0,
  10685. ProjectId: 0,
  10686. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  10687. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  10688. FeedetlSn: item.FeedetlSn,
  10689. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  10690. MedListCodg: item.XtHisAddtionConfig.Code,
  10691. Type: 3,
  10692. }
  10693. customs = append(customs, cus)
  10694. }
  10695. }
  10696. fmt.Println(customs)
  10697. for _, item := range customs {
  10698. var advice_id int64 = 0
  10699. var project_id int64 = 0
  10700. var item_id int64 = 0
  10701. var types int64 = 0
  10702. if item.Type == 1 {
  10703. advice_id = item.AdviceId
  10704. project_id = 0
  10705. item_id = 0
  10706. } else if item.Type == 2 {
  10707. advice_id = 0
  10708. item_id = 0
  10709. project_id = item.ProjectId
  10710. } else if item.Type == 3 {
  10711. advice_id = 0
  10712. item_id = item.ItemId
  10713. project_id = 0
  10714. }
  10715. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  10716. cut, _ := strconv.ParseFloat(item.Cut, 32)
  10717. pric, _ := strconv.ParseFloat(item.Price, 32)
  10718. info := &models.HisOrderInfo{
  10719. OrderNumber: order.Number,
  10720. UploadDate: time.Now().Unix(),
  10721. AdviceId: advice_id,
  10722. DetItemFeeSumamt: detItemFeeSumamt,
  10723. Cnt: cut,
  10724. Pric: pric,
  10725. PatientId: id,
  10726. Status: 1,
  10727. Mtime: time.Now().Unix(),
  10728. Ctime: time.Now().Unix(),
  10729. UserOrgId: adminUser.CurrentOrgId,
  10730. HisPatientId: his.ID,
  10731. OrderId: order.ID,
  10732. ProjectId: project_id,
  10733. Type: types,
  10734. ItemId: item_id,
  10735. }
  10736. service.CreateOrderInfo(info)
  10737. }
  10738. his.SickType = sick_type
  10739. service.UpdataHisPateint(&his)
  10740. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  10741. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  10742. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  10743. if err == nil {
  10744. c.ServeSuccessJSON(map[string]interface{}{
  10745. "msg": "结算成功",
  10746. })
  10747. }
  10748. }
  10749. type CustomOrderInfo struct {
  10750. Name string
  10751. Spec string
  10752. Unit string
  10753. Count float64
  10754. Price float64
  10755. Total float64
  10756. }
  10757. func (c *HisApiController) GetPrivateExpensesInfo() {
  10758. order_id, _ := c.GetInt64("id", 0)
  10759. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  10760. order, _ := service.GetHisOrderByID(order_id)
  10761. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  10762. if order.ID == 0 {
  10763. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  10764. return
  10765. }
  10766. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  10767. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  10768. org_id := c.GetAdminUserInfo().CurrentOrgId
  10769. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  10770. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  10771. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  10772. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  10773. //orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  10774. //var orderInfos_four []*models.HisOrderInfoTwo
  10775. //for _, item := range orderInfos_three {
  10776. // if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  10777. // item.HisPrescriptionProject.IsCheckTeam = 1
  10778. // orderInfos_four = append(orderInfos_four, item)
  10779. //
  10780. // }
  10781. // if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  10782. // item.HisPrescriptionProject.IsCheckTeam = 2
  10783. // orderInfos_two = append(orderInfos_two, item)
  10784. // }
  10785. //}
  10786. //new_order_info := RemoveRepeatedTeam(orderInfos_four)
  10787. //var cus_slice []CustomOrderInfo
  10788. //for _, item := range new_order_info {
  10789. // var cus CustomOrderInfo
  10790. // cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  10791. // cus.Unit = ""
  10792. // cus.Spec = ""
  10793. // var total float64
  10794. // for _, subItem := range orderInfos_four {
  10795. // if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  10796. // total = total + subItem.DetItemFeeSumamt
  10797. // fmt.Println(subItem.DetItemFeeSumamt)
  10798. // }
  10799. // }
  10800. // cus.Count = 1
  10801. // cus.Total = total
  10802. // cus_slice = append(cus_slice, cus)
  10803. //}
  10804. orderInfos = append(orderInfos, orderInfos_two...)
  10805. //if c.GetAdminUserInfo().CurrentOrgId != 10138 || c.GetAdminUserInfo().CurrentOrgId != 10278 {
  10806. //orderInfos = append(orderInfos, orderInfos_three...)
  10807. //}/**/
  10808. patient, _ := service.GetFaPiaoPatientByID(org_id, order.PatientId)
  10809. c.ServeSuccessJSON(map[string]interface{}{
  10810. "order": order,
  10811. "order_info": orderInfos,
  10812. "patient": patient,
  10813. "admin_info": adminInfo,
  10814. "his": his,
  10815. "current_admin": role,
  10816. "org_config": miConfig,
  10817. //"new_order_info": cus_slice,
  10818. })
  10819. }
  10820. func (this *HisApiController) ChangeMedType() {
  10821. med_type := this.GetString("med_type")
  10822. old_med_type := this.GetString("old_med_type")
  10823. ids := this.GetString("ids")
  10824. settle_type, _ := this.GetInt64("settle_type")
  10825. start_time := this.GetString("start_time")
  10826. end_time := this.GetString("end_time")
  10827. ids_arr := strings.Split(ids, ",")
  10828. if settle_type == 1 { //日结
  10829. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  10830. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  10831. prescription.MedType = med_type
  10832. err := service.SaveHisPrescriptionTwo(&prescription)
  10833. if err == nil {
  10834. this.ServeSuccessJSON(map[string]interface{}{
  10835. "msg": "修改成功",
  10836. })
  10837. } else {
  10838. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10839. return
  10840. }
  10841. } else if settle_type == 2 {
  10842. timeLayout := "2006-01-02"
  10843. loc, _ := time.LoadLocation("Local")
  10844. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10845. if err != nil {
  10846. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10847. return
  10848. }
  10849. recordStartTime := theStartTime.Unix()
  10850. start_time_timestamp := recordStartTime
  10851. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  10852. if err != nil {
  10853. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10854. return
  10855. }
  10856. recordEndTime := theEndTime.Unix()
  10857. end_time_timestamp := recordEndTime
  10858. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  10859. if updateErr == nil {
  10860. this.ServeSuccessJSON(map[string]interface{}{
  10861. "msg": "修改成功",
  10862. })
  10863. } else {
  10864. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  10865. return
  10866. }
  10867. }
  10868. }
  10869. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  10870. patient_id, _ := c.GetInt64("patient_id")
  10871. his_patient_id, _ := c.GetInt64("his_patient_id")
  10872. record_date := c.GetString("record_date")
  10873. start_time := c.GetString("start_time")
  10874. end_time := c.GetString("end_time")
  10875. order_status, _ := c.GetInt64("type", 0)
  10876. p_type, _ := c.GetInt64("p_type", 0)
  10877. order_id, _ := c.GetInt64("order_id", 0)
  10878. timeLayout := "2006-01-02"
  10879. loc, _ := time.LoadLocation("Local")
  10880. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10881. if err != nil {
  10882. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10883. return
  10884. }
  10885. recordDateTime := theTime.Unix()
  10886. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10887. if err != nil {
  10888. }
  10889. startRecordDateTime := startTime.Unix()
  10890. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10891. if err != nil {
  10892. }
  10893. endRecordDateTime := endTime.Unix()
  10894. admin := c.GetAdminUserInfo()
  10895. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  10896. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  10897. order, _ := service.GetHisOrderByID(order_id)
  10898. var monthPrescriptions []*models.HisPrescription
  10899. if order_status == 1 || order_status == 0 {
  10900. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10901. } else if order_status == 2 {
  10902. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  10903. }
  10904. var settle_total float64
  10905. for _, item := range monthPrescriptions {
  10906. if len(item.HisPrescriptionProject) > 0 {
  10907. for _, subItem := range item.HisPrescriptionProject {
  10908. count, _ := strconv.ParseFloat(subItem.Count, 64)
  10909. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  10910. settle_total = settle_total + total
  10911. }
  10912. }
  10913. if len(item.HisDoctorAdviceInfo) > 0 {
  10914. for _, subItem := range item.HisDoctorAdviceInfo {
  10915. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  10916. settle_total = settle_total + total
  10917. }
  10918. }
  10919. }
  10920. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  10921. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  10922. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  10923. month_p_info, _ := service.FindPatientPrescriptionInfoTen(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  10924. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  10925. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  10926. //获取所有科室信息
  10927. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  10928. var dia string
  10929. for _, item := range month_p_info {
  10930. if len(dia) == 0 {
  10931. dia = item.Diagnosis
  10932. } else {
  10933. dia = dia + "," + item.Diagnosis
  10934. }
  10935. }
  10936. dia_arr := removeDuplicates(strings.Split(dia, ","))
  10937. dia_arr = removeEmptyStrings(dia_arr)
  10938. c.ServeSuccessJSON(map[string]interface{}{
  10939. "his_info": his_patient_info,
  10940. "xt_info": xt_patient_info,
  10941. "case_history": case_history,
  10942. "info": patientPrescriptionInfo,
  10943. "last_info": lastPatientPrescriptionInfo,
  10944. "month_prescriptions": monthPrescriptions,
  10945. "order": order,
  10946. "doctors": doctors,
  10947. "department": department,
  10948. "settle_total": settle_total,
  10949. "dia_arr": dia_arr,
  10950. })
  10951. return
  10952. }
  10953. func removeEmptyStrings(input []string) []string {
  10954. var output []string
  10955. for _, s := range input {
  10956. if s != "" {
  10957. output = append(output, s)
  10958. }
  10959. }
  10960. return output
  10961. }
  10962. func removeDuplicates(input []string) []string {
  10963. seen := make(map[string]bool)
  10964. output := []string{}
  10965. for _, s := range input {
  10966. if _, exists := seen[s]; !exists {
  10967. seen[s] = true
  10968. output = append(output, s)
  10969. }
  10970. }
  10971. return output
  10972. }
  10973. func (c *HisApiController) GetHisMonthPatientInfo() {
  10974. patient_id, _ := c.GetInt64("patient_id")
  10975. his_patient_id, _ := c.GetInt64("his_patient_id")
  10976. record_date := c.GetString("record_date")
  10977. number := c.GetString("number")
  10978. start_time := c.GetString("start_time")
  10979. end_time := c.GetString("end_time")
  10980. p_type, _ := c.GetInt64("p_type")
  10981. timeLayout := "2006-01-02"
  10982. loc, _ := time.LoadLocation("Local")
  10983. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  10984. if err != nil {
  10985. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  10986. return
  10987. }
  10988. recordDateTime := theTime.Unix()
  10989. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  10990. if err != nil {
  10991. }
  10992. startRecordDateTime := startTime.Unix()
  10993. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  10994. if err != nil {
  10995. }
  10996. endRecordDateTime := endTime.Unix()
  10997. admin := c.GetAdminUserInfo()
  10998. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  10999. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  11000. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  11001. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  11002. var settle_total float64
  11003. for _, item := range monthPrescriptions {
  11004. if len(item.HisPrescriptionProject) > 0 {
  11005. for _, subItem := range item.HisPrescriptionProject {
  11006. count, _ := strconv.ParseFloat(subItem.Count, 64)
  11007. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  11008. settle_total = settle_total + total
  11009. }
  11010. }
  11011. if len(item.HisDoctorAdviceInfo) > 0 {
  11012. for _, subItem := range item.HisDoctorAdviceInfo {
  11013. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  11014. settle_total = settle_total + total
  11015. }
  11016. }
  11017. }
  11018. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  11019. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  11020. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  11021. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  11022. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  11023. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  11024. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  11025. //获取所有科室信息
  11026. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  11027. c.ServeSuccessJSON(map[string]interface{}{
  11028. "his_info": his_patient_info,
  11029. "xt_info": xt_patient_info,
  11030. "case_history": case_history,
  11031. "info": patientPrescriptionInfo,
  11032. "month_prescriptions": monthPrescriptions,
  11033. "order": order,
  11034. "doctors": doctors,
  11035. "department": department,
  11036. "count": count,
  11037. "drugStockConfig": drugStockConfig,
  11038. "last_info": lastPatientPrescriptionInfo,
  11039. "settle_total": settle_total,
  11040. })
  11041. return
  11042. }
  11043. func (c *HisApiController) GetAllOrder() {
  11044. org_id := c.GetAdminUserInfo().CurrentOrgId
  11045. orders, _ := service.GetNewHisOrderList(org_id)
  11046. c.ServeSuccessJSON(map[string]interface{}{
  11047. "order": orders,
  11048. })
  11049. return
  11050. }
  11051. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  11052. newArr = make([]*models.HisOrderInfoTwo, 0)
  11053. for i := 0; i < len(arr); i++ {
  11054. repeat := false
  11055. for j := i + 1; j < len(arr); j++ {
  11056. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  11057. repeat = true
  11058. break
  11059. }
  11060. }
  11061. if !repeat {
  11062. newArr = append(newArr, arr[i])
  11063. }
  11064. }
  11065. return
  11066. }
  11067. // 修改处方退库操作 参数传修改之前的处方数据
  11068. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  11069. if advice.ExecutionState == 1 {
  11070. //查询该病人该药品是否有库存记录
  11071. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  11072. if errcode == gorm.ErrRecordNotFound {
  11073. } else {
  11074. //退库
  11075. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  11076. if advice.PrescribingNumberUnit == drug.MinUnit {
  11077. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11078. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11079. //退库
  11080. warehouseInfo := models.DrugWarehouseInfo{
  11081. StockMinNumber: prescribingNumber,
  11082. }
  11083. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  11084. operation_time := time.Now().Unix()
  11085. creater := advice.AdviceDoctor
  11086. ctime := time.Now().Unix()
  11087. timeStr := time.Now().Format("2006-01-02")
  11088. timeArr := strings.Split(timeStr, "-")
  11089. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11090. total = total + 1
  11091. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11092. cancelStock := models.DrugCancelStock{
  11093. OrderNumber: orderNumber,
  11094. OperaTime: operation_time,
  11095. OrgId: advice.UserOrgId,
  11096. Creater: creater,
  11097. Ctime: ctime,
  11098. Status: 1,
  11099. ReturnTime: advice.AdviceDate,
  11100. Dealer: info.Dealer,
  11101. Manufacturer: info.Manufacturer,
  11102. Type: 1,
  11103. }
  11104. service.AddSigleDrugCancelStock(&cancelStock)
  11105. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11106. dealer, _ := service.GetDealerById(info.Dealer)
  11107. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11108. cancelStockInfo := models.DrugCancelStockInfo{
  11109. OrderNumber: cancelInfo.OrderNumber,
  11110. CancelStockId: cancelInfo.ID,
  11111. DrugId: info.DrugId,
  11112. Count: info.Count,
  11113. Status: 1,
  11114. Ctime: ctime,
  11115. OrgId: advice.UserOrgId,
  11116. Type: 1,
  11117. Manufacturer: manufactureName.ManufacturerName,
  11118. Dealer: dealer.DealerName,
  11119. Total: 0,
  11120. RetailPrice: info.RetailPrice,
  11121. RetailTotalPrice: info.RetailTotalPrice,
  11122. Price: info.Price,
  11123. RegisterAccount: "",
  11124. Remark: info.Remark,
  11125. BatchNumber: info.BatchNumber,
  11126. MaxUnit: info.CountUnit,
  11127. ProductDate: info.ProductDate,
  11128. ExpiryDate: info.ExpiryDate,
  11129. BatchNumberId: info.WarehouseInfoId,
  11130. }
  11131. flow := models.DrugFlow{
  11132. WarehousingId: 0,
  11133. DrugId: info.DrugId,
  11134. Number: "",
  11135. BatchNumber: info.BatchNumber,
  11136. Count: info.Count,
  11137. UserOrgId: advice.UserOrgId,
  11138. PatientId: 0,
  11139. SystemTime: ctime,
  11140. ConsumableType: 4,
  11141. IsSys: 0,
  11142. WarehousingOrder: "",
  11143. WarehouseOutId: 0,
  11144. WarehouseOutOrderNumber: "",
  11145. IsEdit: 0,
  11146. CancelStockId: cancelStock.ID,
  11147. CancelOrderNumber: cancelStock.OrderNumber,
  11148. Manufacturer: info.Manufacturer,
  11149. Dealer: info.Dealer,
  11150. Creator: advice.UserOrgId,
  11151. UpdateCreator: 0,
  11152. Status: 1,
  11153. Ctime: time.Now().Unix(),
  11154. Mtime: 0,
  11155. Price: info.Price,
  11156. WarehousingDetailId: 0,
  11157. WarehouseOutDetailId: 0,
  11158. CancelOutDetailId: 0,
  11159. ExpireDate: info.ExpiryDate,
  11160. ProductDate: info.ProductDate,
  11161. MaxUnit: info.CountUnit,
  11162. MinUnit: "",
  11163. }
  11164. service.CreatedCancelStock(cancelStockInfo)
  11165. service.CreateDrugFlowOne(flow)
  11166. } else {
  11167. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  11168. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  11169. if advice.PrescribingNumberUnit == drug.MaxUnit {
  11170. warehouseInfo := models.DrugWarehouseInfo{
  11171. StockMinNumber: prescribingNumber,
  11172. }
  11173. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  11174. }
  11175. operation_time := time.Now().Unix()
  11176. creater := advice.AdviceDoctor
  11177. ctime := time.Now().Unix()
  11178. timeStr := time.Now().Format("2006-01-02")
  11179. timeArr := strings.Split(timeStr, "-")
  11180. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  11181. total = total + 1
  11182. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  11183. cancelStock := models.DrugCancelStock{
  11184. OrderNumber: orderNumber,
  11185. OperaTime: operation_time,
  11186. OrgId: advice.UserOrgId,
  11187. Creater: creater,
  11188. Ctime: ctime,
  11189. Status: 1,
  11190. ReturnTime: advice.AdviceDate,
  11191. Dealer: info.Dealer,
  11192. Manufacturer: info.Manufacturer,
  11193. Type: 1,
  11194. }
  11195. service.AddSigleDrugCancelStock(&cancelStock)
  11196. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  11197. dealer, _ := service.GetDealerById(info.Dealer)
  11198. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  11199. cancelStockInfo := models.DrugCancelStockInfo{
  11200. OrderNumber: cancelInfo.OrderNumber,
  11201. CancelStockId: cancelInfo.ID,
  11202. DrugId: info.DrugId,
  11203. Count: info.Count,
  11204. Status: 1,
  11205. Ctime: ctime,
  11206. OrgId: advice.UserOrgId,
  11207. Type: 1,
  11208. Manufacturer: manufactureName.ManufacturerName,
  11209. Dealer: dealer.DealerName,
  11210. Total: 0,
  11211. RetailPrice: info.RetailPrice,
  11212. RetailTotalPrice: info.RetailTotalPrice,
  11213. Price: info.Price,
  11214. RegisterAccount: "",
  11215. Remark: info.Remark,
  11216. BatchNumber: info.BatchNumber,
  11217. MaxUnit: info.CountUnit,
  11218. ProductDate: info.ProductDate,
  11219. ExpiryDate: info.ExpiryDate,
  11220. BatchNumberId: info.WarehouseInfoId,
  11221. }
  11222. flow := models.DrugFlow{
  11223. WarehousingId: 0,
  11224. DrugId: info.DrugId,
  11225. Number: "",
  11226. BatchNumber: info.BatchNumber,
  11227. Count: info.Count,
  11228. UserOrgId: advice.UserOrgId,
  11229. PatientId: 0,
  11230. SystemTime: ctime,
  11231. ConsumableType: 4,
  11232. IsSys: 0,
  11233. WarehousingOrder: "",
  11234. WarehouseOutId: 0,
  11235. WarehouseOutOrderNumber: "",
  11236. IsEdit: 0,
  11237. CancelStockId: cancelStock.ID,
  11238. CancelOrderNumber: cancelStock.OrderNumber,
  11239. Manufacturer: info.Manufacturer,
  11240. Dealer: info.Dealer,
  11241. Creator: advice.AdviceDoctor,
  11242. UpdateCreator: 0,
  11243. Status: 1,
  11244. Ctime: time.Now().Unix(),
  11245. Mtime: 0,
  11246. Price: info.Price,
  11247. WarehousingDetailId: 0,
  11248. WarehouseOutDetailId: 0,
  11249. CancelOutDetailId: 0,
  11250. ExpireDate: info.ExpiryDate,
  11251. ProductDate: info.ProductDate,
  11252. MaxUnit: info.CountUnit,
  11253. MinUnit: "",
  11254. }
  11255. service.CreatedCancelStock(cancelStockInfo)
  11256. service.CreateDrugFlowOne(flow)
  11257. }
  11258. }
  11259. }
  11260. return err
  11261. }
  11262. func (this *HisApiController) DeleteNCDS() {
  11263. id, _ := this.GetInt64("id", 0)
  11264. if id > 0 {
  11265. service.DeletePsnNCDSRecordById(id)
  11266. this.ServeSuccessJSON(map[string]interface{}{
  11267. "msg": "删除成功",
  11268. })
  11269. } else {
  11270. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  11271. return
  11272. }
  11273. }
  11274. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  11275. id, _ := c.GetInt64("id")
  11276. advice, _ := service.GetHisDoctorAdviceInfo(id)
  11277. c.ServeSuccessJSON(map[string]interface{}{
  11278. "advice": advice,
  11279. })
  11280. return
  11281. }
  11282. func (c *HisApiController) GetHisMonthChargePatientList() {
  11283. record_date := c.GetString("record_date")
  11284. start_time := c.GetString("start_time")
  11285. end_time := c.GetString("end_time")
  11286. timeLayout := "2006-01-02"
  11287. loc, _ := time.LoadLocation("Local")
  11288. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  11289. if err != nil {
  11290. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11291. return
  11292. }
  11293. if err != nil {
  11294. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  11295. return
  11296. }
  11297. recordDateTime := theTime.Unix()
  11298. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  11299. if err != nil {
  11300. }
  11301. startRecordDateTime := startTime.Unix()
  11302. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  11303. if err != nil {
  11304. }
  11305. endRecordDateTime := endTime.Unix()
  11306. adminInfo := c.GetAdminUserInfo()
  11307. var tempMonthChargePatients []*service.MonthChargePatients
  11308. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  11309. for _, item := range tempPatients {
  11310. //过滤没有处方的
  11311. if len(item.HisPrescription) == 0 {
  11312. tempMonthChargePatients = append(tempMonthChargePatients, item)
  11313. }
  11314. }
  11315. c.ServeSuccessJSON(map[string]interface{}{
  11316. "list": tempMonthChargePatients,
  11317. })
  11318. }
  11319. // PrescriptionDifference 医嘱数量差值结构体
  11320. type PrescriptionDrugDifference struct {
  11321. DrugID int64 //基础库药品id
  11322. ID int64 //医嘱id
  11323. Difference float64 //差值
  11324. Unit string //单位
  11325. }
  11326. type PrescriptionGoodDifference struct {
  11327. GoodID int64 //基础库项目耗材id
  11328. ID int64 //医嘱id
  11329. Difference int64 //差值
  11330. Unit string //单位
  11331. Type int64 //类型
  11332. }
  11333. type EditCustomData struct {
  11334. adviceList []*models.HisDoctorAdviceInfo
  11335. projectList []*models.HisPrescriptionProject
  11336. }
  11337. type SrcCustomData struct {
  11338. adviceList []*models.HisDoctorAdviceInfo
  11339. projectList []*models.HisPrescriptionProject
  11340. }
  11341. // ComparePrescriptions 比较两个医嘱切片中相同药品的数量差值
  11342. func ComparePrescriptions(firstPrescription, secondPrescription []*models.HisDoctorAdviceInfo) []*PrescriptionDrugDifference {
  11343. differences := make([]*PrescriptionDrugDifference, 0)
  11344. // 创建一个 map 来存储第一个切片中的药品信息
  11345. firstMap := make(map[int64]*models.HisDoctorAdviceInfo)
  11346. for _, advice := range firstPrescription {
  11347. firstMap[advice.DrugId] = advice
  11348. }
  11349. // 遍历第二个切片中的药品信息,并比较数量差值
  11350. for _, advice := range secondPrescription {
  11351. if firstAdvice, ok := firstMap[advice.DrugId]; ok {
  11352. diff := &PrescriptionDrugDifference{
  11353. DrugID: advice.DrugId,
  11354. ID: firstAdvice.ID,
  11355. Difference: advice.PrescribingNumber - firstAdvice.PrescribingNumber,
  11356. Unit: firstAdvice.PrescribingNumberUnit,
  11357. }
  11358. differences = append(differences, diff)
  11359. }
  11360. }
  11361. return differences
  11362. }
  11363. // CompareGoodPrescriptions 比较两个医嘱切片中相同耗材项目的数量差值
  11364. func CompareGoodPrescriptions(firstPrescription, secondPrescription []*models.HisPrescriptionProject) []*PrescriptionGoodDifference {
  11365. differences := make([]*PrescriptionGoodDifference, 0)
  11366. // 创建一个 map 来存储第一个切片中的耗材信息
  11367. firstMap := make(map[int64]*models.HisPrescriptionProject)
  11368. for _, good := range firstPrescription {
  11369. firstMap[good.ProjectId] = good
  11370. }
  11371. // 遍历第二个切片中的耗材信息,并比较数量差值
  11372. for _, good := range secondPrescription {
  11373. if firstGood, ok := firstMap[good.ProjectId]; ok {
  11374. count, _ := strconv.ParseInt(good.Count, 10, 64)
  11375. firstCount, _ := strconv.ParseInt(firstGood.Count, 10, 64)
  11376. diff := &PrescriptionGoodDifference{
  11377. GoodID: good.ProjectId,
  11378. ID: firstGood.ID,
  11379. Difference: count - firstCount,
  11380. Unit: firstGood.Unit,
  11381. Type: firstGood.Type,
  11382. }
  11383. differences = append(differences, diff)
  11384. }
  11385. }
  11386. return differences
  11387. }
  11388. func GetCompareData(dataBody map[string]interface{}) (editCustomData EditCustomData, srcCustomData SrcCustomData) {
  11389. var adviceList []*models.HisDoctorAdviceInfo
  11390. var projectList []*models.HisPrescriptionProject
  11391. var advice_ids []int64
  11392. var project_ids []int64
  11393. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  11394. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  11395. //var tempPrescription *models.HisPrescriptionProjectscription
  11396. if len(prescriptions) > 0 {
  11397. for _, item := range prescriptions {
  11398. items := item.(map[string]interface{})
  11399. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  11400. advices := items["advices"].([]interface{})
  11401. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  11402. groupNo := int64(0)
  11403. ctime := time.Now().Unix()
  11404. mtime := ctime
  11405. if len(advices) > 0 {
  11406. for _, advice := range advices {
  11407. var s models.HisDoctorAdviceInfo
  11408. s.AdviceType = 2
  11409. s.StopState = 2
  11410. s.ExecutionState = 2
  11411. s.Status = 1
  11412. s.Groupno = groupNo
  11413. s.CreatedTime = ctime
  11414. s.UpdatedTime = mtime
  11415. s.IsSettle = 2
  11416. SetAdviceWithJSON(&s, advice.(map[string]interface{}))
  11417. //存储切片中
  11418. if s.ID > 0 {
  11419. advice_ids = append(advice_ids, s.ID)
  11420. adviceList = append(adviceList, &s)
  11421. }
  11422. }
  11423. }
  11424. }
  11425. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  11426. projects := items["project"].([]interface{})
  11427. if len(projects) > 0 {
  11428. for _, project := range projects {
  11429. var p models.HisPrescriptionProject
  11430. p.Ctime = time.Now().Unix()
  11431. p.Mtime = time.Now().Unix()
  11432. p.Status = 1
  11433. SetProjectWithJSON(&p, project.(map[string]interface{}))
  11434. if p.ID > 0 {
  11435. project_ids = append(project_ids, p.ID)
  11436. projectList = append(projectList, &p)
  11437. }
  11438. }
  11439. }
  11440. }
  11441. }
  11442. }
  11443. }
  11444. editCustomData.projectList = projectList
  11445. editCustomData.adviceList = adviceList
  11446. list, _ := service.GetBatchHisDoctorAdviceByIDs(advice_ids)
  11447. list2, _ := service.GetBatchHisProjectByIDs(project_ids)
  11448. srcCustomData.adviceList = list
  11449. srcCustomData.projectList = list2
  11450. return
  11451. }