his_api_controller.go 339KB

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