his_api_controller.go 284KB

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