his_api_controller.go 308KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128
  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 {
  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. if pharmacyConfig.IsOpen != 1 {
  1144. if device_number != number_count {
  1145. // 查询该药品最后一次出库记录
  1146. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  1147. //回退库存
  1148. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1149. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  1150. }
  1151. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1152. var stock_max_number int64
  1153. var stock_min_number int64
  1154. if number_count >= drug.MinNumber {
  1155. stock_max_number = device_number / drug.MinNumber
  1156. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  1157. stock_min_number = device_number % drug.MinNumber
  1158. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  1159. } else {
  1160. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  1161. }
  1162. }
  1163. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  1164. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  1165. }
  1166. //删除记录
  1167. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  1168. //查询默认仓库剩余多少库存
  1169. var sum_count int64
  1170. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, druginfo.OrgId, drug_id)
  1171. for _, its := range stockInfo {
  1172. sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
  1173. }
  1174. service.UpdateBaseDrugSumTwo(drug_id, sum_count, druginfo.OrgId)
  1175. }
  1176. }
  1177. }
  1178. }
  1179. }
  1180. //保存处方开药
  1181. if drugOutConfig.IsOpen == 1 {
  1182. //修改处方
  1183. for _, advice := range advices {
  1184. var drug_id int64
  1185. var prescribing_number float64
  1186. var prescribingNumberUnit string
  1187. var prescribingNumber string
  1188. var adviceId int64
  1189. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  1190. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  1191. }
  1192. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  1193. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  1194. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  1195. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  1196. }
  1197. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  1198. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  1199. }
  1200. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  1201. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  1202. }
  1203. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  1204. if drug.ID == 0 {
  1205. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1206. return
  1207. }
  1208. //查询药品的所有库存
  1209. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId, storeConfig.DrugStorehouseOut)
  1210. var total_count int64
  1211. for _, it := range list {
  1212. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  1213. }
  1214. totals := strconv.FormatInt(total_count, 10)
  1215. //查询该药品是否存在开药记录
  1216. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  1217. //新增处方
  1218. if advicelist.ID == 0 {
  1219. //查询最新批次库存
  1220. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1221. var batch_number_count int64
  1222. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1223. batch_number_counts := strconv.FormatInt(batch_number_count, 10)
  1224. all_count, _ := strconv.ParseFloat(totals, 64)
  1225. if prescribingNumberUnit == drug.MinUnit {
  1226. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1227. if drug.IsUse != 1 {
  1228. if prescribing_number > all_count {
  1229. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1230. return
  1231. }
  1232. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1233. if prescribing_number > batch_number_all_count {
  1234. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1235. return
  1236. }
  1237. }
  1238. }
  1239. } else {
  1240. if prescribingNumberUnit == drug.MaxUnit {
  1241. batch_number_all_count, _ := strconv.ParseFloat(batch_number_counts, 64)
  1242. num := prescribing_number * float64(drug.MinNumber)
  1243. if drug.IsUse != 1 {
  1244. if num > all_count {
  1245. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1246. return
  1247. }
  1248. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1249. if prescribing_number > batch_number_all_count {
  1250. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1251. return
  1252. }
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. //修改处方
  1259. if advicelist.ID > 0 {
  1260. //查询最新批次库存
  1261. info, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1262. var batch_number_count int64
  1263. batch_number_count = info.StockMaxNumber*drug.MinNumber + info.StockMinNumber
  1264. var device_number int64
  1265. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  1266. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1267. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1268. device_number = prescribingNumberInt * drug.MinNumber
  1269. }
  1270. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  1271. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  1272. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  1273. device_number = prescribingNumberInt
  1274. }
  1275. var number_count int64
  1276. if prescribingNumberUnit == drug.MaxUnit {
  1277. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1278. number_count = prescribingNumberInt * drug.MinNumber
  1279. }
  1280. if prescribingNumberUnit == drug.MinUnit {
  1281. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  1282. number_count = prescribingNumberInt
  1283. }
  1284. //如果修改的数量大于之前修改的数量
  1285. if (number_count - device_number) > 0 {
  1286. //如果修改的差数量 大于库存数量
  1287. if drug.IsUse != 1 {
  1288. if (number_count - device_number) > total_count {
  1289. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  1290. return
  1291. }
  1292. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1293. if (number_count - device_number) > batch_number_count {
  1294. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(info.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(info.StockMinNumber, 10) + drug.MinUnit)
  1295. return
  1296. }
  1297. }
  1298. if adminInfo.CurrentOrgId == 10215 || adminInfo.CurrentOrgId == 10164 || adminInfo.CurrentOrgId == 3877 {
  1299. //查询历史出库数据总批次
  1300. // 查询该药品最后一次出库记录
  1301. outInfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(drug_id, patient_id, recordDateTime, adviceId)
  1302. var out_count int64
  1303. var in_count int64
  1304. var stock_max_number int64
  1305. var stock_min_number int64
  1306. for _, it := range outInfo {
  1307. if it.CountUnit == drug.MaxUnit {
  1308. it.Count = it.Count * drug.MinNumber
  1309. }
  1310. out_count += it.Count
  1311. warehouseInfoList, _ := service.GetDrugWarehouseInfoById(it.WarehouseInfoId)
  1312. stock_max_number = warehouseInfoList.StockMaxNumber
  1313. stock_min_number = warehouseInfoList.StockMinNumber
  1314. in_count = warehouseInfoList.StockMaxNumber*drug.MinNumber + warehouseInfoList.StockMinNumber
  1315. }
  1316. if out_count > 0 {
  1317. if (number_count - device_number) > in_count {
  1318. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(stock_max_number, 10) + drug.MaxUnit + strconv.FormatInt(stock_min_number, 10) + drug.MinUnit)
  1319. return
  1320. }
  1321. }
  1322. // 未出库
  1323. if out_count == 0 {
  1324. var sum_in_count int64
  1325. warehouseInfo, _ := service.FindLastDrugWarehousingInfoByID(drug_id, storeConfig.DrugStorehouseOut)
  1326. sum_in_count = warehouseInfo.StockMaxNumber*drug.MinNumber + warehouseInfo.StockMinNumber
  1327. //如果修改的数量大于有库存的第一个批次
  1328. if number_count > sum_in_count {
  1329. c.ServeDynamicFailJsonSend(drug.DrugName + "该批次剩余库存不足,剩余库存:" + strconv.FormatInt(warehouseInfo.StockMaxNumber, 10) + drug.MaxUnit + strconv.FormatInt(warehouseInfo.StockMinNumber, 10) + drug.MinUnit)
  1330. return
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }
  1339. }
  1340. }
  1341. }
  1342. }
  1343. }
  1344. }
  1345. }
  1346. if stockConfig.IsOpen == 1 {
  1347. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1348. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1349. if len(prescriptions) > 0 {
  1350. for _, item := range prescriptions {
  1351. items := item.(map[string]interface{})
  1352. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1353. projects := items["project"].([]interface{})
  1354. if len(projects) > 0 {
  1355. for _, project := range projects {
  1356. var project_id int64
  1357. var project_type int64
  1358. var totals float64
  1359. var project_name string
  1360. var parsetotal int64
  1361. var id int64
  1362. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  1363. id = int64(project.(map[string]interface{})["id"].(float64))
  1364. }
  1365. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  1366. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  1367. }
  1368. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  1369. project_type = int64(project.(map[string]interface{})["type"].(float64))
  1370. }
  1371. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  1372. total, _ := project.(map[string]interface{})["total"].(string)
  1373. totals, _ = strconv.ParseFloat(total, 64)
  1374. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  1375. }
  1376. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  1377. project_name = project.(map[string]interface{})["project_name"].(string)
  1378. }
  1379. if project_type == 3 {
  1380. //查找该耗材的出库记录
  1381. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  1382. if len(goodWarehouseInfo) == 0 {
  1383. //查询耗材库存
  1384. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  1385. var stock_count int64
  1386. for _, it := range list {
  1387. stock_count += it.StockCount
  1388. }
  1389. stock_counts := strconv.FormatInt(stock_count, 10)
  1390. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  1391. if totals > stock_total_count {
  1392. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  1393. return
  1394. }
  1395. //查找今日该患者已经出库的所有耗材
  1396. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1397. for _, item := range goodList {
  1398. //回退库存
  1399. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  1400. }
  1401. //删除记录
  1402. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1403. }
  1404. if len(goodWarehouseInfo) > 0 {
  1405. //查询该患者耗材的历史数据
  1406. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  1407. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  1408. //数量发生改变
  1409. if parsetotal != count {
  1410. //查找今日该患者已经出库的所有耗材
  1411. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  1412. for _, item := range goodList {
  1413. //回退库存
  1414. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  1415. //查询默认仓库
  1416. stockList, _ := service.GetStockCountByGoodId(item.GoodId, storeConfig.StorehouseOutInfo, item.OrgId)
  1417. var total_count int64
  1418. for _, it := range stockList {
  1419. total_count += it.StockCount
  1420. }
  1421. //基础库插入数据
  1422. service.UpdateGoodInfoReduceSumCount(item.GoodId, total_count, item.OrgId)
  1423. }
  1424. //删除记录
  1425. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  1426. }
  1427. }
  1428. }
  1429. }
  1430. }
  1431. }
  1432. }
  1433. }
  1434. }
  1435. }
  1436. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1437. var hpInfo models.HisPrescriptionInfo
  1438. if info.ID == 0 {
  1439. var randNum int
  1440. randNum = rand.Intn(10000) + 1000
  1441. timestamp := time.Now().Unix()
  1442. tempTime := time.Unix(timestamp, 0)
  1443. timeFormat := tempTime.Format("20060102150405")
  1444. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1445. hpInfo = models.HisPrescriptionInfo{
  1446. HisPatientId: his_patient_id,
  1447. UserOrgId: adminInfo.CurrentOrgId,
  1448. RecordDate: theTime.Unix(),
  1449. PatientId: patient_id,
  1450. Status: 1,
  1451. Ctime: time.Now().Unix(),
  1452. Mtime: time.Now().Unix(),
  1453. Creator: adminInfo.AdminUser.Id,
  1454. Modifier: adminInfo.AdminUser.Id,
  1455. Diagnosis: diagnose,
  1456. SickHistory: sick_history,
  1457. Departments: department,
  1458. RegisterType: reg_type,
  1459. PrescriptionNumber: p_number,
  1460. PrescriptionStatus: 1,
  1461. Doctor: role.UserName,
  1462. DoctorId: doctor_id,
  1463. SickType: sick_type,
  1464. PType: p_type,
  1465. }
  1466. service.SavePatientPrescriptionInfo(hpInfo)
  1467. redis := service.RedisClient()
  1468. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1469. redis.Set(key, "", time.Second)
  1470. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1471. redis.Set(keyOne, "", time.Second)
  1472. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1473. redis.Set(keySeven, "", time.Second)
  1474. defer redis.Close()
  1475. } else {
  1476. hpInfo = models.HisPrescriptionInfo{
  1477. ID: info.ID,
  1478. UserOrgId: adminInfo.CurrentOrgId,
  1479. RecordDate: info.RecordDate,
  1480. PatientId: info.PatientId,
  1481. Status: 1,
  1482. Ctime: info.Ctime,
  1483. Mtime: time.Now().Unix(),
  1484. Creator: info.Creator,
  1485. Modifier: adminInfo.AdminUser.Id,
  1486. Diagnosis: diagnose,
  1487. SickHistory: sick_history,
  1488. Departments: department,
  1489. RegisterType: reg_type,
  1490. PrescriptionNumber: info.PrescriptionNumber,
  1491. Doctor: role.UserName,
  1492. PrescriptionStatus: info.PrescriptionStatus,
  1493. DoctorId: doctor_id,
  1494. SickType: sick_type,
  1495. PType: info.PType,
  1496. HisPatientId: info.HisPatientId,
  1497. }
  1498. service.SavePatientPrescriptionInfo(hpInfo)
  1499. redis := service.RedisClient()
  1500. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1501. redis.Set(key, "", time.Second)
  1502. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1503. redis.Set(keyOne, "", time.Second)
  1504. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1505. redis.Set(keySeven, "", time.Second)
  1506. defer redis.Close()
  1507. }
  1508. //定义切片
  1509. var adviceList []models.HisDoctorAdviceInfo
  1510. var projectList []models.HisPrescriptionProject
  1511. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1512. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1513. var tempPrescription *models.HisPrescription
  1514. if len(prescriptions) > 0 {
  1515. for _, item := range prescriptions {
  1516. items := item.(map[string]interface{})
  1517. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1518. utils.ErrorLog("id")
  1519. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1520. return
  1521. }
  1522. id := int64(items["id"].(float64))
  1523. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  1524. tempPrescription = &new_prescription
  1525. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1526. utils.ErrorLog("type")
  1527. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1528. return
  1529. }
  1530. types := int64(items["type"].(float64))
  1531. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1532. utils.ErrorLog("med_type")
  1533. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1534. return
  1535. }
  1536. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1537. if med_type == "0" {
  1538. med_type = "14"
  1539. }
  1540. //if order_status == 0 {
  1541. // order_status = 1
  1542. //}
  1543. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  1544. utils.ErrorLog("pre_time")
  1545. }
  1546. preTime, _ := items["pre_time"].(string)
  1547. timeLayout := "2006-01-02"
  1548. loc, _ := time.LoadLocation("Local")
  1549. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  1550. if err != nil {
  1551. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1552. return
  1553. }
  1554. pTime := theTime2.Unix()
  1555. ctime := time.Now().Unix()
  1556. if tempPrescription.ID == 0 {
  1557. prescription := &models.HisPrescription{
  1558. ID: 0,
  1559. PatientId: patient_id,
  1560. UserOrgId: adminInfo.CurrentOrgId,
  1561. RecordDate: recordDateTime,
  1562. Ctime: ctime,
  1563. Mtime: ctime,
  1564. Type: types,
  1565. Modifier: adminInfo.AdminUser.Id,
  1566. Creator: adminInfo.AdminUser.Id,
  1567. Status: 1,
  1568. Doctor: role.UserName,
  1569. HisPatientId: his_patient_id,
  1570. OrderStatus: 1,
  1571. BatchNumber: "",
  1572. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1573. PreTime: pTime,
  1574. PType: p_type,
  1575. MedType: med_type,
  1576. }
  1577. tempPrescription = prescription
  1578. service.SaveHisPrescription(tempPrescription)
  1579. redis := service.RedisClient()
  1580. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1581. redis.Set(key, "", time.Second)
  1582. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1583. redis.Set(keyOne, "", time.Second)
  1584. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1585. redis.Set(keySeven, "", time.Second)
  1586. defer redis.Close()
  1587. } else {
  1588. tempPrescription.ID = id
  1589. tempPrescription.Type = types
  1590. tempPrescription.Modifier = adminInfo.AdminUser.Id
  1591. tempPrescription.Mtime = time.Now().Unix()
  1592. tempPrescription.Doctor = role.UserName
  1593. //tempPrescription.OrderStatus = order_status
  1594. tempPrescription.PreTime = pTime
  1595. tempPrescription.MedType = med_type
  1596. service.SaveHisPrescription(tempPrescription)
  1597. redis := service.RedisClient()
  1598. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1599. redis.Set(key, "", time.Second)
  1600. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1601. redis.Set(keyOne, "", time.Second)
  1602. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1603. redis.Set(keySeven, "", time.Second)
  1604. defer redis.Close()
  1605. }
  1606. //service.SaveHisPrescription(prescription)
  1607. //更改患者挂号状态
  1608. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1609. fmt.Println("更改失败", err2)
  1610. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1611. advices := items["advices"].([]interface{})
  1612. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1613. groupNo := int64(0)
  1614. ctime := time.Now().Unix()
  1615. mtime := ctime
  1616. if len(advices) > 0 {
  1617. for _, advice := range advices {
  1618. var s models.HisDoctorAdviceInfo
  1619. s.PrescriptionId = tempPrescription.ID
  1620. s.AdviceType = 2
  1621. s.AdviceDoctor = doctor_id
  1622. s.StopState = 2
  1623. s.ExecutionState = 2
  1624. s.AdviceDate = recordDateTime
  1625. s.Status = 1
  1626. s.UserOrgId = adminInfo.CurrentOrgId
  1627. s.RecordDate = recordDateTime
  1628. s.StartTime = tempPrescription.PreTime
  1629. s.Groupno = groupNo
  1630. s.CreatedTime = ctime
  1631. s.UpdatedTime = mtime
  1632. s.PatientId = patient_id
  1633. s.HisPatientId = his_patient_id
  1634. s.StartTime = pTime
  1635. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1636. if errcode > 0 {
  1637. c.ServeFailJSONWithSGJErrorCode(errcode)
  1638. return
  1639. }
  1640. s.StartTime = pTime
  1641. var total_count int64 //处方总库存
  1642. //查询改药品信息
  1643. medical, _ := service.GetBaseDrugMedical(s.DrugId)
  1644. prescribingNumberSix := strconv.FormatFloat(s.PrescribingNumber, 'f', -1, 64)
  1645. prescribingNumberSeven, _ := strconv.ParseInt(prescribingNumberSix, 10, 64)
  1646. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit != medical.MinUnit {
  1647. total_count += prescribingNumberSeven * medical.MinNumber
  1648. }
  1649. if s.PrescribingNumberUnit == medical.MinUnit && medical.MaxUnit != medical.MinUnit {
  1650. total_count += prescribingNumberSeven
  1651. }
  1652. if s.PrescribingNumberUnit == medical.MaxUnit && medical.MaxUnit == medical.MinUnit {
  1653. total_count += prescribingNumberSeven
  1654. }
  1655. service.CreateHisDoctorAdvice(&s)
  1656. //存储切片中
  1657. adviceList = append(adviceList, s)
  1658. redis := service.RedisClient()
  1659. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1660. redis.Set(key, "", time.Second)
  1661. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1662. redis.Set(keyOne, "", time.Second)
  1663. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1664. redis.Set(keySeven, "", time.Second)
  1665. var randNum int
  1666. randNum = rand.Intn(10000) + 1000
  1667. timestamp := time.Now().Unix()
  1668. tempTime := time.Unix(timestamp, 0)
  1669. timeFormat := tempTime.Format("20060102150405")
  1670. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1671. service.CreateHisDoctorAdvice(&s)
  1672. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1673. redis.Set(keySix, "", time.Second)
  1674. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1675. redis.Set(keyFive, "", time.Second)
  1676. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1677. redis.Set(keyEight, "", time.Second)
  1678. defer redis.Close()
  1679. }
  1680. }
  1681. }
  1682. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1683. projects := items["project"].([]interface{})
  1684. if len(projects) > 0 {
  1685. for _, project := range projects {
  1686. var p models.HisPrescriptionProject
  1687. p.PrescriptionId = tempPrescription.ID
  1688. p.Ctime = time.Now().Unix()
  1689. p.Mtime = time.Now().Unix()
  1690. p.PatientId = patient_id
  1691. p.RecordDate = recordDateTime
  1692. p.Doctor = doctor_id
  1693. p.UserOrgId = adminInfo.CurrentOrgId
  1694. p.HisPatientId = his_patient_id
  1695. p.Status = 1
  1696. p.StartTime = pTime
  1697. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1698. if errcode > 0 {
  1699. c.ServeFailJSONWithSGJErrorCode(errcode)
  1700. return
  1701. }
  1702. service.CreateHisProjectTwo(&p)
  1703. projectList = append(projectList, p)
  1704. var randNum int
  1705. randNum = rand.Intn(10000) + 1000
  1706. timestamp := time.Now().Unix()
  1707. tempTime := time.Unix(timestamp, 0)
  1708. timeFormat := tempTime.Format("20060102150405")
  1709. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1710. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1711. //新增或者编辑项目,修改对应的标签数据
  1712. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1713. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1714. var label models.HisLabelPrintInfo
  1715. project, _ := service.GetProjectDetail(p.ProjectId)
  1716. if project.CostClassify == 3 { //类别为检验检查
  1717. if p.TeamId > 0 { //检验检查组套
  1718. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1719. if tempLabel.ID == 0 {
  1720. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1721. label.Number = tempPrescription.PrescriptionNumber
  1722. label.ProjectId = project.ID
  1723. label.Status = 1
  1724. label.IsPrint = 2
  1725. label.DoctorId = info.DoctorId
  1726. label.UserOrgId = p.UserOrgId
  1727. label.PatientId = patient_id
  1728. label.RecordDate = recordDateTime
  1729. label.Ctime = time.Now().Unix()
  1730. label.Mtime = time.Now().Unix()
  1731. label.ItemId = p.TeamId
  1732. label.FeedetlSn = p.FeedetlSn
  1733. label.PProjectId = p.ID
  1734. label.ProjectName = team.ProjectTeam
  1735. label.PatientName = patient.Name
  1736. service.CreateHisLabelRecord(&label)
  1737. }
  1738. } else { //单条检验检查项目
  1739. label.Number = tempPrescription.PrescriptionNumber
  1740. label.ProjectId = project.ID
  1741. label.Status = 1
  1742. label.DoctorId = info.DoctorId
  1743. label.UserOrgId = p.UserOrgId
  1744. label.PatientId = patient_id
  1745. label.RecordDate = recordDateTime
  1746. label.IsPrint = 2
  1747. label.Ctime = time.Now().Unix()
  1748. label.Mtime = time.Now().Unix()
  1749. label.FeedetlSn = p.FeedetlSn
  1750. label.PProjectId = p.ID
  1751. label.ItemId = p.TeamId
  1752. label.ProjectName = project.ProjectName
  1753. label.PatientName = patient.Name
  1754. service.CreateHisLabelRecord(&label)
  1755. }
  1756. }
  1757. }
  1758. }
  1759. service.SaveHisProjectTwo(&p)
  1760. }
  1761. }
  1762. }
  1763. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1764. // addition := items["addition"].([]interface{})
  1765. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1766. // ctime := time.Now().Unix()
  1767. // mtime := ctime
  1768. // if len(addition) > 0 {
  1769. // for _, item := range addition {
  1770. // var s models.HisAdditionalCharge
  1771. // s.PrescriptionId = tempPrescription.ID
  1772. // s.Status = 1
  1773. // s.UserOrgId = adminInfo.CurrentOrgId
  1774. // s.RecordDate = recordDateTime
  1775. // s.CreatedTime = ctime
  1776. // s.UpdatedTime = mtime
  1777. // s.PatientId = patient_id
  1778. // s.HisPatientId = his_patient_id
  1779. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1780. // if errcode > 0 {
  1781. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1782. // return
  1783. // }
  1784. // service.CreateAdditionalCharge(&s)
  1785. // var randNum int
  1786. // randNum = rand.Intn(10000) + 1000
  1787. // timestamp := time.Now().Unix()
  1788. // tempTime := time.Unix(timestamp, 0)
  1789. // timeFormat := tempTime.Format("20060102150405")
  1790. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1791. // service.CreateAdditionalCharge(&s)
  1792. //
  1793. // }
  1794. // }
  1795. //}
  1796. }
  1797. }
  1798. //查询今日该患者开的药品处方
  1799. hisdoctorlist, _ := service.GetHisAdviceListByDrugIdTwo(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  1800. drugOutConfig, _ := service.GetDrugOpenConfigOne(adminInfo.CurrentOrgId)
  1801. if drugOutConfig.IsOpen == 1 {
  1802. for _, item := range hisdoctorlist {
  1803. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, item.DrugId)
  1804. // 查询该药品最后一次出库记录
  1805. druginfo, _ := service.GetLastDrugWarehouseOutByDrugIdTwenty(item.DrugId, patient_id, recordDateTime, item.ID)
  1806. if len(druginfo) > 0 {
  1807. //回退库存
  1808. for _, it := range druginfo {
  1809. if it.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  1810. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1811. }
  1812. if it.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  1813. service.ModifyDrugWarehouseInfoStockMinNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1814. }
  1815. if it.CountUnit == drug.MaxUnit && drug.MaxUnit == drug.MinUnit {
  1816. service.ModifyDrugWarehouseInfoStockMaxNumber(it.Count, it.DrugId, it.OrgId, it.WarehouseInfoId)
  1817. }
  1818. }
  1819. }
  1820. //删除记录
  1821. service.DeleteDrugAutoWarehouseSeven(item.DrugId, patient_id, recordDateTime, item.ID)
  1822. if drugOutConfig.IsOpen == 1 {
  1823. //出库
  1824. if drug.IsUse == 2 {
  1825. creater := adminInfo.AdminUser.Id
  1826. service.HisDrugsDelivery(item.UserOrgId, creater, item)
  1827. }
  1828. //更新字典里面的库存
  1829. stockInfo, _ := service.GetDrugAllStockInfo(storeConfig.DrugStorehouseOut, item.UserOrgId, item.DrugId)
  1830. var sum_count int64
  1831. for _, its := range stockInfo {
  1832. sum_count += its.StockMaxNumber*drug.MinNumber + its.StockMinNumber
  1833. }
  1834. service.UpdateBaseDrugSumTwo(item.DrugId, sum_count, item.UserOrgId)
  1835. }
  1836. }
  1837. }
  1838. }
  1839. //redisClient := service.RedisClient()
  1840. //defer redisClient.Close()
  1841. //
  1842. //list := models.HisList{
  1843. // Patient_id: patient_id,
  1844. // Advice_id:0,
  1845. // Record_date: 0,
  1846. // Advice: adviceList,
  1847. // Project: nil,
  1848. //}
  1849. //hisLis = append(hisLis, list)
  1850. //
  1851. //advice_json, _ := json.Marshal(&hisLis)
  1852. //redisClient.RPush("111", advice_json).Result()
  1853. //result, _ := redisClient.RPop("111").Result()
  1854. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1855. //
  1856. //var dat []map[string]interface{}
  1857. //json.Unmarshal([]byte(result), &dat)
  1858. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1859. //
  1860. //for k,v:=range dat{
  1861. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1862. //}
  1863. //project_json, _ := json.Marshal(&projectList)
  1864. //redisClient.LPush("222", project_json).Result()
  1865. if err == nil {
  1866. c.ServeSuccessJSON(map[string]interface{}{
  1867. "msg": "保存成功",
  1868. })
  1869. return
  1870. } else {
  1871. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1872. return
  1873. }
  1874. }
  1875. func (c *HisApiController) EditHisPrescription() {
  1876. record_date := c.GetString("record_date")
  1877. patient_id, _ := c.GetInt64("patient_id")
  1878. reg_type, _ := c.GetInt64("reg_type")
  1879. //diagnose, _ := c.GetInt64("diagnose", 0)
  1880. diagnose := c.GetString("diagnose")
  1881. sick_type, _ := c.GetInt64("sick_type")
  1882. sick_history := c.GetString("sick_history")
  1883. doctor_id, _ := c.GetInt64("doctor", 0)
  1884. department, _ := c.GetInt64("department", 0)
  1885. his_patient_id, _ := c.GetInt64("his_patient_id")
  1886. p_type, _ := c.GetInt64("p_type")
  1887. dataBody := make(map[string]interface{}, 0)
  1888. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1889. if err != nil {
  1890. utils.ErrorLog(err.Error())
  1891. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1892. return
  1893. }
  1894. timeLayout := "2006-01-02"
  1895. loc, _ := time.LoadLocation("Local")
  1896. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1897. if err != nil {
  1898. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1899. return
  1900. }
  1901. adminInfo := c.GetAdminUserInfo()
  1902. recordDateTime := theTime.Unix()
  1903. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1904. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1905. var hpInfo models.HisPrescriptionInfo
  1906. if info.ID == 0 {
  1907. var randNum int
  1908. randNum = rand.Intn(10000) + 1000
  1909. timestamp := time.Now().Unix()
  1910. tempTime := time.Unix(timestamp, 0)
  1911. timeFormat := tempTime.Format("20060102150405")
  1912. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1913. hpInfo = models.HisPrescriptionInfo{
  1914. UserOrgId: adminInfo.CurrentOrgId,
  1915. RecordDate: theTime.Unix(),
  1916. PatientId: patient_id,
  1917. Status: 1,
  1918. Ctime: time.Now().Unix(),
  1919. Mtime: time.Now().Unix(),
  1920. Creator: adminInfo.AdminUser.Id,
  1921. Modifier: adminInfo.AdminUser.Id,
  1922. Diagnosis: diagnose,
  1923. SickHistory: sick_history,
  1924. Departments: department,
  1925. RegisterType: reg_type,
  1926. PrescriptionNumber: p_number,
  1927. PrescriptionStatus: 1,
  1928. Doctor: role.UserName,
  1929. DoctorId: doctor_id,
  1930. SickType: sick_type,
  1931. PType: p_type,
  1932. }
  1933. service.SavePatientPrescriptionInfo(hpInfo)
  1934. } else {
  1935. hpInfo = models.HisPrescriptionInfo{
  1936. ID: info.ID,
  1937. UserOrgId: adminInfo.CurrentOrgId,
  1938. RecordDate: info.RecordDate,
  1939. PatientId: info.PatientId,
  1940. Status: 1,
  1941. Ctime: info.Ctime,
  1942. Mtime: time.Now().Unix(),
  1943. Creator: info.Creator,
  1944. Modifier: adminInfo.AdminUser.Id,
  1945. Diagnosis: diagnose,
  1946. SickHistory: sick_history,
  1947. Departments: department,
  1948. RegisterType: reg_type,
  1949. PrescriptionNumber: info.PrescriptionNumber,
  1950. Doctor: role.UserName,
  1951. PrescriptionStatus: info.PrescriptionStatus,
  1952. DoctorId: doctor_id,
  1953. SickType: sick_type,
  1954. PType: info.PType,
  1955. }
  1956. service.SavePatientPrescriptionInfo(hpInfo)
  1957. }
  1958. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1959. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1960. if len(prescriptions) > 0 {
  1961. for _, item := range prescriptions {
  1962. items := item.(map[string]interface{})
  1963. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1964. utils.ErrorLog("id")
  1965. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1966. return
  1967. }
  1968. id := int64(items["id"].(float64))
  1969. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1970. utils.ErrorLog("type")
  1971. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1972. return
  1973. }
  1974. types := int64(items["type"].(float64))
  1975. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1976. utils.ErrorLog("med_type")
  1977. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1978. return
  1979. }
  1980. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1981. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1982. ctime := time.Now().Unix()
  1983. prescription := &models.HisPrescription{
  1984. ID: id,
  1985. PatientId: patient_id,
  1986. UserOrgId: adminInfo.CurrentOrgId,
  1987. RecordDate: recordDateTime,
  1988. Ctime: ctime,
  1989. Mtime: ctime,
  1990. Type: types,
  1991. Modifier: adminInfo.AdminUser.Id,
  1992. Creator: adminInfo.AdminUser.Id,
  1993. Status: 1,
  1994. Doctor: role.UserName,
  1995. HisPatientId: his_patient_id,
  1996. OrderStatus: 1,
  1997. BatchNumber: "",
  1998. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1999. PType: hpInfo.PType,
  2000. MedType: med_type,
  2001. }
  2002. if historyPrescription.ID > 0 {
  2003. prescription.PreTime = historyPrescription.PreTime
  2004. }
  2005. service.SaveHisPrescription(prescription)
  2006. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  2007. advices := items["advices"].([]interface{})
  2008. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2009. groupNo := int64(0)
  2010. ctime := time.Now().Unix()
  2011. mtime := ctime
  2012. if len(advices) > 0 {
  2013. for _, advice := range advices {
  2014. var s models.HisDoctorAdviceInfo
  2015. s.PrescriptionId = prescription.ID
  2016. s.AdviceType = 2
  2017. s.AdviceDoctor = adminInfo.AdminUser.Id
  2018. s.StopState = 2
  2019. s.ExecutionState = 2
  2020. s.AdviceDate = recordDateTime
  2021. s.Status = 1
  2022. s.UserOrgId = adminInfo.CurrentOrgId
  2023. s.RecordDate = recordDateTime
  2024. s.StartTime = prescription.PreTime
  2025. s.Groupno = groupNo
  2026. s.CreatedTime = ctime
  2027. s.UpdatedTime = mtime
  2028. s.PatientId = patient_id
  2029. s.HisPatientId = his_patient_id
  2030. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  2031. if errcode > 0 {
  2032. c.ServeFailJSONWithSGJErrorCode(errcode)
  2033. return
  2034. }
  2035. service.CreateHisDoctorAdvice(&s)
  2036. redis := service.RedisClient()
  2037. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  2038. redis.Set(key, "", time.Second)
  2039. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  2040. fmt.Println("keyOne", keyOne)
  2041. redis.Set(keyOne, "", time.Second)
  2042. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  2043. redis.Set(keySeven, "", time.Second)
  2044. redis.Close()
  2045. }
  2046. }
  2047. }
  2048. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  2049. projects := items["project"].([]interface{})
  2050. if len(projects) > 0 {
  2051. for _, project := range projects {
  2052. var p models.HisPrescriptionProject
  2053. p.PrescriptionId = prescription.ID
  2054. p.Ctime = time.Now().Unix()
  2055. p.Mtime = time.Now().Unix()
  2056. p.PatientId = patient_id
  2057. p.RecordDate = recordDateTime
  2058. p.UserOrgId = adminInfo.CurrentOrgId
  2059. p.HisPatientId = his_patient_id
  2060. p.Status = 1
  2061. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  2062. if errcode > 0 {
  2063. c.ServeFailJSONWithSGJErrorCode(errcode)
  2064. return
  2065. }
  2066. service.CreateHisProjectTwo(&p)
  2067. }
  2068. }
  2069. }
  2070. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  2071. addition := items["addition"].([]interface{})
  2072. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  2073. ctime := time.Now().Unix()
  2074. mtime := ctime
  2075. if len(addition) > 0 {
  2076. for _, item := range addition {
  2077. var s models.HisAdditionalCharge
  2078. s.PrescriptionId = prescription.ID
  2079. s.Status = 1
  2080. s.UserOrgId = adminInfo.CurrentOrgId
  2081. s.RecordDate = recordDateTime
  2082. s.CreatedTime = ctime
  2083. s.UpdatedTime = mtime
  2084. s.PatientId = patient_id
  2085. s.HisPatientId = his_patient_id
  2086. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  2087. if errcode > 0 {
  2088. c.ServeFailJSONWithSGJErrorCode(errcode)
  2089. return
  2090. }
  2091. service.CreateAdditionalCharge(&s)
  2092. }
  2093. }
  2094. }
  2095. }
  2096. }
  2097. }
  2098. if err == nil {
  2099. c.ServeSuccessJSON(map[string]interface{}{
  2100. "msg": "保存成功",
  2101. })
  2102. return
  2103. } else {
  2104. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2105. return
  2106. }
  2107. }
  2108. func (c *HisApiController) DeletePrescription() {
  2109. prescription_id, _ := c.GetInt64("id")
  2110. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  2111. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  2112. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2113. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2114. //已收费和已发药限制逻辑
  2115. isCharge := false
  2116. isMedicine := false
  2117. new_prescription, p_err := service.GetPrescriptionById(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2118. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2119. for _, item := range new_prescriptions {
  2120. if item.IsMedicine == 1 {
  2121. isMedicine = true
  2122. }
  2123. }
  2124. for _, item := range new_prescriptions {
  2125. if item.OrderStatus == 4 {
  2126. isCharge = true
  2127. }
  2128. }
  2129. if p_err != nil {
  2130. if new_prescription.ID > 0 {
  2131. if new_prescription.OrderStatus == 2 {
  2132. isCharge = true
  2133. }
  2134. }
  2135. }
  2136. for _, item := range advices {
  2137. if item.IsMedicine == 1 {
  2138. isMedicine = true
  2139. }
  2140. }
  2141. if isCharge {
  2142. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2143. return
  2144. }
  2145. if isMedicine {
  2146. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2147. return
  2148. }
  2149. //已收费和已发药限制逻辑
  2150. if len(projects) > 0 {
  2151. for _, item := range projects {
  2152. service.DeletePrintInfo(item.ID) //删除打印信息
  2153. if stockConfig.IsOpen == 1 {
  2154. if item.Type == 3 {
  2155. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  2156. f_count, _ := strconv.ParseFloat(item.Count, 64)
  2157. good.Total = good.Total + f_count
  2158. service.UpdateGoodInfo(&good)
  2159. operation_time := time.Now().Unix()
  2160. creater := c.GetAdminUserInfo().AdminUser.Id
  2161. //创建退库单
  2162. timeStr := time.Now().Format("2006-01-02")
  2163. timeArr := strings.Split(timeStr, "-")
  2164. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  2165. total = total + 1
  2166. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2167. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2168. cancelStock := models.CancelStock{
  2169. OrderNumber: orderNumber,
  2170. OperaTime: operation_time,
  2171. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2172. Creater: creater,
  2173. Ctime: time.Now().Unix(),
  2174. Status: 1,
  2175. ReturnTime: item.RecordDate,
  2176. Type: 1,
  2177. StorehouseId: houseConfig.StorehouseOutInfo,
  2178. IsCheck: 1,
  2179. }
  2180. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  2181. if msgerrkonde == gorm.ErrRecordNotFound {
  2182. service.AddSigleCancelStock(&cancelStock)
  2183. }
  2184. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  2185. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2186. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2187. //查询该耗材是否出库
  2188. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  2189. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2190. deaerler, _ := service.GetDealerById(info.Dealer)
  2191. if info.ID > 0 {
  2192. cancelStockInfo := models.CancelStockInfo{
  2193. GoodId: item.ProjectId,
  2194. CancelStockId: cancel.ID,
  2195. GoodTypeId: good.GoodTypeId,
  2196. Count: prescribingNumber,
  2197. Price: info.Price,
  2198. Total: 0,
  2199. ProductDate: info.ProductDate,
  2200. ExpiryDate: info.ExpiryDate,
  2201. Ctime: time.Now().Unix(),
  2202. Status: 1,
  2203. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2204. OrderNumber: cancel.OrderNumber,
  2205. Type: 0,
  2206. Dealer: deaerler.DealerName,
  2207. Manufacturer: manufacturer.ManufacturerName,
  2208. Number: info.Number,
  2209. RegisterAccount: "",
  2210. Remark: "",
  2211. WarehouseInfoId: info.WarehouseInfotId,
  2212. PatientId: info.PatientId,
  2213. RecordDate: info.SysRecordTime,
  2214. StorehouseId: houseConfig.StorehouseOutInfo,
  2215. IsCheck: 1,
  2216. }
  2217. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2218. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  2219. flow := models.VmStockFlow{
  2220. WarehousingId: 0,
  2221. GoodId: item.ProjectId,
  2222. Number: info.Number,
  2223. LicenseNumber: info.LicenseNumber,
  2224. Count: prescribingNumber,
  2225. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2226. PatientId: item.PatientId,
  2227. SystemTime: info.SysRecordTime,
  2228. ConsumableType: 7,
  2229. IsSys: 0,
  2230. WarehousingOrder: "",
  2231. WarehouseOutId: 0,
  2232. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2233. IsEdit: 0,
  2234. CancelStockId: cancel.ID,
  2235. CancelOrderNumber: cancel.OrderNumber,
  2236. Manufacturer: manufacturer.ID,
  2237. Dealer: 0,
  2238. Creator: c.GetAdminUserInfo().CurrentOrgId,
  2239. UpdateCreator: 0,
  2240. Status: 1,
  2241. Ctime: time.Now().Unix(),
  2242. Mtime: 0,
  2243. Price: info.Price,
  2244. WarehousingDetailId: info.WarehouseInfotId,
  2245. WarehouseOutDetailId: 0,
  2246. CancelOutDetailId: cancelInfo.ID,
  2247. ProductDate: info.ProductDate,
  2248. ExpireDate: info.ExpiryDate,
  2249. StorehouseId: houseConfig.StorehouseOutInfo,
  2250. }
  2251. service.CreateStockFlowOne(flow)
  2252. //删除出库表
  2253. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  2254. //查询今日该患者开了多少耗材
  2255. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  2256. var total_count int64
  2257. var cha_count int64
  2258. for _, item := range projectList {
  2259. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2260. total_count += count
  2261. }
  2262. //回退库存
  2263. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2264. //查询今日该耗材退库数量
  2265. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  2266. var cancel_Count int64
  2267. for _, items := range cancelInfoOne {
  2268. cancel_Count += items.Count
  2269. }
  2270. cha_count = total_count - cancel_Count
  2271. if total_count > cancel_Count {
  2272. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  2273. if err == gorm.ErrRecordNotFound {
  2274. //没有记录,则创建出库单
  2275. timeStr := time.Now().Format("2006-01-02")
  2276. timeArr := strings.Split(timeStr, "-")
  2277. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  2278. total = total + 1
  2279. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2280. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2281. number = number + total
  2282. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2283. warehouseOut := models.WarehouseOut{
  2284. WarehouseOutOrderNumber: warehousing_out_order,
  2285. OperationTime: time.Now().Unix(),
  2286. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  2287. Creater: creater,
  2288. Ctime: time.Now().Unix(),
  2289. Status: 1,
  2290. WarehouseOutTime: info.SysRecordTime,
  2291. Dealer: 0,
  2292. Manufacturer: 0,
  2293. Type: 1,
  2294. IsSys: 1,
  2295. StorehouseId: houseConfig.StorehouseOutInfo,
  2296. IsCheck: 1,
  2297. }
  2298. err := service.AddSigleWarehouseOut(&warehouseOut)
  2299. if err != nil {
  2300. utils.TraceLog("创建出库单失败 err = %v", err)
  2301. return
  2302. }
  2303. prepare := &models.DialysisBeforePrepare{
  2304. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2305. PatientId: info.PatientId,
  2306. RecordDate: info.SysRecordTime,
  2307. GoodId: item.ProjectId,
  2308. GoodTypeId: info.GoodTypeId,
  2309. Count: cha_count,
  2310. StorehouseId: houseConfig.StorehouseOutInfo,
  2311. }
  2312. //出库
  2313. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2314. } else if err == nil {
  2315. prepare := &models.DialysisBeforePrepare{
  2316. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2317. PatientId: info.PatientId,
  2318. RecordDate: info.SysRecordTime,
  2319. GoodId: item.ProjectId,
  2320. GoodTypeId: info.GoodTypeId,
  2321. Count: cha_count,
  2322. StorehouseId: houseConfig.StorehouseOutInfo,
  2323. }
  2324. //出库
  2325. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2326. }
  2327. }
  2328. }
  2329. }
  2330. }
  2331. }
  2332. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2333. fmt.Println(err)
  2334. }
  2335. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  2336. fmt.Println(err)
  2337. if len(advices) > 0 {
  2338. for _, item := range advices {
  2339. redis := service.RedisClient()
  2340. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  2341. redis.Set(keyFive, "", time.Second)
  2342. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  2343. redis.Set(keyOne, "", time.Second)
  2344. redis.Close()
  2345. }
  2346. }
  2347. if drugStockConfig.IsOpen == 1 {
  2348. fmt.Println("woowowowowowowowowowowowowowo", len(advices))
  2349. if len(advices) > 0 {
  2350. for _, item := range advices {
  2351. creater := c.GetAdminUserInfo().AdminUser.Id
  2352. service.DrugAutoAddCancelInfo(item, creater)
  2353. }
  2354. }
  2355. }
  2356. c.ServeSuccessJSON(map[string]interface{}{
  2357. "msg": "删除成功",
  2358. })
  2359. return
  2360. }
  2361. func (c *HisApiController) DeleteDoctorAdvice() {
  2362. id, _ := c.GetInt64("id")
  2363. advice, _ := service.GetHisDoctorAdvicesById(id)
  2364. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2365. //已收费和已发药的限制逻辑
  2366. isCharge := false
  2367. isMedicine := false
  2368. new_prescription, _ := service.GetPrescriptionById(advice.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2369. //获取今天该患者所有处方,判断是否发药或者收费
  2370. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2371. for _, item := range new_prescriptions {
  2372. if item.IsMedicine == 1 {
  2373. isMedicine = true
  2374. }
  2375. }
  2376. for _, item := range new_prescriptions {
  2377. if item.OrderStatus == 4 {
  2378. isCharge = true
  2379. }
  2380. }
  2381. if isMedicine {
  2382. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2383. return
  2384. }
  2385. if isCharge {
  2386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2387. return
  2388. }
  2389. advices, _ := service.GetHisPrescriptionAdviceByID(advice.PrescriptionId)
  2390. for _, item := range advices {
  2391. if item.IsMedicine == 1 {
  2392. isMedicine = true
  2393. }
  2394. }
  2395. if isMedicine {
  2396. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeleteMedicineWrong)
  2397. return
  2398. }
  2399. if new_prescription.ID > 0 {
  2400. if new_prescription.OrderStatus == 2 {
  2401. isCharge = true
  2402. }
  2403. }
  2404. if isCharge {
  2405. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2406. return
  2407. }
  2408. //已收费和已发药的限制逻辑
  2409. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  2410. redis := service.RedisClient()
  2411. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  2412. redis.Set(keyFive, "", time.Second)
  2413. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  2414. redis.Set(keyOne, "", time.Second)
  2415. defer redis.Close()
  2416. if err == nil {
  2417. if drugStockConfig.IsOpen == 1 {
  2418. //查询是否在处方中出库
  2419. openConfig, _ := service.GetDrugOpenConfigOne(c.GetAdminUserInfo().CurrentOrgId)
  2420. if openConfig.IsOpen != 1 {
  2421. //判断该医嘱是否执行了
  2422. if advice.ExecutionState == 1 {
  2423. creater := c.GetAdminUserInfo().AdminUser.Id
  2424. service.DrugAutoAddCancelInfo(&advice, creater)
  2425. }
  2426. }
  2427. //开启保存处方扣减功能
  2428. if openConfig.IsOpen == 1 {
  2429. creater := c.GetAdminUserInfo().AdminUser.Id
  2430. service.DrugAutoAddCancelInfo(&advice, creater)
  2431. }
  2432. }
  2433. c.ServeSuccessJSON(map[string]interface{}{
  2434. "msg": "删除成功",
  2435. })
  2436. return
  2437. } else {
  2438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2439. return
  2440. }
  2441. }
  2442. func (c *HisApiController) DeleteProject() {
  2443. id, _ := c.GetInt64("id")
  2444. adminInfo := c.GetAdminUserInfo()
  2445. project, _ := service.GetHisProjectByID(id)
  2446. // var consumable models.DialysisBeforePrepare
  2447. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2448. isCharge := false
  2449. isMedicine := false
  2450. new_prescription, _ := service.GetPrescriptionById(project.PrescriptionId, c.GetAdminUserInfo().CurrentOrgId)
  2451. new_prescriptions, _ := service.GetHisPrescription(c.GetAdminUserInfo().CurrentOrgId, new_prescription.PatientId, new_prescription.RecordDate, new_prescription.PType)
  2452. for _, item := range new_prescriptions {
  2453. if item.IsMedicine == 1 {
  2454. isMedicine = true
  2455. }
  2456. }
  2457. for _, item := range new_prescriptions {
  2458. if item.OrderStatus == 4 {
  2459. isCharge = true
  2460. }
  2461. }
  2462. if isMedicine {
  2463. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePMedicineWrong)
  2464. return
  2465. }
  2466. if isCharge {
  2467. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrong)
  2468. return
  2469. }
  2470. if new_prescription.ID > 0 {
  2471. if new_prescription.OrderStatus == 2 {
  2472. isCharge = true
  2473. }
  2474. }
  2475. if isCharge {
  2476. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDeletePChargeWrongTwo)
  2477. return
  2478. }
  2479. service.DeletePrintInfo(id)
  2480. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2481. label.Status = 0
  2482. service.CreateHisLabelRecord(&label)
  2483. if stockConfig.IsOpen == 1 {
  2484. if project.Type == 2 {
  2485. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2486. fmt.Println(err)
  2487. }
  2488. if project.Type == 3 {
  2489. houseConfig, _ := service.GetAllStoreHouseConfig(c.GetAdminUserInfo().CurrentOrgId)
  2490. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2491. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2492. operation_time := time.Now().Unix()
  2493. creater := adminInfo.AdminUser.Id
  2494. //创建退库单
  2495. timeStr := time.Now().Format("2006-01-02")
  2496. timeArr := strings.Split(timeStr, "-")
  2497. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2498. total = total + 1
  2499. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2500. cancelStock := models.CancelStock{
  2501. OrderNumber: orderNumber,
  2502. OperaTime: operation_time,
  2503. OrgId: adminInfo.CurrentOrgId,
  2504. Creater: creater,
  2505. Ctime: time.Now().Unix(),
  2506. Status: 1,
  2507. ReturnTime: project.RecordDate,
  2508. Type: 1,
  2509. StorehouseId: houseConfig.StorehouseOutInfo,
  2510. }
  2511. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2512. if msgerrkonde == gorm.ErrRecordNotFound {
  2513. service.AddSigleCancelStock(&cancelStock)
  2514. }
  2515. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2516. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2517. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2518. //获取该耗材有库存的第一条数据
  2519. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2520. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2521. deaerler, _ := service.GetDealerById(info.Dealer)
  2522. if info.ID > 0 {
  2523. cancelStockInfo := models.CancelStockInfo{
  2524. GoodId: project.ProjectId,
  2525. CancelStockId: cancel.ID,
  2526. GoodTypeId: good.GoodTypeId,
  2527. Count: prescribingNumber,
  2528. Price: info.Price,
  2529. Total: 0,
  2530. ProductDate: info.ProductDate,
  2531. ExpiryDate: info.ExpiryDate,
  2532. Ctime: time.Now().Unix(),
  2533. Status: 1,
  2534. OrgId: adminInfo.CurrentOrgId,
  2535. OrderNumber: cancel.OrderNumber,
  2536. Type: 0,
  2537. Dealer: deaerler.DealerName,
  2538. Manufacturer: manufacturer.ManufacturerName,
  2539. Number: info.Number,
  2540. RegisterAccount: "",
  2541. Remark: "",
  2542. WarehouseInfoId: info.WarehouseInfotId,
  2543. PatientId: info.PatientId,
  2544. RecordDate: info.SysRecordTime,
  2545. StorehouseId: houseConfig.StorehouseOutInfo,
  2546. }
  2547. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2548. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2549. flow := models.VmStockFlow{
  2550. WarehousingId: 0,
  2551. GoodId: project.ProjectId,
  2552. Number: info.Number,
  2553. LicenseNumber: info.LicenseNumber,
  2554. Count: prescribingNumber,
  2555. UserOrgId: adminInfo.CurrentOrgId,
  2556. PatientId: project.PatientId,
  2557. SystemTime: time.Now().Unix(),
  2558. ConsumableType: 7,
  2559. IsSys: 0,
  2560. WarehousingOrder: "",
  2561. WarehouseOutId: 0,
  2562. WarehouseOutOrderNumber: "",
  2563. IsEdit: 0,
  2564. CancelStockId: cancel.ID,
  2565. CancelOrderNumber: cancel.OrderNumber,
  2566. Manufacturer: manufacturer.ID,
  2567. Dealer: 0,
  2568. Creator: adminInfo.AdminUser.Id,
  2569. UpdateCreator: 0,
  2570. Status: 1,
  2571. Ctime: time.Now().Unix(),
  2572. Mtime: 0,
  2573. Price: info.Price,
  2574. WarehousingDetailId: info.WarehouseInfotId,
  2575. WarehouseOutDetailId: 0,
  2576. CancelOutDetailId: cancelInfo.ID,
  2577. ProductDate: info.ProductDate,
  2578. ExpireDate: info.ExpiryDate,
  2579. StorehouseId: houseConfig.StorehouseOutInfo,
  2580. }
  2581. service.CreateStockFlowOne(flow)
  2582. //删除出库表
  2583. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2584. //查询今日该患者开了多少耗材
  2585. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2586. var total_count int64
  2587. var cha_count int64
  2588. for _, item := range projectList {
  2589. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2590. total_count += count
  2591. }
  2592. //回退库存
  2593. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2594. //查询今日该耗材退库数量
  2595. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2596. var cancel_count int64
  2597. for _, items := range cancelInfoOne {
  2598. cancel_count += items.Count
  2599. }
  2600. cha_count = total_count - cancel_count
  2601. if total_count > cancel_count {
  2602. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2603. if err == gorm.ErrRecordNotFound {
  2604. //没有记录,则创建出库单
  2605. timeStr := time.Now().Format("2006-01-02")
  2606. timeArr := strings.Split(timeStr, "-")
  2607. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2608. total = total + 1
  2609. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2610. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2611. number = number + total
  2612. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2613. warehouseOut := models.WarehouseOut{
  2614. WarehouseOutOrderNumber: warehousing_out_order,
  2615. OperationTime: time.Now().Unix(),
  2616. OrgId: adminInfo.CurrentOrgId,
  2617. Creater: creater,
  2618. Ctime: time.Now().Unix(),
  2619. Status: 1,
  2620. WarehouseOutTime: info.SysRecordTime,
  2621. Dealer: 0,
  2622. Manufacturer: 0,
  2623. Type: 1,
  2624. IsSys: 1,
  2625. StorehouseId: houseConfig.StorehouseOutInfo,
  2626. }
  2627. err := service.AddSigleWarehouseOut(&warehouseOut)
  2628. if err != nil {
  2629. utils.TraceLog("创建出库单失败 err = %v", err)
  2630. return
  2631. }
  2632. prepare := &models.DialysisBeforePrepare{
  2633. UserOrgId: adminInfo.CurrentOrgId,
  2634. PatientId: info.PatientId,
  2635. RecordDate: info.SysRecordTime,
  2636. GoodId: project.ProjectId,
  2637. GoodTypeId: info.GoodTypeId,
  2638. Count: cha_count,
  2639. StorehouseId: houseConfig.StorehouseOutInfo,
  2640. }
  2641. //出库
  2642. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2643. } else if err == nil {
  2644. prepare := &models.DialysisBeforePrepare{
  2645. UserOrgId: adminInfo.CurrentOrgId,
  2646. PatientId: info.PatientId,
  2647. RecordDate: info.SysRecordTime,
  2648. GoodId: project.ProjectId,
  2649. GoodTypeId: info.GoodTypeId,
  2650. Count: cha_count,
  2651. StorehouseId: houseConfig.StorehouseOutInfo,
  2652. }
  2653. //出库
  2654. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2655. }
  2656. }
  2657. stockList, _ := service.GetStockCountByGoodId(project.ProjectId, houseConfig.StorehouseOutInfo, project.UserOrgId)
  2658. var total_count_one int64
  2659. for _, it := range stockList {
  2660. total_count_one += it.StockCount
  2661. }
  2662. //基础库插入数据
  2663. service.UpdateGoodInfoSumCount(project.ProjectId, total_count_one, project.UserOrgId)
  2664. }
  2665. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2666. fmt.Println(err)
  2667. }
  2668. }
  2669. c.ServeSuccessJSON(map[string]interface{}{
  2670. "msg": "删除成功",
  2671. })
  2672. return
  2673. }
  2674. func (c *HisApiController) CreateHisAdditionalCharge() {
  2675. his_patient_id, _ := c.GetInt64("his_patient_id")
  2676. patient_id, _ := c.GetInt64("patient_id")
  2677. record_date := c.GetString("record_date")
  2678. timeLayout := "2006-01-02"
  2679. loc, _ := time.LoadLocation("Local")
  2680. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2681. if err != nil {
  2682. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2683. return
  2684. }
  2685. adminInfo := c.GetAdminUserInfo()
  2686. recordDateTime := theTime.Unix()
  2687. dataBody := make(map[string]interface{}, 0)
  2688. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2689. if err != nil {
  2690. utils.ErrorLog(err.Error())
  2691. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2692. return
  2693. }
  2694. var additions []*models.HisAdditionalCharge
  2695. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2696. additions, _ := dataBody["addition"].([]interface{})
  2697. if len(additions) > 0 {
  2698. for _, item := range additions {
  2699. items := item.(map[string]interface{})
  2700. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2701. utils.ErrorLog("item_id")
  2702. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2703. return
  2704. }
  2705. item_id := int64(items["item_id"].(float64))
  2706. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2707. utils.ErrorLog("item_name")
  2708. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2709. return
  2710. }
  2711. item_name := items["item_name"].(string)
  2712. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2713. utils.ErrorLog("price")
  2714. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2715. return
  2716. }
  2717. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2718. ctime := time.Now().Unix()
  2719. additional := &models.HisAdditionalCharge{
  2720. PatientId: patient_id,
  2721. HisPatientId: his_patient_id,
  2722. UserOrgId: adminInfo.CurrentOrgId,
  2723. RecordDate: recordDateTime,
  2724. CreatedTime: ctime,
  2725. UpdatedTime: ctime,
  2726. Modifier: adminInfo.AdminUser.Id,
  2727. Creator: adminInfo.AdminUser.Id,
  2728. Price: price,
  2729. ItemName: item_name,
  2730. ItemId: item_id,
  2731. Status: 1,
  2732. }
  2733. additions = append(additions, additional)
  2734. }
  2735. }
  2736. }
  2737. for _, item := range additions {
  2738. service.CreateAddtionalCharge(item)
  2739. }
  2740. c.ServeSuccessJSON(map[string]interface{}{
  2741. "msg": "创建成功",
  2742. })
  2743. }
  2744. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2745. blood_fat := c.GetString("blood_fat")
  2746. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2747. blood_sugar := c.GetString("blood_sugar")
  2748. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2749. chief_conplaint := c.GetString("chief_conplaint")
  2750. dbp := c.GetString("dbp")
  2751. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2752. delivery_way, _ := c.GetInt64("delivery_way")
  2753. diagnostic := c.GetString("diagnostic")
  2754. family_history := c.GetString("family_history")
  2755. height := c.GetString("height")
  2756. history_of_present_illness := c.GetString("history_of_present_illness")
  2757. is_infect, _ := c.GetInt64("is_infect")
  2758. past_history := c.GetString("past_history")
  2759. patient_id, _ := c.GetInt64("patient_id")
  2760. his_patient_id, _ := c.GetInt64("his_patient_id")
  2761. personal_history := c.GetString("personal_history")
  2762. pulse := c.GetString("pulse")
  2763. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2764. sbp := c.GetString("sbp")
  2765. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2766. heightfloat, _ := strconv.ParseFloat(height, 64)
  2767. sicktype := c.GetString("sick_type")
  2768. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2769. symptom := c.GetString("symptom")
  2770. sick_date := c.GetString("sick_date")
  2771. temperatures := c.GetString("temperature")
  2772. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2773. record_date := c.GetString("record_date")
  2774. breathing := c.GetString("breathing")
  2775. doctor_advice := c.GetString("doctor_advice")
  2776. remark := c.GetString("remark")
  2777. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2778. sick, _ := c.GetInt64("sick")
  2779. diagnose, _ := c.GetInt64("diagnose")
  2780. //id, _ := c.GetInt64("id")
  2781. timeLayout := "2006-01-02"
  2782. loc, _ := time.LoadLocation("Local")
  2783. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2784. allergic_history := c.GetString("allergic_history")
  2785. if err != nil {
  2786. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2787. return
  2788. }
  2789. recordDateTime := theTime.Unix()
  2790. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2791. if err != nil {
  2792. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2793. return
  2794. }
  2795. sickTimes := sickTime.Unix()
  2796. ctime := time.Now().Unix()
  2797. primary_disease := c.GetString("primary_disease")
  2798. confirm_failure_date := c.GetString("confirm_failure_date")
  2799. confirm_failure_date_time, _ := time.ParseInLocation(timeLayout+" 15:04:05", confirm_failure_date+" 00:00:00", loc)
  2800. drug_allergy_history := c.GetString("drug_allergy_history")
  2801. physical_examination := c.GetString("physical_examination")
  2802. special_inspection := c.GetString("special_inspection")
  2803. lab_apparatus := c.GetString("lab_apparatus")
  2804. caseHistory := models.HisPatientCaseHistory{
  2805. HisPatientId: his_patient_id,
  2806. PatientId: patient_id,
  2807. Temperature: temperature,
  2808. BloodSugar: bloodsugarfloat,
  2809. Pulse: pulsefloat,
  2810. Sbp: sbpfloat,
  2811. Dbp: dbpfloat,
  2812. Height: heightfloat,
  2813. BloodFat: bloodfatfloat,
  2814. SickType: sick_type,
  2815. Symptom: symptom,
  2816. SickDate: sickTimes,
  2817. IsInfect: is_infect,
  2818. HistoryOfPresentIllness: history_of_present_illness,
  2819. PastHistory: past_history,
  2820. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2821. ChiefConplaint: chief_conplaint,
  2822. PersonalHistory: personal_history,
  2823. FamilyHistory: family_history,
  2824. Diagnostic: diagnostic,
  2825. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2826. Status: 1,
  2827. Ctime: ctime,
  2828. Mtime: ctime,
  2829. RecordDate: recordDateTime,
  2830. DeliveryWay: delivery_way,
  2831. Breathing: breathingfloat,
  2832. DoctorAdvice: doctor_advice,
  2833. Remark: remark,
  2834. Sick: sick,
  2835. Diagnose: diagnose,
  2836. AllergicHistory: allergic_history,
  2837. PrimaryDisease: primary_disease,
  2838. ConfirmFailureDate: confirm_failure_date_time.Unix(),
  2839. DrugAllergyHistory: drug_allergy_history,
  2840. PhysicalExamination: physical_examination,
  2841. SpecialInspection: special_inspection,
  2842. LabApparatus: lab_apparatus,
  2843. }
  2844. //查询该患者是否有病历
  2845. _, errcodes := service.GetHisPatientCaseHistoryById(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId)
  2846. if errcodes == gorm.ErrRecordNotFound {
  2847. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2848. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2849. if err != nil {
  2850. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2851. return
  2852. }
  2853. c.ServeSuccessJSON(map[string]interface{}{
  2854. "caseHistory": caseHistory,
  2855. "historyInfo": historyInfo,
  2856. })
  2857. return
  2858. } else if errcodes == nil {
  2859. err := service.UpdatePatientCaseHistory(patient_id, recordDateTime, c.GetAdminUserInfo().CurrentOrgId, &caseHistory)
  2860. historyInfo, _ := service.GetLastHisPatientCaseHistoryById(patient_id)
  2861. if err != nil {
  2862. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2863. return
  2864. }
  2865. c.ServeSuccessJSON(map[string]interface{}{
  2866. "caseHistory": caseHistory,
  2867. "historyInfo": historyInfo,
  2868. })
  2869. }
  2870. //查询该患者是否有病历
  2871. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2872. //if errcode == gorm.ErrRecordNotFound {
  2873. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2874. // if err != nil {
  2875. // c.ServeSuccessJSON(map[string]interface{}{
  2876. // "msg": "保存成功",
  2877. // })
  2878. // }
  2879. //} else if errcode == nil {
  2880. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2881. // return
  2882. //}
  2883. }
  2884. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2885. patient_id, _ := c.GetInt64("patient_id", 0)
  2886. adminUser := c.GetAdminUserInfo()
  2887. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2888. c.ServeSuccessJSON(map[string]interface{}{
  2889. "list": caseHistorys,
  2890. })
  2891. }
  2892. func (c *HisApiController) GetHisPatientCaseHistory() {
  2893. record_date, _ := c.GetInt64("record_date", 0)
  2894. patient_id, _ := c.GetInt64("patient_id", 0)
  2895. admin := c.GetAdminUserInfo()
  2896. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2897. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2898. c.ServeSuccessJSON(map[string]interface{}{
  2899. "info": info,
  2900. "case_history": case_history,
  2901. })
  2902. }
  2903. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2904. template_name := c.GetString("template_name")
  2905. template_remark := c.GetString("template_remark")
  2906. doctor := c.GetAdminUserInfo().AdminUser.Id
  2907. diagnostic := c.GetString("diagnostic")
  2908. chief_conplaint := c.GetString("chief_conplain")
  2909. history_of_present_illness := c.GetString("history_of_present_illness")
  2910. past_history := c.GetString("past_history")
  2911. personal_history := c.GetString("personal_history")
  2912. family_history := c.GetString("family_history")
  2913. user_name := c.GetString("user_name")
  2914. doctor_advice := c.GetString("doctor_advice")
  2915. remark := c.GetString("remark")
  2916. //record_date := c.GetString("record_date")
  2917. //fmt.Println("record_date--------",record_date)
  2918. //timeLayout := "2006-01-02"
  2919. //loc, _ := time.LoadLocation("Local")
  2920. //
  2921. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2922. //if err != nil {
  2923. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2924. // return
  2925. //}
  2926. //recordDateTime := theTime.Unix()
  2927. ctime := time.Now().Unix()
  2928. template := models.HisCaseHistoryTemplate{
  2929. HistoryOfPresentIllness: history_of_present_illness,
  2930. PastHistory: past_history,
  2931. ChiefConplaint: chief_conplaint,
  2932. PersonalHistory: personal_history,
  2933. FamilyHistory: family_history,
  2934. Diagnostic: diagnostic,
  2935. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2936. Status: 1,
  2937. Ctime: ctime,
  2938. Mtime: ctime,
  2939. RecordDate: time.Now().Unix(),
  2940. TemplateName: template_name,
  2941. TemplateRemark: template_remark,
  2942. Creator: doctor,
  2943. Modifier: doctor,
  2944. UserName: user_name,
  2945. DoctorAdvice: doctor_advice,
  2946. Remark: remark,
  2947. }
  2948. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2949. if err == nil {
  2950. c.ServeSuccessJSON(map[string]interface{}{
  2951. "msg": "保存成功",
  2952. })
  2953. } else {
  2954. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2955. return
  2956. }
  2957. }
  2958. func (c *HisApiController) GetCaseHistoryTemplate() {
  2959. timeLayout := "2006-01-02"
  2960. loc, _ := time.LoadLocation("Local")
  2961. keyword := c.GetString("keyword")
  2962. start_time := c.GetString("start_time")
  2963. end_time := c.GetString("end_time")
  2964. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2965. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2966. admin := c.GetAdminUserInfo()
  2967. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2968. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2969. c.ServeSuccessJSON(map[string]interface{}{
  2970. "template": template,
  2971. //"history": history,
  2972. })
  2973. }
  2974. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2975. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2976. utils.ErrorLog("drug_name")
  2977. return enums.ErrorCodeParamWrong
  2978. }
  2979. adviceName, _ := json["drug_name"].(string)
  2980. if len(adviceName) == 0 {
  2981. utils.ErrorLog("len(advice_name) == 0")
  2982. return enums.ErrorCodeParamWrong
  2983. }
  2984. advice.AdviceName = adviceName
  2985. adviceDesc, _ := json["advice_desc"].(string)
  2986. advice.AdviceDesc = adviceDesc
  2987. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2988. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2989. advice.DrugSpec = drugSpec
  2990. }
  2991. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2992. remark, _ := json["remark"].(string)
  2993. advice.Remark = remark
  2994. }
  2995. if json["id"] == nil {
  2996. advice.DrugId = 0
  2997. } else {
  2998. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2999. drug_id := int64(json["id"].(float64))
  3000. advice.DrugId = drug_id
  3001. }
  3002. }
  3003. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3004. advice_id := int64(json["advice_id"].(float64))
  3005. advice.ID = advice_id
  3006. if advice.ID > 0 {
  3007. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3008. if err == nil {
  3009. if hisAdvice.ID > 0 {
  3010. advice.ExecutionTime = hisAdvice.ExecutionTime
  3011. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3012. advice.ExecutionState = hisAdvice.ExecutionState
  3013. advice.CheckTime = hisAdvice.CheckTime
  3014. advice.Checker = hisAdvice.Checker
  3015. advice.CheckState = hisAdvice.CheckState
  3016. advice.StartTime = hisAdvice.StartTime
  3017. advice.FeedetlSn = hisAdvice.FeedetlSn
  3018. }
  3019. }
  3020. }
  3021. }
  3022. //
  3023. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3024. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3025. // advice.ExecutionTime = execution_time
  3026. //}
  3027. //
  3028. //
  3029. //
  3030. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3031. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3032. // advice.ExecutionStaff = execution_staff
  3033. //}
  3034. //
  3035. //
  3036. //
  3037. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3038. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3039. // advice.ExecutionState = execution_state
  3040. //}
  3041. //
  3042. //
  3043. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3044. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3045. // advice.CheckTime = check_time
  3046. //}
  3047. //
  3048. //
  3049. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3050. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3051. // advice.CheckState = check_state
  3052. //}
  3053. //
  3054. //
  3055. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3056. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3057. // advice.Checker = checker
  3058. //}
  3059. //
  3060. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3061. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3062. // advice.StartTime = start_time
  3063. //}
  3064. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3065. drugSpecUnit, _ := json["min_unit"].(string)
  3066. advice.DrugSpecUnit = drugSpecUnit
  3067. }
  3068. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3069. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3070. advice.SingleDose = singleDose
  3071. }
  3072. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3073. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3074. advice.SingleDoseUnit = singleDoseUnit
  3075. }
  3076. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3077. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3078. advice.PrescribingNumber = prescribingNumber
  3079. }
  3080. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3081. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3082. advice.PrescribingNumberUnit = prescribingNumberUnit
  3083. }
  3084. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3085. deliveryWay, _ := json["delivery_way"].(string)
  3086. advice.DeliveryWay = deliveryWay
  3087. }
  3088. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3089. executionFrequency, _ := json["execution_frequency"].(string)
  3090. advice.ExecutionFrequency = executionFrequency
  3091. }
  3092. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3093. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3094. advice.Price = price
  3095. }
  3096. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3097. med_list_codg, _ := json["medical_insurance_number"].(string)
  3098. advice.MedListCodg = med_list_codg
  3099. }
  3100. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3101. day := int64(json["day"].(float64))
  3102. advice.Day = day
  3103. }
  3104. return 0
  3105. }
  3106. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3107. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3108. id := int64(json["id"].(float64))
  3109. project.ID = id
  3110. historyProject, _ := service.GetHisProjectByID(id)
  3111. project.FeedetlSn = historyProject.FeedetlSn
  3112. }
  3113. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3114. project_id := int64(json["project_id"].(float64))
  3115. project.ProjectId = project_id
  3116. }
  3117. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3118. // price := int64(json["price"].(float64))
  3119. // formatInt_price := strconv.FormatInt(price, 10)
  3120. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3121. // project.Price = float_price
  3122. // }
  3123. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3124. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3125. project.Price = price
  3126. }
  3127. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3128. total, _ := json["total"].(string)
  3129. project.Count = total
  3130. }
  3131. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3132. medical_code, _ := json["medical_code"].(string)
  3133. project.MedListCodg = medical_code
  3134. }
  3135. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3136. single_dose, _ := json["single_dose"].(string)
  3137. project.SingleDose = single_dose
  3138. }
  3139. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3140. delivery_way, _ := json["delivery_way"].(string)
  3141. project.DeliveryWay = delivery_way
  3142. }
  3143. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3144. execution_frequency, _ := json["execution_frequency"].(string)
  3145. project.ExecutionFrequency = execution_frequency
  3146. }
  3147. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3148. remark, _ := json["remark"].(string)
  3149. project.Remark = remark
  3150. }
  3151. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3152. day, _ := json["number_days"].(string)
  3153. project.Day = day
  3154. }
  3155. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3156. unit, _ := json["unit"].(string)
  3157. project.Unit = unit
  3158. }
  3159. return 0
  3160. }
  3161. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3162. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3163. id := int64(json["id"].(float64))
  3164. historyAddtions, _ := service.GetHisAdditionByID(id)
  3165. additionalCharge.ID = id
  3166. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  3167. }
  3168. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3169. item_id := int64(json["item_id"].(float64))
  3170. additionalCharge.ItemId = item_id
  3171. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3172. if config.ID > 0 {
  3173. if len(config.Code) > 0 {
  3174. additionalCharge.MedListCodg = config.Code
  3175. }
  3176. }
  3177. }
  3178. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3179. // price := int64(json["price"].(float64))
  3180. // formatInt_price := strconv.FormatInt(price, 10)
  3181. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3182. // additionalCharge.Price = float_price
  3183. // }
  3184. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3185. // price := int64(json["price"].(float64))
  3186. // formatInt_price := strconv.FormatInt(price, 10)
  3187. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3188. // additionalCharge.Price = float_price
  3189. //}
  3190. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3191. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3192. additionalCharge.Price = price
  3193. }
  3194. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3195. count, _ := json["count"].(string)
  3196. counts, _ := strconv.ParseInt(count, 10, 64)
  3197. additionalCharge.Count = counts
  3198. }
  3199. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3200. item_name, _ := json["item_name"].(string)
  3201. additionalCharge.ItemName = item_name
  3202. }
  3203. return 0
  3204. }
  3205. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  3206. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3207. utils.ErrorLog("drug_name")
  3208. return enums.ErrorCodeParamWrong
  3209. }
  3210. adviceName, _ := json["drug_name"].(string)
  3211. if len(adviceName) == 0 {
  3212. utils.ErrorLog("len(advice_name) == 0")
  3213. return enums.ErrorCodeParamWrong
  3214. }
  3215. advice.AdviceName = adviceName
  3216. adviceDesc, _ := json["advice_desc"].(string)
  3217. advice.AdviceDesc = adviceDesc
  3218. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3219. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3220. advice.DrugSpec = drugSpec
  3221. }
  3222. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3223. remark, _ := json["remark"].(string)
  3224. advice.Remark = remark
  3225. }
  3226. if json["id"] == nil {
  3227. advice.DrugId = 0
  3228. } else {
  3229. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3230. drug_id := int64(json["id"].(float64))
  3231. advice.DrugId = drug_id
  3232. }
  3233. }
  3234. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  3235. groupno := int64(json["groupno"].(float64))
  3236. advice.Groupno = groupno
  3237. }
  3238. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  3239. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  3240. advice.HospApprFlag = hosp_appr_flag
  3241. }
  3242. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3243. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3244. advice.PrescribingNumber = prescribingNumber
  3245. }
  3246. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3247. // frequency_type := int64(json["frequency_type"].(float64))
  3248. // advice.FrequencyType = frequency_type
  3249. //}
  3250. //
  3251. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3252. // day_count := int64(json["day_count"].(float64))
  3253. // advice.DayCount = day_count
  3254. //}
  3255. //
  3256. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3257. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3258. // week_day, _ := json["week_day"].(string)
  3259. // advice.WeekDay = week_day
  3260. //}
  3261. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3262. drugSpecUnit, _ := json["min_unit"].(string)
  3263. advice.DrugSpecUnit = drugSpecUnit
  3264. }
  3265. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3266. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3267. advice.SingleDose = singleDose
  3268. }
  3269. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3270. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3271. advice.SingleDoseUnit = singleDoseUnit
  3272. }
  3273. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3274. deliveryWay, _ := json["delivery_way"].(string)
  3275. advice.DeliveryWay = deliveryWay
  3276. }
  3277. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3278. executionFrequency, _ := json["execution_frequency"].(string)
  3279. advice.ExecutionFrequency = executionFrequency
  3280. }
  3281. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3282. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3283. advice.Price = price
  3284. }
  3285. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3286. med_list_codg, _ := json["medical_insurance_number"].(string)
  3287. advice.MedListCodg = med_list_codg
  3288. }
  3289. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3290. day := int64(json["day"].(float64))
  3291. advice.Day = day
  3292. }
  3293. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3294. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3295. advice.PrescribingNumberUnit = prescribingNumberUnit
  3296. }
  3297. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  3298. advice_id := int64(json["advice_id"].(float64))
  3299. advice.ID = advice_id
  3300. if advice.ID > 0 {
  3301. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  3302. if err == nil {
  3303. if hisAdvice.ID > 0 {
  3304. advice.ExecutionTime = hisAdvice.ExecutionTime
  3305. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  3306. advice.ExecutionState = hisAdvice.ExecutionState
  3307. advice.CheckTime = hisAdvice.CheckTime
  3308. advice.Checker = hisAdvice.Checker
  3309. advice.CheckState = hisAdvice.CheckState
  3310. advice.StartTime = hisAdvice.StartTime
  3311. advice.HospApprFlag = hisAdvice.HospApprFlag
  3312. advice.IsMedicine = hisAdvice.IsMedicine
  3313. if hisAdvice.UserOrgId == 10028 {
  3314. 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 {
  3315. advice.ExecutionTime = 0
  3316. advice.ExecutionStaff = 0
  3317. advice.ExecutionState = 2
  3318. advice.CheckTime = 0
  3319. advice.Checker = 0
  3320. advice.CheckState = 2
  3321. }
  3322. } else {
  3323. 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 {
  3324. advice.ExecutionTime = 0
  3325. advice.ExecutionStaff = 0
  3326. advice.ExecutionState = 2
  3327. advice.CheckTime = 0
  3328. advice.Checker = 0
  3329. advice.CheckState = 2
  3330. }
  3331. }
  3332. //advice.Groupno = hisAdvice.Groupno
  3333. }
  3334. }
  3335. }
  3336. }
  3337. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  3338. //
  3339. //if drugStockConfig.IsOpen == 1 {
  3340. //
  3341. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  3342. // if advice.ID == 0 { //医嘱不存在
  3343. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  3344. // drug.Total = drug.Total - advice.PrescribingNumber
  3345. // service.UpdateBaseDrugLib(&drug)
  3346. //
  3347. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  3348. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  3349. // drug.Total = drug.Total - num
  3350. // service.UpdateBaseDrugLib(&drug)
  3351. // }
  3352. //
  3353. // } else if advice.ID > 0 { //医嘱存在
  3354. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  3355. // var num float64
  3356. //
  3357. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  3358. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  3359. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  3360. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  3361. // drug.Total = drug.Total + num
  3362. // service.UpdateBaseDrugLib(&drug)
  3363. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  3364. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  3365. // drug.Total = drug.Total - num
  3366. // service.UpdateBaseDrugLib(&drug)
  3367. // }
  3368. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  3369. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3370. // if num2 > advice.PrescribingNumber {
  3371. // num = num2 - advice.PrescribingNumber
  3372. // drug.Total = drug.Total + num
  3373. // service.UpdateBaseDrugLib(&drug)
  3374. // } else if num2 < advice.PrescribingNumber {
  3375. // num = advice.PrescribingNumber - num2
  3376. // drug.Total = drug.Total - num
  3377. // service.UpdateBaseDrugLib(&drug)
  3378. // }
  3379. //
  3380. // }
  3381. //
  3382. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  3383. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  3384. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  3385. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3386. // if num1 > num2 {
  3387. // num = num1 - num2
  3388. // drug.Total = drug.Total + num
  3389. // service.UpdateBaseDrugLib(&drug)
  3390. // } else if num1 < num2 {
  3391. // num = num2 - num1
  3392. // drug.Total = drug.Total - num
  3393. // service.UpdateBaseDrugLib(&drug)
  3394. // }
  3395. //
  3396. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  3397. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  3398. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  3399. // if hisAdvice.PrescribingNumber > num2 {
  3400. // num = hisAdvice.PrescribingNumber - num2
  3401. // drug.Total = drug.Total + num
  3402. // service.UpdateBaseDrugLib(&drug)
  3403. // } else if num2 < advice.PrescribingNumber {
  3404. // num = num2 - hisAdvice.PrescribingNumber
  3405. // drug.Total = drug.Total - num
  3406. // service.UpdateBaseDrugLib(&drug)
  3407. // }
  3408. //
  3409. // }
  3410. // }
  3411. // }
  3412. //}
  3413. //
  3414. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  3415. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3416. // advice.ExecutionTime = execution_time
  3417. //}
  3418. //
  3419. //
  3420. //
  3421. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3422. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3423. // advice.ExecutionStaff = execution_staff
  3424. //}
  3425. //
  3426. //
  3427. //
  3428. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3429. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3430. // advice.ExecutionState = execution_state
  3431. //}
  3432. //
  3433. //
  3434. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3435. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3436. // advice.CheckTime = check_time
  3437. //}
  3438. //
  3439. //
  3440. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3441. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3442. // advice.CheckState = check_state
  3443. //}
  3444. //
  3445. //
  3446. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3447. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3448. // advice.Checker = checker
  3449. //}
  3450. //
  3451. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3452. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3453. // advice.StartTime = start_time
  3454. //}
  3455. return 0
  3456. }
  3457. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3458. project.ExecutionStaff = 0
  3459. project.ExecutionState = 2
  3460. project.ExecutionTime = 0
  3461. project.Checker = 0
  3462. project.CheckState = 2
  3463. project.CheckTime = 0
  3464. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3465. id := int64(json["id"].(float64))
  3466. project.ID = id
  3467. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3468. project.ExecutionStaff = temp_project.ExecutionStaff
  3469. project.ExecutionState = temp_project.ExecutionState
  3470. project.ExecutionTime = temp_project.ExecutionTime
  3471. project.Checker = temp_project.Checker
  3472. project.CheckState = temp_project.CheckState
  3473. project.CheckTime = temp_project.CheckTime
  3474. project.TeamId = temp_project.TeamId
  3475. }
  3476. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3477. types := int64(json["type"].(float64))
  3478. project.Type = types
  3479. }
  3480. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3481. project_id := int64(json["project_id"].(float64))
  3482. project.ProjectId = project_id
  3483. }
  3484. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3485. team_id := int64(json["team_id"].(float64))
  3486. project.TeamId = team_id
  3487. }
  3488. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3489. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3490. project.Price = price
  3491. }
  3492. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3493. total, _ := json["total"].(string)
  3494. //totals, _ := strconv.ParseInt(total, 10, 64)
  3495. project.Count = total
  3496. }
  3497. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3498. medical_code, _ := json["medical_code"].(string)
  3499. project.MedListCodg = medical_code
  3500. }
  3501. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3502. single_dose, _ := json["single_dose"].(string)
  3503. project.SingleDose = single_dose
  3504. }
  3505. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3506. delivery_way, _ := json["delivery_way"].(string)
  3507. project.DeliveryWay = delivery_way
  3508. }
  3509. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3510. execution_frequency, _ := json["execution_frequency"].(string)
  3511. project.ExecutionFrequency = execution_frequency
  3512. }
  3513. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3514. remark, _ := json["remark"].(string)
  3515. project.Remark = remark
  3516. }
  3517. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3518. day, _ := json["number_days"].(string)
  3519. project.Day = day
  3520. }
  3521. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3522. unit, _ := json["unit"].(string)
  3523. project.Unit = unit
  3524. }
  3525. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3526. // frequency_type := int64(json["frequency_type"].(float64))
  3527. // project.FrequencyType = frequency_type
  3528. //}
  3529. //
  3530. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3531. // day_count := int64(json["day_count"].(float64))
  3532. // project.DayCount = day_count
  3533. //}
  3534. //
  3535. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3536. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3537. // week_day, _ := json["week_day"].(string)
  3538. // project.WeekDay = week_day
  3539. //}
  3540. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3541. //
  3542. //if project.ID == 0 {
  3543. // if stockConfig.IsOpen == 1 {
  3544. // if project.Type == 3 {
  3545. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3546. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3547. // good.Total = good.Total - f_count
  3548. // service.UpdateGoodInfo(&good)
  3549. // }
  3550. // }
  3551. //
  3552. //} else {
  3553. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3554. //
  3555. // if stockConfig.IsOpen == 1 {
  3556. // if project.Type == 3 {
  3557. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3558. // if project.Count < temp_project.Count {
  3559. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3560. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3561. //
  3562. // other_count := f_count_two - f_count_one
  3563. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3564. // good.Total = good.Total + other_count_two
  3565. // service.UpdateGoodInfo(&good)
  3566. // } else if project.Count > temp_project.Count {
  3567. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3568. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3569. //
  3570. // other_count := f_count_one - f_count_two
  3571. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3572. // good.Total = good.Total - other_count_two
  3573. // service.UpdateGoodInfo(&good)
  3574. // }
  3575. //
  3576. // }
  3577. // }
  3578. //
  3579. //}
  3580. return 0
  3581. }
  3582. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3583. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3584. id := int64(json["id"].(float64))
  3585. additionalCharge.ID = id
  3586. }
  3587. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3588. item_id := int64(json["item_id"].(float64))
  3589. additionalCharge.ItemId = item_id
  3590. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3591. if config.ID > 0 {
  3592. if len(config.Code) > 0 {
  3593. additionalCharge.MedListCodg = config.Code
  3594. }
  3595. }
  3596. }
  3597. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3598. // price := int64(json["price"].(float64))
  3599. // formatInt_price := strconv.FormatInt(price, 10)
  3600. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3601. // additionalCharge.Price = float_price
  3602. // }
  3603. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3604. // price := int64(json["price"].(float64))
  3605. // formatInt_price := strconv.FormatInt(price, 10)
  3606. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3607. // additionalCharge.Price = float_price
  3608. //}
  3609. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3610. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3611. additionalCharge.Price = price
  3612. }
  3613. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3614. count, _ := json["count"].(string)
  3615. counts, _ := strconv.ParseInt(count, 10, 64)
  3616. additionalCharge.Count = counts
  3617. }
  3618. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3619. item_name, _ := json["item_name"].(string)
  3620. additionalCharge.ItemName = item_name
  3621. }
  3622. return 0
  3623. }
  3624. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3625. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3626. utils.ErrorLog("drug_name")
  3627. return enums.ErrorCodeParamWrong
  3628. }
  3629. adviceName, _ := json["drug_name"].(string)
  3630. if len(adviceName) == 0 {
  3631. utils.ErrorLog("len(advice_name) == 0")
  3632. return enums.ErrorCodeParamWrong
  3633. }
  3634. advice.AdviceName = adviceName
  3635. adviceDesc, _ := json["advice_desc"].(string)
  3636. advice.AdviceDesc = adviceDesc
  3637. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3638. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3639. advice.DrugSpec = drugSpec
  3640. }
  3641. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3642. remark, _ := json["remark"].(string)
  3643. advice.Remark = remark
  3644. }
  3645. if json["id"] == nil {
  3646. advice.DrugId = 0
  3647. } else {
  3648. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3649. drug_id := int64(json["id"].(float64))
  3650. advice.DrugId = drug_id
  3651. }
  3652. }
  3653. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3654. drugSpecUnit, _ := json["min_unit"].(string)
  3655. advice.DrugSpecUnit = drugSpecUnit
  3656. }
  3657. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3658. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3659. advice.SingleDose = singleDose
  3660. }
  3661. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3662. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3663. advice.SingleDoseUnit = singleDoseUnit
  3664. }
  3665. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3666. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3667. advice.PrescribingNumber = prescribingNumber
  3668. }
  3669. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3670. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3671. advice.PrescribingNumberUnit = prescribingNumberUnit
  3672. }
  3673. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3674. deliveryWay, _ := json["delivery_way"].(string)
  3675. advice.DeliveryWay = deliveryWay
  3676. }
  3677. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3678. executionFrequency, _ := json["execution_frequency"].(string)
  3679. advice.ExecutionFrequency = executionFrequency
  3680. }
  3681. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3682. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3683. advice.Price = price
  3684. }
  3685. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3686. med_list_codg, _ := json["medical_insurance_number"].(string)
  3687. advice.MedListCodg = med_list_codg
  3688. }
  3689. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3690. day := int64(json["day"].(float64))
  3691. advice.Day = day
  3692. }
  3693. return 0
  3694. }
  3695. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3696. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3697. types := int64(json["type"].(float64))
  3698. project.Type = types
  3699. }
  3700. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3701. project_id := int64(json["project_id"].(float64))
  3702. project.ProjectId = project_id
  3703. }
  3704. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3705. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3706. project.Price = price
  3707. }
  3708. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3709. total, _ := json["total"].(string)
  3710. //totals, _ := strconv.ParseInt(total, 10, 64)
  3711. project.Count = total
  3712. }
  3713. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3714. medical_code, _ := json["medical_code"].(string)
  3715. project.MedListCodg = medical_code
  3716. }
  3717. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3718. single_dose, _ := json["single_dose"].(string)
  3719. project.SingleDose = single_dose
  3720. }
  3721. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3722. delivery_way, _ := json["delivery_way"].(string)
  3723. project.DeliveryWay = delivery_way
  3724. }
  3725. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3726. execution_frequency, _ := json["execution_frequency"].(string)
  3727. project.ExecutionFrequency = execution_frequency
  3728. }
  3729. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3730. remark, _ := json["remark"].(string)
  3731. project.Remark = remark
  3732. }
  3733. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3734. day, _ := json["number_days"].(string)
  3735. project.Day = day
  3736. }
  3737. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3738. unit, _ := json["unit"].(string)
  3739. project.Unit = unit
  3740. }
  3741. return 0
  3742. }
  3743. func (c *HisApiController) GetHisOrderList() {
  3744. page, _ := c.GetInt64("page", -1)
  3745. limit, _ := c.GetInt64("limit", -1)
  3746. start_time := c.GetString("start_time")
  3747. end_time := c.GetString("end_time")
  3748. types, _ := c.GetInt64("type", 0)
  3749. keywords := c.GetString("keywords")
  3750. p_type, _ := c.GetInt64("p_type", 0)
  3751. sort_type, _ := c.GetInt64("sort_type", 0)
  3752. charge_type, _ := c.GetInt64("charge_type", 0)
  3753. timeLayout := "2006-01-02"
  3754. loc, _ := time.LoadLocation("Local")
  3755. var startTime int64
  3756. if len(start_time) > 0 {
  3757. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3758. if err != nil {
  3759. //fmt.Println(err)
  3760. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3761. return
  3762. }
  3763. startTime = theTime.Unix()
  3764. }
  3765. var endTime int64
  3766. if len(end_time) > 0 {
  3767. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3768. if err != nil {
  3769. utils.ErrorLog(err.Error())
  3770. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3771. return
  3772. }
  3773. endTime = theTime.Unix()
  3774. }
  3775. adminUser := c.GetAdminUserInfo()
  3776. org_id := adminUser.CurrentOrgId
  3777. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time, charge_type)
  3778. for _, item := range order {
  3779. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3780. item.DoctorName = info.Doctor
  3781. item.DepartmentName = info.XtHisDepartment.Name
  3782. }
  3783. if err == nil {
  3784. c.ServeSuccessJSON(map[string]interface{}{
  3785. "order": order,
  3786. "total": total,
  3787. })
  3788. } else {
  3789. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3790. return
  3791. }
  3792. }
  3793. func (c *HisApiController) GetHisOrder() {
  3794. patient_id, _ := c.GetInt64("patient_id", 0)
  3795. number := c.GetString("number")
  3796. adminInfo := c.GetAdminUserInfo()
  3797. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3798. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3799. if err == nil {
  3800. c.ServeSuccessJSON(map[string]interface{}{
  3801. "order": order,
  3802. "prescription": prescriptions,
  3803. })
  3804. } else {
  3805. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3806. return
  3807. }
  3808. }
  3809. func (c *HisApiController) GetHisPrescriptionList() {
  3810. record_date := c.GetString("record_date")
  3811. keywords := c.GetString("keywords")
  3812. page, _ := c.GetInt64("page")
  3813. limit, _ := c.GetInt64("limit")
  3814. timeLayout := "2006-01-02"
  3815. loc, _ := time.LoadLocation("Local")
  3816. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3817. if err != nil {
  3818. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3819. return
  3820. }
  3821. recordDateTime := theTime.Unix()
  3822. adminInfo := c.GetAdminUserInfo()
  3823. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3824. //adminInfo := c.GetAdminUserInfo()
  3825. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3826. //fmt.Println(prescriptionOrder)
  3827. if err == nil {
  3828. c.ServeSuccessJSON(map[string]interface{}{
  3829. "order": prescriptionOrder,
  3830. "total": total,
  3831. })
  3832. } else {
  3833. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3834. return
  3835. }
  3836. }
  3837. func (c *HisApiController) GetHisPrescriptionInfo() {
  3838. id, _ := c.GetInt64("id")
  3839. adminInfo := c.GetAdminUserInfo()
  3840. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3841. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3842. if err == nil {
  3843. c.ServeSuccessJSON(map[string]interface{}{
  3844. "order": prescriptionOrder,
  3845. "prescription": prescription,
  3846. })
  3847. } else {
  3848. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3849. return
  3850. }
  3851. }
  3852. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3853. adminUser := c.GetAdminUserInfo()
  3854. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3855. c.ServeSuccessJSON(map[string]interface{}{
  3856. "config": config,
  3857. })
  3858. }
  3859. type ResultTwo struct {
  3860. ErrMsg interface{} `json:"err_msg"`
  3861. InfRefmsgid string `json:"inf_refmsgid"`
  3862. Infcode int64 `json:"infcode"`
  3863. Output struct {
  3864. Baseinfo struct {
  3865. Age float64 `json:"age"`
  3866. Brdy string `json:"brdy"`
  3867. Certno string `json:"certno"`
  3868. Gend string `json:"gend"`
  3869. Naty string `json:"naty"`
  3870. PsnCertType string `json:"psn_cert_type"`
  3871. PsnName string `json:"psn_name"`
  3872. PsnNo string `json:"psn_no"`
  3873. } `json:"baseinfo"`
  3874. Idetinfo []interface{} `json:"idetinfo"`
  3875. Iinfo []struct {
  3876. Balc float64 `json:"balc"`
  3877. CvlservFlag string `json:"cvlserv_flag"`
  3878. EmpName string `json:"emp_name"`
  3879. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3880. Insutype string `json:"insutype"`
  3881. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3882. PausInsuDate interface{} `json:"paus_insu_date"`
  3883. PsnInsuDate string `json:"psn_insu_date"`
  3884. PsnInsuStas string `json:"psn_insu_stas"`
  3885. PsnType string `json:"psn_type"`
  3886. } `json:"insuinfo"`
  3887. } `json:"output"`
  3888. RefmsgTime string `json:"refmsg_time"`
  3889. RespondTime string `json:"respond_time"`
  3890. Signtype interface{} `json:"signtype"`
  3891. WarnInfo interface{} `json:"warn_info"`
  3892. }
  3893. type ResultThree struct {
  3894. Cainfo interface{} `json:"cainfo"`
  3895. ErrMsg interface{} `json:"err_msg"`
  3896. InfRefmsgid string `json:"inf_refmsgid"`
  3897. Infcode int64 `json:"infcode"`
  3898. Output struct {
  3899. Data struct {
  3900. IptOtpNo string `json:"ipt_otp_no"`
  3901. MdtrtID string `json:"mdtrt_id"`
  3902. PsnNo string `json:"psn_no"`
  3903. } `json:"data"`
  3904. } `json:"output"`
  3905. RefmsgTime string `json:"refmsg_time"`
  3906. RespondTime string `json:"respond_time"`
  3907. Signtype interface{} `json:"signtype"`
  3908. WarnMsg interface{} `json:"warn_msg"`
  3909. }
  3910. type ResultFour struct {
  3911. Cainfo string `json:"cainfo"`
  3912. ErrMsg string `json:"err_msg"`
  3913. InfRefmsgid string `json:"inf_refmsgid"`
  3914. Infcode int64 `json:"infcode"`
  3915. Output struct {
  3916. Result []struct {
  3917. BasMednFlag string `json:"bas_medn_flag"`
  3918. ChldMedcFlag string `json:"chld_medc_flag"`
  3919. ChrgitmLv string `json:"chrgitm_lv"`
  3920. Cnt float64 `json:"cnt"`
  3921. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3922. DrtReimFlag string `json:"drt_reim_flag"`
  3923. FeedetlSn string `json:"feedetl_sn"`
  3924. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3925. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3926. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3927. ListSpItemFlag string `json:"list_sp_item_flag"`
  3928. LmtUsedFlag string `json:"lmt_used_flag"`
  3929. MedChrgitmType string `json:"med_chrgitm_type"`
  3930. Memo string `json:"memo"`
  3931. OverlmtAmt float64 `json:"overlmt_amt"`
  3932. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3933. Pric float64 `json:"pric"`
  3934. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3935. SelfpayProp float64 `json:"selfpay_prop"`
  3936. } `json:"result"`
  3937. } `json:"output"`
  3938. RefmsgTime string `json:"refmsg_time"`
  3939. RespondTime string `json:"respond_time"`
  3940. Signtype string `json:"signtype"`
  3941. WarnMsg string `json:"warn_msg"`
  3942. }
  3943. type ResultFive struct {
  3944. Insutype string `json:"insutype"`
  3945. }
  3946. type ResultSix struct {
  3947. Cainfo interface{} `json:"cainfo"`
  3948. ErrMsg interface{} `json:"err_msg"`
  3949. InfRefmsgid string `json:"inf_refmsgid"`
  3950. Infcode int64 `json:"infcode"`
  3951. Output struct {
  3952. } `json:"output"`
  3953. RefmsgTime string `json:"refmsg_time"`
  3954. RespondTime string `json:"respond_time"`
  3955. Signtype interface{} `json:"signtype"`
  3956. WarnMsg interface{} `json:"warn_msg"`
  3957. }
  3958. type ResultSeven struct {
  3959. Cainfo string `json:"cainfo"`
  3960. ErrMsg string `json:"err_msg"`
  3961. InfRefmsgid string `json:"inf_refmsgid"`
  3962. Infcode int64 `json:"infcode"`
  3963. Output struct {
  3964. Setldetail []interface{} `json:"setldetail"`
  3965. Setlinfo struct {
  3966. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3967. AcctPay float64 `json:"acct_pay"`
  3968. ActPayDedc float64 `json:"act_pay_dedc"`
  3969. Age float64 `json:"age"`
  3970. Balc float64 `json:"balc"`
  3971. Brdy string `json:"brdy"`
  3972. Certno string `json:"certno"`
  3973. ClrOptins string `json:"clr_optins"`
  3974. ClrType string `json:"clr_type"`
  3975. ClrWay string `json:"clr_way"`
  3976. CvlservFlag string `json:"cvlserv_flag"`
  3977. CvlservPay float64 `json:"cvlserv_pay"`
  3978. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3979. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3980. Gend string `json:"gend"`
  3981. HifesPay float64 `json:"hifes_pay"`
  3982. HifmiPay float64 `json:"hifmi_pay"`
  3983. HifobPay float64 `json:"hifob_pay"`
  3984. HifpPay float64 `json:"hifp_pay"`
  3985. HospPartAmt float64 `json:"hosp_part_amt"`
  3986. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3987. Insutype string `json:"insutype"`
  3988. MafPay float64 `json:"maf_pay"`
  3989. MdtrtCertType string `json:"mdtrt_cert_type"`
  3990. MdtrtID string `json:"mdtrt_id"`
  3991. MedType string `json:"med_type"`
  3992. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3993. MedinsSetlID string `json:"medins_setl_id"`
  3994. Naty string `json:"naty"`
  3995. OthPay float64 `json:"oth_pay"`
  3996. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3997. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3998. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3999. PsnCashPay float64 `json:"psn_cash_pay"`
  4000. PsnCertType string `json:"psn_cert_type"`
  4001. PsnName string `json:"psn_name"`
  4002. PsnNo string `json:"psn_no"`
  4003. PsnPartAmt float64 `json:"psn_part_amt"`
  4004. PsnType string `json:"psn_type"`
  4005. SetlID string `json:"setl_id"`
  4006. SetlTime string `json:"setl_time"`
  4007. } `json:"setlinfo"`
  4008. } `json:"output"`
  4009. RefmsgTime string `json:"refmsg_time"`
  4010. RespondTime string `json:"respond_time"`
  4011. Signtype interface{} `json:"signtype"`
  4012. WarnMsg interface{} `json:"warn_msg"`
  4013. }
  4014. type ResultEight struct {
  4015. Cainfo string `json:"cainfo"`
  4016. ErrMsg string `json:"err_msg"`
  4017. InfRefmsgid string `json:"inf_refmsgid"`
  4018. Infcode int64 `json:"infcode"`
  4019. Output struct {
  4020. Stmtinfo struct {
  4021. SetlOptins string `json:"setl_optins"`
  4022. StmtRslt string `json:"stmt_rslt"`
  4023. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  4024. } `json:"stmtinfo"`
  4025. } `json:"output"`
  4026. RefmsgTime string `json:"refmsg_time"`
  4027. RespondTime string `json:"respond_time"`
  4028. Signtype interface{} `json:"signtype"`
  4029. WarnMsg interface{} `json:"warn_msg"`
  4030. }
  4031. type ResultNine struct {
  4032. Cainfo string `json:"cainfo"`
  4033. ErrMsg string `json:"err_msg"`
  4034. InfRefmsgid string `json:"inf_refmsgid"`
  4035. Infcode int64 `json:"infcode"`
  4036. Output struct {
  4037. FileQuryNo string `json:"file_qury_no"`
  4038. } `json:"output"`
  4039. RefmsgTime string `json:"refmsg_time"`
  4040. RespondTime string `json:"respond_time"`
  4041. Signtype interface{} `json:"signtype"`
  4042. WarnMsg interface{} `json:"warn_msg"`
  4043. }
  4044. type ResultTen struct {
  4045. Cainfo string `json:"cainfo"`
  4046. ErrMsg string `json:"err_msg"`
  4047. InfRefmsgid string `json:"inf_refmsgid"`
  4048. Infcode int64 `json:"infcode"`
  4049. Output struct {
  4050. DldEndtime string `json:"dld_endtime"`
  4051. FileQuryNo string `json:"file_qury_no"`
  4052. Filename string `json:"filename"`
  4053. } `json:"output"`
  4054. RefmsgTime string `json:"refmsg_time"`
  4055. RespondTime string `json:"respond_time"`
  4056. Signtype interface{} `json:"signtype"`
  4057. WarnMsg interface{} `json:"warn_msg"`
  4058. }
  4059. type ResultEleven struct {
  4060. Cainfo string `json:"cainfo"`
  4061. ErrMsg string `json:"err_msg"`
  4062. InfRefmsgid string `json:"inf_refmsgid"`
  4063. Infcode int64 `json:"infcode"`
  4064. Output struct {
  4065. Setlinfo struct {
  4066. FixmedinsName string `json:"fixmedins_name"`
  4067. FixmedinsCode string `json:"fixmedins_code"`
  4068. PsnNo string `json:"psn_no"`
  4069. PsnName string `json:"psn_name"`
  4070. HifobPay float64 `json:"hifob_pay"`
  4071. Gend string `json:"gend"`
  4072. Brdy string `json:"brdy"`
  4073. PsnCertType string `json:"psn_cert_type"`
  4074. PsnType string `json:"psn_type"`
  4075. EmpName string `json:"emp_name"`
  4076. Certno string `json:"certno"`
  4077. Insutype string `json:"insutype"`
  4078. MedfeeSumamt float64 `json:"medfee_sumamt"`
  4079. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  4080. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  4081. PreselfpayAmt float64 `json:"preselfpay_amt"`
  4082. InscpScpAmt float64 `json:"inscp_scp_amt"`
  4083. ActPayDedc float64 `json:"act_pay_dedc"`
  4084. HifpPay float64 `json:"hifp_pay"`
  4085. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  4086. CvlservPay float64 `json:"cvlserv_pay"`
  4087. HifesPay float64 `json:"hifes_pay"`
  4088. HifmiPay float64 `json:"hifmi_pay"`
  4089. MafPay float64 `json:"maf_pay"`
  4090. OthPay float64 `json:"oth_pay"`
  4091. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  4092. PsnPay float64 `json:"psn_pay"`
  4093. AcctPay float64 `json:"acct_pay"`
  4094. CashPayamt float64 `json:"cash_payamt"`
  4095. Balc float64 `json:"balc"`
  4096. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  4097. MedinsSetlId string `json:"medins_setl_id"`
  4098. RefdSetlFlag string `json:"refd_setl_flag"`
  4099. SetlTime string `json:"setl_time"`
  4100. MedType string `json:"med_type"`
  4101. } `json:"setlinfo"`
  4102. } `json:"output"`
  4103. RefmsgTime string `json:"refmsg_time"`
  4104. RespondTime string `json:"respond_time"`
  4105. Signtype interface{} `json:"signtype"`
  4106. WarnMsg interface{} `json:"warn_msg"`
  4107. }
  4108. type Custom struct {
  4109. DetItemFeeSumamt string
  4110. Cut string
  4111. FeedetlSn string
  4112. Price string
  4113. MedListCodg string
  4114. Type int64
  4115. AdviceId int64
  4116. ProjectId int64
  4117. ItemId int64
  4118. }
  4119. //获取个人信息----挂号-----上传就诊信息
  4120. func (c *HisApiController) GetRegisterInfo() {
  4121. id, _ := c.GetInt64("id")
  4122. record_time := c.GetString("record_time")
  4123. settlementValue, _ := c.GetInt64("settlement_value")
  4124. medical_insurance_card := c.GetString("medical_insurance_card")
  4125. name := c.GetString("name")
  4126. id_card_type, _ := c.GetInt64("id_card_type")
  4127. certificates, _ := c.GetInt64("certificates")
  4128. medical_care, _ := c.GetInt64("medical_care")
  4129. birthday := c.GetString("birthday")
  4130. age, _ := c.GetInt64("age")
  4131. id_card := c.GetString("id_card")
  4132. register_type, _ := c.GetInt64("register")
  4133. doctor, _ := c.GetInt64("doctor")
  4134. department, _ := c.GetInt64("department")
  4135. gender, _ := c.GetInt64("sex")
  4136. phone := c.GetString("phone")
  4137. registration_fee, _ := c.GetFloat("registration_fee")
  4138. medical_expenses, _ := c.GetFloat("medical_expenses")
  4139. social_type, _ := c.GetInt64("social_type")
  4140. //diagnosis_id, _ := c.GetInt64("diagnosis")
  4141. diagnosis_ids := c.GetString("diagnosis")
  4142. sick_type, _ := c.GetInt64("sick_type")
  4143. reg_type := c.GetString("p_type")
  4144. timeLayout := "2006-01-02"
  4145. loc, _ := time.LoadLocation("Local")
  4146. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  4147. birthUnix := birthdays.Unix()
  4148. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4149. if err != nil {
  4150. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4151. return
  4152. }
  4153. recordDateTime := theTime.Unix()
  4154. adminInfo := c.GetAdminUserInfo()
  4155. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  4156. if tempPatient.ID == 0 {
  4157. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  4158. return
  4159. }
  4160. var patient service.Patients
  4161. if id == 0 {
  4162. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  4163. } else {
  4164. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  4165. }
  4166. if patient.ID == 0 {
  4167. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  4168. return
  4169. }
  4170. if len(patient.IdCardNo) == 0 {
  4171. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  4172. return
  4173. }
  4174. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4175. if len(his) >= 1 {
  4176. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  4177. if len(his) >= 1 && order.ID == 0 {
  4178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  4179. return
  4180. }
  4181. }
  4182. timeStr := time.Now().Format("2006-01-02 15:04:05")
  4183. fmt.Println(timeStr)
  4184. timeArr := strings.Split(timeStr, " ")
  4185. fmt.Println(timeArr)
  4186. timeArrTwo := strings.Split(timeArr[0], "-")
  4187. timeArrThree := strings.Split(timeArr[1], ":")
  4188. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  4189. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  4190. if len(lists) == 0 {
  4191. var hisPatient models.XtHisPatient
  4192. hisPatient = models.XtHisPatient{
  4193. Name: name,
  4194. Age: age,
  4195. Gender: gender,
  4196. Birthday: birthUnix,
  4197. Phone: phone,
  4198. MedicalTreatmentType: medical_care,
  4199. IdType: certificates,
  4200. IdCardNo: id_card,
  4201. BalanceAccountsType: settlementValue,
  4202. SocialType: social_type,
  4203. MedicalInsuranceNumber: medical_insurance_card,
  4204. RegisterType: register_type,
  4205. RegisterCost: registration_fee,
  4206. TreatmentCost: medical_expenses,
  4207. AdminUserId: adminInfo.AdminUser.Id,
  4208. UserOrgId: adminInfo.CurrentOrgId,
  4209. Status: 1,
  4210. RecordDate: recordDateTime,
  4211. IsReturn: 1,
  4212. PatientId: patient.ID,
  4213. Ctime: time.Now().Unix(),
  4214. Mtime: time.Now().Unix(),
  4215. Number: str,
  4216. IdCardType: id_card_type,
  4217. Departments: department,
  4218. Doctor: doctor,
  4219. PType: reg_type,
  4220. Diagnosis: diagnosis_ids,
  4221. SickType: sick_type,
  4222. }
  4223. service.CreateHisPatient(&hisPatient)
  4224. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4225. c.ServeSuccessJSON(map[string]interface{}{
  4226. "his_info": hisPatient,
  4227. })
  4228. } else {
  4229. //chrgBchno := rand.Intn(1000000) + 10000
  4230. var hisPatient models.XtHisPatient
  4231. hisPatient = models.XtHisPatient{
  4232. Name: name,
  4233. Age: age,
  4234. Gender: gender,
  4235. Birthday: birthUnix,
  4236. Phone: phone,
  4237. MedicalTreatmentType: medical_care,
  4238. IdType: certificates,
  4239. IdCardNo: id_card,
  4240. BalanceAccountsType: settlementValue,
  4241. SocialType: social_type,
  4242. MedicalInsuranceNumber: medical_insurance_card,
  4243. RegisterType: register_type,
  4244. RegisterCost: registration_fee,
  4245. TreatmentCost: medical_expenses,
  4246. AdminUserId: adminInfo.AdminUser.Id,
  4247. UserOrgId: adminInfo.CurrentOrgId,
  4248. Status: 1,
  4249. RecordDate: recordDateTime,
  4250. IsReturn: 1,
  4251. PatientId: patient.ID,
  4252. Ctime: time.Now().Unix(),
  4253. Mtime: time.Now().Unix(),
  4254. Number: str,
  4255. IdCardType: id_card_type,
  4256. Departments: department,
  4257. Doctor: doctor,
  4258. PType: reg_type,
  4259. Diagnosis: diagnosis_ids,
  4260. SickType: sick_type,
  4261. }
  4262. service.CreateHisPatient(&hisPatient)
  4263. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  4264. c.ServeSuccessJSON(map[string]interface{}{
  4265. "his_info": hisPatient,
  4266. })
  4267. }
  4268. }
  4269. //上传明细----结算
  4270. func (c *HisApiController) GetUploadInfo() {
  4271. id, _ := c.GetInt64("id")
  4272. record_time := c.GetString("record_time")
  4273. his_patient_id, _ := c.GetInt64("his_patient_id")
  4274. pay_way, _ := c.GetInt64("pay_way")
  4275. pay_price, _ := c.GetFloat("pay_price")
  4276. pay_card_no := c.GetString("pay_card_no")
  4277. discount_price, _ := c.GetFloat("discount_price")
  4278. preferential_price, _ := c.GetFloat("preferential_price")
  4279. reality_price, _ := c.GetFloat("reality_price")
  4280. found_price, _ := c.GetFloat("found_price")
  4281. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  4282. private_price, _ := c.GetFloat("private_price")
  4283. timeLayout := "2006-01-02"
  4284. loc, _ := time.LoadLocation("Local")
  4285. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  4286. fapiao_code := c.GetString("fapiao_code")
  4287. fapiao_number := c.GetString("fapiao_number")
  4288. diagnosis_id := c.GetString("diagnosis")
  4289. sick_type, _ := c.GetInt64("sick_type")
  4290. reg_type, _ := c.GetInt64("p_type")
  4291. order_id, _ := c.GetInt64("order_id")
  4292. dec_way := c.GetString("dec_way") //是否使用押金支付bool类型
  4293. tmp_decimal := c.GetString("tmp_decimal")
  4294. var decimal float64 //本次使用的押金
  4295. var errmsg error
  4296. tx := service.XTWriteDB().Begin() //开了事务
  4297. //只检测扣费函数SpendDeposit有没有返回错误,如果有则回滚所有以TX结尾的方法(去掉TX即为原先的方法)
  4298. defer func() {
  4299. if errmsg != nil {
  4300. utils.ErrorLog("事务失败,原因为: %v", errmsg.Error())
  4301. tx.Rollback()
  4302. } else {
  4303. tx.Commit()
  4304. }
  4305. }()
  4306. if dec_way == "true" && tmp_decimal == "0" || dec_way == "true" && tmp_decimal == "" {
  4307. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为0")
  4308. return
  4309. }
  4310. if len(tmp_decimal) > 0 {
  4311. if tmp_decimal[0] == 45 {
  4312. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金不能为负数")
  4313. return
  4314. }
  4315. }
  4316. tt, errs := strconv.ParseFloat(tmp_decimal, 64)
  4317. fmt.Println(errs)
  4318. //if errs != nil {
  4319. // c.ServeFailJsonSend(enums.ErrorCodeParamWrong, "押金金额错误")
  4320. // return
  4321. //}
  4322. decimal = tt
  4323. his, _ := service.GetHisPatientByIdThreeTX(his_patient_id, tx)
  4324. tempOrder, _ := service.GetHisOrderByIDTX(order_id, tx)
  4325. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  4326. if err != nil {
  4327. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4328. return
  4329. }
  4330. recordDateTime := theTime.Unix()
  4331. adminUser := c.GetAdminUserInfo()
  4332. var prescriptions []*models.HisPrescription
  4333. var start_time int64
  4334. var end_time int64
  4335. ids_str := c.GetString("ids")
  4336. ids_arr := strings.Split(ids_str, ",")
  4337. if tempOrder.ID == 0 {
  4338. if settle_accounts_type == 1 { //日结
  4339. fmt.Println(reg_type)
  4340. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  4341. prescriptions, _ = service.GetPrescriptionByIdsTX(ids_arr, adminUser.CurrentOrgId, tx)
  4342. } else {
  4343. prescriptions, _ = service.GetSettleHisPrescriptionTX(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type, tx)
  4344. }
  4345. } else { //月结
  4346. start_time_str := c.GetString("start_time")
  4347. end_time_str := c.GetString("end_time")
  4348. timeLayout := "2006-01-02"
  4349. loc, _ := time.LoadLocation("Local")
  4350. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  4351. if err != nil {
  4352. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4353. return
  4354. }
  4355. recordStartTime := theStartTime.Unix()
  4356. start_time = recordStartTime
  4357. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  4358. if err != nil {
  4359. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4360. return
  4361. }
  4362. recordEndTime := theEndTime.Unix()
  4363. end_time = recordEndTime
  4364. prescriptions, _ = service.GetMonthHisPrescriptionTX(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type, tx)
  4365. }
  4366. timestamp := time.Now().Unix()
  4367. tempTime := time.Unix(timestamp, 0)
  4368. timeFormat := tempTime.Format("20060102150405")
  4369. chrgBchno := rand.Intn(100000) + 10000
  4370. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  4371. strconv.FormatInt(his.PatientId, 10)
  4372. var ids []int64
  4373. for _, item := range prescriptions {
  4374. ids = append(ids, item.ID)
  4375. }
  4376. var total float64
  4377. for _, item := range prescriptions {
  4378. fmt.Println(item)
  4379. if item.Type == 1 { //药品
  4380. for _, subItem := range item.HisDoctorAdviceInfo {
  4381. total = total + (subItem.Price * subItem.PrescribingNumber)
  4382. }
  4383. }
  4384. if item.Type == 2 { //项目
  4385. for _, subItem := range item.HisPrescriptionProject {
  4386. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4387. total = total + (subItem.Price * cnt)
  4388. }
  4389. }
  4390. for _, subItem := range item.HisAdditionalCharge {
  4391. total = total + (subItem.Price * float64(subItem.Count))
  4392. }
  4393. }
  4394. if reg_type == 1111 || reg_type == 1112 {
  4395. reg_type = 11
  4396. }
  4397. tm := time.Unix(time.Now().Unix(), 0)
  4398. allTotal := fmt.Sprintf("%.4f", total)
  4399. totals, _ := strconv.ParseFloat(allTotal, 64)
  4400. order := &models.HisOrder{
  4401. UserOrgId: adminUser.CurrentOrgId,
  4402. HisPatientId: his.ID,
  4403. PatientId: id,
  4404. SettleAccountsDate: recordDateTime,
  4405. Ctime: time.Now().Unix(),
  4406. Mtime: time.Now().Unix(),
  4407. Status: 1,
  4408. OrderStatus: 2,
  4409. MdtrtId: his.Number,
  4410. Number: chrg_bchno,
  4411. MedfeeSumamt: totals,
  4412. PayWay: pay_way,
  4413. PayPrice: pay_price,
  4414. MedType: strconv.Itoa(int(reg_type)),
  4415. PayCardNo: pay_card_no,
  4416. DiscountPrice: discount_price,
  4417. PreferentialPrice: preferential_price,
  4418. RealityPrice: reality_price,
  4419. FoundPrice: found_price,
  4420. MedicalInsurancePrice: medical_insurance_price,
  4421. PrivatePrice: private_price,
  4422. SettleEndTime: end_time,
  4423. SettleStartTime: start_time,
  4424. SettleType: settle_accounts_type,
  4425. FaPiaoCode: fapiao_code,
  4426. FaPiaoNumber: fapiao_number,
  4427. Diagnosis: diagnosis_id,
  4428. PType: 2,
  4429. SetlTime: tm.Format("2006-01-02 15:04:05"),
  4430. Decimal: decimal,
  4431. }
  4432. err = service.CreateOrderTX(order, tx)
  4433. if err != nil {
  4434. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4435. return
  4436. }
  4437. var customs []*Custom
  4438. for _, item := range prescriptions {
  4439. if item.Type == 1 { //药品a
  4440. for _, subItem := range item.HisDoctorAdviceInfo {
  4441. cus := &Custom{
  4442. AdviceId: subItem.ID,
  4443. ProjectId: 0,
  4444. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  4445. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  4446. FeedetlSn: subItem.FeedetlSn,
  4447. Price: fmt.Sprintf("%.2f", subItem.Price),
  4448. MedListCodg: subItem.MedListCodg,
  4449. Type: 1,
  4450. }
  4451. customs = append(customs, cus)
  4452. }
  4453. }
  4454. if item.Type == 2 { //项目
  4455. for _, subItem := range item.HisPrescriptionProject {
  4456. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4457. cus := &Custom{
  4458. AdviceId: 0,
  4459. ProjectId: subItem.ID,
  4460. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4461. Cut: fmt.Sprintf("%.4f", cnt),
  4462. FeedetlSn: subItem.FeedetlSn,
  4463. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4464. MedListCodg: subItem.MedListCodg,
  4465. Type: 2,
  4466. }
  4467. customs = append(customs, cus)
  4468. }
  4469. }
  4470. for _, item := range item.HisAdditionalCharge {
  4471. cus := &Custom{
  4472. ItemId: item.ID,
  4473. AdviceId: 0,
  4474. ProjectId: 0,
  4475. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4476. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4477. FeedetlSn: item.FeedetlSn,
  4478. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4479. MedListCodg: item.XtHisAddtionConfig.Code,
  4480. Type: 3,
  4481. }
  4482. customs = append(customs, cus)
  4483. }
  4484. }
  4485. for _, item := range customs {
  4486. var advice_id int64 = 0
  4487. var project_id int64 = 0
  4488. var item_id int64 = 0
  4489. var types int64 = 0
  4490. if item.Type == 1 {
  4491. advice_id = item.AdviceId
  4492. project_id = 0
  4493. item_id = 0
  4494. } else if item.Type == 2 {
  4495. advice_id = 0
  4496. item_id = 0
  4497. project_id = item.ProjectId
  4498. } else if item.Type == 3 {
  4499. advice_id = 0
  4500. item_id = item.ItemId
  4501. project_id = 0
  4502. }
  4503. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4504. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4505. pric, _ := strconv.ParseFloat(item.Price, 32)
  4506. info := &models.HisOrderInfo{
  4507. OrderNumber: order.Number,
  4508. UploadDate: time.Now().Unix(),
  4509. AdviceId: advice_id,
  4510. DetItemFeeSumamt: detItemFeeSumamt,
  4511. Cnt: cut,
  4512. Pric: pric,
  4513. PatientId: id,
  4514. Status: 1,
  4515. Mtime: time.Now().Unix(),
  4516. Ctime: time.Now().Unix(),
  4517. UserOrgId: adminUser.CurrentOrgId,
  4518. HisPatientId: his.ID,
  4519. OrderId: order.ID,
  4520. ProjectId: project_id,
  4521. Type: types,
  4522. ItemId: item_id,
  4523. }
  4524. service.CreateOrderInfoTX(info, tx)
  4525. }
  4526. his.Diagnosis = diagnosis_id
  4527. his.SickType = sick_type
  4528. his.RegisterType = reg_type
  4529. his.MedicalTreatmentType = reg_type
  4530. service.UpdataHisPateintTX(&his, tx)
  4531. err = service.UpDatePrescriptionNumberTX(adminUser.CurrentOrgId, ids, chrg_bchno, tx)
  4532. err = service.UpDateHisPrescriptionInfoNumberTX(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id, tx)
  4533. err = service.UpdataOrderStatusTwoTX(chrg_bchno, adminUser.CurrentOrgId, tx)
  4534. //判断是否使用了押金
  4535. if dec_way == "true" {
  4536. tmpstring := strconv.FormatInt(order.ID, 10)
  4537. //扣押金
  4538. errmsg = service.SpendDeposit(c.GetAdminUserInfo().CurrentOrgId, id, c.GetAdminUserInfo().AdminUser.Id, tmpstring, decimal)
  4539. order.Decimal = decimal
  4540. service.UpDateOrderTwo(order)
  4541. if errmsg != nil {
  4542. c.ServeFailJsonSend(enums.ErrorCodeParamWrong, errmsg.Error())
  4543. //c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4544. return
  4545. }
  4546. }
  4547. if err == nil {
  4548. c.ServeSuccessJSON(map[string]interface{}{
  4549. "msg": "结算成功",
  4550. })
  4551. }
  4552. } else {
  4553. if tempOrder.IsPre > 0 {
  4554. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4555. totals, _ := strconv.ParseFloat(allTotal, 64)
  4556. tempOrder.OrderStatus = 2
  4557. tempOrder.PayWay = pay_way
  4558. tempOrder.PayPrice = pay_price
  4559. tempOrder.PayCardNo = pay_card_no
  4560. tempOrder.DiscountPrice = discount_price
  4561. tempOrder.PreferentialPrice = preferential_price
  4562. tempOrder.RealityPrice = reality_price
  4563. tempOrder.FoundPrice = found_price
  4564. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4565. tempOrder.PrivatePrice = private_price
  4566. tempOrder.FaPiaoCode = fapiao_code
  4567. tempOrder.FaPiaoNumber = fapiao_number
  4568. tempOrder.PType = 2
  4569. tempOrder.MedfeeSumamt = totals
  4570. tempOrder.Diagnosis = diagnosis_id
  4571. err = service.SaveHisOrder(&tempOrder)
  4572. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4573. if err != nil {
  4574. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4575. return
  4576. }
  4577. if err == nil {
  4578. c.ServeSuccessJSON(map[string]interface{}{
  4579. "msg": "结算成功",
  4580. })
  4581. }
  4582. }
  4583. }
  4584. }
  4585. //退款
  4586. func (c *HisApiController) Refund() {
  4587. order_id, _ := c.GetInt64("order_id")
  4588. order, _ := service.GetHisOrderByID(order_id)
  4589. adminUser := c.GetAdminUserInfo()
  4590. orgid := c.GetAdminUserInfo().CurrentOrgId
  4591. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4592. if err != nil {
  4593. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4594. return
  4595. }
  4596. tmp := strconv.FormatInt(order.ID, 10)
  4597. //当押金不为零时产生退费记录
  4598. if order.Decimal != 0 {
  4599. err = service.MoneyIncrease(orgid, order.PatientId, tmp, order.Decimal)
  4600. if err != nil {
  4601. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4602. return
  4603. }
  4604. }
  4605. c.ServeSuccessJSON(map[string]interface{}{
  4606. "msg": "退费成功",
  4607. })
  4608. }
  4609. func (c *HisApiController) RefundNumber() {
  4610. his_patient_id, _ := c.GetInt64("id")
  4611. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4612. info.Status = 0
  4613. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4614. if count > 0 {
  4615. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4616. return
  4617. }
  4618. err := service.SaveHisPatient(info)
  4619. if err == nil {
  4620. c.ServeSuccessJSON(map[string]interface{}{
  4621. "msg": "退号成功",
  4622. })
  4623. } else {
  4624. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4625. return
  4626. }
  4627. }
  4628. func (this *HisApiController) AdditionalCharge() {
  4629. dataBody := make(map[string]interface{}, 0)
  4630. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4631. fmt.Println(err)
  4632. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4633. patient_id := int64(dataBody["patient_id"].(float64))
  4634. medicineData, _ := dataBody["medicineData"].([]interface{})
  4635. adminUserInfo := this.GetAdminUserInfo()
  4636. orgId := adminUserInfo.CurrentOrgId
  4637. admin_user_id := adminUserInfo.AdminUser.Id
  4638. timeStr := time.Now().Format("2006-01-02")
  4639. timeLayout := "2006-01-02 15:04:05"
  4640. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4641. timenow := timeStringToTime.Unix()
  4642. var additionalCharges []*models.HisAdditionalCharge
  4643. for _, item := range medicineData {
  4644. var randNum int
  4645. randNum = rand.Intn(10000) + 1000
  4646. timestamp := time.Now().Unix()
  4647. tempTime := time.Unix(timestamp, 0)
  4648. timeFormat := tempTime.Format("20060102150405")
  4649. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4650. items := item.(map[string]interface{})
  4651. money := items["price"].(string)
  4652. item_id_str := items["item_id"].(string)
  4653. name := items["name"].(string)
  4654. id_str := items["id"].(string)
  4655. moneys, _ := strconv.ParseInt(money, 10, 64)
  4656. monStr := strconv.FormatInt(moneys, 10)
  4657. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4658. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4659. id, _ := strconv.ParseInt(id_str, 10, 64)
  4660. additionalCharge := &models.HisAdditionalCharge{
  4661. ID: id,
  4662. HisPatientId: his_patient_id,
  4663. UserOrgId: orgId,
  4664. PatientId: patient_id,
  4665. RecordDate: timenow,
  4666. Price: monneyStr,
  4667. Status: 1,
  4668. ItemName: name,
  4669. ItemId: item_id,
  4670. AdminUserId: admin_user_id,
  4671. CreatedTime: time.Now().Unix(),
  4672. OrderStatus: 0,
  4673. PrescriptionNumber: "",
  4674. BatchNumber: "",
  4675. FeedetlSn: p_number,
  4676. }
  4677. service.CreateAdditionalCharge(additionalCharge)
  4678. additionalCharges = append(additionalCharges, additionalCharge)
  4679. }
  4680. this.ServeSuccessJSON(map[string]interface{}{
  4681. "msg": "添加成功",
  4682. "additional_charges": additionalCharges,
  4683. })
  4684. }
  4685. func (this *HisApiController) DeleteAddition() {
  4686. id, _ := this.GetInt64("id")
  4687. //TODO 需要判断是否已经结算
  4688. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4689. if err == nil {
  4690. this.ServeSuccessJSON(map[string]interface{}{
  4691. "msg": "删除成功",
  4692. })
  4693. return
  4694. } else {
  4695. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4696. return
  4697. }
  4698. }
  4699. func (this *HisApiController) GetAdminUsers() {
  4700. adminUser := this.GetAdminUserInfo()
  4701. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4702. this.ServeSuccessJSON(map[string]interface{}{
  4703. "doctors": doctors,
  4704. })
  4705. }
  4706. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4707. change_type, _ := this.GetInt64("type", 0)
  4708. record_date := this.GetString("record_time")
  4709. patient_id, _ := this.GetInt64("patient_id", 0)
  4710. p_type, _ := this.GetInt64("p_type", 0)
  4711. timeLayout := "2006-01-02"
  4712. loc, _ := time.LoadLocation("Local")
  4713. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4714. record_time := theAdviceRecordTime.Unix()
  4715. adminUserInfo := this.GetAdminUserInfo()
  4716. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4717. if err == nil {
  4718. if len(prescriptions) == 0 {
  4719. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4720. return
  4721. } else {
  4722. this.ServeSuccessJSON(map[string]interface{}{
  4723. "prescriptions": prescriptions,
  4724. })
  4725. return
  4726. }
  4727. } else {
  4728. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4729. return
  4730. }
  4731. }
  4732. func (this *HisApiController) GetCallHisPrescription() {
  4733. patient_id, _ := this.GetInt64("patient_id", 0)
  4734. timeLayout := "2006-01-02"
  4735. loc, _ := time.LoadLocation("Local")
  4736. start_time := this.GetString("start_time")
  4737. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4738. end_time := this.GetString("end_time")
  4739. p_type, _ := this.GetInt64("p_type")
  4740. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4741. adminUserInfo := this.GetAdminUserInfo()
  4742. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4743. if err == nil {
  4744. this.ServeSuccessJSON(map[string]interface{}{
  4745. "prescriptions": prescriptions,
  4746. })
  4747. return
  4748. } else {
  4749. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4750. return
  4751. }
  4752. }
  4753. func (this *HisApiController) GetHisDayPrescription() {
  4754. timeLayout := "2006-01-02"
  4755. loc, _ := time.LoadLocation("Local")
  4756. start_time := this.GetString("start_time")
  4757. patient_id, _ := this.GetInt64("patient_id", 0)
  4758. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4759. end_time := this.GetString("end_time")
  4760. p_type, _ := this.GetInt64("p_type")
  4761. order_status, _ := this.GetInt64("type")
  4762. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4763. adminUserInfo := this.GetAdminUserInfo()
  4764. var dayHisPrescription []*models.HisPrescription
  4765. var err error
  4766. if order_status == 1 || order_status == 0 {
  4767. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4768. } else if order_status == 2 {
  4769. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4770. }
  4771. var settle_total float64
  4772. for _, item := range dayHisPrescription {
  4773. if len(item.HisPrescriptionProject) > 0 {
  4774. for _, subItem := range item.HisPrescriptionProject {
  4775. count, _ := strconv.ParseFloat(subItem.Count, 64)
  4776. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  4777. settle_total = settle_total + total
  4778. }
  4779. }
  4780. if len(item.HisDoctorAdviceInfo) > 0 {
  4781. for _, subItem := range item.HisDoctorAdviceInfo {
  4782. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  4783. settle_total = settle_total + total
  4784. }
  4785. }
  4786. }
  4787. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  4788. if err == nil {
  4789. this.ServeSuccessJSON(map[string]interface{}{
  4790. "day_prescription": dayHisPrescription,
  4791. "settle_total": settle_total,
  4792. })
  4793. return
  4794. } else {
  4795. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4796. return
  4797. }
  4798. }
  4799. func (c *HisApiController) GetHisChargePatientList() {
  4800. record_date := c.GetString("record_date")
  4801. order_status, _ := c.GetInt64("type")
  4802. timeLayout := "2006-01-02"
  4803. loc, _ := time.LoadLocation("Local")
  4804. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4805. if err != nil {
  4806. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4807. return
  4808. }
  4809. recordDateTime := theTime.Unix()
  4810. adminInfo := c.GetAdminUserInfo()
  4811. var tempPatients []*service.NewTempPatients
  4812. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4813. if order_status != 2 {
  4814. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4815. } else {
  4816. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4817. }
  4818. var patients []*service.NewTempPatients
  4819. var patients_two []*service.NewTempPatients
  4820. for _, item := range tempPatients {
  4821. //过滤掉没挂号的和没开处方的
  4822. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4823. patients = append(patients, item)
  4824. }
  4825. //过滤掉没挂号的
  4826. if len(item.HisPatient) > 0 {
  4827. patients_two = append(patients_two, item)
  4828. }
  4829. }
  4830. c.ServeSuccessJSON(map[string]interface{}{
  4831. "list": patients,
  4832. "list_two": patients_two,
  4833. })
  4834. }
  4835. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4836. record_date := c.GetString("record_date")
  4837. timeLayout := "2006-01-02"
  4838. loc, _ := time.LoadLocation("Local")
  4839. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4840. if err != nil {
  4841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4842. return
  4843. }
  4844. recordDateTime := theTime.Unix()
  4845. adminUser := c.GetAdminUserInfo()
  4846. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4847. var patients []*service.Patients
  4848. for _, item := range tempPatients {
  4849. if item.HisPatient.ID == 0 {
  4850. patients = append(patients, item)
  4851. }
  4852. }
  4853. c.ServeSuccessJSON(map[string]interface{}{
  4854. "list": patients,
  4855. //"list_two": patients_two,
  4856. })
  4857. }
  4858. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4859. newArr = make([]*service.Patients, 0)
  4860. for i := 0; i < len(patient); i++ {
  4861. repeat := false
  4862. for j := i + 1; j < len(patient); j++ {
  4863. if patient[i].ID == patient[j].ID {
  4864. repeat = true
  4865. break
  4866. }
  4867. }
  4868. if !repeat {
  4869. newArr = append(newArr, patient[i])
  4870. }
  4871. }
  4872. return
  4873. }
  4874. func (c *HisApiController) GetHisChargePatientInfo() {
  4875. patient_id, _ := c.GetInt64("patient_id")
  4876. his_patient_id, _ := c.GetInt64("his_patient_id")
  4877. record_date := c.GetString("record_date")
  4878. //start_time := c.GetString("start_time")
  4879. //end_time := c.GetString("end_time")
  4880. order_status, _ := c.GetInt64("type", 0)
  4881. p_type, _ := c.GetInt64("p_type", 0)
  4882. order_id, _ := c.GetInt64("order_id", 0)
  4883. timeLayout := "2006-01-02"
  4884. loc, _ := time.LoadLocation("Local")
  4885. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4886. if err != nil {
  4887. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4888. return
  4889. }
  4890. recordDateTime := theTime.Unix()
  4891. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4892. //if err != nil {
  4893. //
  4894. //}
  4895. //startRecordDateTime := startTime.Unix()
  4896. //
  4897. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4898. //if err != nil {
  4899. //
  4900. //}
  4901. //endRecordDateTime := endTime.Unix()
  4902. admin := c.GetAdminUserInfo()
  4903. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4904. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4905. var prescriptions []*models.HisPrescription
  4906. //var unChargeMonthPrescriptions []*models.HisPrescription
  4907. order, _ := service.GetHisOrderByID(order_id)
  4908. if order_status == 1 || order_status == 0 {
  4909. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4910. } else if order_status == 2 {
  4911. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4912. //unChargeMonthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4913. }
  4914. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  4915. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  4916. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  4917. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  4918. //获取所有科室信息
  4919. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  4920. c.ServeSuccessJSON(map[string]interface{}{
  4921. "his_info": his_patient_info,
  4922. "xt_info": xt_patient_info,
  4923. "prescription": prescriptions,
  4924. "case_history": case_history,
  4925. "info": patientPrescriptionInfo,
  4926. "last_info": lastPatientPrescriptionInfo,
  4927. "order": order,
  4928. "doctors": doctors,
  4929. "department": department,
  4930. })
  4931. return
  4932. }
  4933. func (c *HisApiController) GetAllOrderDetail() {
  4934. order_id, _ := c.GetInt64("id", 0)
  4935. order, _ := service.GetHisOrderByID(order_id)
  4936. if order.ID == 0 {
  4937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4938. return
  4939. }
  4940. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4941. org_id := c.GetAdminUserInfo().CurrentOrgId
  4942. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4943. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4944. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4945. c.ServeSuccessJSON(map[string]interface{}{
  4946. "order": order,
  4947. "order_info": order_info,
  4948. "patient": patient,
  4949. "admin_info": adminInfo,
  4950. "hospital_record": record,
  4951. })
  4952. return
  4953. }
  4954. func (c *HisApiController) GetAllOrderDetailCollect() {
  4955. order_id, _ := c.GetInt64("id", 0)
  4956. order, _ := service.GetHisOrderByID(order_id)
  4957. if order.ID == 0 {
  4958. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4959. return
  4960. }
  4961. org_id := c.GetAdminUserInfo().CurrentOrgId
  4962. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4963. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4964. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4965. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4966. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4967. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4968. var bedCostTotal float64 = 0 //床位总费
  4969. //var bedCostSelfTotal float64 = 0 //床位自费
  4970. var operationCostTotal float64 = 0 //手术费
  4971. //var operationCostSelfTotal float64 = 0 //手术费
  4972. var otherCostTotal float64 = 0 //其他费用
  4973. //var otherCostSelfTotal float64 = 0 //其他费用
  4974. var materialCostTotal float64 = 0 //材料费
  4975. //var materialCostSelfTotal float64 = 0 //材料费
  4976. var westernMedicineCostTotal float64 = 0 //西药费
  4977. //var westernMedicineCostSelfTotal float64 = 0 //西药费
  4978. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4979. //var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4980. var checkCostTotal float64 = 0 //检查费
  4981. //var checkCostSelfTotal float64 = 0 //检查费
  4982. var laboratoryCostTotal float64 = 0 //化验费
  4983. //var laboratoryCostSelfTotal float64 = 0 //化验费
  4984. var treatCostTotal float64 = 0 //治疗费用
  4985. //var treatCostSelfTotal float64 = 0 //治疗费用
  4986. var zhenChaCostTotal float64 = 0 //其他费用
  4987. //var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4988. decimal.DivisionPrecision = 2
  4989. var BalanceAccountsType int64
  4990. if his.ID > 0 {
  4991. BalanceAccountsType = his.BalanceAccountsType
  4992. } else {
  4993. BalanceAccountsType = record.BalanceAccountsType
  4994. }
  4995. if BalanceAccountsType != 2 {
  4996. for _, item := range order_info {
  4997. if org_id == 10215 {
  4998. if item.MedChrgitmType == "01" { //床位费
  4999. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5000. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5001. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5002. }
  5003. if item.MedChrgitmType == "02" { //诊察费
  5004. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5005. //zhenChaCostSelfTotal = zhenChaCostTotal
  5006. }
  5007. if item.MedChrgitmType == "03" { //检查费
  5008. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5009. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5010. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5011. }
  5012. //if item.MedChrgitmType == "02" { //检查费
  5013. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5014. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5015. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5016. //}
  5017. if item.MedChrgitmType == "04" { //化验费
  5018. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5019. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5020. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5021. }
  5022. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5023. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5024. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5025. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5026. }
  5027. if item.MedChrgitmType == "06" { //手术费
  5028. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5029. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5030. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5031. }
  5032. if item.MedChrgitmType == "08" { //材料费
  5033. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5034. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5035. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5036. }
  5037. if item.MedChrgitmType == "09" { //西药费
  5038. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5039. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5040. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5041. }
  5042. if item.MedChrgitmType == "11" { //中成费
  5043. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5044. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5045. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5046. }
  5047. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5048. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5049. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5050. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5051. }
  5052. } else if org_id == 10188 || org_id == 10217 {
  5053. if item.MedChrgitmType == "01" { //床位费
  5054. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5055. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5056. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5057. }
  5058. if item.MedChrgitmType == "02" { //诊察费
  5059. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5060. //zhenChaCostSelfTotal = zhenChaCostTotal
  5061. }
  5062. if item.MedChrgitmType == "03" { //检查费
  5063. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5064. //checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5065. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5066. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5067. }
  5068. //if item.MedChrgitmType == "02" { //检查费
  5069. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5070. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5071. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5072. //}
  5073. if item.MedChrgitmType == "04" { //化验费
  5074. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5075. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5076. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5077. }
  5078. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5079. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5080. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5081. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5082. }
  5083. if item.MedChrgitmType == "06" { //手术费
  5084. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5085. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5086. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5087. }
  5088. if item.MedChrgitmType == "08" { //材料费
  5089. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5090. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5091. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5092. }
  5093. if item.MedChrgitmType == "09" { //西药费
  5094. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5095. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5096. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5097. }
  5098. if item.MedChrgitmType == "11" { //中成费
  5099. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5100. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5101. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5102. }
  5103. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5104. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5105. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5106. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5107. }
  5108. } else {
  5109. if item.MedChrgitmType == "01" { //床位费
  5110. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5111. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5112. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5113. }
  5114. //if item.MedChrgitmType == "02" { //诊察费
  5115. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5116. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5117. //}
  5118. if item.MedChrgitmType == "03" { //检查费
  5119. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5120. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5121. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5122. }
  5123. //if item.MedChrgitmType == "02" { //检查费
  5124. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5125. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5126. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5127. //}
  5128. if item.MedChrgitmType == "04" { //化验费
  5129. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5130. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5131. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5132. }
  5133. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5134. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5135. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5136. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5137. }
  5138. if item.MedChrgitmType == "06" { //手术费
  5139. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5140. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5141. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5142. }
  5143. if item.MedChrgitmType == "08" { //材料费
  5144. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5145. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5146. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5147. }
  5148. if item.MedChrgitmType == "09" { //西药费
  5149. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5150. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5151. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5152. }
  5153. if item.MedChrgitmType == "11" { //中成费
  5154. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5155. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5156. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5157. }
  5158. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5159. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5160. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5161. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5162. }
  5163. }
  5164. }
  5165. c.ServeSuccessJSON(map[string]interface{}{
  5166. "order": order,
  5167. "order_info": order_info,
  5168. "patient": patient,
  5169. "admin_info": adminInfo,
  5170. "his_hospital": record,
  5171. "bedCostTotal": bedCostTotal,
  5172. "operationCostTotal": operationCostTotal,
  5173. "otherCostTotal": otherCostTotal,
  5174. "materialCostTotal": materialCostTotal,
  5175. "westernMedicineCostTotal": westernMedicineCostTotal,
  5176. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5177. "checkCostTotal": checkCostTotal,
  5178. "zhenChaCostTotal": zhenChaCostTotal,
  5179. "laboratoryCostTotal": laboratoryCostTotal,
  5180. "treatCostTotal": treatCostTotal,
  5181. })
  5182. } else {
  5183. for _, item := range order_info {
  5184. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5185. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5186. item.MedChrgitmType = "09"
  5187. }
  5188. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5189. if item.HisPrescriptionProject.Type == 2 {
  5190. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5191. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5192. case 0:
  5193. item.MedChrgitmType = "0"
  5194. break
  5195. case 1:
  5196. item.MedChrgitmType = "14"
  5197. break
  5198. case 2:
  5199. item.MedChrgitmType = "05"
  5200. break
  5201. case 3:
  5202. item.MedChrgitmType = "03"
  5203. break
  5204. case 4:
  5205. item.MedChrgitmType = "03"
  5206. break
  5207. case 5:
  5208. item.MedChrgitmType = "08"
  5209. break
  5210. case 6:
  5211. item.MedChrgitmType = "14"
  5212. break
  5213. case 7:
  5214. item.MedChrgitmType = "14"
  5215. break
  5216. case 8:
  5217. item.MedChrgitmType = "03"
  5218. break
  5219. case 9:
  5220. item.MedChrgitmType = "14"
  5221. break
  5222. case 10:
  5223. item.MedChrgitmType = "14"
  5224. break
  5225. case 11:
  5226. item.MedChrgitmType = "06"
  5227. break
  5228. case 12:
  5229. item.MedChrgitmType = "12"
  5230. break
  5231. case 13:
  5232. item.MedChrgitmType = "01"
  5233. break
  5234. case 14:
  5235. item.MedChrgitmType = "04"
  5236. break
  5237. case 15:
  5238. item.MedChrgitmType = "14"
  5239. break
  5240. }
  5241. } else {
  5242. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5243. case 1:
  5244. item.MedChrgitmType = "14"
  5245. break
  5246. case 2:
  5247. item.MedChrgitmType = "05"
  5248. break
  5249. case 3:
  5250. item.MedChrgitmType = "04"
  5251. break
  5252. case 4:
  5253. item.MedChrgitmType = "14"
  5254. break
  5255. case 5:
  5256. item.MedChrgitmType = "08"
  5257. break
  5258. case 6:
  5259. item.MedChrgitmType = "14"
  5260. break
  5261. case 7:
  5262. item.MedChrgitmType = "14"
  5263. break
  5264. case 8:
  5265. item.MedChrgitmType = "03"
  5266. break
  5267. case 9:
  5268. item.MedChrgitmType = "14"
  5269. break
  5270. }
  5271. }
  5272. } else if item.HisPrescriptionProject.Type == 3 {
  5273. item.MedChrgitmType = "08"
  5274. }
  5275. }
  5276. }
  5277. for _, item := range order_info {
  5278. if org_id == 10215 {
  5279. if item.MedChrgitmType == "01" { //床位费
  5280. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5281. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5282. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5283. }
  5284. if item.MedChrgitmType == "02" { //诊察费
  5285. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5286. //zhenChaCostSelfTotal = zhenChaCostTotal
  5287. }
  5288. if item.MedChrgitmType == "03" { //检查费
  5289. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5290. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5291. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5292. }
  5293. //if item.MedChrgitmType == "02" { //检查费
  5294. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5295. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5296. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5297. //}
  5298. if item.MedChrgitmType == "04" { //化验费
  5299. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5300. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5301. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5302. }
  5303. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5304. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5305. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5306. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5307. }
  5308. if item.MedChrgitmType == "06" { //手术费
  5309. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5310. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5311. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5312. }
  5313. if item.MedChrgitmType == "08" { //材料费
  5314. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5315. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5316. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5317. }
  5318. if item.MedChrgitmType == "09" { //西药费
  5319. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5320. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5321. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5322. }
  5323. if item.MedChrgitmType == "11" { //中成费
  5324. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5325. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5326. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5327. }
  5328. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5329. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5330. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5331. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5332. }
  5333. } else {
  5334. if item.MedChrgitmType == "01" { //床位费
  5335. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5336. //bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5337. //bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5338. }
  5339. //if item.MedChrgitmType == "02" { //诊察费
  5340. // zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5341. // //zhenChaCostSelfTotal = zhenChaCostTotal
  5342. //}
  5343. if item.MedChrgitmType == "03" { //检查费
  5344. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5345. //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5346. //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5347. }
  5348. //if item.MedChrgitmType == "02" { //检查费
  5349. // checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5350. // //checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5351. // //checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5352. //}
  5353. if item.MedChrgitmType == "04" { //化验费
  5354. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5355. //laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5356. //laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5357. }
  5358. if item.MedChrgitmType == "05" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5359. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5360. //treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5361. //treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5362. }
  5363. if item.MedChrgitmType == "06" { //手术费
  5364. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5365. //operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5366. //operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5367. }
  5368. if item.MedChrgitmType == "08" { //材料费
  5369. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5370. //materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5371. //materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5372. }
  5373. if item.MedChrgitmType == "09" { //西药费
  5374. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5375. //westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5376. //westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5377. }
  5378. if item.MedChrgitmType == "11" { //中成费
  5379. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5380. //chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5381. //chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5382. }
  5383. if item.MedChrgitmType == "14" || item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5384. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5385. //otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5386. //otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5387. }
  5388. }
  5389. }
  5390. c.ServeSuccessJSON(map[string]interface{}{
  5391. "order": order,
  5392. "order_info": order_info,
  5393. "patient": patient,
  5394. "admin_info": adminInfo,
  5395. "his_hospital": record,
  5396. "bedCostTotal": bedCostTotal,
  5397. "operationCostTotal": operationCostTotal,
  5398. "otherCostTotal": otherCostTotal,
  5399. "materialCostTotal": materialCostTotal,
  5400. "westernMedicineCostTotal": westernMedicineCostTotal,
  5401. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5402. "checkCostTotal": checkCostTotal,
  5403. "zhenChaCostTotal": zhenChaCostTotal,
  5404. "laboratoryCostTotal": laboratoryCostTotal,
  5405. "treatCostTotal": treatCostTotal,
  5406. })
  5407. }
  5408. }
  5409. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  5410. page, _ := c.GetInt64("page")
  5411. limit, _ := c.GetInt64("limit")
  5412. keywords := c.GetString("keywords")
  5413. start_time := c.GetString("start_time")
  5414. end_time := c.GetString("end_time")
  5415. //clr_type := c.GetString("clr_type")
  5416. insutype := c.GetString("insutype")
  5417. timeLayout := "2006-01-02"
  5418. loc, _ := time.LoadLocation("Local")
  5419. var theStartTIme int64
  5420. if len(start_time) > 0 {
  5421. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5422. theStartTIme = theTime.Unix()
  5423. }
  5424. var theEndtTIme int64
  5425. if len(end_time) > 0 {
  5426. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5427. theEndtTIme = theTime.Unix()
  5428. }
  5429. if page <= 0 {
  5430. page = 1
  5431. }
  5432. if limit <= 0 {
  5433. limit = 10
  5434. }
  5435. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  5436. c.ServeSuccessJSON(map[string]interface{}{
  5437. "total": total,
  5438. "list": list,
  5439. })
  5440. return
  5441. }
  5442. func (c *HisApiController) GetPutOnRecordList() {
  5443. page, _ := c.GetInt64("page")
  5444. limit, _ := c.GetInt64("limit")
  5445. keywords := c.GetString("keywords")
  5446. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  5447. if page <= 0 {
  5448. page = 1
  5449. }
  5450. if limit <= 0 {
  5451. limit = 10
  5452. }
  5453. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  5454. c.ServeSuccessJSON(map[string]interface{}{
  5455. "total": total,
  5456. "list": list,
  5457. })
  5458. return
  5459. }
  5460. func (c *HisApiController) GetCompareData() {
  5461. start_time := c.GetString("start_time")
  5462. end_time := c.GetString("end_time")
  5463. insutype := c.GetString("insutype")
  5464. clr_type := c.GetString("clr_type")
  5465. timeLayout := "2006-01-02"
  5466. loc, _ := time.LoadLocation("Local")
  5467. var theStartTIme int64
  5468. if len(start_time) > 0 {
  5469. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5470. if err != nil {
  5471. theStartTIme = 0
  5472. }
  5473. theStartTIme = theTime.Unix()
  5474. }
  5475. var theEndtTIme int64
  5476. if len(end_time) > 0 {
  5477. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5478. if err != nil {
  5479. theEndtTIme = 0
  5480. }
  5481. theEndtTIme = theTime.Unix()
  5482. }
  5483. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  5484. fmt.Println(err)
  5485. if err == nil {
  5486. c.ServeSuccessJSON(map[string]interface{}{
  5487. "list": formData,
  5488. })
  5489. } else {
  5490. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  5491. return
  5492. }
  5493. }
  5494. func (c *HisApiController) GetFaPiaoData() {
  5495. order_id, _ := c.GetInt64("order_id")
  5496. patient_id, _ := c.GetInt64("patient_id")
  5497. number := c.GetString("number")
  5498. adminUser := c.GetAdminUserInfo()
  5499. order, _ := service.GetHisOrderByID(order_id)
  5500. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  5501. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  5502. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  5503. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  5504. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  5505. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  5506. var bedCostTotal float64 = 0 //床位总费
  5507. var bedCostSelfTotal float64 = 0 //床位自费
  5508. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  5509. var operationCostTotal float64 = 0 //手术费
  5510. var operationCostSelfTotal float64 = 0 //手术费
  5511. var operationCostPartSelfTotal float64 = 0 //手术费
  5512. var otherCostTotal float64 = 0 //其他费用
  5513. var otherCostSelfTotal float64 = 0 //其他费用
  5514. var otherCostPartSelfTotal float64 = 0 //其他费用
  5515. var materialCostTotal float64 = 0 //材料费
  5516. var materialCostSelfTotal float64 = 0 //材料费
  5517. var materialCostPartSelfTotal float64 = 0 //材料费
  5518. var westernMedicineCostTotal float64 = 0 //西药费
  5519. var westernMedicineCostSelfTotal float64 = 0 //西药费
  5520. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  5521. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  5522. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  5523. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  5524. var checkCostTotal float64 = 0 //检查费
  5525. var checkCostSelfTotal float64 = 0 //检查费
  5526. var checkCostPartSelfTotal float64 = 0 //检查费
  5527. var laboratoryCostTotal float64 = 0 //化验费
  5528. var laboratoryCostSelfTotal float64 = 0 //化验费
  5529. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  5530. var treatCostTotal float64 = 0 //治疗费用
  5531. var treatCostSelfTotal float64 = 0 //治疗费用
  5532. var treatCostPartSelfTotal float64 = 0 //治疗费用
  5533. var zhenChaCostTotal float64 = 0 //其他费用
  5534. var zhenChaCostSelfTotal float64 = 0 //其他费用
  5535. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  5536. decimal.DivisionPrecision = 2
  5537. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5538. var balanceAccountsType int64
  5539. if his.ID > 0 {
  5540. balanceAccountsType = his.BalanceAccountsType
  5541. } else {
  5542. balanceAccountsType = his_hospital_record.BalanceAccountsType
  5543. }
  5544. if balanceAccountsType == 2 {
  5545. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  5546. for _, item := range orderInfos_two {
  5547. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  5548. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  5549. item.MedChrgitmType = "09"
  5550. }
  5551. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  5552. if item.HisPrescriptionProject.Type == 2 {
  5553. if c.GetAdminUserInfo().CurrentOrgId == 10215 {
  5554. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5555. case 0:
  5556. item.MedChrgitmType = "0"
  5557. break
  5558. case 1:
  5559. item.MedChrgitmType = "14"
  5560. break
  5561. case 2:
  5562. item.MedChrgitmType = "05"
  5563. break
  5564. case 3:
  5565. item.MedChrgitmType = "03"
  5566. break
  5567. case 4:
  5568. item.MedChrgitmType = "03"
  5569. break
  5570. case 5:
  5571. item.MedChrgitmType = "08"
  5572. break
  5573. case 6:
  5574. item.MedChrgitmType = "14"
  5575. break
  5576. case 7:
  5577. item.MedChrgitmType = "14"
  5578. break
  5579. case 8:
  5580. item.MedChrgitmType = "03"
  5581. break
  5582. case 9:
  5583. item.MedChrgitmType = "14"
  5584. break
  5585. case 10:
  5586. item.MedChrgitmType = "14"
  5587. break
  5588. case 11:
  5589. item.MedChrgitmType = "06"
  5590. break
  5591. case 12:
  5592. item.MedChrgitmType = "12"
  5593. break
  5594. case 13:
  5595. item.MedChrgitmType = "01"
  5596. break
  5597. case 14:
  5598. item.MedChrgitmType = "04"
  5599. break
  5600. case 15:
  5601. item.MedChrgitmType = "02"
  5602. break
  5603. }
  5604. } else {
  5605. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  5606. case 1:
  5607. item.MedChrgitmType = "14"
  5608. break
  5609. case 2:
  5610. item.MedChrgitmType = "05"
  5611. break
  5612. case 3:
  5613. item.MedChrgitmType = "03"
  5614. break
  5615. case 4:
  5616. item.MedChrgitmType = "03"
  5617. break
  5618. case 5:
  5619. item.MedChrgitmType = "08"
  5620. break
  5621. case 6:
  5622. item.MedChrgitmType = "14"
  5623. break
  5624. case 7:
  5625. item.MedChrgitmType = "14"
  5626. break
  5627. case 8:
  5628. item.MedChrgitmType = "03"
  5629. break
  5630. case 9:
  5631. item.MedChrgitmType = "14"
  5632. break
  5633. }
  5634. }
  5635. } else if item.HisPrescriptionProject.Type == 3 {
  5636. item.MedChrgitmType = "08"
  5637. }
  5638. }
  5639. }
  5640. for _, item := range orderInfos_two {
  5641. fmt.Println(item.MedChrgitmType)
  5642. if item.MedChrgitmType == "01" { //床位费
  5643. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5644. bedCostSelfTotal = bedCostTotal
  5645. }
  5646. if item.MedChrgitmType == "02" { //诊察费
  5647. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5648. zhenChaCostSelfTotal = zhenChaCostTotal
  5649. }
  5650. if item.MedChrgitmType == "03" { //检查费
  5651. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5652. checkCostSelfTotal = checkCostTotal
  5653. }
  5654. if item.MedChrgitmType == "04" { //化验费
  5655. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5656. laboratoryCostSelfTotal = laboratoryCostTotal
  5657. }
  5658. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  5659. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5660. treatCostSelfTotal = treatCostTotal
  5661. }
  5662. if item.MedChrgitmType == "06" { //手术费
  5663. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5664. operationCostSelfTotal = treatCostTotal
  5665. }
  5666. if item.MedChrgitmType == "08" { //材料费
  5667. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5668. materialCostSelfTotal = materialCostTotal
  5669. }
  5670. if item.MedChrgitmType == "09" { //西药费
  5671. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5672. westernMedicineCostSelfTotal = westernMedicineCostTotal
  5673. }
  5674. if item.MedChrgitmType == "11" { //中成费
  5675. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5676. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  5677. }
  5678. if c.GetAdminUserInfo().CurrentOrgId == 10106 {
  5679. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" || item.MedChrgitmType == "02" { //其他费
  5680. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5681. otherCostSelfTotal = otherCostTotal
  5682. }
  5683. } else {
  5684. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5685. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5686. otherCostSelfTotal = otherCostTotal
  5687. }
  5688. }
  5689. }
  5690. } else {
  5691. for _, item := range orderInfos {
  5692. if item.MedChrgitmType == "01" { //床位费
  5693. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5694. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5695. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5696. }
  5697. if item.MedChrgitmType == "02" { //诊察费
  5698. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5699. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5700. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5701. }
  5702. if c.GetAdminUserInfo().CurrentOrgId == 10188 || c.GetAdminUserInfo().CurrentOrgId == 10217 {
  5703. if item.MedChrgitmType == "03" { //检查费
  5704. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5705. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5706. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5707. }
  5708. } else {
  5709. if item.MedChrgitmType == "03" { //检查费
  5710. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5711. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5712. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5713. }
  5714. }
  5715. if item.MedChrgitmType == "04" { //化验费
  5716. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5717. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5718. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5719. }
  5720. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  5721. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5722. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5723. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5724. }
  5725. if item.MedChrgitmType == "06" { //手术费
  5726. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5727. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5728. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5729. }
  5730. if item.MedChrgitmType == "08" || item.MedChrgitmType == "1401" { //材料费
  5731. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5732. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5733. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5734. }
  5735. if item.MedChrgitmType == "09" { //西药费
  5736. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5737. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5738. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5739. }
  5740. if item.MedChrgitmType == "11" { //中成费
  5741. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5742. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5743. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5744. }
  5745. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  5746. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  5747. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  5748. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  5749. }
  5750. }
  5751. }
  5752. timeLayout := "2006-01-02"
  5753. loc, _ := time.LoadLocation("Local")
  5754. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.InHosptialTime, loc)
  5755. if err != nil {
  5756. }
  5757. startRecordDateTime := startTime.Unix()
  5758. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", his_hospital_record.OutHosptialTime, loc)
  5759. if err != nil {
  5760. }
  5761. endRecordDateTime := endTime.Unix()
  5762. pre_pay_money := service.GetUserMoney(order.PatientId, adminUser.CurrentOrgId)
  5763. sum, _ := service.RefundListSum(adminUser.CurrentOrgId, startRecordDateTime, endRecordDateTime, order.PatientId)
  5764. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  5765. c.ServeSuccessJSON(map[string]interface{}{
  5766. "order_number": order.Number, //业务流水号
  5767. "id_card_no": his.IdCardNo, //社会保障号
  5768. "department_name": department.Name, //科室
  5769. "number": his.Number, //门诊号
  5770. "date": order.SettleAccountsDate, //结算日期
  5771. "name": order.PsnName, //姓名
  5772. "gender": order.Gend, //性别
  5773. "psn_cash_money": order.PsnCashPay, //个人支付
  5774. "pay_way": "门诊", //结算方式
  5775. "medfee_sumamt": order.MedfeeSumamt, //总费用
  5776. "admin_user_name": admin.UserName, //收款员
  5777. "order": order,
  5778. "order_info": orderInfos_two,
  5779. "his": his,
  5780. "bedCostTotal": bedCostTotal,
  5781. "bedCostSelfTotal": bedCostSelfTotal,
  5782. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  5783. "operationCostTotal": operationCostTotal,
  5784. "operationCostSelfTotal": operationCostSelfTotal,
  5785. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  5786. "otherCostTotal": otherCostTotal,
  5787. "otherCostSelfTotal": otherCostSelfTotal,
  5788. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  5789. "materialCostTotal": materialCostTotal,
  5790. "materialCostSelfTotal": materialCostSelfTotal,
  5791. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  5792. "westernMedicineCostTotal": westernMedicineCostTotal,
  5793. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  5794. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  5795. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  5796. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  5797. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  5798. "checkCostTotal": checkCostTotal,
  5799. "checkCostSelfTotal": checkCostSelfTotal,
  5800. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  5801. "laboratoryCostTotal": laboratoryCostTotal,
  5802. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  5803. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  5804. "treatCostTotal": treatCostTotal,
  5805. "treatCostSelfTotal": treatCostSelfTotal,
  5806. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  5807. "zhenChaCostTotal": zhenChaCostTotal,
  5808. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  5809. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  5810. "his_hospital_record": his_hospital_record,
  5811. "pre_pay_money": pre_pay_money,
  5812. "refund_sum": sum,
  5813. })
  5814. }
  5815. func (this *HisApiController) GetIncomeStatisticsData() {
  5816. start_time := this.GetString("start_time")
  5817. end_time := this.GetString("end_time")
  5818. key_words := this.GetString("key_words")
  5819. limit, _ := this.GetInt64("limit")
  5820. page, _ := this.GetInt64("page")
  5821. if page <= 0 {
  5822. page = 1
  5823. }
  5824. if limit <= 0 {
  5825. limit = 10
  5826. }
  5827. statistics_type, _ := this.GetInt64("statistics_type")
  5828. admin := this.GetAdminUserInfo()
  5829. timeLayout := "2006-01-02"
  5830. loc, _ := time.LoadLocation("Local")
  5831. var theStartTIme int64
  5832. if len(start_time) > 0 {
  5833. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5834. if err != nil {
  5835. theStartTIme = 0
  5836. }
  5837. theStartTIme = theTime.Unix()
  5838. }
  5839. var theEndtTIme int64
  5840. if len(end_time) > 0 {
  5841. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5842. if err != nil {
  5843. theEndtTIme = 0
  5844. }
  5845. theEndtTIme = theTime.Unix()
  5846. }
  5847. if statistics_type == 1 {
  5848. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5849. this.ServeSuccessJSON(map[string]interface{}{
  5850. "list": list,
  5851. "total": total,
  5852. })
  5853. } else {
  5854. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  5855. this.ServeSuccessJSON(map[string]interface{}{
  5856. "list": list,
  5857. "total": total,
  5858. })
  5859. }
  5860. }
  5861. func (c *HisApiController) PostProjectInformation() {
  5862. adminUser := c.GetAdminUserInfo()
  5863. orgId := adminUser.CurrentOrgId
  5864. dataBody := make(map[string]interface{}, 0)
  5865. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5866. if err != nil {
  5867. utils.ErrorLog(err.Error())
  5868. return
  5869. }
  5870. utils.ErrorLog("%v", dataBody)
  5871. var projectList []*models.HisProject
  5872. var total_goods []interface{}
  5873. tempProjects := dataBody["projects"].([]interface{})
  5874. total_goods = tempProjects
  5875. for index, projectMap := range tempProjects {
  5876. projectM := projectMap.(map[string]interface{})
  5877. var project models.HisProject
  5878. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  5879. utils.ErrorLog("project_name")
  5880. return
  5881. }
  5882. project_name, _ := projectM["project_name"].(string)
  5883. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  5884. err_log := models.ExportErrLog{
  5885. LogType: 6,
  5886. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5887. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  5888. Status: 1,
  5889. CreateTime: time.Now().Unix(),
  5890. UpdateTime: time.Now().Unix(),
  5891. ExportTime: time.Now().Unix(),
  5892. }
  5893. service.CreateExportErrLog(&err_log)
  5894. continue
  5895. }
  5896. project.ProjectName = project_name
  5897. prices := projectM["price"].(string)
  5898. price, _ := strconv.ParseFloat(prices, 64)
  5899. if price <= 0 { //名字为空则生成一条导入错误日志
  5900. err_log := models.ExportErrLog{
  5901. LogType: 6,
  5902. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5903. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  5904. Status: 1,
  5905. CreateTime: time.Now().Unix(),
  5906. UpdateTime: time.Now().Unix(),
  5907. ExportTime: time.Now().Unix(),
  5908. }
  5909. service.CreateExportErrLog(&err_log)
  5910. continue
  5911. }
  5912. project.Price = price
  5913. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  5914. utils.ErrorLog("unit_id")
  5915. return
  5916. }
  5917. unit := projectM["unit"].(string)
  5918. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  5919. err_log := models.ExportErrLog{
  5920. LogType: 6,
  5921. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5922. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  5923. Status: 1,
  5924. CreateTime: time.Now().Unix(),
  5925. UpdateTime: time.Now().Unix(),
  5926. ExportTime: time.Now().Unix(),
  5927. }
  5928. service.CreateExportErrLog(&err_log)
  5929. continue
  5930. }
  5931. project.Unit = unit
  5932. cost_classify := projectM["cost_classify"].(string)
  5933. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  5934. err_log := models.ExportErrLog{
  5935. LogType: 6,
  5936. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5937. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5938. Status: 1,
  5939. CreateTime: time.Now().Unix(),
  5940. UpdateTime: time.Now().Unix(),
  5941. ExportTime: time.Now().Unix(),
  5942. }
  5943. service.CreateExportErrLog(&err_log)
  5944. continue
  5945. }
  5946. var costClassify = "费用类别"
  5947. var cost_classify_id int64
  5948. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  5949. if len(cost_classify) != 0 {
  5950. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  5951. if errcode == gorm.ErrRecordNotFound {
  5952. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  5953. dataconfig := models.DictDataconfig{
  5954. ParentId: costClassifyConfig.ID,
  5955. Module: "system",
  5956. OrgId: orgId,
  5957. Name: cost_classify,
  5958. FieldName: "",
  5959. Value: costConfig.Value + 1,
  5960. CreatedTime: "",
  5961. UpdatedTime: "",
  5962. CreateUserId: adminUser.AdminUser.Id,
  5963. Status: 1,
  5964. Remark: "",
  5965. DeleteIdSystem: 0,
  5966. Title: "",
  5967. Content: "",
  5968. Order: 0,
  5969. Code: "",
  5970. }
  5971. service.CreatedDicConfig(&dataconfig)
  5972. }
  5973. }
  5974. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5975. for _, it := range costClassList {
  5976. if cost_classify == it.Name {
  5977. cost_classify_id = int64(it.Value)
  5978. }
  5979. }
  5980. project.CostClassify = cost_classify_id
  5981. executive_section := projectM["executive_section"].(string)
  5982. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5983. err_log := models.ExportErrLog{
  5984. LogType: 6,
  5985. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5986. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5987. Status: 1,
  5988. CreateTime: time.Now().Unix(),
  5989. UpdateTime: time.Now().Unix(),
  5990. ExportTime: time.Now().Unix(),
  5991. }
  5992. service.CreateExportErrLog(&err_log)
  5993. continue
  5994. }
  5995. if len(executive_section) != 0 {
  5996. //查找科室是否有内容
  5997. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5998. if errcodedepart == gorm.ErrRecordNotFound {
  5999. department := models.XtHisDepartment{
  6000. Name: executive_section,
  6001. Status: 1,
  6002. UserOrgId: adminUser.CurrentOrgId,
  6003. CreatedTime: time.Now().Unix(),
  6004. }
  6005. service.CreateDePartment(&department)
  6006. }
  6007. }
  6008. var executive_section_id int64
  6009. departMentList, _ := service.GetAllDepartMent(orgId)
  6010. for _, it := range departMentList {
  6011. if executive_section == it.Name {
  6012. executive_section_id = it.ID
  6013. }
  6014. }
  6015. project.ExecutiveSection = executive_section_id
  6016. medical_coverage := projectM["medical_coverage"].(string)
  6017. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  6018. err_log := models.ExportErrLog{
  6019. LogType: 6,
  6020. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6021. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  6022. Status: 1,
  6023. CreateTime: time.Now().Unix(),
  6024. UpdateTime: time.Now().Unix(),
  6025. ExportTime: time.Now().Unix(),
  6026. }
  6027. service.CreateExportErrLog(&err_log)
  6028. continue
  6029. }
  6030. var medicalCoverage = "医保等级"
  6031. var medical_coverage_id int64
  6032. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  6033. if len(medical_coverage) != 0 {
  6034. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  6035. if errormedicalcoverage == gorm.ErrRecordNotFound {
  6036. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  6037. dataconfig := models.DictDataconfig{
  6038. ParentId: medicalCoverageConfig.ID,
  6039. Module: "system",
  6040. OrgId: orgId,
  6041. Name: medical_coverage,
  6042. FieldName: "",
  6043. Value: medicalCoverageConfig.Value + 1,
  6044. CreatedTime: "",
  6045. UpdatedTime: "",
  6046. CreateUserId: adminUser.AdminUser.Id,
  6047. Status: 1,
  6048. Remark: "",
  6049. DeleteIdSystem: 0,
  6050. Title: "",
  6051. Content: "",
  6052. Order: 0,
  6053. Code: "",
  6054. }
  6055. service.CreatedDicConfig(&dataconfig)
  6056. }
  6057. }
  6058. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  6059. for _, it := range medicalCoverageList {
  6060. if medical_coverage == it.Name {
  6061. medical_coverage_id = int64(it.Value)
  6062. }
  6063. }
  6064. project.MedicalCoverage = medical_coverage_id
  6065. pinyin := projectM["pinyin"].(string)
  6066. project.Pinyin = pinyin
  6067. wubi := projectM["wubi"].(string)
  6068. project.Wubi = wubi
  6069. statistical_classification := projectM["statistical_classification"].(string)
  6070. var statisticalClassification = "统计分类"
  6071. var statistical_classification_id int64
  6072. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  6073. if len(statistical_classification) != 0 {
  6074. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  6075. if classificationerrcodes == gorm.ErrRecordNotFound {
  6076. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  6077. dataconfig := models.DictDataconfig{
  6078. ParentId: classiFication.ID,
  6079. Module: "system",
  6080. OrgId: orgId,
  6081. Name: statistical_classification,
  6082. FieldName: "",
  6083. Value: classiFicationConfig.Value + 1,
  6084. CreatedTime: "",
  6085. UpdatedTime: "",
  6086. CreateUserId: adminUser.AdminUser.Id,
  6087. Status: 1,
  6088. Remark: "",
  6089. DeleteIdSystem: 0,
  6090. Title: "",
  6091. Content: "",
  6092. Order: 0,
  6093. Code: "",
  6094. }
  6095. service.CreatedDicConfig(&dataconfig)
  6096. }
  6097. }
  6098. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  6099. for _, it := range classiFicationList {
  6100. if statistical_classification == it.Name {
  6101. statistical_classification_id = int64(it.Value)
  6102. }
  6103. }
  6104. project.StatisticalClassification = statistical_classification_id
  6105. disease_directory := int64(projectM["disease_directory"].(float64))
  6106. project.DiseaseDirectory = disease_directory
  6107. is_record := int64(projectM["is_record"].(float64))
  6108. project.IsRecord = is_record
  6109. medical_code := projectM["medical_code"].(string)
  6110. project.MedicalCode = medical_code
  6111. tube_color := projectM["tube_color"].(string)
  6112. var tubeColor = "试管颜色"
  6113. var tube_color_id int64
  6114. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  6115. if len(tube_color) != 0 {
  6116. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  6117. if errcodetube == gorm.ErrRecordNotFound {
  6118. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  6119. dataconfig := models.DictDataconfig{
  6120. ParentId: tubeColorConfig.ID,
  6121. Module: "system",
  6122. OrgId: orgId,
  6123. Name: tube_color,
  6124. FieldName: "",
  6125. Value: tubeConfig.Value + 1,
  6126. CreatedTime: "",
  6127. UpdatedTime: "",
  6128. CreateUserId: adminUser.AdminUser.Id,
  6129. Status: 1,
  6130. Remark: "",
  6131. DeleteIdSystem: 0,
  6132. Title: "",
  6133. Content: "",
  6134. Order: 0,
  6135. Code: "",
  6136. }
  6137. service.CreatedDicConfig(&dataconfig)
  6138. }
  6139. }
  6140. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  6141. for _, it := range tubeColorList {
  6142. if tube_color == it.Name {
  6143. tube_color_id = int64(it.Value)
  6144. }
  6145. }
  6146. project.TubeColor = tube_color_id
  6147. single_dose := projectM["single_dose"].(string)
  6148. project.SingleDose = single_dose
  6149. execution_frequency := projectM["execution_frequency"].(string)
  6150. project.ExecutionFrequency = execution_frequency
  6151. delivery_way := projectM["delivery_way"].(string)
  6152. project.DeliveryWay = delivery_way
  6153. number_days := projectM["number_days"].(string)
  6154. project.NumberDays = number_days
  6155. total := projectM["total"].(string)
  6156. project.Total = total
  6157. medical_status := int64(projectM["medical_status"].(float64))
  6158. project.MedicalStatus = medical_status
  6159. category := int64(projectM["category"].(float64))
  6160. project.Category = category
  6161. specail_project := int64(projectM["specail_project"].(float64))
  6162. project.SpecailProject = specail_project
  6163. social_security_directory_code := projectM["social_security_directory_code"].(string)
  6164. project.SocialSecurityDirectoryCode = social_security_directory_code
  6165. remark := projectM["remark"].(string)
  6166. project.Remark = remark
  6167. record_date := projectM["record_date"].(string)
  6168. timeLayout := "2006-01-02"
  6169. loc, _ := time.LoadLocation("Local")
  6170. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6171. project.RecordDate = theTime.Unix()
  6172. projectList = append(projectList, &project)
  6173. }
  6174. export_time := time.Now().Unix()
  6175. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  6176. if len(projectList) > 0 {
  6177. for _, item := range projectList {
  6178. project := models.HisProject{
  6179. ProjectName: item.ProjectName,
  6180. Price: item.Price,
  6181. Unit: item.Unit,
  6182. CostClassify: item.CostClassify,
  6183. ExecutiveSection: item.ExecutiveSection,
  6184. MedicalCoverage: item.MedicalCoverage,
  6185. UserOrgId: orgId,
  6186. Status: 1,
  6187. CreatedTime: time.Now().Unix(),
  6188. Pinyin: item.Pinyin,
  6189. Wubi: item.Wubi,
  6190. StatisticalClassification: item.StatisticalClassification,
  6191. DiseaseDirectory: item.DiseaseDirectory,
  6192. IsRecord: item.IsRecord,
  6193. MedicalCode: item.MedicalCode,
  6194. TubeColor: item.TubeColor,
  6195. SingleDose: item.SingleDose,
  6196. DeliveryWay: item.DeliveryWay,
  6197. NumberDays: item.NumberDays,
  6198. Total: item.Total,
  6199. Category: item.Category,
  6200. MedicalStatus: item.MedicalStatus,
  6201. SpecailProject: item.SpecailProject,
  6202. RecordDate: item.RecordDate,
  6203. Remark: item.Remark,
  6204. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  6205. ExecutionFrequency: item.ExecutionFrequency,
  6206. }
  6207. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  6208. if errcodeproject == gorm.ErrRecordNotFound {
  6209. service.CreateProjectInfomation(&project)
  6210. } else if errcodeproject == nil {
  6211. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  6212. }
  6213. log := models.ExportLog{
  6214. LogType: 6,
  6215. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6216. TotalNum: int64(len(total_goods)),
  6217. FailNum: int64(len(errLogs)),
  6218. SuccessNum: int64(len(projectList)),
  6219. CreateTime: time.Now().Unix(),
  6220. UpdateTime: time.Now().Unix(),
  6221. ExportTime: export_time,
  6222. Status: 1,
  6223. }
  6224. service.CreateExportLog(&log)
  6225. c.ServeSuccessJSON(map[string]interface{}{
  6226. "msg": "导入成功",
  6227. "total_num": len(total_goods),
  6228. "success_num": len(projectList),
  6229. "fail_num": int64(len(errLogs)),
  6230. })
  6231. }
  6232. } else {
  6233. log := models.ExportLog{
  6234. LogType: 6,
  6235. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6236. TotalNum: int64(len(total_goods)),
  6237. FailNum: int64(len(errLogs)),
  6238. SuccessNum: int64(len(projectList)),
  6239. CreateTime: time.Now().Unix(),
  6240. UpdateTime: time.Now().Unix(),
  6241. ExportTime: export_time,
  6242. Status: 1,
  6243. }
  6244. service.CreateExportLog(&log)
  6245. c.ServeSuccessJSON(map[string]interface{}{
  6246. "msg": "导入成功",
  6247. "total_num": len(total_goods),
  6248. "success_num": len(projectList),
  6249. "fail_num": int64(len(errLogs)),
  6250. })
  6251. }
  6252. }
  6253. //func (this *HisApiController) EditProjectInformation(){
  6254. //
  6255. // id, _ := this.GetInt64("id")
  6256. // project_team := this.GetString("project_team")
  6257. // price := this.GetString("price")
  6258. // price_float, _ := strconv.ParseFloat(price, 64)
  6259. // pinyin := this.GetString("pinyin")
  6260. // wubi := this.GetString("wubi")
  6261. // tube_color, _ := this.GetInt64("tube_color")
  6262. // team_type, _ := this.GetInt64("team_type")
  6263. // remark := this.GetString("remark")
  6264. // ids := this.GetString("ids")
  6265. // item_id := this.GetString("item_id")
  6266. // projectTeam := models.XtHisProjectTeam{
  6267. // ProjectTeam: project_team,
  6268. // Price: price_float,
  6269. // Pinyin: pinyin,
  6270. // Wubi: wubi,
  6271. // TubeColor: tube_color,
  6272. // TeamType: team_type,
  6273. // Remark: remark,
  6274. // ProjectId: ids,
  6275. // ItemId: item_id,
  6276. // }
  6277. //
  6278. //
  6279. // dataBody := make(map[string]interface{}, 0)
  6280. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  6281. // if err != nil {
  6282. // utils.ErrorLog(err.Error())
  6283. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6284. // return
  6285. // }
  6286. //
  6287. // err = service.UpdatedProjectTeam(id, &projectTeam)
  6288. //
  6289. //
  6290. // if err != nil {
  6291. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  6292. // return
  6293. // }
  6294. //
  6295. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  6296. // infos, _ := dataBody["info"].([]interface{})
  6297. // if len(infos) > 0 {
  6298. // var ids []string
  6299. //
  6300. // for _, item := range infos {
  6301. // items := item.(map[string]interface{})
  6302. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  6303. // utils.ErrorLog("id")
  6304. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6305. // return
  6306. // }
  6307. // id := int64(items["id"].(float64))
  6308. //
  6309. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6310. // utils.ErrorLog("type")
  6311. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6312. // return
  6313. // }
  6314. // types := int64(items["type"].(float64))
  6315. //
  6316. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  6317. // utils.ErrorLog("number")
  6318. // }
  6319. //
  6320. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  6321. //
  6322. // projectList := models.XtHisProjectList{
  6323. // Number: number,
  6324. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  6325. // ProjectId: id,
  6326. // Status: 1,
  6327. // CreatedTime: time.Now().Unix(),
  6328. // UpdatedTime: time.Now().Unix(),
  6329. // TeamId: projectTeam.ID,
  6330. // Type: types,
  6331. // }
  6332. // list := projectList
  6333. //
  6334. // service.CreateProjectList(&list)
  6335. //
  6336. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  6337. //
  6338. // }
  6339. // ids_str := strings.Join(ids, ",")
  6340. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  6341. // service.SaveProjectTeam(&projectTeam)
  6342. // this.ServeSuccessJSON(map[string]interface{}{
  6343. // "projectTeam": projectTeam,
  6344. // })
  6345. // }
  6346. // }
  6347. //}
  6348. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  6349. name := c.GetString("name")
  6350. mode_id, _ := c.GetInt64("mode", 0)
  6351. types, _ := c.GetInt64("type", 0)
  6352. patient_id, _ := c.GetInt64("patient_id", 0)
  6353. types = 1
  6354. adminInfo := c.GetAdminUserInfo()
  6355. template := &models.HisPrescriptionTemplate{
  6356. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  6357. PatientId: patient_id,
  6358. Type: types,
  6359. Status: 1,
  6360. Ctime: time.Now().Unix(),
  6361. Mtime: time.Now().Unix(),
  6362. Name: name,
  6363. Mode: mode_id,
  6364. }
  6365. dataBody := make(map[string]interface{}, 0)
  6366. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  6367. if err != nil {
  6368. utils.ErrorLog(err.Error())
  6369. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6370. return
  6371. }
  6372. err = service.CreateHisPrescriptionTemplate(template)
  6373. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  6374. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  6375. if len(prescriptions) > 0 {
  6376. for _, item := range prescriptions {
  6377. items := item.(map[string]interface{})
  6378. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  6379. utils.ErrorLog("type")
  6380. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6381. return
  6382. }
  6383. types := int64(items["type"].(float64))
  6384. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  6385. utils.ErrorLog("med_type")
  6386. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6387. return
  6388. }
  6389. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  6390. ctime := time.Now().Unix()
  6391. prescription := &models.HisPrescriptionInfoTemplate{
  6392. PatientId: patient_id,
  6393. UserOrgId: adminInfo.CurrentOrgId,
  6394. Ctime: ctime,
  6395. Mtime: ctime,
  6396. Type: types,
  6397. Modifier: adminInfo.AdminUser.Id,
  6398. Creator: adminInfo.AdminUser.Id,
  6399. Status: 1,
  6400. PTemplateId: template.ID,
  6401. MedType: med_type,
  6402. }
  6403. service.CreateHisPrescriptionInfoTemplate(prescription)
  6404. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  6405. advices := items["advices"].([]interface{})
  6406. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  6407. ctime := time.Now().Unix()
  6408. mtime := ctime
  6409. if len(advices) > 0 {
  6410. for _, advice := range advices {
  6411. var s models.HisPrescriptionAdviceTemplate
  6412. s.PrescriptionId = prescription.ID
  6413. s.AdviceType = 2
  6414. s.StopState = 2
  6415. s.ExecutionState = 2
  6416. s.Status = 1
  6417. s.UserOrgId = adminInfo.CurrentOrgId
  6418. s.CreatedTime = ctime
  6419. s.UpdatedTime = mtime
  6420. s.PatientId = patient_id
  6421. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  6422. if errcode > 0 {
  6423. c.ServeFailJSONWithSGJErrorCode(errcode)
  6424. return
  6425. }
  6426. service.CreateHisPrescriptionAdviceTemplate(&s)
  6427. }
  6428. }
  6429. }
  6430. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  6431. projects := items["project"].([]interface{})
  6432. if len(projects) > 0 {
  6433. for _, project := range projects {
  6434. var p models.HisPrescriptionProjectTemplate
  6435. p.PrescriptionId = prescription.ID
  6436. p.Ctime = time.Now().Unix()
  6437. p.Mtime = time.Now().Unix()
  6438. p.PatientId = patient_id
  6439. p.UserOrgId = adminInfo.CurrentOrgId
  6440. p.Status = 1
  6441. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  6442. if errcode > 0 {
  6443. c.ServeFailJSONWithSGJErrorCode(errcode)
  6444. return
  6445. }
  6446. service.CreateHisPrescriptionProjectTemplate(&p)
  6447. }
  6448. }
  6449. }
  6450. }
  6451. c.ServeSuccessJSON(map[string]interface{}{
  6452. "msg": "创建成功",
  6453. })
  6454. }
  6455. }
  6456. }
  6457. func (c *HisApiController) PreSettle() {
  6458. id, _ := c.GetInt64("id")
  6459. record_time := c.GetString("record_time")
  6460. his_patient_id, _ := c.GetInt64("his_patient_id")
  6461. timeLayout := "2006-01-02"
  6462. loc, _ := time.LoadLocation("Local")
  6463. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  6464. diagnosis_id := c.GetString("diagnosis")
  6465. sick_type, _ := c.GetInt64("sick_type")
  6466. reg_type, _ := c.GetInt64("p_type")
  6467. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6468. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  6469. if err != nil {
  6470. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6471. return
  6472. }
  6473. recordDateTime := theTime.Unix()
  6474. adminUser := c.GetAdminUserInfo()
  6475. var prescriptions []*models.HisPrescription
  6476. var start_time int64
  6477. var end_time int64
  6478. ids_str := c.GetString("ids")
  6479. ids_arr := strings.Split(ids_str, ",")
  6480. fmt.Println(reg_type)
  6481. if settle_accounts_type == 1 { //日结
  6482. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  6483. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  6484. } else {
  6485. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  6486. }
  6487. fmt.Println(prescriptions)
  6488. } else { //月结
  6489. start_time_str := c.GetString("start_time")
  6490. end_time_str := c.GetString("end_time")
  6491. timeLayout := "2006-01-02"
  6492. loc, _ := time.LoadLocation("Local")
  6493. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  6494. if err != nil {
  6495. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6496. return
  6497. }
  6498. recordStartTime := theStartTime.Unix()
  6499. start_time = recordStartTime
  6500. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  6501. if err != nil {
  6502. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6503. return
  6504. }
  6505. recordEndTime := theEndTime.Unix()
  6506. end_time = recordEndTime
  6507. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  6508. }
  6509. if reg_type == 1111 || reg_type == 1112 {
  6510. reg_type = 11
  6511. }
  6512. timestamp := time.Now().Unix()
  6513. tempTime := time.Unix(timestamp, 0)
  6514. timeFormat := tempTime.Format("20060102150405")
  6515. chrgBchno := rand.Intn(100000) + 10000
  6516. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  6517. strconv.FormatInt(his.PatientId, 10)
  6518. var ids []int64
  6519. for _, item := range prescriptions {
  6520. ids = append(ids, item.ID)
  6521. }
  6522. fmt.Println(ids)
  6523. var total float64
  6524. for _, item := range prescriptions {
  6525. fmt.Println(item)
  6526. if item.Type == 1 { //药品
  6527. for _, subItem := range item.HisDoctorAdviceInfo {
  6528. total = total + (subItem.Price * subItem.PrescribingNumber)
  6529. }
  6530. }
  6531. if item.Type == 2 { //项目
  6532. for _, subItem := range item.HisPrescriptionProject {
  6533. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6534. total = total + (subItem.Price * cnt)
  6535. }
  6536. }
  6537. for _, subItem := range item.HisAdditionalCharge {
  6538. total = total + (subItem.Price * float64(subItem.Count))
  6539. }
  6540. }
  6541. allTotal := fmt.Sprintf("%.2f", total)
  6542. totals, _ := strconv.ParseFloat(allTotal, 64)
  6543. order := &models.HisOrder{
  6544. UserOrgId: adminUser.CurrentOrgId,
  6545. HisPatientId: his.ID,
  6546. PatientId: id,
  6547. SettleAccountsDate: recordDateTime,
  6548. Ctime: time.Now().Unix(),
  6549. Mtime: time.Now().Unix(),
  6550. Status: 1,
  6551. OrderStatus: 1,
  6552. MdtrtId: his.Number,
  6553. Number: chrg_bchno,
  6554. MedfeeSumamt: totals,
  6555. SettleEndTime: end_time,
  6556. SettleStartTime: start_time,
  6557. SettleType: settle_accounts_type,
  6558. PType: 2,
  6559. IsPre: 1,
  6560. MedType: strconv.Itoa(int(reg_type)),
  6561. Diagnosis: diagnosis_id,
  6562. }
  6563. err = service.CreateOrder(order)
  6564. if err != nil {
  6565. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  6566. return
  6567. }
  6568. var customs []*Custom
  6569. for _, item := range prescriptions {
  6570. fmt.Println(item.Type)
  6571. if item.Type == 1 { //药品
  6572. for _, subItem := range item.HisDoctorAdviceInfo {
  6573. cus := &Custom{
  6574. AdviceId: subItem.ID,
  6575. ProjectId: 0,
  6576. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  6577. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  6578. FeedetlSn: subItem.FeedetlSn,
  6579. Price: fmt.Sprintf("%.2f", subItem.Price),
  6580. MedListCodg: subItem.MedListCodg,
  6581. Type: 1,
  6582. }
  6583. customs = append(customs, cus)
  6584. }
  6585. }
  6586. if item.Type == 2 { //项目
  6587. for _, subItem := range item.HisPrescriptionProject {
  6588. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  6589. cus := &Custom{
  6590. AdviceId: 0,
  6591. ProjectId: subItem.ID,
  6592. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  6593. Cut: fmt.Sprintf("%.2f", cnt),
  6594. FeedetlSn: subItem.FeedetlSn,
  6595. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  6596. MedListCodg: subItem.MedListCodg,
  6597. Type: 2,
  6598. }
  6599. customs = append(customs, cus)
  6600. }
  6601. }
  6602. for _, item := range item.HisAdditionalCharge {
  6603. cus := &Custom{
  6604. ItemId: item.ID,
  6605. AdviceId: 0,
  6606. ProjectId: 0,
  6607. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  6608. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  6609. FeedetlSn: item.FeedetlSn,
  6610. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  6611. MedListCodg: item.XtHisAddtionConfig.Code,
  6612. Type: 3,
  6613. }
  6614. customs = append(customs, cus)
  6615. }
  6616. }
  6617. fmt.Println(customs)
  6618. for _, item := range customs {
  6619. var advice_id int64 = 0
  6620. var project_id int64 = 0
  6621. var item_id int64 = 0
  6622. var types int64 = 0
  6623. if item.Type == 1 {
  6624. advice_id = item.AdviceId
  6625. project_id = 0
  6626. item_id = 0
  6627. } else if item.Type == 2 {
  6628. advice_id = 0
  6629. item_id = 0
  6630. project_id = item.ProjectId
  6631. } else if item.Type == 3 {
  6632. advice_id = 0
  6633. item_id = item.ItemId
  6634. project_id = 0
  6635. }
  6636. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  6637. cut, _ := strconv.ParseFloat(item.Cut, 32)
  6638. pric, _ := strconv.ParseFloat(item.Price, 32)
  6639. info := &models.HisOrderInfo{
  6640. OrderNumber: order.Number,
  6641. UploadDate: time.Now().Unix(),
  6642. AdviceId: advice_id,
  6643. DetItemFeeSumamt: detItemFeeSumamt,
  6644. Cnt: cut,
  6645. Pric: pric,
  6646. PatientId: id,
  6647. Status: 1,
  6648. Mtime: time.Now().Unix(),
  6649. Ctime: time.Now().Unix(),
  6650. UserOrgId: adminUser.CurrentOrgId,
  6651. HisPatientId: his.ID,
  6652. OrderId: order.ID,
  6653. ProjectId: project_id,
  6654. Type: types,
  6655. ItemId: item_id,
  6656. }
  6657. service.CreateOrderInfo(info)
  6658. }
  6659. his.SickType = sick_type
  6660. service.UpdataHisPateint(&his)
  6661. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  6662. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  6663. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  6664. if err == nil {
  6665. c.ServeSuccessJSON(map[string]interface{}{
  6666. "msg": "结算成功",
  6667. })
  6668. }
  6669. }
  6670. type CustomOrderInfo struct {
  6671. Name string
  6672. Spec string
  6673. Unit string
  6674. Count float64
  6675. Price float64
  6676. Total float64
  6677. }
  6678. func (c *HisApiController) GetPrivateExpensesInfo() {
  6679. order_id, _ := c.GetInt64("id", 0)
  6680. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  6681. order, _ := service.GetHisOrderByID(order_id)
  6682. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  6683. if order.ID == 0 {
  6684. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  6685. return
  6686. }
  6687. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  6688. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  6689. org_id := c.GetAdminUserInfo().CurrentOrgId
  6690. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  6691. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  6692. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  6693. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  6694. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  6695. var orderInfos_four []*models.HisOrderInfoTwo
  6696. for _, item := range orderInfos_three {
  6697. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  6698. item.HisPrescriptionProject.IsCheckTeam = 1
  6699. orderInfos_four = append(orderInfos_four, item)
  6700. }
  6701. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  6702. item.HisPrescriptionProject.IsCheckTeam = 2
  6703. orderInfos_two = append(orderInfos_two, item)
  6704. }
  6705. }
  6706. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  6707. var cus_slice []CustomOrderInfo
  6708. for _, item := range new_order_info {
  6709. var cus CustomOrderInfo
  6710. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  6711. cus.Unit = ""
  6712. cus.Spec = ""
  6713. var total float64
  6714. for _, subItem := range orderInfos_four {
  6715. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  6716. total = total + subItem.DetItemFeeSumamt
  6717. fmt.Println(subItem.DetItemFeeSumamt)
  6718. }
  6719. }
  6720. cus.Count = 1
  6721. cus.Total = total
  6722. cus_slice = append(cus_slice, cus)
  6723. }
  6724. orderInfos = append(orderInfos, orderInfos_two...)
  6725. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  6726. orderInfos = append(orderInfos, orderInfos_three...)
  6727. }
  6728. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  6729. c.ServeSuccessJSON(map[string]interface{}{
  6730. "order": order,
  6731. "order_info": orderInfos,
  6732. "patient": patient,
  6733. "admin_info": adminInfo,
  6734. "his": his,
  6735. "current_admin": role,
  6736. "org_config": miConfig,
  6737. "new_order_info": cus_slice,
  6738. })
  6739. }
  6740. func (this *HisApiController) ChangeMedType() {
  6741. med_type := this.GetString("med_type")
  6742. old_med_type := this.GetString("old_med_type")
  6743. ids := this.GetString("ids")
  6744. settle_type, _ := this.GetInt64("settle_type")
  6745. start_time := this.GetString("start_time")
  6746. end_time := this.GetString("end_time")
  6747. ids_arr := strings.Split(ids, ",")
  6748. if settle_type == 1 { //日结
  6749. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  6750. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  6751. prescription.MedType = med_type
  6752. err := service.SaveHisPrescription(&prescription)
  6753. if err == nil {
  6754. this.ServeSuccessJSON(map[string]interface{}{
  6755. "msg": "修改成功",
  6756. })
  6757. } else {
  6758. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6759. return
  6760. }
  6761. } else if settle_type == 2 {
  6762. timeLayout := "2006-01-02"
  6763. loc, _ := time.LoadLocation("Local")
  6764. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6765. if err != nil {
  6766. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6767. return
  6768. }
  6769. recordStartTime := theStartTime.Unix()
  6770. start_time_timestamp := recordStartTime
  6771. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  6772. if err != nil {
  6773. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6774. return
  6775. }
  6776. recordEndTime := theEndTime.Unix()
  6777. end_time_timestamp := recordEndTime
  6778. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  6779. if updateErr == nil {
  6780. this.ServeSuccessJSON(map[string]interface{}{
  6781. "msg": "修改成功",
  6782. })
  6783. } else {
  6784. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  6785. return
  6786. }
  6787. }
  6788. }
  6789. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  6790. patient_id, _ := c.GetInt64("patient_id")
  6791. his_patient_id, _ := c.GetInt64("his_patient_id")
  6792. record_date := c.GetString("record_date")
  6793. start_time := c.GetString("start_time")
  6794. end_time := c.GetString("end_time")
  6795. order_status, _ := c.GetInt64("type", 0)
  6796. p_type, _ := c.GetInt64("p_type", 0)
  6797. order_id, _ := c.GetInt64("order_id", 0)
  6798. timeLayout := "2006-01-02"
  6799. loc, _ := time.LoadLocation("Local")
  6800. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6801. if err != nil {
  6802. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6803. return
  6804. }
  6805. recordDateTime := theTime.Unix()
  6806. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6807. if err != nil {
  6808. }
  6809. startRecordDateTime := startTime.Unix()
  6810. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6811. if err != nil {
  6812. }
  6813. endRecordDateTime := endTime.Unix()
  6814. admin := c.GetAdminUserInfo()
  6815. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  6816. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6817. order, _ := service.GetHisOrderByID(order_id)
  6818. var monthPrescriptions []*models.HisPrescription
  6819. if order_status == 1 || order_status == 0 {
  6820. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6821. } else if order_status == 2 {
  6822. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  6823. }
  6824. var settle_total float64
  6825. for _, item := range monthPrescriptions {
  6826. if len(item.HisPrescriptionProject) > 0 {
  6827. for _, subItem := range item.HisPrescriptionProject {
  6828. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6829. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6830. settle_total = settle_total + total
  6831. }
  6832. }
  6833. if len(item.HisDoctorAdviceInfo) > 0 {
  6834. for _, subItem := range item.HisDoctorAdviceInfo {
  6835. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6836. settle_total = settle_total + total
  6837. }
  6838. }
  6839. }
  6840. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6841. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6842. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6843. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6844. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6845. //获取所有科室信息
  6846. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6847. c.ServeSuccessJSON(map[string]interface{}{
  6848. "his_info": his_patient_info,
  6849. "xt_info": xt_patient_info,
  6850. "case_history": case_history,
  6851. "info": patientPrescriptionInfo,
  6852. "last_info": lastPatientPrescriptionInfo,
  6853. "month_prescriptions": monthPrescriptions,
  6854. "order": order,
  6855. "doctors": doctors,
  6856. "department": department,
  6857. "settle_total": settle_total,
  6858. })
  6859. return
  6860. }
  6861. func (c *HisApiController) GetHisMonthPatientInfo() {
  6862. patient_id, _ := c.GetInt64("patient_id")
  6863. his_patient_id, _ := c.GetInt64("his_patient_id")
  6864. record_date := c.GetString("record_date")
  6865. number := c.GetString("number")
  6866. start_time := c.GetString("start_time")
  6867. end_time := c.GetString("end_time")
  6868. p_type, _ := c.GetInt64("p_type")
  6869. timeLayout := "2006-01-02"
  6870. loc, _ := time.LoadLocation("Local")
  6871. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  6872. if err != nil {
  6873. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  6874. return
  6875. }
  6876. recordDateTime := theTime.Unix()
  6877. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  6878. if err != nil {
  6879. }
  6880. startRecordDateTime := startTime.Unix()
  6881. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  6882. if err != nil {
  6883. }
  6884. endRecordDateTime := endTime.Unix()
  6885. admin := c.GetAdminUserInfo()
  6886. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  6887. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  6888. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  6889. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  6890. var settle_total float64
  6891. for _, item := range monthPrescriptions {
  6892. if len(item.HisPrescriptionProject) > 0 {
  6893. for _, subItem := range item.HisPrescriptionProject {
  6894. count, _ := strconv.ParseFloat(subItem.Count, 64)
  6895. total, _ := decimal.NewFromFloat(count * subItem.Price).Round(2).Float64()
  6896. settle_total = settle_total + total
  6897. }
  6898. }
  6899. if len(item.HisDoctorAdviceInfo) > 0 {
  6900. for _, subItem := range item.HisDoctorAdviceInfo {
  6901. total, _ := decimal.NewFromFloat(subItem.PrescribingNumber * subItem.Price).Round(2).Float64()
  6902. settle_total = settle_total + total
  6903. }
  6904. }
  6905. }
  6906. settle_total, _ = decimal.NewFromFloat(settle_total).Round(2).Float64()
  6907. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  6908. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  6909. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  6910. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  6911. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  6912. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  6913. //获取所有科室信息
  6914. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  6915. c.ServeSuccessJSON(map[string]interface{}{
  6916. "his_info": his_patient_info,
  6917. "xt_info": xt_patient_info,
  6918. "case_history": case_history,
  6919. "info": patientPrescriptionInfo,
  6920. "month_prescriptions": monthPrescriptions,
  6921. "order": order,
  6922. "doctors": doctors,
  6923. "department": department,
  6924. "count": count,
  6925. "drugStockConfig": drugStockConfig,
  6926. "last_info": lastPatientPrescriptionInfo,
  6927. "settle_total": settle_total,
  6928. })
  6929. return
  6930. }
  6931. func (c *HisApiController) GetAllOrder() {
  6932. org_id := c.GetAdminUserInfo().CurrentOrgId
  6933. orders, _ := service.GetNewHisOrderList(org_id)
  6934. c.ServeSuccessJSON(map[string]interface{}{
  6935. "order": orders,
  6936. })
  6937. return
  6938. }
  6939. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  6940. newArr = make([]*models.HisOrderInfoTwo, 0)
  6941. for i := 0; i < len(arr); i++ {
  6942. repeat := false
  6943. for j := i + 1; j < len(arr); j++ {
  6944. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  6945. repeat = true
  6946. break
  6947. }
  6948. }
  6949. if !repeat {
  6950. newArr = append(newArr, arr[i])
  6951. }
  6952. }
  6953. return
  6954. }
  6955. //修改处方退库操作 参数传修改之前的处方数据
  6956. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  6957. if advice.ExecutionState == 1 {
  6958. //查询该病人该药品是否有库存记录
  6959. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  6960. if errcode == gorm.ErrRecordNotFound {
  6961. } else {
  6962. //退库
  6963. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  6964. if advice.PrescribingNumberUnit == drug.MinUnit {
  6965. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6966. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6967. //退库
  6968. warehouseInfo := models.DrugWarehouseInfo{
  6969. StockMinNumber: prescribingNumber,
  6970. }
  6971. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  6972. operation_time := time.Now().Unix()
  6973. creater := advice.AdviceDoctor
  6974. ctime := time.Now().Unix()
  6975. timeStr := time.Now().Format("2006-01-02")
  6976. timeArr := strings.Split(timeStr, "-")
  6977. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6978. total = total + 1
  6979. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6980. cancelStock := models.DrugCancelStock{
  6981. OrderNumber: orderNumber,
  6982. OperaTime: operation_time,
  6983. OrgId: advice.UserOrgId,
  6984. Creater: creater,
  6985. Ctime: ctime,
  6986. Status: 1,
  6987. ReturnTime: advice.AdviceDate,
  6988. Dealer: info.Dealer,
  6989. Manufacturer: info.Manufacturer,
  6990. Type: 1,
  6991. }
  6992. service.AddSigleDrugCancelStock(&cancelStock)
  6993. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6994. dealer, _ := service.GetDealerById(info.Dealer)
  6995. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6996. cancelStockInfo := models.DrugCancelStockInfo{
  6997. OrderNumber: cancelInfo.OrderNumber,
  6998. CancelStockId: cancelInfo.ID,
  6999. DrugId: info.DrugId,
  7000. Count: info.Count,
  7001. Status: 1,
  7002. Ctime: ctime,
  7003. OrgId: advice.UserOrgId,
  7004. Type: 1,
  7005. Manufacturer: manufactureName.ManufacturerName,
  7006. Dealer: dealer.DealerName,
  7007. Total: 0,
  7008. RetailPrice: info.RetailPrice,
  7009. RetailTotalPrice: info.RetailTotalPrice,
  7010. Price: info.Price,
  7011. RegisterAccount: "",
  7012. Remark: info.Remark,
  7013. BatchNumber: info.BatchNumber,
  7014. MaxUnit: info.CountUnit,
  7015. ProductDate: info.ProductDate,
  7016. ExpiryDate: info.ExpiryDate,
  7017. BatchNumberId: info.WarehouseInfoId,
  7018. }
  7019. flow := models.DrugFlow{
  7020. WarehousingId: 0,
  7021. DrugId: info.DrugId,
  7022. Number: "",
  7023. BatchNumber: info.BatchNumber,
  7024. Count: info.Count,
  7025. UserOrgId: advice.UserOrgId,
  7026. PatientId: 0,
  7027. SystemTime: ctime,
  7028. ConsumableType: 4,
  7029. IsSys: 0,
  7030. WarehousingOrder: "",
  7031. WarehouseOutId: 0,
  7032. WarehouseOutOrderNumber: "",
  7033. IsEdit: 0,
  7034. CancelStockId: cancelStock.ID,
  7035. CancelOrderNumber: cancelStock.OrderNumber,
  7036. Manufacturer: info.Manufacturer,
  7037. Dealer: info.Dealer,
  7038. Creator: advice.UserOrgId,
  7039. UpdateCreator: 0,
  7040. Status: 1,
  7041. Ctime: time.Now().Unix(),
  7042. Mtime: 0,
  7043. Price: info.Price,
  7044. WarehousingDetailId: 0,
  7045. WarehouseOutDetailId: 0,
  7046. CancelOutDetailId: 0,
  7047. ExpireDate: info.ExpiryDate,
  7048. ProductDate: info.ProductDate,
  7049. MaxUnit: info.CountUnit,
  7050. MinUnit: "",
  7051. }
  7052. service.CreatedCancelStock(cancelStockInfo)
  7053. service.CreateDrugFlowOne(flow)
  7054. } else {
  7055. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  7056. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  7057. if advice.PrescribingNumberUnit == drug.MaxUnit {
  7058. warehouseInfo := models.DrugWarehouseInfo{
  7059. StockMinNumber: prescribingNumber,
  7060. }
  7061. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  7062. }
  7063. operation_time := time.Now().Unix()
  7064. creater := advice.AdviceDoctor
  7065. ctime := time.Now().Unix()
  7066. timeStr := time.Now().Format("2006-01-02")
  7067. timeArr := strings.Split(timeStr, "-")
  7068. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  7069. total = total + 1
  7070. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  7071. cancelStock := models.DrugCancelStock{
  7072. OrderNumber: orderNumber,
  7073. OperaTime: operation_time,
  7074. OrgId: advice.UserOrgId,
  7075. Creater: creater,
  7076. Ctime: ctime,
  7077. Status: 1,
  7078. ReturnTime: advice.AdviceDate,
  7079. Dealer: info.Dealer,
  7080. Manufacturer: info.Manufacturer,
  7081. Type: 1,
  7082. }
  7083. service.AddSigleDrugCancelStock(&cancelStock)
  7084. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  7085. dealer, _ := service.GetDealerById(info.Dealer)
  7086. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  7087. cancelStockInfo := models.DrugCancelStockInfo{
  7088. OrderNumber: cancelInfo.OrderNumber,
  7089. CancelStockId: cancelInfo.ID,
  7090. DrugId: info.DrugId,
  7091. Count: info.Count,
  7092. Status: 1,
  7093. Ctime: ctime,
  7094. OrgId: advice.UserOrgId,
  7095. Type: 1,
  7096. Manufacturer: manufactureName.ManufacturerName,
  7097. Dealer: dealer.DealerName,
  7098. Total: 0,
  7099. RetailPrice: info.RetailPrice,
  7100. RetailTotalPrice: info.RetailTotalPrice,
  7101. Price: info.Price,
  7102. RegisterAccount: "",
  7103. Remark: info.Remark,
  7104. BatchNumber: info.BatchNumber,
  7105. MaxUnit: info.CountUnit,
  7106. ProductDate: info.ProductDate,
  7107. ExpiryDate: info.ExpiryDate,
  7108. BatchNumberId: info.WarehouseInfoId,
  7109. }
  7110. flow := models.DrugFlow{
  7111. WarehousingId: 0,
  7112. DrugId: info.DrugId,
  7113. Number: "",
  7114. BatchNumber: info.BatchNumber,
  7115. Count: info.Count,
  7116. UserOrgId: advice.UserOrgId,
  7117. PatientId: 0,
  7118. SystemTime: ctime,
  7119. ConsumableType: 4,
  7120. IsSys: 0,
  7121. WarehousingOrder: "",
  7122. WarehouseOutId: 0,
  7123. WarehouseOutOrderNumber: "",
  7124. IsEdit: 0,
  7125. CancelStockId: cancelStock.ID,
  7126. CancelOrderNumber: cancelStock.OrderNumber,
  7127. Manufacturer: info.Manufacturer,
  7128. Dealer: info.Dealer,
  7129. Creator: advice.AdviceDoctor,
  7130. UpdateCreator: 0,
  7131. Status: 1,
  7132. Ctime: time.Now().Unix(),
  7133. Mtime: 0,
  7134. Price: info.Price,
  7135. WarehousingDetailId: 0,
  7136. WarehouseOutDetailId: 0,
  7137. CancelOutDetailId: 0,
  7138. ExpireDate: info.ExpiryDate,
  7139. ProductDate: info.ProductDate,
  7140. MaxUnit: info.CountUnit,
  7141. MinUnit: "",
  7142. }
  7143. service.CreatedCancelStock(cancelStockInfo)
  7144. service.CreateDrugFlowOne(flow)
  7145. }
  7146. }
  7147. }
  7148. return err
  7149. }
  7150. func (this *HisApiController) DeleteNCDS() {
  7151. id, _ := this.GetInt64("id", 0)
  7152. if id > 0 {
  7153. service.DeletePsnNCDSRecordById(id)
  7154. this.ServeSuccessJSON(map[string]interface{}{
  7155. "msg": "删除成功",
  7156. })
  7157. } else {
  7158. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  7159. return
  7160. }
  7161. }
  7162. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  7163. id, _ := c.GetInt64("id")
  7164. advice, _ := service.GetHisDoctorAdviceInfo(id)
  7165. c.ServeSuccessJSON(map[string]interface{}{
  7166. "advice": advice,
  7167. })
  7168. return
  7169. }
  7170. func (c *HisApiController) GetHisMonthChargePatientList() {
  7171. record_date := c.GetString("record_date")
  7172. start_time := c.GetString("start_time")
  7173. end_time := c.GetString("end_time")
  7174. timeLayout := "2006-01-02"
  7175. loc, _ := time.LoadLocation("Local")
  7176. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  7177. if err != nil {
  7178. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7179. return
  7180. }
  7181. if err != nil {
  7182. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  7183. return
  7184. }
  7185. recordDateTime := theTime.Unix()
  7186. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  7187. if err != nil {
  7188. }
  7189. startRecordDateTime := startTime.Unix()
  7190. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  7191. if err != nil {
  7192. }
  7193. endRecordDateTime := endTime.Unix()
  7194. adminInfo := c.GetAdminUserInfo()
  7195. var tempMonthChargePatients []*service.MonthChargePatients
  7196. tempPatients, _ := service.GetMonthUnChargeHisPatientList(adminInfo.CurrentOrgId, recordDateTime, startRecordDateTime, endRecordDateTime)
  7197. for _, item := range tempPatients {
  7198. //过滤没有处方的
  7199. if len(item.HisPrescription) == 0 {
  7200. tempMonthChargePatients = append(tempMonthChargePatients, item)
  7201. }
  7202. }
  7203. c.ServeSuccessJSON(map[string]interface{}{
  7204. "list": tempMonthChargePatients,
  7205. })
  7206. }