his_api_controller.go 247KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916
  1. package controllers
  2. import "C"
  3. import (
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "fmt"
  10. "github.com/astaxie/beego"
  11. "github.com/jinzhu/gorm"
  12. "github.com/shopspring/decimal"
  13. "math/rand"
  14. "reflect"
  15. "strconv"
  16. "strings"
  17. "syscall"
  18. "time"
  19. "unsafe"
  20. )
  21. type HisApiController struct {
  22. BaseAuthAPIController
  23. }
  24. func HisManagerApiRegistRouters() {
  25. beego.Router("/api/hispatient/list", &HisApiController{}, "get:GetHisPatientList")
  26. beego.Router("/api/hispatient/get", &HisApiController{}, "get:GetHisPatientInfo")
  27. beego.Router("/api/hisprescription/config", &HisApiController{}, "get:GetHisPrescriptionConfig")
  28. beego.Router("/api/hisprescription/delete", &HisApiController{}, "post:DeletePrescription")
  29. beego.Router("/api/advice/delete", &HisApiController{}, "post:DeleteDoctorAdvice")
  30. beego.Router("/api/project/delete", &HisApiController{}, "post:DeleteProject")
  31. beego.Router("/api/addition_charge/delete", &HisApiController{}, "post:DeleteAddition")
  32. beego.Router("/api/hisprescription/list", &HisApiController{}, "get:GetHisPrescriptionList")
  33. beego.Router("/api/hisprescription/info", &HisApiController{}, "get:GetHisPrescriptionInfo")
  34. beego.Router("/api/hisprescription/create", &HisApiController{}, "post:CreateHisPrescription")
  35. beego.Router("/api/hisprescription/edit", &HisApiController{}, "post:EditHisPrescription")
  36. beego.Router("/api/doctorworkstation/casehistory/list", &HisApiController{}, "get:GetHisPatientCaseHistoryList")
  37. beego.Router("/api/doctorworkstation/casehistory/get", &HisApiController{}, "get:GetHisPatientCaseHistory")
  38. beego.Router("/api/doctorworkstation/casehistory/create", &HisApiController{}, "get:CreateHisPatientCaseHistory")
  39. beego.Router("/api/doctorworkstation/casehistorytemplate/create", &HisApiController{}, "get:CreateCaseHistoryTemplate")
  40. beego.Router("/api/doctorworkstation/casehistorytemplate/get", &HisApiController{}, "get:GetCaseHistoryTemplate")
  41. beego.Router("/api/hisorder/list", &HisApiController{}, "get:GetHisOrderList")
  42. beego.Router("/api/hisorder/get", &HisApiController{}, "get:GetHisOrder")
  43. beego.Router("/api/register/get", &HisApiController{}, "get:GetRegisterInfo")
  44. beego.Router("/api/upload/get", &HisApiController{}, "get:GetUploadInfo")
  45. beego.Router("/api/presettle/get", &HisApiController{}, "get:PreSettle")
  46. beego.Router("/api/refund/post", &HisApiController{}, "post:Refund")
  47. beego.Router("/api/refundnumber/post", &HisApiController{}, "post:RefundNumber")
  48. beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  49. beego.Router("/api/doctor/list", &HisApiController{}, "get:GetAdminUsers")
  50. //beego.Router("/api/medicalinsurance/config", &HisApiController{}, "get:GetMedicalInsuranceConfig")
  51. //新增附加费用
  52. //beego.Router("/api/his/additionalcharge", &HisApiController{}, "Post:AdditionalCharge")
  53. //beego.Router("/api/additionalcharge/get", &HisApiController{}, "Get:GetAdditionalcharge")
  54. beego.Router("/api/hisprescription/get", &HisApiController{}, "Get:GetLastOrNextHisPrescription")
  55. beego.Router("/api/callhisprescription/get", &HisApiController{}, "Get:GetCallHisPrescription")
  56. beego.Router("/api/dayprescription/get", &HisApiController{}, "get:GetHisDayPrescription")
  57. beego.Router("/api/charge/list", &HisApiController{}, "get:GetHisChargePatientList")
  58. beego.Router("/api/charge/info", &HisApiController{}, "get:GetHisChargePatientInfo")
  59. beego.Router("/api/unregister/list", &HisApiController{}, "get:GetHisUnRegisterPatientList")
  60. beego.Router("/api/orderdetail/get", &HisApiController{}, "get:GetAllOrderDetail")
  61. beego.Router("/api/orderdetaicollect/get", &HisApiController{}, "get:GetAllOrderDetailCollect")
  62. beego.Router("/api/cost/compare", &HisApiController{}, "get:GetMedicalInsuranceCostCompareList")
  63. beego.Router("/api/record/list", &HisApiController{}, "get:GetPutOnRecordList")
  64. beego.Router("/api/comparedata/get", &HisApiController{}, "get:GetCompareData")
  65. beego.Router("/api/fapiao/get", &HisApiController{}, "get:GetFaPiaoData")
  66. beego.Router("/api/incomestatistics/get", &HisApiController{}, "get:GetIncomeStatisticsData")
  67. beego.Router("/api/postprojectinformation", &HisApiController{}, "post:PostProjectInformation")
  68. //beego.Router("/api/editprojectinformation", &HisApiController{}, "post:EditProjectInformation")
  69. beego.Router("/api/hisprescriptiontemplate/create", &HisApiController{}, "post:CreateHisPrescriptionTemplate")
  70. beego.Router("/api/privateexpenses/get", &HisApiController{}, "get:GetPrivateExpensesInfo")
  71. beego.Router("/api/changemedtype/post", &HisApiController{}, "post:ChangeMedType")
  72. beego.Router("/api/refunddetail/post", &HisApiController{}, "post:RefudDetail")
  73. beego.Router("/api/privateexpensesorder/get", &HisApiController{}, "get:GetPrivateExpensesOrder")
  74. beego.Router("/api/uncharge/list", &HisApiController{}, "get:GetHisUnChargePatientList")
  75. beego.Router("/api/monthcharge/info", &HisApiController{}, "get:GetHisMonthChargePatientInfo")
  76. beego.Router("/api/monthhispatient/get", &HisApiController{}, "get:GetHisMonthPatientInfo")
  77. beego.Router("/api/orders", &HisApiController{}, "get:GetAllOrder")
  78. beego.Router("/api/psn/ncds/delete", &HisApiController{}, "post:DeleteNCDS")
  79. beego.Router("/api/bailin/export", &PublicApiController{}, "get:GetBaiLinExportData")
  80. beego.Router("/api/his/gethistdoctoradviceinfo", &HisApiController{}, "get:GetHisDoctorAdviceInfo")
  81. }
  82. func (c *PublicApiController) GetBaiLinExportData() {
  83. data := service.GetBaiLinOrderData()
  84. fmt.Println(len(data))
  85. var new_data []*models.NewCustomHisOrder
  86. for _, item := range data {
  87. if item.NewCustomHisOrderInfo.NewCustomHisPrescriptionProject.ID != 0 {
  88. new_data = append(new_data, item)
  89. }
  90. }
  91. fmt.Println(len(new_data))
  92. c.ServeSuccessJSON(map[string]interface{}{
  93. "list": new_data,
  94. })
  95. }
  96. func (c *HisApiController) GetHisUnChargePatientList() {
  97. record_date := c.GetString("record_date")
  98. timeLayout := "2006-01-02"
  99. loc, _ := time.LoadLocation("Local")
  100. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  101. if err != nil {
  102. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  103. return
  104. }
  105. recordDateTime := theTime.Unix()
  106. adminInfo := c.GetAdminUserInfo()
  107. var tempPatients []*service.NewTempPatients
  108. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  109. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  110. var patients []*service.NewTempPatients
  111. var patients_two []*service.NewTempPatients
  112. for _, item := range tempPatients {
  113. //过滤掉没挂号的和没开处方的
  114. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  115. patients = append(patients, item)
  116. }
  117. //过滤掉没挂号的
  118. if len(item.HisPatient) > 0 {
  119. patients_two = append(patients_two, item)
  120. }
  121. }
  122. c.ServeSuccessJSON(map[string]interface{}{
  123. "list": patients,
  124. "list_two": patients_two,
  125. })
  126. }
  127. func (c *HisApiController) GetPrivateExpensesOrder() {
  128. //id, _ := c.GetInt64("id")
  129. //record_time := c.GetString("record_time")
  130. order_id, _ := c.GetInt64("order_id")
  131. admin_user_id, _ := c.GetInt64("admin_user_id")
  132. //timeLayout := "2006-01-02"
  133. //loc, _ := time.LoadLocation("Local")
  134. //
  135. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  136. //if err != nil {
  137. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  138. // return
  139. //}
  140. //recordDateTime := theTime.Unix()
  141. adminUser := c.GetAdminUserInfo()
  142. order, _ := service.GetHisOrderByID(order_id)
  143. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, order.MdtrtId)
  144. orderInfos, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  145. diagnosis_ids := strings.Split(his.Diagnosis, ",")
  146. //var config []*models.HisXtDiagnoseConfig
  147. var name string
  148. for _, item := range diagnosis_ids {
  149. id, _ := strconv.ParseInt(item, 10, 64)
  150. diagnosisConfig, _ := service.FindDiagnoseById(id)
  151. if len(name) == 0 {
  152. name = diagnosisConfig.ClassName
  153. } else {
  154. name = name + "," + diagnosisConfig.ClassName
  155. }
  156. }
  157. decimal.DivisionPrecision = 2
  158. for _, item := range orderInfos {
  159. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  160. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  161. item.MedChrgitmType = "09"
  162. }
  163. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  164. if item.HisPrescriptionProject.Type == 2 {
  165. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  166. case 1:
  167. item.MedChrgitmType = "14"
  168. break
  169. case 2:
  170. item.MedChrgitmType = "05"
  171. break
  172. case 3:
  173. item.MedChrgitmType = "04"
  174. break
  175. case 4:
  176. item.MedChrgitmType = "14"
  177. break
  178. case 5:
  179. item.MedChrgitmType = "08"
  180. break
  181. case 6:
  182. item.MedChrgitmType = "14"
  183. break
  184. case 7:
  185. item.MedChrgitmType = "14"
  186. break
  187. case 8:
  188. item.MedChrgitmType = "03"
  189. break
  190. case 9:
  191. item.MedChrgitmType = "14"
  192. break
  193. }
  194. } else if item.HisPrescriptionProject.Type == 3 {
  195. item.MedChrgitmType = "08"
  196. }
  197. }
  198. }
  199. order.PsnCashPay = order.MedfeeSumamt
  200. //var user_name string
  201. //role, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  202. //if role.ID == 0 {
  203. // user_name = "管理员"
  204. //} else {
  205. // user_name = role.UserName
  206. //}
  207. org, _ := service.GetOrgById(adminUser.CurrentOrgId)
  208. printor_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, admin_user_id)
  209. charge_admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, order.Creator)
  210. patient, _ := service.GetPatientByID(order.UserOrgId, order.PatientId)
  211. c.ServeSuccessJSON(map[string]interface{}{
  212. "org_name": org.OrgName,
  213. "name": patient.Name,
  214. "order_infos": orderInfos,
  215. "number": order.MdtrtId,
  216. "date": order.SettleAccountsDate,
  217. "charge_admin": charge_admin,
  218. "printor_admin": printor_admin,
  219. "info": order,
  220. })
  221. }
  222. func (c *HisApiController) RefudDetail() {
  223. order_id, _ := c.GetInt64("order_id")
  224. order, _ := service.GetHisOrderByID(order_id)
  225. adminUser := c.GetAdminUserInfo()
  226. service.UpdataOrderInfoStatus(order_id, order.Number, adminUser.CurrentOrgId)
  227. c.ServeSuccessJSON(map[string]interface{}{
  228. "msg": "撤销成功",
  229. })
  230. }
  231. func (c *HisApiController) Sscard() {
  232. //r := CardInit()
  233. //if r == 0 {
  234. // GetBaseInfo()
  235. //}
  236. //c.ServeSuccessJSON(map[string]interface{}{
  237. // "list": "11",
  238. //})
  239. }
  240. func GetBaseInfo() error {
  241. //handle := syscall.MustLoadDLL("SSCard.dll")
  242. //ReadCardBas := handle.MustFindProc("ReadCardBas")
  243. //
  244. //str := make([]byte, 256)
  245. //str1 := make([]byte, 256)
  246. //r, _, ferr := ReadCardBas.Call((uintptr)(unsafe.Pointer(&str[0])), IntPtr(1024), (uintptr)(unsafe.Pointer(&str1[0])), IntPtr(1024))
  247. //if ferr != nil {
  248. // fmt.Println("ReadCardBas 报错", ferr.Error())
  249. // return ferr
  250. //}
  251. //
  252. //fmt.Println(string(str))
  253. //
  254. //fmt.Println(r)
  255. return nil
  256. }
  257. func CardInit() int {
  258. //DllTestDef := syscall.MustLoadDLL("SSCard.dll")
  259. //add := DllTestDef.MustFindProc("Init")
  260. //ret, _, err := add.Call(StrPtr("http://igb.hsa.gdgov.cn/gdyb_inf/poc/api/card/initDll"), StrPtr("440200"))
  261. //if err != nil {
  262. // fmt.Println("SSCard的运算结果为:", ret)
  263. //}
  264. //result := int(ret)
  265. return 0
  266. }
  267. func IntPtr(n int) uintptr {
  268. return uintptr(n)
  269. }
  270. func StrPtr(s string) uintptr {
  271. return uintptr(unsafe.Pointer(syscall.StringBytePtr(s)))
  272. }
  273. func (c *HisApiController) GetHisPatientList() {
  274. //types, _ := c.GetInt64("type", 0)
  275. record_date := c.GetString("record_date")
  276. sch_type, _ := c.GetInt64("sch_type")
  277. timeLayout := "2006-01-02"
  278. loc, _ := time.LoadLocation("Local")
  279. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  280. if err != nil {
  281. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  282. return
  283. }
  284. recordDateTime := theTime.Unix()
  285. adminInfo := c.GetAdminUserInfo()
  286. //patients, _ := service.GetHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  287. patients, _ := service.GetNewHisPatientList(adminInfo.CurrentOrgId, recordDateTime)
  288. patients_two, _ := service.GetScheduleHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime, sch_type)
  289. //获取当前用户的信息
  290. adminUserInfo, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, adminInfo.AdminUser.Id)
  291. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  292. //获取所有科室信息
  293. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  294. c.ServeSuccessJSON(map[string]interface{}{
  295. "list": patients,
  296. "list_two": patients_two,
  297. "info": adminUserInfo,
  298. "doctors": doctors,
  299. "department": department,
  300. })
  301. }
  302. type CustomTemplate struct {
  303. ID int64 `gorm:"column:id" json:"id" form:"id"`
  304. UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
  305. RecordDate int64 `gorm:"column:record_date" json:"record_date" form:"record_date"`
  306. PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
  307. Status int64 `gorm:"column:status" json:"status" form:"status"`
  308. Ctime int64 `gorm:"column:ctime" json:"ctime" form:"ctime"`
  309. Mtime int64 `gorm:"column:mtime" json:"mtime" form:"mtime"`
  310. Type int64 `gorm:"column:type" json:"type" form:"type"`
  311. Creator int64 `gorm:"column:creator" json:"creator" form:"creator"`
  312. Modifier int64 `gorm:"column:modifier" json:"modifier" form:"modifier"`
  313. PType int64 `gorm:"column:p_type" json:"p_type" form:"p_type"`
  314. PTemplateId int64 `gorm:"column:p_template_id" json:"p_template_id" form:"p_template_id"`
  315. HisPrescriptionAdviceTemplate []*models.HisPrescriptionAdviceTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"advices"`
  316. HisPrescriptionProjectTemplate []*models.HisPrescriptionProjectTemplate `gorm:"ForeignKey:PrescriptionId;AssociationForeignKey:ID" json:"project"`
  317. MedType string `gorm:"column:med_type" json:"med_type" form:"med_type"`
  318. }
  319. func (c *HisApiController) GetHisPatientInfo() {
  320. patient_id, _ := c.GetInt64("patient_id")
  321. his_patient_id, _ := c.GetInt64("his_patient_id")
  322. record_date := c.GetString("record_date")
  323. number := c.GetString("number")
  324. //start_time := c.GetString("start_time")
  325. //end_time := c.GetString("end_time")
  326. p_type, _ := c.GetInt64("p_type")
  327. timeLayout := "2006-01-02"
  328. loc, _ := time.LoadLocation("Local")
  329. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  330. if err != nil {
  331. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  332. return
  333. }
  334. recordDateTime := theTime.Unix()
  335. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  336. //if err != nil {
  337. //
  338. //}
  339. //startRecordDateTime := startTime.Unix()
  340. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  341. //if err != nil {
  342. //
  343. //}
  344. //endRecordDateTime := endTime.Unix()
  345. admin := c.GetAdminUserInfo()
  346. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  347. //his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  348. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  349. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  350. var prescriptions []*models.HisPrescription
  351. var last_prescriptions []*models.HisPrescription
  352. var sch_prescriptions []CustomTemplate
  353. last_p_info, _ := service.FindLastPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  354. if p_type == 1 { //住院
  355. prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  356. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  357. } else { //门诊
  358. prescriptions, _ = service.GetNewHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  359. last_prescriptions, _ = service.GetHisPrescription(admin.CurrentOrgId, patient_id, last_p_info.RecordDate, p_type)
  360. }
  361. sch, _ := service.GetPatientSch(patient_id, recordDateTime, admin.CurrentOrgId)
  362. if sch.ID > 0 {
  363. var week string
  364. t := time.Now()
  365. switch t.Weekday().String() {
  366. case "Monday":
  367. week = "周一"
  368. break
  369. case "Tuesday":
  370. week = "周二"
  371. break
  372. case "Wednesday":
  373. week = "周三"
  374. break
  375. case "Thursday":
  376. week = "周四"
  377. break
  378. case "Friday":
  379. week = "周五"
  380. break
  381. case "Saturday":
  382. week = "周六"
  383. break
  384. case "Sunday":
  385. week = "周日"
  386. break
  387. }
  388. mode_template, _ := service.GetHisPrescriptionBySchMode(sch.ModeId, patient_id, admin.CurrentOrgId)
  389. temp_sch_prescriptions, _ := service.GetHisPrescriptionTemplate(mode_template.ID, admin.CurrentOrgId)
  390. //根据推送频率组装新的数组
  391. for _, item := range temp_sch_prescriptions {
  392. var cus CustomTemplate
  393. cus.ID = item.ID
  394. cus.UserOrgId = item.UserOrgId
  395. cus.PatientId = item.PatientId
  396. cus.MedType = item.MedType
  397. cus.RecordDate = item.RecordDate
  398. cus.Type = item.Type
  399. cus.PType = item.PType
  400. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  401. if find := strings.Contains(subItem.Drug.DrugStatus, "停用"); !find {
  402. if subItem.FrequencyType == 1 { //每次必推
  403. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  404. }
  405. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 { //按照星期来推
  406. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  407. }
  408. if subItem.FrequencyType == 2 { //按照天数频率
  409. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  410. now := p.Unix()
  411. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  412. dayStr2 := "-" + dayStr
  413. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  414. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  415. advices, _ := service.FindAllHisDoctorAdviceByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.DrugId)
  416. if len(advices) == 0 {
  417. cus.HisPrescriptionAdviceTemplate = append(cus.HisPrescriptionAdviceTemplate, subItem)
  418. }
  419. }
  420. }
  421. }
  422. for _, subItem := range item.HisPrescriptionProjectTemplate {
  423. if subItem.Type == 2 {
  424. if subItem.XtHisProject.MedicalStatus != 1 {
  425. if subItem.FrequencyType == 1 {
  426. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  427. }
  428. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  429. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  430. }
  431. if subItem.FrequencyType == 2 {
  432. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  433. now := p.Unix()
  434. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  435. dayStr2 := "-" + dayStr
  436. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  437. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  438. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  439. if len(projects) == 0 {
  440. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  441. }
  442. }
  443. }
  444. } else if subItem.Type == 3 {
  445. if find := strings.Contains(subItem.GoodInfo.GoodStatus, "停用"); !find {
  446. if subItem.FrequencyType == 1 {
  447. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  448. }
  449. if subItem.FrequencyType == 3 && strings.Index(subItem.WeekDay, week) != -1 {
  450. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  451. }
  452. if subItem.FrequencyType == 2 {
  453. p, _ := time.Parse("2006-01-02", time.Now().Format("2006-01-02"))
  454. now := p.Unix()
  455. dayStr := strconv.FormatInt(subItem.DayCount, 10)
  456. dayStr2 := "-" + dayStr
  457. count, _ := strconv.ParseInt(dayStr2, 10, 64)
  458. oldTime := time.Now().AddDate(0, 0, int(count)).Unix()
  459. projects, _ := service.FindAllHisProjectByTime(now, oldTime, patient_id, c.GetAdminUserInfo().CurrentOrgId, subItem.ProjectId)
  460. if len(projects) == 0 {
  461. cus.HisPrescriptionProjectTemplate = append(cus.HisPrescriptionProjectTemplate, subItem)
  462. }
  463. }
  464. }
  465. }
  466. }
  467. sch_prescriptions = append(sch_prescriptions, cus)
  468. }
  469. for _, item := range sch_prescriptions {
  470. if len(item.HisPrescriptionProjectTemplate) == 0 {
  471. item.HisPrescriptionProjectTemplate = make([]*models.HisPrescriptionProjectTemplate, 0)
  472. }
  473. if len(item.HisPrescriptionAdviceTemplate) == 0 {
  474. item.HisPrescriptionAdviceTemplate = make([]*models.HisPrescriptionAdviceTemplate, 0)
  475. }
  476. }
  477. }
  478. _, config := service.FindHisStockPriceRecordByOrgId(admin.CurrentOrgId)
  479. if config.ID > 0 && config.IsOpen == 1 {
  480. for _, item := range sch_prescriptions {
  481. for _, subItem := range item.HisPrescriptionAdviceTemplate {
  482. info, _ := service.GetWarehoseInfoByDrugId(subItem.DrugId, admin.CurrentOrgId)
  483. if info.RetailPrice > 0 {
  484. subItem.Drug.MinPrice = info.RetailPrice
  485. }
  486. }
  487. }
  488. }
  489. if config.ID > 0 && config.IsOpen == 1 {
  490. for _, item := range sch_prescriptions {
  491. for _, subItem := range item.HisPrescriptionProjectTemplate {
  492. if subItem.Type == 3 {
  493. info, _ := service.GetGoodWarehoseInfoByGoodId(subItem.ProjectId, admin.CurrentOrgId)
  494. if info.Price > 0 {
  495. subItem.GoodInfo.PackingPrice = info.Price
  496. }
  497. }
  498. }
  499. }
  500. }
  501. //prescriptions, _ := service.GetHisPrescription(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime)
  502. //monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  503. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  504. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  505. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  506. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  507. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  508. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  509. //获取所有科室信息
  510. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  511. c.ServeSuccessJSON(map[string]interface{}{
  512. "his_info": his_patient_info,
  513. "xt_info": xt_patient_info,
  514. "prescription": prescriptions,
  515. "case_history": case_history,
  516. "info": patientPrescriptionInfo,
  517. //"month_prescriptions": monthPrescriptions,
  518. "order": order,
  519. "doctors": doctors,
  520. "department": department,
  521. "sch_prescriptions": sch_prescriptions,
  522. "last_prescriptions": last_prescriptions,
  523. "schedule": sch,
  524. "count": count,
  525. "drugStockConfig": drugStockConfig,
  526. "last_info": lastPatientPrescriptionInfo,
  527. })
  528. return
  529. }
  530. func (c *HisApiController) GetHisPrescriptionConfig() {
  531. adminInfo := c.GetAdminUserInfo()
  532. //获取医嘱模版
  533. advices, _ := service.FindAllHisAdviceTemplate(adminInfo.CurrentOrgId)
  534. //获取所有基础药
  535. drugs, _ := service.GetAllDrugLibList(adminInfo.CurrentOrgId)
  536. _, config := service.FindHisStockPriceRecordByOrgId(adminInfo.CurrentOrgId)
  537. if config.ID > 0 && config.IsOpen == 1 {
  538. for _, item := range drugs {
  539. var index = 0
  540. for _, subItem := range item.OtherDrugWarehouseInfo {
  541. if index == 0 {
  542. index = index + 1
  543. if subItem.RetailPrice > 0 {
  544. item.MinPrice = subItem.RetailPrice
  545. }
  546. }
  547. }
  548. }
  549. }
  550. manufacturers, _ := service.GetAllManufacturerList(adminInfo.CurrentOrgId)
  551. drugways, _, _ := service.GetDrugWayDics(adminInfo.CurrentOrgId)
  552. efs, _, _ := service.GetExecutionFrequencyDics(adminInfo.CurrentOrgId)
  553. doctors, _ := service.GetHisAdminUserDoctors(adminInfo.CurrentOrgId)
  554. //获取所有科室信息
  555. department, _ := service.GetAllDepartMent(adminInfo.CurrentOrgId)
  556. //获取诊断信息
  557. sick, _ := service.FindAllSick(adminInfo.CurrentOrgId)
  558. diagnose, _ := service.FindAllDiagnose(adminInfo.CurrentOrgId)
  559. additions, _ := service.FindAllAddition(adminInfo.CurrentOrgId)
  560. c.ServeSuccessJSON(map[string]interface{}{
  561. "drugs": drugs,
  562. "advices_template": advices,
  563. "drugways": drugways,
  564. "efs": efs,
  565. "doctors": doctors,
  566. "department": department,
  567. "sick": sick,
  568. "additions": additions,
  569. "diagnose": diagnose,
  570. "manufacturers": manufacturers,
  571. })
  572. }
  573. func (c *HisApiController) CreateHisPrescription() {
  574. record_date := c.GetString("record_date")
  575. patient_id, _ := c.GetInt64("patient_id")
  576. reg_type, _ := c.GetInt64("reg_type")
  577. diagnose := c.GetString("diagnose")
  578. sick_type, _ := c.GetInt64("sick_type")
  579. sick_history := c.GetString("sick_history")
  580. doctor_id, _ := c.GetInt64("doctor", 0)
  581. department, _ := c.GetInt64("department", 0)
  582. his_patient_id, _ := c.GetInt64("his_patient_id")
  583. p_type, _ := c.GetInt64("p_type")
  584. dataBody := make(map[string]interface{}, 0)
  585. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  586. if err != nil {
  587. utils.ErrorLog(err.Error())
  588. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  589. return
  590. }
  591. timeLayout := "2006-01-02"
  592. loc, _ := time.LoadLocation("Local")
  593. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  594. if err != nil {
  595. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  596. return
  597. }
  598. adminInfo := c.GetAdminUserInfo()
  599. recordDateTime := theTime.Unix()
  600. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  601. if his_patient_id == 0 { //前端传过来的挂号id为0时,进行多一步判断
  602. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient_id, recordDateTime)
  603. if len(lists) == 1 {
  604. his_patient_id = lists[0].ID
  605. }
  606. }
  607. patient, _ := service.GetPatientByIDTwo(adminInfo.CurrentOrgId, patient_id)
  608. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  609. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  610. if drugStockConfig.IsOpen == 1 {
  611. //校验库存总量
  612. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  613. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  614. if len(prescriptions) > 0 {
  615. for _, item := range prescriptions {
  616. items := item.(map[string]interface{})
  617. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  618. advices := items["advices"].([]interface{})
  619. if len(advices) > 0 {
  620. for _, advice := range advices {
  621. var drug_id int64
  622. var prescribing_number float64
  623. var prescribingNumberUnit string
  624. var prescribingNumber string
  625. var adviceId int64
  626. if advice.(map[string]interface{})["id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["id"]).String() == "float64" {
  627. drug_id = int64(advice.(map[string]interface{})["id"].(float64))
  628. }
  629. if advice.(map[string]interface{})["prescribing_number"] != nil || reflect.TypeOf(advice.(map[string]interface{})["prescribing_number"]).String() == "string" {
  630. prescribing_number_str := advice.(map[string]interface{})["prescribing_number"].(string)
  631. prescribing_number, _ = strconv.ParseFloat(prescribing_number_str, 64)
  632. prescribingNumber = advice.(map[string]interface{})["prescribing_number"].(string)
  633. }
  634. if advice.(map[string]interface{})["prescribing_number_unit"] != nil && reflect.TypeOf(advice.(map[string]interface{})["prescribing_number_unit"]).String() == "string" {
  635. prescribingNumberUnit, _ = advice.(map[string]interface{})["prescribing_number_unit"].(string)
  636. }
  637. if advice.(map[string]interface{})["advice_id"] != nil || reflect.TypeOf(advice.(map[string]interface{})["advice_id"]).String() == "float64" {
  638. adviceId = int64(advice.(map[string]interface{})["advice_id"].(float64))
  639. }
  640. drug, _ := service.FindBaseDrugLibRecordSeven(adminInfo.CurrentOrgId, drug_id)
  641. if drug.ID == 0 {
  642. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  643. return
  644. }
  645. //查询药品的所有库存
  646. list, _ := service.GetDrugWarehouseInfoPrescriptionSeven(drug_id, adminInfo.CurrentOrgId)
  647. var total_count int64
  648. for _, it := range list {
  649. total_count += it.StockMaxNumber*drug.MinNumber + it.StockMinNumber
  650. }
  651. totals := strconv.FormatInt(total_count, 10)
  652. //查询该药品是否存在开药记录
  653. advicelist, _ := service.GetHisAdviceListByDrugIdEight(drug_id, patient_id, recordDateTime, adviceId)
  654. //新增处方
  655. if advicelist.ID == 0 {
  656. all_count, _ := strconv.ParseFloat(totals, 64)
  657. if prescribingNumberUnit == drug.MinUnit {
  658. if prescribing_number > all_count {
  659. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  660. return
  661. }
  662. } else {
  663. if prescribingNumberUnit == drug.MaxUnit {
  664. num := prescribing_number * float64(drug.MinNumber)
  665. if num > all_count {
  666. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  667. return
  668. }
  669. }
  670. }
  671. }
  672. //修改处方
  673. if advicelist.ID > 0 {
  674. var device_number int64
  675. if advicelist.PrescribingNumberUnit == drug.MaxUnit {
  676. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  677. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  678. device_number = prescribingNumberInt * drug.MinNumber
  679. }
  680. if advicelist.PrescribingNumberUnit == drug.MinUnit {
  681. prescribingNumberOne := strconv.FormatFloat(advicelist.PrescribingNumber, 'f', -1, 64)
  682. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumberOne, 10, 64)
  683. device_number = prescribingNumberInt
  684. }
  685. var number_count int64
  686. if prescribingNumberUnit == drug.MaxUnit {
  687. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  688. number_count = prescribingNumberInt * drug.MinNumber
  689. }
  690. if prescribingNumberUnit == drug.MinUnit {
  691. prescribingNumberInt, _ := strconv.ParseInt(prescribingNumber, 10, 64)
  692. number_count = prescribingNumberInt
  693. }
  694. //如果修改的数量大于之前修改的数量
  695. if (number_count - device_number) > 0 {
  696. //如果修改的差数量 大于库存数量
  697. if (number_count - device_number) > total_count {
  698. c.ServeDynamicFailJsonSend(drug.DrugName + "库存不足")
  699. return
  700. }
  701. }
  702. if device_number != number_count {
  703. // 查询该药品最后一次出库记录
  704. druginfo, _ := service.GetLastDrugWarehouseOutByDrugId(drug_id, patient_id, recordDateTime, adviceId)
  705. //回退库存
  706. if druginfo.CountUnit == drug.MaxUnit && drug.MaxUnit != drug.MinUnit {
  707. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, number_count)
  708. }
  709. if druginfo.CountUnit == drug.MinUnit && drug.MaxUnit != drug.MinUnit {
  710. var stock_max_number int64
  711. var stock_min_number int64
  712. if number_count >= drug.MinNumber {
  713. stock_max_number = device_number / drug.MinNumber
  714. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, stock_max_number)
  715. stock_min_number = device_number % drug.MinNumber
  716. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, stock_min_number)
  717. } else {
  718. service.ModefyDrugByWarehouseInfoOne(druginfo.WarehouseInfoId, device_number)
  719. }
  720. }
  721. if druginfo.CountUnit == drug.MaxUnit && druginfo.CountUnit == drug.MinUnit && drug.MaxUnit == drug.MinUnit {
  722. service.ModefyDrugByWarehouseInfo(druginfo.WarehouseInfoId, device_number)
  723. }
  724. //删除记录
  725. service.DeleteDrugAutoWarehouseSeven(drug_id, patient_id, recordDateTime, adviceId)
  726. }
  727. }
  728. }
  729. }
  730. }
  731. }
  732. }
  733. }
  734. }
  735. if stockConfig.IsOpen == 1 {
  736. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  737. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  738. if len(prescriptions) > 0 {
  739. for _, item := range prescriptions {
  740. items := item.(map[string]interface{})
  741. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  742. projects := items["project"].([]interface{})
  743. if len(projects) > 0 {
  744. for _, project := range projects {
  745. var project_id int64
  746. var project_type int64
  747. var totals float64
  748. var project_name string
  749. var parsetotal int64
  750. var id int64
  751. if project.(map[string]interface{})["id"] != nil || reflect.TypeOf(project.(map[string]interface{})["id"]).String() == "float64" {
  752. id = int64(project.(map[string]interface{})["id"].(float64))
  753. }
  754. if project.(map[string]interface{})["project_id"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_id"]).String() == "float64" {
  755. project_id = int64(project.(map[string]interface{})["project_id"].(float64))
  756. }
  757. if project.(map[string]interface{})["type"] != nil || reflect.TypeOf(project.(map[string]interface{})["type"]).String() == "float64" {
  758. project_type = int64(project.(map[string]interface{})["type"].(float64))
  759. }
  760. if project.(map[string]interface{})["total"] != nil || reflect.TypeOf(project.(map[string]interface{})["total"]).String() == "string" {
  761. total, _ := project.(map[string]interface{})["total"].(string)
  762. totals, _ = strconv.ParseFloat(total, 64)
  763. parsetotal, _ = strconv.ParseInt(total, 10, 64)
  764. }
  765. if project.(map[string]interface{})["project_name"] != nil || reflect.TypeOf(project.(map[string]interface{})["project_name"]).String() == "string" {
  766. project_name = project.(map[string]interface{})["project_name"].(string)
  767. }
  768. if project_type == 3 {
  769. //查找该耗材的出库记录
  770. goodWarehouseInfo, _ := service.GetAutoRecordByGoodIdSevenEight(project_id, patient_id, recordDateTime)
  771. //var total_count int64
  772. //for _, it := range goodWarehouseInfo {
  773. // total_count += it.Count
  774. //}
  775. if len(goodWarehouseInfo) == 0 {
  776. //查询耗材库存
  777. list, _ := service.GetGoodWarehouseInfoSeven(project_id)
  778. var stock_count int64
  779. for _, it := range list {
  780. stock_count += it.StockCount
  781. }
  782. stock_counts := strconv.FormatInt(stock_count, 10)
  783. stock_total_count, _ := strconv.ParseFloat(stock_counts, 64)
  784. if totals > stock_total_count {
  785. c.ServeDynamicFailJsonSend(project_name + "库存不足")
  786. return
  787. }
  788. //查找今日该患者已经出库的所有耗材
  789. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  790. for _, item := range goodList {
  791. //回退库存
  792. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  793. }
  794. //删除记录
  795. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  796. }
  797. if len(goodWarehouseInfo) > 0 {
  798. //查询该患者耗材的历史数据
  799. ordProject, _ := service.GetHisProjectPrescriptionByPatientIdOne(id)
  800. count, _ := strconv.ParseInt(ordProject.Count, 10, 64)
  801. //数量发生改变
  802. if parsetotal != count {
  803. //查找今日该患者已经出库的所有耗材
  804. goodList, _ := service.GetAllAutoRecordByPatient(patient_id, recordDateTime)
  805. for _, item := range goodList {
  806. //回退库存
  807. service.ModefyWarehouseInfo(item.Count, item.WarehouseInfotId)
  808. }
  809. //删除记录
  810. service.DeleteAutoWarehouse(patient_id, recordDateTime)
  811. }
  812. }
  813. }
  814. }
  815. }
  816. }
  817. }
  818. }
  819. }
  820. }
  821. info, _ := service.FindHisPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  822. var hpInfo models.HisPrescriptionInfo
  823. if info.ID == 0 {
  824. var randNum int
  825. randNum = rand.Intn(10000) + 1000
  826. timestamp := time.Now().Unix()
  827. tempTime := time.Unix(timestamp, 0)
  828. timeFormat := tempTime.Format("20060102150405")
  829. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  830. hpInfo = models.HisPrescriptionInfo{
  831. HisPatientId: his_patient_id,
  832. UserOrgId: adminInfo.CurrentOrgId,
  833. RecordDate: theTime.Unix(),
  834. PatientId: patient_id,
  835. Status: 1,
  836. Ctime: time.Now().Unix(),
  837. Mtime: time.Now().Unix(),
  838. Creator: adminInfo.AdminUser.Id,
  839. Modifier: adminInfo.AdminUser.Id,
  840. Diagnosis: diagnose,
  841. SickHistory: sick_history,
  842. Departments: department,
  843. RegisterType: reg_type,
  844. PrescriptionNumber: p_number,
  845. PrescriptionStatus: 1,
  846. Doctor: role.UserName,
  847. DoctorId: doctor_id,
  848. SickType: sick_type,
  849. PType: p_type,
  850. }
  851. service.SavePatientPrescriptionInfo(hpInfo)
  852. redis := service.RedisClient()
  853. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  854. redis.Set(key, "", time.Second)
  855. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  856. redis.Set(keyOne, "", time.Second)
  857. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  858. redis.Set(keySeven, "", time.Second)
  859. defer redis.Close()
  860. } else {
  861. hpInfo = models.HisPrescriptionInfo{
  862. ID: info.ID,
  863. UserOrgId: adminInfo.CurrentOrgId,
  864. RecordDate: info.RecordDate,
  865. PatientId: info.PatientId,
  866. Status: 1,
  867. Ctime: info.Ctime,
  868. Mtime: time.Now().Unix(),
  869. Creator: info.Creator,
  870. Modifier: adminInfo.AdminUser.Id,
  871. Diagnosis: diagnose,
  872. SickHistory: sick_history,
  873. Departments: department,
  874. RegisterType: reg_type,
  875. PrescriptionNumber: info.PrescriptionNumber,
  876. Doctor: role.UserName,
  877. PrescriptionStatus: info.PrescriptionStatus,
  878. DoctorId: doctor_id,
  879. SickType: sick_type,
  880. PType: info.PType,
  881. HisPatientId: info.HisPatientId,
  882. }
  883. service.SavePatientPrescriptionInfo(hpInfo)
  884. redis := service.RedisClient()
  885. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  886. redis.Set(key, "", time.Second)
  887. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  888. redis.Set(keyOne, "", time.Second)
  889. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  890. redis.Set(keySeven, "", time.Second)
  891. defer redis.Close()
  892. }
  893. //定义切片
  894. var adviceList []models.HisDoctorAdviceInfo
  895. var projectList []models.HisPrescriptionProject
  896. //var hisLis []models.HisList
  897. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  898. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  899. var tempPrescription *models.HisPrescription
  900. if len(prescriptions) > 0 {
  901. for _, item := range prescriptions {
  902. items := item.(map[string]interface{})
  903. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  904. utils.ErrorLog("id")
  905. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  906. return
  907. }
  908. id := int64(items["id"].(float64))
  909. new_prescription, _ := service.GetPrescriptionById(id, adminInfo.CurrentOrgId)
  910. tempPrescription = &new_prescription
  911. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  912. utils.ErrorLog("type")
  913. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  914. return
  915. }
  916. types := int64(items["type"].(float64))
  917. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  918. utils.ErrorLog("med_type")
  919. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  920. return
  921. }
  922. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  923. if med_type == "0" {
  924. med_type = "14"
  925. }
  926. //if order_status == 0 {
  927. // order_status = 1
  928. //}
  929. if items["pre_time"] == nil || reflect.TypeOf(items["pre_time"]).String() != "string" {
  930. utils.ErrorLog("pre_time")
  931. }
  932. preTime, _ := items["pre_time"].(string)
  933. timeLayout := "2006-01-02"
  934. loc, _ := time.LoadLocation("Local")
  935. theTime2, err := time.ParseInLocation(timeLayout+" 15:04", preTime, loc)
  936. if err != nil {
  937. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  938. return
  939. }
  940. pTime := theTime2.Unix()
  941. ctime := time.Now().Unix()
  942. if tempPrescription.ID == 0 {
  943. prescription := &models.HisPrescription{
  944. ID: 0,
  945. PatientId: patient_id,
  946. UserOrgId: adminInfo.CurrentOrgId,
  947. RecordDate: recordDateTime,
  948. Ctime: ctime,
  949. Mtime: ctime,
  950. Type: types,
  951. Modifier: adminInfo.AdminUser.Id,
  952. Creator: adminInfo.AdminUser.Id,
  953. Status: 1,
  954. Doctor: role.UserName,
  955. HisPatientId: his_patient_id,
  956. OrderStatus: 1,
  957. BatchNumber: "",
  958. PrescriptionNumber: hpInfo.PrescriptionNumber,
  959. PreTime: pTime,
  960. PType: p_type,
  961. MedType: med_type,
  962. }
  963. tempPrescription = prescription
  964. service.SaveHisPrescription(tempPrescription)
  965. redis := service.RedisClient()
  966. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  967. redis.Set(key, "", time.Second)
  968. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  969. redis.Set(keyOne, "", time.Second)
  970. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  971. redis.Set(keySeven, "", time.Second)
  972. defer redis.Close()
  973. } else {
  974. tempPrescription.ID = id
  975. tempPrescription.Type = types
  976. tempPrescription.Modifier = adminInfo.AdminUser.Id
  977. tempPrescription.Mtime = time.Now().Unix()
  978. tempPrescription.Doctor = role.UserName
  979. //tempPrescription.OrderStatus = order_status
  980. tempPrescription.PreTime = pTime
  981. tempPrescription.MedType = med_type
  982. service.SaveHisPrescription(tempPrescription)
  983. redis := service.RedisClient()
  984. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  985. redis.Set(key, "", time.Second)
  986. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  987. redis.Set(keyOne, "", time.Second)
  988. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  989. redis.Set(keySeven, "", time.Second)
  990. defer redis.Close()
  991. }
  992. //service.SaveHisPrescription(prescription)
  993. //更改患者挂号状态
  994. _, err2 := service.UpdateHisPatientIsReturn(patient_id, recordDateTime, adminInfo.CurrentOrgId)
  995. fmt.Println("更改失败", err2)
  996. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  997. advices := items["advices"].([]interface{})
  998. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  999. groupNo := int64(0)
  1000. ctime := time.Now().Unix()
  1001. mtime := ctime
  1002. if len(advices) > 0 {
  1003. for _, advice := range advices {
  1004. var s models.HisDoctorAdviceInfo
  1005. s.PrescriptionId = tempPrescription.ID
  1006. s.AdviceType = 2
  1007. s.AdviceDoctor = doctor_id
  1008. s.StopState = 2
  1009. s.ExecutionState = 2
  1010. s.AdviceDate = recordDateTime
  1011. s.Status = 1
  1012. s.UserOrgId = adminInfo.CurrentOrgId
  1013. s.RecordDate = recordDateTime
  1014. s.StartTime = tempPrescription.PreTime
  1015. s.Groupno = groupNo
  1016. s.CreatedTime = ctime
  1017. s.UpdatedTime = mtime
  1018. s.PatientId = patient_id
  1019. s.HisPatientId = his_patient_id
  1020. s.StartTime = pTime
  1021. errcode := c.setAdviceWithJSON(&s, advice.(map[string]interface{}))
  1022. if errcode > 0 {
  1023. c.ServeFailJSONWithSGJErrorCode(errcode)
  1024. return
  1025. }
  1026. s.StartTime = pTime
  1027. service.CreateHisDoctorAdvice(&s)
  1028. //存储切片中
  1029. adviceList = append(adviceList, s)
  1030. redis := service.RedisClient()
  1031. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1032. redis.Set(key, "", time.Second)
  1033. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1034. redis.Set(keyOne, "", time.Second)
  1035. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1036. redis.Set(keySeven, "", time.Second)
  1037. var randNum int
  1038. randNum = rand.Intn(10000) + 1000
  1039. timestamp := time.Now().Unix()
  1040. tempTime := time.Unix(timestamp, 0)
  1041. timeFormat := tempTime.Format("20060102150405")
  1042. s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "1" + "-" + strconv.FormatInt(s.ID, 10)
  1043. service.CreateHisDoctorAdvice(&s)
  1044. keySix := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1045. redis.Set(keySix, "", time.Second)
  1046. keyFive := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1047. redis.Set(keyFive, "", time.Second)
  1048. keyEight := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1049. redis.Set(keyEight, "", time.Second)
  1050. defer redis.Close()
  1051. }
  1052. }
  1053. }
  1054. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1055. projects := items["project"].([]interface{})
  1056. if len(projects) > 0 {
  1057. for _, project := range projects {
  1058. var p models.HisPrescriptionProject
  1059. p.PrescriptionId = tempPrescription.ID
  1060. p.Ctime = time.Now().Unix()
  1061. p.Mtime = time.Now().Unix()
  1062. p.PatientId = patient_id
  1063. p.RecordDate = recordDateTime
  1064. p.Doctor = doctor_id
  1065. p.UserOrgId = adminInfo.CurrentOrgId
  1066. p.HisPatientId = his_patient_id
  1067. p.Status = 1
  1068. p.StartTime = pTime
  1069. errcode := c.setProjectWithJSON(&p, project.(map[string]interface{}))
  1070. if errcode > 0 {
  1071. c.ServeFailJSONWithSGJErrorCode(errcode)
  1072. return
  1073. }
  1074. service.CreateHisProjectTwo(&p)
  1075. projectList = append(projectList, p)
  1076. var randNum int
  1077. randNum = rand.Intn(10000) + 1000
  1078. timestamp := time.Now().Unix()
  1079. tempTime := time.Unix(timestamp, 0)
  1080. timeFormat := tempTime.Format("20060102150405")
  1081. p.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "2" + "-" + strconv.FormatInt(p.ID, 10)
  1082. if p.Type == 2 { //因为项目和耗材的基础库存在id相同的情况,所以需要根据该字段来判断,type为2的话为从项目开出来的
  1083. //新增或者编辑项目,修改对应的标签数据
  1084. labelOrigin, _ := service.GetProjectById(p.UserOrgId, p.ID, patient_id, recordDateTime)
  1085. if labelOrigin.ID == 0 { //当天某个人的处方中的项目不存在
  1086. var label models.HisLabelPrintInfo
  1087. project, _ := service.GetProjectDetail(p.ProjectId)
  1088. if project.CostClassify == 3 { //类别为检验检查
  1089. if p.TeamId > 0 { //检验检查组套
  1090. tempLabel, _ := service.GetProjectByTeamId(p.UserOrgId, p.TeamId, patient_id, recordDateTime)
  1091. if tempLabel.ID == 0 {
  1092. team, _ := service.GetProjectTeamDetail(p.TeamId)
  1093. label.Number = tempPrescription.PrescriptionNumber
  1094. label.ProjectId = project.ID
  1095. label.Status = 1
  1096. label.IsPrint = 2
  1097. label.DoctorId = info.DoctorId
  1098. label.UserOrgId = p.UserOrgId
  1099. label.PatientId = patient_id
  1100. label.RecordDate = recordDateTime
  1101. label.Ctime = time.Now().Unix()
  1102. label.Mtime = time.Now().Unix()
  1103. label.ItemId = p.TeamId
  1104. label.FeedetlSn = p.FeedetlSn
  1105. label.PProjectId = p.ID
  1106. label.ProjectName = team.ProjectTeam
  1107. label.PatientName = patient.Name
  1108. service.CreateHisLabelRecord(&label)
  1109. }
  1110. } else { //单条检验检查项目
  1111. label.Number = tempPrescription.PrescriptionNumber
  1112. label.ProjectId = project.ID
  1113. label.Status = 1
  1114. label.DoctorId = info.DoctorId
  1115. label.UserOrgId = p.UserOrgId
  1116. label.PatientId = patient_id
  1117. label.RecordDate = recordDateTime
  1118. label.IsPrint = 2
  1119. label.Ctime = time.Now().Unix()
  1120. label.Mtime = time.Now().Unix()
  1121. label.FeedetlSn = p.FeedetlSn
  1122. label.PProjectId = p.ID
  1123. label.ItemId = p.TeamId
  1124. label.ProjectName = project.ProjectName
  1125. label.PatientName = patient.Name
  1126. service.CreateHisLabelRecord(&label)
  1127. }
  1128. }
  1129. }
  1130. }
  1131. service.SaveHisProjectTwo(&p)
  1132. //if p.Type == 3 { //处理透前准备耗材数量数据
  1133. // consumables, _ := service.FindHisConsumablesByID(adminInfo.CurrentOrgId, patient_id, recordDateTime, p.ProjectId)
  1134. // if consumables.ID > 0 {
  1135. // cnt, _ := strconv.ParseInt(p.Count, 10, 64)
  1136. // consumables.Count = cnt
  1137. // service.UpdateConsumables(&consumables)
  1138. // }
  1139. //}
  1140. }
  1141. }
  1142. }
  1143. //if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1144. // addition := items["addition"].([]interface{})
  1145. // //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1146. // ctime := time.Now().Unix()
  1147. // mtime := ctime
  1148. // if len(addition) > 0 {
  1149. // for _, item := range addition {
  1150. // var s models.HisAdditionalCharge
  1151. // s.PrescriptionId = tempPrescription.ID
  1152. // s.Status = 1
  1153. // s.UserOrgId = adminInfo.CurrentOrgId
  1154. // s.RecordDate = recordDateTime
  1155. // s.CreatedTime = ctime
  1156. // s.UpdatedTime = mtime
  1157. // s.PatientId = patient_id
  1158. // s.HisPatientId = his_patient_id
  1159. // errcode := c.setAddtionWithJSON(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1160. // if errcode > 0 {
  1161. // c.ServeFailJSONWithSGJErrorCode(errcode)
  1162. // return
  1163. // }
  1164. // service.CreateAdditionalCharge(&s)
  1165. // var randNum int
  1166. // randNum = rand.Intn(10000) + 1000
  1167. // timestamp := time.Now().Unix()
  1168. // tempTime := time.Unix(timestamp, 0)
  1169. // timeFormat := tempTime.Format("20060102150405")
  1170. // s.FeedetlSn = timeFormat + strconv.FormatInt(int64(randNum), 10) + "-" + "3" + "-" + strconv.FormatInt(s.ID, 10)
  1171. // service.CreateAdditionalCharge(&s)
  1172. //
  1173. // }
  1174. // }
  1175. //}
  1176. }
  1177. }
  1178. }
  1179. //redisClient := service.RedisClient()
  1180. //defer redisClient.Close()
  1181. //
  1182. //list := models.HisList{
  1183. // Patient_id: patient_id,
  1184. // Advice_id:0,
  1185. // Record_date: 0,
  1186. // Advice: adviceList,
  1187. // Project: nil,
  1188. //}
  1189. //hisLis = append(hisLis, list)
  1190. //
  1191. //advice_json, _ := json.Marshal(&hisLis)
  1192. //redisClient.RPush("111", advice_json).Result()
  1193. //result, _ := redisClient.RPop("111").Result()
  1194. //fmt.Println("resuilt2332323323232323232323232322323233232",redisClient.LLen("111"))
  1195. //
  1196. //var dat []map[string]interface{}
  1197. //json.Unmarshal([]byte(result), &dat)
  1198. //fmt.Println("hhhh2332323232233223322332322323232323",dat)
  1199. //
  1200. //for k,v:=range dat{
  1201. // fmt.Println("第",k,"个数的值是:",v,v["Advice"],v["Patient_id"])
  1202. //}
  1203. //project_json, _ := json.Marshal(&projectList)
  1204. //redisClient.LPush("222", project_json).Result()
  1205. if err == nil {
  1206. c.ServeSuccessJSON(map[string]interface{}{
  1207. "msg": "保存成功",
  1208. })
  1209. return
  1210. } else {
  1211. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1212. return
  1213. }
  1214. }
  1215. func (c *HisApiController) EditHisPrescription() {
  1216. record_date := c.GetString("record_date")
  1217. patient_id, _ := c.GetInt64("patient_id")
  1218. reg_type, _ := c.GetInt64("reg_type")
  1219. //diagnose, _ := c.GetInt64("diagnose", 0)
  1220. diagnose := c.GetString("diagnose")
  1221. sick_type, _ := c.GetInt64("sick_type")
  1222. sick_history := c.GetString("sick_history")
  1223. doctor_id, _ := c.GetInt64("doctor", 0)
  1224. department, _ := c.GetInt64("department", 0)
  1225. his_patient_id, _ := c.GetInt64("his_patient_id")
  1226. p_type, _ := c.GetInt64("p_type")
  1227. dataBody := make(map[string]interface{}, 0)
  1228. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  1229. if err != nil {
  1230. utils.ErrorLog(err.Error())
  1231. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1232. return
  1233. }
  1234. timeLayout := "2006-01-02"
  1235. loc, _ := time.LoadLocation("Local")
  1236. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  1237. if err != nil {
  1238. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1239. return
  1240. }
  1241. adminInfo := c.GetAdminUserInfo()
  1242. recordDateTime := theTime.Unix()
  1243. role, _ := service.GetAdminUserInfoByID(adminInfo.CurrentOrgId, doctor_id)
  1244. info, _ := service.FindPatientPrescriptionInfo(adminInfo.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  1245. var hpInfo models.HisPrescriptionInfo
  1246. if info.ID == 0 {
  1247. var randNum int
  1248. randNum = rand.Intn(10000) + 1000
  1249. timestamp := time.Now().Unix()
  1250. tempTime := time.Unix(timestamp, 0)
  1251. timeFormat := tempTime.Format("20060102150405")
  1252. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  1253. hpInfo = models.HisPrescriptionInfo{
  1254. UserOrgId: adminInfo.CurrentOrgId,
  1255. RecordDate: theTime.Unix(),
  1256. PatientId: patient_id,
  1257. Status: 1,
  1258. Ctime: time.Now().Unix(),
  1259. Mtime: time.Now().Unix(),
  1260. Creator: adminInfo.AdminUser.Id,
  1261. Modifier: adminInfo.AdminUser.Id,
  1262. Diagnosis: diagnose,
  1263. SickHistory: sick_history,
  1264. Departments: department,
  1265. RegisterType: reg_type,
  1266. PrescriptionNumber: p_number,
  1267. PrescriptionStatus: 1,
  1268. Doctor: role.UserName,
  1269. DoctorId: doctor_id,
  1270. SickType: sick_type,
  1271. PType: p_type,
  1272. }
  1273. service.SavePatientPrescriptionInfo(hpInfo)
  1274. } else {
  1275. hpInfo = models.HisPrescriptionInfo{
  1276. ID: info.ID,
  1277. UserOrgId: adminInfo.CurrentOrgId,
  1278. RecordDate: info.RecordDate,
  1279. PatientId: info.PatientId,
  1280. Status: 1,
  1281. Ctime: info.Ctime,
  1282. Mtime: time.Now().Unix(),
  1283. Creator: info.Creator,
  1284. Modifier: adminInfo.AdminUser.Id,
  1285. Diagnosis: diagnose,
  1286. SickHistory: sick_history,
  1287. Departments: department,
  1288. RegisterType: reg_type,
  1289. PrescriptionNumber: info.PrescriptionNumber,
  1290. Doctor: role.UserName,
  1291. PrescriptionStatus: info.PrescriptionStatus,
  1292. DoctorId: doctor_id,
  1293. SickType: sick_type,
  1294. PType: info.PType,
  1295. }
  1296. service.SavePatientPrescriptionInfo(hpInfo)
  1297. }
  1298. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  1299. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  1300. if len(prescriptions) > 0 {
  1301. for _, item := range prescriptions {
  1302. items := item.(map[string]interface{})
  1303. if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  1304. utils.ErrorLog("id")
  1305. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1306. return
  1307. }
  1308. id := int64(items["id"].(float64))
  1309. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  1310. utils.ErrorLog("type")
  1311. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1312. return
  1313. }
  1314. types := int64(items["type"].(float64))
  1315. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  1316. utils.ErrorLog("med_type")
  1317. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  1318. return
  1319. }
  1320. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  1321. historyPrescription, _ := service.GetHisPrescriptionByID(adminInfo.CurrentOrgId, id)
  1322. ctime := time.Now().Unix()
  1323. prescription := &models.HisPrescription{
  1324. ID: id,
  1325. PatientId: patient_id,
  1326. UserOrgId: adminInfo.CurrentOrgId,
  1327. RecordDate: recordDateTime,
  1328. Ctime: ctime,
  1329. Mtime: ctime,
  1330. Type: types,
  1331. Modifier: adminInfo.AdminUser.Id,
  1332. Creator: adminInfo.AdminUser.Id,
  1333. Status: 1,
  1334. Doctor: role.UserName,
  1335. HisPatientId: his_patient_id,
  1336. OrderStatus: 1,
  1337. BatchNumber: "",
  1338. PrescriptionNumber: hpInfo.PrescriptionNumber,
  1339. PType: hpInfo.PType,
  1340. MedType: med_type,
  1341. }
  1342. if historyPrescription.ID > 0 {
  1343. prescription.PreTime = historyPrescription.PreTime
  1344. }
  1345. service.SaveHisPrescription(prescription)
  1346. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  1347. advices := items["advices"].([]interface{})
  1348. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1349. groupNo := int64(0)
  1350. ctime := time.Now().Unix()
  1351. mtime := ctime
  1352. if len(advices) > 0 {
  1353. for _, advice := range advices {
  1354. var s models.HisDoctorAdviceInfo
  1355. s.PrescriptionId = prescription.ID
  1356. s.AdviceType = 2
  1357. s.AdviceDoctor = adminInfo.AdminUser.Id
  1358. s.StopState = 2
  1359. s.ExecutionState = 2
  1360. s.AdviceDate = recordDateTime
  1361. s.Status = 1
  1362. s.UserOrgId = adminInfo.CurrentOrgId
  1363. s.RecordDate = recordDateTime
  1364. s.StartTime = prescription.PreTime
  1365. s.Groupno = groupNo
  1366. s.CreatedTime = ctime
  1367. s.UpdatedTime = mtime
  1368. s.PatientId = patient_id
  1369. s.HisPatientId = his_patient_id
  1370. errcode := c.setAdviceWithJSONTwo(&s, advice.(map[string]interface{}))
  1371. if errcode > 0 {
  1372. c.ServeFailJSONWithSGJErrorCode(errcode)
  1373. return
  1374. }
  1375. service.CreateHisDoctorAdvice(&s)
  1376. redis := service.RedisClient()
  1377. key := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(theTime.Unix(), 10) + ":his_advices_list_all"
  1378. redis.Set(key, "", time.Second)
  1379. keyOne := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + ":" + strconv.FormatInt(patient_id, 10) + ":" + strconv.FormatInt(recordDateTime, 10) + ":his_doctor_advice"
  1380. fmt.Println("keyOne", keyOne)
  1381. redis.Set(keyOne, "", time.Second)
  1382. keySeven := "scheduals_" + record_date + "_" + strconv.FormatInt(adminInfo.CurrentOrgId, 10)
  1383. redis.Set(keySeven, "", time.Second)
  1384. redis.Close()
  1385. }
  1386. }
  1387. }
  1388. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  1389. projects := items["project"].([]interface{})
  1390. if len(projects) > 0 {
  1391. for _, project := range projects {
  1392. var p models.HisPrescriptionProject
  1393. p.PrescriptionId = prescription.ID
  1394. p.Ctime = time.Now().Unix()
  1395. p.Mtime = time.Now().Unix()
  1396. p.PatientId = patient_id
  1397. p.RecordDate = recordDateTime
  1398. p.UserOrgId = adminInfo.CurrentOrgId
  1399. p.HisPatientId = his_patient_id
  1400. p.Status = 1
  1401. errcode := c.setProjectWithJSONTwo(&p, project.(map[string]interface{}))
  1402. if errcode > 0 {
  1403. c.ServeFailJSONWithSGJErrorCode(errcode)
  1404. return
  1405. }
  1406. service.CreateHisProjectTwo(&p)
  1407. }
  1408. }
  1409. }
  1410. if items["addition"] != nil && reflect.TypeOf(items["addition"]).String() == "[]interface {}" {
  1411. addition := items["addition"].([]interface{})
  1412. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  1413. ctime := time.Now().Unix()
  1414. mtime := ctime
  1415. if len(addition) > 0 {
  1416. for _, item := range addition {
  1417. var s models.HisAdditionalCharge
  1418. s.PrescriptionId = prescription.ID
  1419. s.Status = 1
  1420. s.UserOrgId = adminInfo.CurrentOrgId
  1421. s.RecordDate = recordDateTime
  1422. s.CreatedTime = ctime
  1423. s.UpdatedTime = mtime
  1424. s.PatientId = patient_id
  1425. s.HisPatientId = his_patient_id
  1426. errcode := c.setAddtionWithJSONTwo(&s, item.(map[string]interface{}), adminInfo.CurrentOrgId)
  1427. if errcode > 0 {
  1428. c.ServeFailJSONWithSGJErrorCode(errcode)
  1429. return
  1430. }
  1431. service.CreateAdditionalCharge(&s)
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. if err == nil {
  1439. c.ServeSuccessJSON(map[string]interface{}{
  1440. "msg": "保存成功",
  1441. })
  1442. return
  1443. } else {
  1444. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  1445. return
  1446. }
  1447. }
  1448. func (c *HisApiController) DeletePrescription() {
  1449. prescription_id, _ := c.GetInt64("id")
  1450. projects, _ := service.GetHisPrescriptionProjectsByID(prescription_id)
  1451. advices, _ := service.GetHisPrescriptionAdviceByID(prescription_id)
  1452. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1453. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1454. if len(projects) > 0 {
  1455. for _, item := range projects {
  1456. service.DeletePrintInfo(item.ID) //删除打印信息
  1457. if stockConfig.IsOpen == 1 {
  1458. if item.Type == 3 {
  1459. good, _ := service.FindGoodInfoByIdTwo(item.ProjectId)
  1460. f_count, _ := strconv.ParseFloat(item.Count, 64)
  1461. good.Total = good.Total + f_count
  1462. service.UpdateGoodInfo(&good)
  1463. operation_time := time.Now().Unix()
  1464. creater := c.GetAdminUserInfo().AdminUser.Id
  1465. //创建退库单
  1466. timeStr := time.Now().Format("2006-01-02")
  1467. timeArr := strings.Split(timeStr, "-")
  1468. total, _ := service.FindAllCancelStockTotal(c.GetAdminUserInfo().CurrentOrgId)
  1469. total = total + 1
  1470. orderNumber := "CKTKD" + strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1471. cancelStock := models.CancelStock{
  1472. OrderNumber: orderNumber,
  1473. OperaTime: operation_time,
  1474. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1475. Creater: creater,
  1476. Ctime: time.Now().Unix(),
  1477. Status: 1,
  1478. ReturnTime: item.RecordDate,
  1479. Type: 1,
  1480. }
  1481. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(item.RecordDate, c.GetAdminUserInfo().CurrentOrgId)
  1482. if msgerrkonde == gorm.ErrRecordNotFound {
  1483. service.AddSigleCancelStock(&cancelStock)
  1484. }
  1485. cancel, _ := service.GetLastCancelStockById(c.GetAdminUserInfo().CurrentOrgId)
  1486. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  1487. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1488. //查询该耗材是否出库
  1489. info, _ := service.GetLastWarehoseByGoodId(item.ProjectId, item.PatientId, item.RecordDate)
  1490. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  1491. deaerler, _ := service.GetDealerById(info.Dealer)
  1492. if info.ID > 0 {
  1493. cancelStockInfo := models.CancelStockInfo{
  1494. GoodId: item.ProjectId,
  1495. CancelStockId: cancel.ID,
  1496. GoodTypeId: good.GoodTypeId,
  1497. Count: prescribingNumber,
  1498. Price: info.Price,
  1499. Total: 0,
  1500. ProductDate: info.ProductDate,
  1501. ExpiryDate: info.ExpiryDate,
  1502. Ctime: time.Now().Unix(),
  1503. Status: 1,
  1504. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1505. OrderNumber: cancel.OrderNumber,
  1506. Type: 0,
  1507. Dealer: deaerler.DealerName,
  1508. Manufacturer: manufacturer.ManufacturerName,
  1509. Number: info.Number,
  1510. RegisterAccount: "",
  1511. Remark: "",
  1512. WarehouseInfoId: info.WarehouseInfotId,
  1513. PatientId: info.PatientId,
  1514. RecordDate: info.SysRecordTime,
  1515. }
  1516. service.CreateCancelStockInfoOne(&cancelStockInfo)
  1517. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(item.ProjectId)
  1518. flow := models.VmStockFlow{
  1519. WarehousingId: 0,
  1520. GoodId: item.ProjectId,
  1521. Number: info.Number,
  1522. LicenseNumber: info.LicenseNumber,
  1523. Count: prescribingNumber,
  1524. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1525. PatientId: item.PatientId,
  1526. SystemTime: info.SysRecordTime,
  1527. ConsumableType: 7,
  1528. IsSys: 0,
  1529. WarehousingOrder: "",
  1530. WarehouseOutId: 0,
  1531. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1532. IsEdit: 0,
  1533. CancelStockId: cancel.ID,
  1534. CancelOrderNumber: cancel.OrderNumber,
  1535. Manufacturer: manufacturer.ID,
  1536. Dealer: 0,
  1537. Creator: c.GetAdminUserInfo().CurrentOrgId,
  1538. UpdateCreator: 0,
  1539. Status: 1,
  1540. Ctime: time.Now().Unix(),
  1541. Mtime: 0,
  1542. Price: info.Price,
  1543. WarehousingDetailId: info.WarehouseInfotId,
  1544. WarehouseOutDetailId: 0,
  1545. CancelOutDetailId: cancelInfo.ID,
  1546. ProductDate: info.ProductDate,
  1547. ExpireDate: info.ExpiryDate,
  1548. }
  1549. service.CreateStockFlowOne(flow)
  1550. //删除出库表
  1551. service.DeleteAutoRedeceDetailTen(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, item.ProjectId)
  1552. //查询今日该患者开了多少耗材
  1553. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1554. var total_count int64
  1555. var cha_count int64
  1556. for _, item := range projectList {
  1557. count, _ := strconv.ParseInt(item.Count, 10, 64)
  1558. total_count += count
  1559. }
  1560. //回退库存
  1561. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  1562. //查询今日该耗材退库数量
  1563. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, item.ProjectId, info.SysRecordTime)
  1564. var cancel_Count int64
  1565. for _, items := range cancelInfoOne {
  1566. cancel_Count += items.Count
  1567. }
  1568. cha_count = total_count - cancel_Count
  1569. if total_count > cancel_Count {
  1570. out, err := service.FindStockOutByIsSys(c.GetAdminUserInfo().CurrentOrgId, 1, info.SysRecordTime)
  1571. if err == gorm.ErrRecordNotFound {
  1572. //没有记录,则创建出库单
  1573. timeStr := time.Now().Format("2006-01-02")
  1574. timeArr := strings.Split(timeStr, "-")
  1575. total, _ := service.FindAllWarehouseOut(c.GetAdminUserInfo().CurrentOrgId)
  1576. total = total + 1
  1577. warehousing_out_order := strconv.FormatInt(c.GetAdminUserInfo().CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  1578. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  1579. number = number + total
  1580. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  1581. warehouseOut := models.WarehouseOut{
  1582. WarehouseOutOrderNumber: warehousing_out_order,
  1583. OperationTime: time.Now().Unix(),
  1584. OrgId: c.GetAdminUserInfo().CurrentOrgId,
  1585. Creater: creater,
  1586. Ctime: time.Now().Unix(),
  1587. Status: 1,
  1588. WarehouseOutTime: info.SysRecordTime,
  1589. Dealer: 0,
  1590. Manufacturer: 0,
  1591. Type: 1,
  1592. IsSys: 1,
  1593. }
  1594. err := service.AddSigleWarehouseOut(&warehouseOut)
  1595. if err != nil {
  1596. utils.TraceLog("创建出库单失败 err = %v", err)
  1597. return
  1598. }
  1599. prepare := &models.DialysisBeforePrepare{
  1600. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1601. PatientId: info.PatientId,
  1602. RecordDate: info.SysRecordTime,
  1603. GoodId: item.ProjectId,
  1604. GoodTypeId: info.GoodTypeId,
  1605. Count: cha_count,
  1606. }
  1607. //出库
  1608. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  1609. } else if err == nil {
  1610. prepare := &models.DialysisBeforePrepare{
  1611. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  1612. PatientId: info.PatientId,
  1613. RecordDate: info.SysRecordTime,
  1614. GoodId: item.ProjectId,
  1615. GoodTypeId: info.GoodTypeId,
  1616. Count: cha_count,
  1617. }
  1618. //出库
  1619. service.ConsumablesDelivery(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  1620. }
  1621. }
  1622. }
  1623. }
  1624. }
  1625. }
  1626. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1627. fmt.Println(err)
  1628. }
  1629. if drugStockConfig.IsOpen == 1 {
  1630. err := service.DelelteHisPrescription(prescription_id, c.GetAdminUserInfo().CurrentOrgId)
  1631. fmt.Println(err)
  1632. if len(advices) > 0 {
  1633. for _, item := range advices {
  1634. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, item.DrugId)
  1635. redis := service.RedisClient()
  1636. keyFive := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_advices_list_all"
  1637. redis.Set(keyFive, "", time.Second)
  1638. keyOne := strconv.FormatInt(item.UserOrgId, 10) + ":" + strconv.FormatInt(item.PatientId, 10) + ":" + strconv.FormatInt(item.AdviceDate, 10) + ":his_doctor_advice"
  1639. redis.Set(keyOne, "", time.Second)
  1640. redis.Close()
  1641. //查询该药品是否存在出库记录
  1642. info, errcode := service.GetDrugAutoWarehouseOutSeven(item.PatientId, item.AdviceDate, item.DrugId, item.ID)
  1643. if errcode == gorm.ErrRecordNotFound {
  1644. } else if errcode == nil {
  1645. if item.PrescribingNumberUnit == drug.MinUnit {
  1646. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1647. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1648. //退库
  1649. warehouseInfo := models.DrugWarehouseInfo{
  1650. StockMinNumber: prescribingNumber,
  1651. }
  1652. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1653. adminUserInfo := c.GetAdminUserInfo()
  1654. operation_time := time.Now().Unix()
  1655. creater := adminUserInfo.AdminUser.Id
  1656. ctime := time.Now().Unix()
  1657. timeStr := time.Now().Format("2006-01-02")
  1658. timeArr := strings.Split(timeStr, "-")
  1659. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1660. total = total + 1
  1661. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1662. cancelStock := models.DrugCancelStock{
  1663. OrderNumber: orderNumber,
  1664. OperaTime: operation_time,
  1665. OrgId: adminUserInfo.CurrentOrgId,
  1666. Creater: creater,
  1667. Ctime: ctime,
  1668. Status: 1,
  1669. ReturnTime: item.AdviceDate,
  1670. Dealer: info.Dealer,
  1671. Manufacturer: info.Manufacturer,
  1672. Type: 1,
  1673. }
  1674. service.AddSigleDrugCancelStock(&cancelStock)
  1675. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1676. dealer, _ := service.GetDealerById(info.Dealer)
  1677. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1678. cancelStockInfo := models.DrugCancelStockInfo{
  1679. OrderNumber: cancelInfo.OrderNumber,
  1680. CancelStockId: cancelInfo.ID,
  1681. DrugId: info.DrugId,
  1682. Count: prescribingNumber,
  1683. Status: 1,
  1684. Ctime: ctime,
  1685. OrgId: adminUserInfo.CurrentOrgId,
  1686. Type: 1,
  1687. Manufacturer: manufactureName.ManufacturerName,
  1688. Dealer: dealer.DealerName,
  1689. Total: 0,
  1690. RetailPrice: info.RetailPrice,
  1691. RetailTotalPrice: info.RetailTotalPrice,
  1692. Price: info.Price,
  1693. RegisterAccount: "",
  1694. Remark: info.Remark,
  1695. BatchNumber: info.BatchNumber,
  1696. MaxUnit: info.CountUnit,
  1697. ProductDate: info.ProductDate,
  1698. ExpiryDate: info.ExpiryDate,
  1699. BatchNumberId: info.WarehouseInfoId,
  1700. }
  1701. flow := models.DrugFlow{
  1702. WarehousingId: 0,
  1703. DrugId: info.DrugId,
  1704. Number: "",
  1705. BatchNumber: info.BatchNumber,
  1706. Count: prescribingNumber,
  1707. UserOrgId: adminUserInfo.CurrentOrgId,
  1708. PatientId: 0,
  1709. SystemTime: info.SysRecordTime,
  1710. ConsumableType: 7,
  1711. IsSys: 0,
  1712. WarehousingOrder: "",
  1713. WarehouseOutId: 0,
  1714. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1715. IsEdit: 0,
  1716. CancelStockId: cancelStock.ID,
  1717. CancelOrderNumber: cancelStock.OrderNumber,
  1718. Manufacturer: info.Manufacturer,
  1719. Dealer: info.Dealer,
  1720. Creator: adminUserInfo.AdminUser.Id,
  1721. UpdateCreator: 0,
  1722. Status: 1,
  1723. Ctime: time.Now().Unix(),
  1724. Mtime: 0,
  1725. Price: info.Price,
  1726. WarehousingDetailId: 0,
  1727. WarehouseOutDetailId: 0,
  1728. CancelOutDetailId: 0,
  1729. ExpireDate: info.ExpiryDate,
  1730. ProductDate: info.ProductDate,
  1731. MaxUnit: info.CountUnit,
  1732. MinUnit: "",
  1733. AdviceId: info.AdviceId,
  1734. }
  1735. service.CreatedCancelStock(cancelStockInfo)
  1736. service.CreateDrugFlowOne(flow)
  1737. //删除出库记录
  1738. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1739. //删除流水
  1740. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1741. } else {
  1742. floatPrescrip := strconv.FormatFloat(item.PrescribingNumber, 'f', -1, 32)
  1743. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1744. if item.PrescribingNumberUnit == drug.MaxUnit {
  1745. warehouseInfo := models.DrugWarehouseInfo{
  1746. StockMaxNumber: prescribingNumber,
  1747. }
  1748. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1749. }
  1750. adminUserInfo := c.GetAdminUserInfo()
  1751. operation_time := time.Now().Unix()
  1752. creater := adminUserInfo.AdminUser.Id
  1753. ctime := time.Now().Unix()
  1754. timeStr := time.Now().Format("2006-01-02")
  1755. timeArr := strings.Split(timeStr, "-")
  1756. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1757. total = total + 1
  1758. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1759. cancelStock := models.DrugCancelStock{
  1760. OrderNumber: orderNumber,
  1761. OperaTime: operation_time,
  1762. OrgId: adminUserInfo.CurrentOrgId,
  1763. Creater: creater,
  1764. Ctime: ctime,
  1765. Status: 1,
  1766. ReturnTime: item.AdviceDate,
  1767. Dealer: info.Dealer,
  1768. Manufacturer: info.Manufacturer,
  1769. Type: 1,
  1770. }
  1771. service.AddSigleDrugCancelStock(&cancelStock)
  1772. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1773. dealer, _ := service.GetDealerById(info.Dealer)
  1774. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1775. cancelStockInfo := models.DrugCancelStockInfo{
  1776. OrderNumber: cancelInfo.OrderNumber,
  1777. CancelStockId: cancelInfo.ID,
  1778. DrugId: info.DrugId,
  1779. // Count: info.Count,
  1780. Count: prescribingNumber,
  1781. Status: 1,
  1782. Ctime: ctime,
  1783. OrgId: adminUserInfo.CurrentOrgId,
  1784. Type: 1,
  1785. Manufacturer: manufactureName.ManufacturerName,
  1786. Dealer: dealer.DealerName,
  1787. Total: 0,
  1788. RetailPrice: info.RetailPrice,
  1789. RetailTotalPrice: info.RetailTotalPrice,
  1790. Price: info.Price,
  1791. RegisterAccount: "",
  1792. Remark: info.Remark,
  1793. BatchNumber: info.BatchNumber,
  1794. MaxUnit: info.CountUnit,
  1795. ProductDate: info.ProductDate,
  1796. ExpiryDate: info.ExpiryDate,
  1797. BatchNumberId: info.WarehouseInfoId,
  1798. }
  1799. flow := models.DrugFlow{
  1800. WarehousingId: 0,
  1801. DrugId: info.DrugId,
  1802. Number: "",
  1803. BatchNumber: info.BatchNumber,
  1804. //Count: info.Count,
  1805. Count: prescribingNumber,
  1806. UserOrgId: adminUserInfo.CurrentOrgId,
  1807. PatientId: 0,
  1808. SystemTime: info.SysRecordTime,
  1809. ConsumableType: 7,
  1810. IsSys: 0,
  1811. WarehousingOrder: "",
  1812. WarehouseOutId: 0,
  1813. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1814. IsEdit: 0,
  1815. CancelStockId: cancelStock.ID,
  1816. CancelOrderNumber: cancelStock.OrderNumber,
  1817. Manufacturer: info.Manufacturer,
  1818. Dealer: info.Dealer,
  1819. Creator: adminUserInfo.AdminUser.Id,
  1820. UpdateCreator: 0,
  1821. Status: 1,
  1822. Ctime: time.Now().Unix(),
  1823. Mtime: 0,
  1824. Price: info.Price,
  1825. WarehousingDetailId: 0,
  1826. WarehouseOutDetailId: 0,
  1827. CancelOutDetailId: 0,
  1828. ExpireDate: info.ExpiryDate,
  1829. ProductDate: info.ProductDate,
  1830. MaxUnit: info.CountUnit,
  1831. MinUnit: "",
  1832. AdviceId: info.AdviceId,
  1833. }
  1834. service.CreatedCancelStock(cancelStockInfo)
  1835. service.CreateDrugFlowOne(flow)
  1836. //删除出库记录
  1837. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, item.ID)
  1838. //删除流水
  1839. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, item.ID)
  1840. }
  1841. }
  1842. if item.PrescribingNumberUnit == drug.MinUnit {
  1843. drug.Total = drug.Total + item.PrescribingNumber
  1844. service.UpdateBaseDrugLib(&drug)
  1845. } else {
  1846. if item.PrescribingNumberUnit == drug.MaxUnit {
  1847. item.PrescribingNumber = item.PrescribingNumber * float64(drug.MinNumber)
  1848. drug.Total = drug.Total + item.PrescribingNumber
  1849. service.UpdateBaseDrugLib(&drug)
  1850. }
  1851. }
  1852. }
  1853. }
  1854. }
  1855. c.ServeSuccessJSON(map[string]interface{}{
  1856. "msg": "删除成功",
  1857. })
  1858. return
  1859. }
  1860. func (c *HisApiController) DeleteDoctorAdvice() {
  1861. id, _ := c.GetInt64("id")
  1862. advice, _ := service.GetHisDoctorAdvicesById(id)
  1863. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  1864. err := service.DelelteDoctorAdvice(id, c.GetAdminUserInfo().CurrentOrgId)
  1865. redis := service.RedisClient()
  1866. keyFive := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_advices_list_all"
  1867. redis.Set(keyFive, "", time.Second)
  1868. keyOne := strconv.FormatInt(advice.UserOrgId, 10) + ":" + strconv.FormatInt(advice.PatientId, 10) + ":" + strconv.FormatInt(advice.AdviceDate, 10) + ":his_doctor_advice"
  1869. redis.Set(keyOne, "", time.Second)
  1870. defer redis.Close()
  1871. if err == nil {
  1872. if drugStockConfig.IsOpen == 1 {
  1873. //判断该医嘱是否执行了
  1874. if advice.ExecutionState == 1 {
  1875. //查询该病人该药品是否有库存记录
  1876. info, errcode := service.GetDrugAutoWarehouseOutSeven(advice.PatientId, advice.AdviceDate, advice.DrugId, advice.ID)
  1877. if errcode == gorm.ErrRecordNotFound {
  1878. } else {
  1879. //退库
  1880. drug, _ := service.FindBaseDrugLibRecord(c.GetAdminUserInfo().CurrentOrgId, advice.DrugId)
  1881. if advice.PrescribingNumberUnit == drug.MinUnit {
  1882. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  1883. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1884. //退库
  1885. warehouseInfo := models.DrugWarehouseInfo{
  1886. StockMinNumber: prescribingNumber,
  1887. }
  1888. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  1889. adminUserInfo := c.GetAdminUserInfo()
  1890. operation_time := time.Now().Unix()
  1891. creater := adminUserInfo.AdminUser.Id
  1892. ctime := time.Now().Unix()
  1893. timeStr := time.Now().Format("2006-01-02")
  1894. timeArr := strings.Split(timeStr, "-")
  1895. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1896. total = total + 1
  1897. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1898. cancelStock := models.DrugCancelStock{
  1899. OrderNumber: orderNumber,
  1900. OperaTime: operation_time,
  1901. OrgId: adminUserInfo.CurrentOrgId,
  1902. Creater: creater,
  1903. Ctime: ctime,
  1904. Status: 1,
  1905. ReturnTime: advice.AdviceDate,
  1906. Dealer: info.Dealer,
  1907. Manufacturer: info.Manufacturer,
  1908. Type: 1,
  1909. }
  1910. service.AddSigleDrugCancelStock(&cancelStock)
  1911. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  1912. dealer, _ := service.GetDealerById(info.Dealer)
  1913. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  1914. cancelStockInfo := models.DrugCancelStockInfo{
  1915. OrderNumber: cancelInfo.OrderNumber,
  1916. CancelStockId: cancelInfo.ID,
  1917. DrugId: info.DrugId,
  1918. Count: info.Count,
  1919. Status: 1,
  1920. Ctime: ctime,
  1921. OrgId: adminUserInfo.CurrentOrgId,
  1922. Type: 1,
  1923. Manufacturer: manufactureName.ManufacturerName,
  1924. Dealer: dealer.DealerName,
  1925. Total: 0,
  1926. RetailPrice: info.RetailPrice,
  1927. RetailTotalPrice: info.RetailTotalPrice,
  1928. Price: info.Price,
  1929. RegisterAccount: "",
  1930. Remark: info.Remark,
  1931. BatchNumber: info.BatchNumber,
  1932. MaxUnit: info.CountUnit,
  1933. ProductDate: info.ProductDate,
  1934. ExpiryDate: info.ExpiryDate,
  1935. BatchNumberId: info.WarehouseInfoId,
  1936. }
  1937. flow := models.DrugFlow{
  1938. WarehousingId: 0,
  1939. DrugId: info.DrugId,
  1940. Number: "",
  1941. BatchNumber: info.BatchNumber,
  1942. Count: info.Count,
  1943. UserOrgId: adminUserInfo.CurrentOrgId,
  1944. PatientId: 0,
  1945. SystemTime: info.SysRecordTime,
  1946. ConsumableType: 7,
  1947. IsSys: 0,
  1948. WarehousingOrder: "",
  1949. WarehouseOutId: 0,
  1950. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  1951. IsEdit: 0,
  1952. CancelStockId: cancelStock.ID,
  1953. CancelOrderNumber: cancelStock.OrderNumber,
  1954. Manufacturer: info.Manufacturer,
  1955. Dealer: info.Dealer,
  1956. Creator: adminUserInfo.AdminUser.Id,
  1957. UpdateCreator: 0,
  1958. Status: 1,
  1959. Ctime: time.Now().Unix(),
  1960. Mtime: 0,
  1961. Price: info.Price,
  1962. WarehousingDetailId: 0,
  1963. WarehouseOutDetailId: 0,
  1964. CancelOutDetailId: 0,
  1965. ExpireDate: info.ExpiryDate,
  1966. ProductDate: info.ProductDate,
  1967. MaxUnit: info.CountUnit,
  1968. MinUnit: "",
  1969. AdviceId: info.AdviceId,
  1970. }
  1971. service.CreatedCancelStock(cancelStockInfo)
  1972. service.CreateDrugFlowOne(flow)
  1973. //删除出库记录
  1974. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  1975. //删除流水
  1976. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  1977. } else {
  1978. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  1979. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  1980. if advice.PrescribingNumberUnit == drug.MaxUnit {
  1981. warehouseInfo := models.DrugWarehouseInfo{
  1982. StockMaxNumber: prescribingNumber,
  1983. }
  1984. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  1985. }
  1986. adminUserInfo := c.GetAdminUserInfo()
  1987. operation_time := time.Now().Unix()
  1988. creater := adminUserInfo.AdminUser.Id
  1989. ctime := time.Now().Unix()
  1990. timeStr := time.Now().Format("2006-01-02")
  1991. timeArr := strings.Split(timeStr, "-")
  1992. total, _ := service.FindAllDrugCancelStockTotal(adminUserInfo.CurrentOrgId)
  1993. total = total + 1
  1994. orderNumber := "CKTKD" + strconv.FormatInt(adminUserInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  1995. cancelStock := models.DrugCancelStock{
  1996. OrderNumber: orderNumber,
  1997. OperaTime: operation_time,
  1998. OrgId: adminUserInfo.CurrentOrgId,
  1999. Creater: creater,
  2000. Ctime: ctime,
  2001. Status: 1,
  2002. ReturnTime: advice.AdviceDate,
  2003. Dealer: info.Dealer,
  2004. Manufacturer: info.Manufacturer,
  2005. Type: 1,
  2006. }
  2007. service.AddSigleDrugCancelStock(&cancelStock)
  2008. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  2009. dealer, _ := service.GetDealerById(info.Dealer)
  2010. cancelInfo, _ := service.GetLastDrugCancelStockById(adminUserInfo.CurrentOrgId)
  2011. cancelStockInfo := models.DrugCancelStockInfo{
  2012. OrderNumber: cancelInfo.OrderNumber,
  2013. CancelStockId: cancelInfo.ID,
  2014. DrugId: info.DrugId,
  2015. Count: info.Count,
  2016. Status: 1,
  2017. Ctime: ctime,
  2018. OrgId: adminUserInfo.CurrentOrgId,
  2019. Type: 1,
  2020. Manufacturer: manufactureName.ManufacturerName,
  2021. Dealer: dealer.DealerName,
  2022. Total: 0,
  2023. RetailPrice: info.RetailPrice,
  2024. RetailTotalPrice: info.RetailTotalPrice,
  2025. Price: info.Price,
  2026. RegisterAccount: "",
  2027. Remark: info.Remark,
  2028. BatchNumber: info.BatchNumber,
  2029. MaxUnit: info.CountUnit,
  2030. ProductDate: info.ProductDate,
  2031. ExpiryDate: info.ExpiryDate,
  2032. BatchNumberId: info.WarehouseInfoId,
  2033. }
  2034. flow := models.DrugFlow{
  2035. WarehousingId: 0,
  2036. DrugId: info.DrugId,
  2037. Number: "",
  2038. BatchNumber: info.BatchNumber,
  2039. Count: info.Count,
  2040. UserOrgId: adminUserInfo.CurrentOrgId,
  2041. PatientId: 0,
  2042. SystemTime: info.SysRecordTime,
  2043. ConsumableType: 7,
  2044. IsSys: 0,
  2045. WarehousingOrder: "",
  2046. WarehouseOutId: 0,
  2047. WarehouseOutOrderNumber: info.WarehouseOutOrderNumber,
  2048. IsEdit: 0,
  2049. CancelStockId: cancelStock.ID,
  2050. CancelOrderNumber: cancelStock.OrderNumber,
  2051. Manufacturer: info.Manufacturer,
  2052. Dealer: info.Dealer,
  2053. Creator: adminUserInfo.AdminUser.Id,
  2054. UpdateCreator: 0,
  2055. Status: 1,
  2056. Ctime: time.Now().Unix(),
  2057. Mtime: 0,
  2058. Price: info.Price,
  2059. WarehousingDetailId: 0,
  2060. WarehouseOutDetailId: 0,
  2061. CancelOutDetailId: 0,
  2062. ExpireDate: info.ExpiryDate,
  2063. ProductDate: info.ProductDate,
  2064. MaxUnit: info.CountUnit,
  2065. MinUnit: "",
  2066. AdviceId: info.AdviceId,
  2067. }
  2068. service.CreatedCancelStock(cancelStockInfo)
  2069. service.CreateDrugFlowOne(flow)
  2070. //删除出库记录
  2071. service.UpdateDrugFlowSeven(info.PatientId, info.SysRecordTime, info.DrugId, advice.ID)
  2072. //删除流水
  2073. service.UpdateDrugFlowTens(info.PatientId, info.WarehouseOutOrderNumber, info.DrugId, advice.ID)
  2074. }
  2075. }
  2076. }
  2077. }
  2078. c.ServeSuccessJSON(map[string]interface{}{
  2079. "msg": "删除成功",
  2080. })
  2081. return
  2082. } else {
  2083. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2084. return
  2085. }
  2086. }
  2087. func (c *HisApiController) DeleteProject() {
  2088. id, _ := c.GetInt64("id")
  2089. adminInfo := c.GetAdminUserInfo()
  2090. project, _ := service.GetHisProjectByID(id)
  2091. // var consumable models.DialysisBeforePrepare
  2092. _, stockConfig := service.FindAutomaticReduceRecordByOrgId(c.GetAdminUserInfo().CurrentOrgId)
  2093. service.DeletePrintInfo(id)
  2094. label, _ := service.GetProjectById(adminInfo.CurrentOrgId, id, project.RecordDate, project.PatientId)
  2095. label.Status = 0
  2096. service.CreateHisLabelRecord(&label)
  2097. if stockConfig.IsOpen == 1 {
  2098. if project.Type == 2 {
  2099. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2100. fmt.Println(err)
  2101. }
  2102. if project.Type == 3 {
  2103. good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  2104. f_count, _ := strconv.ParseFloat(project.Count, 64)
  2105. good.Total = good.Total + f_count
  2106. service.UpdateGoodInfo(&good)
  2107. operation_time := time.Now().Unix()
  2108. creater := adminInfo.AdminUser.Id
  2109. //创建退库单
  2110. timeStr := time.Now().Format("2006-01-02")
  2111. timeArr := strings.Split(timeStr, "-")
  2112. total, _ := service.FindAllCancelStockTotal(adminInfo.CurrentOrgId)
  2113. total = total + 1
  2114. orderNumber := "CKTKD" + strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  2115. cancelStock := models.CancelStock{
  2116. OrderNumber: orderNumber,
  2117. OperaTime: operation_time,
  2118. OrgId: adminInfo.CurrentOrgId,
  2119. Creater: creater,
  2120. Ctime: time.Now().Unix(),
  2121. Status: 1,
  2122. ReturnTime: project.RecordDate,
  2123. Type: 1,
  2124. }
  2125. _, msgerrkonde := service.GetCancelStockDetailByOrderNumberOne(project.RecordDate, adminInfo.CurrentOrgId)
  2126. if msgerrkonde == gorm.ErrRecordNotFound {
  2127. service.AddSigleCancelStock(&cancelStock)
  2128. }
  2129. cancel, _ := service.GetLastCancelStockById(adminInfo.CurrentOrgId)
  2130. floatPrescrip := strconv.FormatFloat(f_count, 'f', -1, 32)
  2131. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  2132. //获取该耗材有库存的第一条数据
  2133. info, _ := service.GetLastWarehoseByGoodId(project.ProjectId, project.PatientId, project.RecordDate)
  2134. manufacturer, _ := service.GetManufactureById(info.Manufacturer)
  2135. deaerler, _ := service.GetDealerById(info.Dealer)
  2136. if info.ID > 0 {
  2137. cancelStockInfo := models.CancelStockInfo{
  2138. GoodId: project.ProjectId,
  2139. CancelStockId: cancel.ID,
  2140. GoodTypeId: good.GoodTypeId,
  2141. Count: prescribingNumber,
  2142. Price: info.Price,
  2143. Total: 0,
  2144. ProductDate: info.ProductDate,
  2145. ExpiryDate: info.ExpiryDate,
  2146. Ctime: time.Now().Unix(),
  2147. Status: 1,
  2148. OrgId: adminInfo.CurrentOrgId,
  2149. OrderNumber: cancel.OrderNumber,
  2150. Type: 0,
  2151. Dealer: deaerler.DealerName,
  2152. Manufacturer: manufacturer.ManufacturerName,
  2153. Number: info.Number,
  2154. RegisterAccount: "",
  2155. Remark: "",
  2156. WarehouseInfoId: info.WarehouseInfotId,
  2157. PatientId: info.PatientId,
  2158. RecordDate: info.SysRecordTime,
  2159. }
  2160. service.CreateCancelStockInfoOne(&cancelStockInfo)
  2161. cancelInfo, _ := service.GetLastCancelStockInfoByGoodId(project.ProjectId)
  2162. flow := models.VmStockFlow{
  2163. WarehousingId: 0,
  2164. GoodId: project.ProjectId,
  2165. Number: info.Number,
  2166. LicenseNumber: info.LicenseNumber,
  2167. Count: prescribingNumber,
  2168. UserOrgId: adminInfo.CurrentOrgId,
  2169. PatientId: project.PatientId,
  2170. SystemTime: time.Now().Unix(),
  2171. ConsumableType: 7,
  2172. IsSys: 0,
  2173. WarehousingOrder: "",
  2174. WarehouseOutId: 0,
  2175. WarehouseOutOrderNumber: "",
  2176. IsEdit: 0,
  2177. CancelStockId: cancel.ID,
  2178. CancelOrderNumber: cancel.OrderNumber,
  2179. Manufacturer: manufacturer.ID,
  2180. Dealer: 0,
  2181. Creator: adminInfo.AdminUser.Id,
  2182. UpdateCreator: 0,
  2183. Status: 1,
  2184. Ctime: time.Now().Unix(),
  2185. Mtime: 0,
  2186. Price: info.Price,
  2187. WarehousingDetailId: info.WarehouseInfotId,
  2188. WarehouseOutDetailId: 0,
  2189. CancelOutDetailId: cancelInfo.ID,
  2190. ProductDate: info.ProductDate,
  2191. ExpireDate: info.ExpiryDate,
  2192. }
  2193. service.CreateStockFlowOne(flow)
  2194. //删除出库表
  2195. service.DeleteAutoRedeceDetailTen(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, project.ProjectId)
  2196. //查询今日该患者开了多少耗材
  2197. projectList, _ := service.GetHisPrepscritionByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2198. var total_count int64
  2199. var cha_count int64
  2200. for _, item := range projectList {
  2201. count, _ := strconv.ParseInt(item.Count, 10, 64)
  2202. total_count += count
  2203. }
  2204. //回退库存
  2205. service.UpDateWarehouseInfoByStockDelete(info.WarehouseInfotId, total_count)
  2206. //查询今日该耗材退库数量
  2207. cancelInfoOne, _ := service.GetCancelStockInfoByPatientId(info.PatientId, project.ProjectId, info.SysRecordTime)
  2208. var cancel_count int64
  2209. for _, items := range cancelInfoOne {
  2210. cancel_count += items.Count
  2211. }
  2212. cha_count = total_count - cancel_count
  2213. if total_count > cancel_count {
  2214. out, err := service.FindStockOutByIsSys(adminInfo.CurrentOrgId, 1, info.SysRecordTime)
  2215. if err == gorm.ErrRecordNotFound {
  2216. //没有记录,则创建出库单
  2217. timeStr := time.Now().Format("2006-01-02")
  2218. timeArr := strings.Split(timeStr, "-")
  2219. total, _ := service.FindAllWarehouseOut(adminInfo.CurrentOrgId)
  2220. total = total + 1
  2221. warehousing_out_order := strconv.FormatInt(adminInfo.CurrentOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000"
  2222. number, _ := strconv.ParseInt(warehousing_out_order, 10, 64)
  2223. number = number + total
  2224. warehousing_out_order = "CKD" + strconv.FormatInt(number, 10)
  2225. warehouseOut := models.WarehouseOut{
  2226. WarehouseOutOrderNumber: warehousing_out_order,
  2227. OperationTime: time.Now().Unix(),
  2228. OrgId: adminInfo.CurrentOrgId,
  2229. Creater: creater,
  2230. Ctime: time.Now().Unix(),
  2231. Status: 1,
  2232. WarehouseOutTime: info.SysRecordTime,
  2233. Dealer: 0,
  2234. Manufacturer: 0,
  2235. Type: 1,
  2236. IsSys: 1,
  2237. }
  2238. err := service.AddSigleWarehouseOut(&warehouseOut)
  2239. if err != nil {
  2240. utils.TraceLog("创建出库单失败 err = %v", err)
  2241. return
  2242. }
  2243. prepare := &models.DialysisBeforePrepare{
  2244. UserOrgId: adminInfo.CurrentOrgId,
  2245. PatientId: info.PatientId,
  2246. RecordDate: info.SysRecordTime,
  2247. GoodId: project.ProjectId,
  2248. GoodTypeId: info.GoodTypeId,
  2249. Count: cha_count,
  2250. }
  2251. //出库
  2252. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &warehouseOut, cha_count)
  2253. } else if err == nil {
  2254. prepare := &models.DialysisBeforePrepare{
  2255. UserOrgId: adminInfo.CurrentOrgId,
  2256. PatientId: info.PatientId,
  2257. RecordDate: info.SysRecordTime,
  2258. GoodId: project.ProjectId,
  2259. GoodTypeId: info.GoodTypeId,
  2260. Count: cha_count,
  2261. }
  2262. //出库
  2263. service.ConsumablesDelivery(adminInfo.CurrentOrgId, info.PatientId, info.SysRecordTime, prepare, &out, cha_count)
  2264. }
  2265. }
  2266. }
  2267. err := service.DelelteProject(id, c.GetAdminUserInfo().CurrentOrgId)
  2268. fmt.Println(err)
  2269. }
  2270. }
  2271. c.ServeSuccessJSON(map[string]interface{}{
  2272. "msg": "删除成功",
  2273. })
  2274. return
  2275. }
  2276. func (c *HisApiController) CreateHisAdditionalCharge() {
  2277. his_patient_id, _ := c.GetInt64("his_patient_id")
  2278. patient_id, _ := c.GetInt64("patient_id")
  2279. record_date := c.GetString("record_date")
  2280. timeLayout := "2006-01-02"
  2281. loc, _ := time.LoadLocation("Local")
  2282. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2283. if err != nil {
  2284. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2285. return
  2286. }
  2287. adminInfo := c.GetAdminUserInfo()
  2288. recordDateTime := theTime.Unix()
  2289. dataBody := make(map[string]interface{}, 0)
  2290. err = json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  2291. if err != nil {
  2292. utils.ErrorLog(err.Error())
  2293. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2294. return
  2295. }
  2296. var additions []*models.HisAdditionalCharge
  2297. if dataBody["addition"] != nil && reflect.TypeOf(dataBody["addition"]).String() == "[]interface {}" {
  2298. additions, _ := dataBody["addition"].([]interface{})
  2299. if len(additions) > 0 {
  2300. for _, item := range additions {
  2301. items := item.(map[string]interface{})
  2302. if items["item_id"] == nil || reflect.TypeOf(items["item_id"]).String() != "float64" {
  2303. utils.ErrorLog("item_id")
  2304. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2305. return
  2306. }
  2307. item_id := int64(items["item_id"].(float64))
  2308. if items["item_name"] == nil || reflect.TypeOf(items["item_name"]).String() != "string" {
  2309. utils.ErrorLog("item_name")
  2310. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2311. return
  2312. }
  2313. item_name := items["item_name"].(string)
  2314. if items["price"] == nil || reflect.TypeOf(items["price"]).String() != "string" {
  2315. utils.ErrorLog("price")
  2316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2317. return
  2318. }
  2319. price, _ := strconv.ParseFloat(items["price"].(string), 64)
  2320. ctime := time.Now().Unix()
  2321. additional := &models.HisAdditionalCharge{
  2322. PatientId: patient_id,
  2323. HisPatientId: his_patient_id,
  2324. UserOrgId: adminInfo.CurrentOrgId,
  2325. RecordDate: recordDateTime,
  2326. CreatedTime: ctime,
  2327. UpdatedTime: ctime,
  2328. Modifier: adminInfo.AdminUser.Id,
  2329. Creator: adminInfo.AdminUser.Id,
  2330. Price: price,
  2331. ItemName: item_name,
  2332. ItemId: item_id,
  2333. Status: 1,
  2334. }
  2335. additions = append(additions, additional)
  2336. }
  2337. }
  2338. }
  2339. for _, item := range additions {
  2340. service.CreateAddtionalCharge(item)
  2341. }
  2342. c.ServeSuccessJSON(map[string]interface{}{
  2343. "msg": "创建成功",
  2344. })
  2345. }
  2346. func (c *HisApiController) CreateHisPatientCaseHistory() {
  2347. blood_fat := c.GetString("blood_fat")
  2348. bloodfatfloat, _ := strconv.ParseFloat(blood_fat, 64)
  2349. blood_sugar := c.GetString("blood_sugar")
  2350. bloodsugarfloat, _ := strconv.ParseFloat(blood_sugar, 64)
  2351. chief_conplaint := c.GetString("chief_conplaint")
  2352. dbp := c.GetString("dbp")
  2353. dbpfloat, _ := strconv.ParseFloat(dbp, 64)
  2354. delivery_way, _ := c.GetInt64("delivery_way")
  2355. diagnostic := c.GetString("diagnostic")
  2356. family_history := c.GetString("family_history")
  2357. height := c.GetString("height")
  2358. history_of_present_illness := c.GetString("history_of_present_illness")
  2359. is_infect, _ := c.GetInt64("is_infect")
  2360. past_history := c.GetString("past_history")
  2361. patient_id, _ := c.GetInt64("patient_id")
  2362. his_patient_id, _ := c.GetInt64("his_patient_id")
  2363. personal_history := c.GetString("personal_history")
  2364. pulse := c.GetString("pulse")
  2365. pulsefloat, _ := strconv.ParseFloat(pulse, 64)
  2366. sbp := c.GetString("sbp")
  2367. sbpfloat, _ := strconv.ParseFloat(sbp, 64)
  2368. heightfloat, _ := strconv.ParseFloat(height, 64)
  2369. sicktype := c.GetString("sick_type")
  2370. sick_type, _ := strconv.ParseInt(sicktype, 10, 64)
  2371. symptom := c.GetString("symptom")
  2372. sick_date := c.GetString("sick_date")
  2373. temperatures := c.GetString("temperature")
  2374. temperature, _ := strconv.ParseFloat(temperatures, 64)
  2375. record_date := c.GetString("record_date")
  2376. breathing := c.GetString("breathing")
  2377. doctor_advice := c.GetString("doctor_advice")
  2378. remark := c.GetString("remark")
  2379. breathingfloat, _ := strconv.ParseFloat(breathing, 64)
  2380. sick, _ := c.GetInt64("sick")
  2381. diagnose, _ := c.GetInt64("diagnose")
  2382. id, _ := c.GetInt64("id")
  2383. timeLayout := "2006-01-02"
  2384. loc, _ := time.LoadLocation("Local")
  2385. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2386. allergic_history := c.GetString("allergic_history")
  2387. if err != nil {
  2388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2389. return
  2390. }
  2391. recordDateTime := theTime.Unix()
  2392. sickTime, err := time.ParseInLocation(timeLayout+" 15:04:05", sick_date+" 00:00:00", loc)
  2393. if err != nil {
  2394. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2395. return
  2396. }
  2397. sickTimes := sickTime.Unix()
  2398. ctime := time.Now().Unix()
  2399. caseHistory := models.HisPatientCaseHistory{
  2400. HisPatientId: his_patient_id,
  2401. PatientId: patient_id,
  2402. Temperature: temperature,
  2403. BloodSugar: bloodsugarfloat,
  2404. Pulse: pulsefloat,
  2405. Sbp: sbpfloat,
  2406. Dbp: dbpfloat,
  2407. Height: heightfloat,
  2408. BloodFat: bloodfatfloat,
  2409. SickType: sick_type,
  2410. Symptom: symptom,
  2411. SickDate: sickTimes,
  2412. IsInfect: is_infect,
  2413. HistoryOfPresentIllness: history_of_present_illness,
  2414. PastHistory: past_history,
  2415. Doctor: c.GetAdminUserInfo().AdminUser.Id,
  2416. ChiefConplaint: chief_conplaint,
  2417. PersonalHistory: personal_history,
  2418. FamilyHistory: family_history,
  2419. Diagnostic: diagnostic,
  2420. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2421. Status: 1,
  2422. Ctime: ctime,
  2423. Mtime: ctime,
  2424. RecordDate: recordDateTime,
  2425. DeliveryWay: delivery_way,
  2426. Breathing: breathingfloat,
  2427. DoctorAdvice: doctor_advice,
  2428. Remark: remark,
  2429. Sick: sick,
  2430. Diagnose: diagnose,
  2431. AllergicHistory: allergic_history,
  2432. }
  2433. //查询该患者是否有病历
  2434. _, errcodes := service.GetHisPatientCaseHistoryById(id)
  2435. if errcodes == gorm.ErrRecordNotFound {
  2436. err = service.SaveHisPatientCaseHistory(&caseHistory)
  2437. if err != nil {
  2438. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2439. return
  2440. }
  2441. c.ServeSuccessJSON(map[string]interface{}{
  2442. "caseHistory": caseHistory,
  2443. })
  2444. return
  2445. } else if errcodes == nil {
  2446. err := service.UpdatePatientCaseHistory(id, &caseHistory)
  2447. if err != nil {
  2448. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2449. return
  2450. }
  2451. c.ServeSuccessJSON(map[string]interface{}{
  2452. "caseHistory": caseHistory,
  2453. })
  2454. }
  2455. //查询该患者是否有病历
  2456. //_, errcode := service.GetHisPatientCaseHistoryById(his_patient_id)
  2457. //if errcode == gorm.ErrRecordNotFound {
  2458. // err = service.SaveHisPatientCaseHistory(caseHistory)
  2459. // if err != nil {
  2460. // c.ServeSuccessJSON(map[string]interface{}{
  2461. // "msg": "保存成功",
  2462. // })
  2463. // }
  2464. //} else if errcode == nil {
  2465. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  2466. // return
  2467. //}
  2468. }
  2469. func (c *HisApiController) GetHisPatientCaseHistoryList() {
  2470. patient_id, _ := c.GetInt64("patient_id", 0)
  2471. adminUser := c.GetAdminUserInfo()
  2472. caseHistorys, _ := service.GetHisPatientCaseHistoryList(adminUser.CurrentOrgId, patient_id)
  2473. c.ServeSuccessJSON(map[string]interface{}{
  2474. "list": caseHistorys,
  2475. })
  2476. }
  2477. func (c *HisApiController) GetHisPatientCaseHistory() {
  2478. record_date, _ := c.GetInt64("record_date", 0)
  2479. patient_id, _ := c.GetInt64("patient_id", 0)
  2480. admin := c.GetAdminUserInfo()
  2481. info, _ := service.GetHisPatientInfo(admin.CurrentOrgId, patient_id, record_date)
  2482. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, record_date)
  2483. c.ServeSuccessJSON(map[string]interface{}{
  2484. "info": info,
  2485. "case_history": case_history,
  2486. })
  2487. }
  2488. func (c *HisApiController) CreateCaseHistoryTemplate() {
  2489. template_name := c.GetString("template_name")
  2490. template_remark := c.GetString("template_remark")
  2491. doctor := c.GetAdminUserInfo().AdminUser.Id
  2492. diagnostic := c.GetString("diagnostic")
  2493. chief_conplaint := c.GetString("chief_conplain")
  2494. history_of_present_illness := c.GetString("history_of_present_illness")
  2495. past_history := c.GetString("past_history")
  2496. personal_history := c.GetString("personal_history")
  2497. family_history := c.GetString("family_history")
  2498. user_name := c.GetString("user_name")
  2499. doctor_advice := c.GetString("doctor_advice")
  2500. remark := c.GetString("remark")
  2501. //record_date := c.GetString("record_date")
  2502. //fmt.Println("record_date--------",record_date)
  2503. //timeLayout := "2006-01-02"
  2504. //loc, _ := time.LoadLocation("Local")
  2505. //
  2506. //theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  2507. //if err != nil {
  2508. // c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  2509. // return
  2510. //}
  2511. //recordDateTime := theTime.Unix()
  2512. ctime := time.Now().Unix()
  2513. template := models.HisCaseHistoryTemplate{
  2514. HistoryOfPresentIllness: history_of_present_illness,
  2515. PastHistory: past_history,
  2516. ChiefConplaint: chief_conplaint,
  2517. PersonalHistory: personal_history,
  2518. FamilyHistory: family_history,
  2519. Diagnostic: diagnostic,
  2520. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  2521. Status: 1,
  2522. Ctime: ctime,
  2523. Mtime: ctime,
  2524. RecordDate: time.Now().Unix(),
  2525. TemplateName: template_name,
  2526. TemplateRemark: template_remark,
  2527. Creator: doctor,
  2528. Modifier: doctor,
  2529. UserName: user_name,
  2530. DoctorAdvice: doctor_advice,
  2531. Remark: remark,
  2532. }
  2533. err := service.SaveHisPatientCaseHistoryTemplate(template)
  2534. if err == nil {
  2535. c.ServeSuccessJSON(map[string]interface{}{
  2536. "msg": "保存成功",
  2537. })
  2538. } else {
  2539. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  2540. return
  2541. }
  2542. }
  2543. func (c *HisApiController) GetCaseHistoryTemplate() {
  2544. timeLayout := "2006-01-02"
  2545. loc, _ := time.LoadLocation("Local")
  2546. keyword := c.GetString("keyword")
  2547. start_time := c.GetString("start_time")
  2548. end_time := c.GetString("end_time")
  2549. startTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  2550. endTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  2551. admin := c.GetAdminUserInfo()
  2552. template, _ := service.GetHisPatientCaseHistoryTemplate(admin.CurrentOrgId, startTime.Unix(), endTime.Unix(), keyword)
  2553. //history, _ := service.GetHisPatientCaseHistory(admin.CurrentOrgId)
  2554. c.ServeSuccessJSON(map[string]interface{}{
  2555. "template": template,
  2556. //"history": history,
  2557. })
  2558. }
  2559. func (c *HisApiController) setAdviceWithJSONTwo(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2560. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2561. utils.ErrorLog("drug_name")
  2562. return enums.ErrorCodeParamWrong
  2563. }
  2564. adviceName, _ := json["drug_name"].(string)
  2565. if len(adviceName) == 0 {
  2566. utils.ErrorLog("len(advice_name) == 0")
  2567. return enums.ErrorCodeParamWrong
  2568. }
  2569. advice.AdviceName = adviceName
  2570. adviceDesc, _ := json["advice_desc"].(string)
  2571. advice.AdviceDesc = adviceDesc
  2572. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2573. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2574. advice.DrugSpec = drugSpec
  2575. }
  2576. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2577. remark, _ := json["remark"].(string)
  2578. advice.Remark = remark
  2579. }
  2580. if json["id"] == nil {
  2581. advice.DrugId = 0
  2582. } else {
  2583. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2584. drug_id := int64(json["id"].(float64))
  2585. advice.DrugId = drug_id
  2586. }
  2587. }
  2588. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2589. advice_id := int64(json["advice_id"].(float64))
  2590. advice.ID = advice_id
  2591. if advice.ID > 0 {
  2592. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2593. if err == nil {
  2594. if hisAdvice.ID > 0 {
  2595. advice.ExecutionTime = hisAdvice.ExecutionTime
  2596. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2597. advice.ExecutionState = hisAdvice.ExecutionState
  2598. advice.CheckTime = hisAdvice.CheckTime
  2599. advice.Checker = hisAdvice.Checker
  2600. advice.CheckState = hisAdvice.CheckState
  2601. advice.StartTime = hisAdvice.StartTime
  2602. advice.FeedetlSn = hisAdvice.FeedetlSn
  2603. }
  2604. }
  2605. }
  2606. }
  2607. //
  2608. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2609. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  2610. // advice.ExecutionTime = execution_time
  2611. //}
  2612. //
  2613. //
  2614. //
  2615. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  2616. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  2617. // advice.ExecutionStaff = execution_staff
  2618. //}
  2619. //
  2620. //
  2621. //
  2622. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  2623. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  2624. // advice.ExecutionState = execution_state
  2625. //}
  2626. //
  2627. //
  2628. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  2629. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  2630. // advice.CheckTime = check_time
  2631. //}
  2632. //
  2633. //
  2634. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  2635. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  2636. // advice.CheckState = check_state
  2637. //}
  2638. //
  2639. //
  2640. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  2641. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  2642. // advice.Checker = checker
  2643. //}
  2644. //
  2645. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  2646. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  2647. // advice.StartTime = start_time
  2648. //}
  2649. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2650. drugSpecUnit, _ := json["min_unit"].(string)
  2651. advice.DrugSpecUnit = drugSpecUnit
  2652. }
  2653. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2654. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2655. advice.SingleDose = singleDose
  2656. }
  2657. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2658. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2659. advice.SingleDoseUnit = singleDoseUnit
  2660. }
  2661. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2662. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2663. advice.PrescribingNumber = prescribingNumber
  2664. }
  2665. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2666. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2667. advice.PrescribingNumberUnit = prescribingNumberUnit
  2668. }
  2669. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2670. deliveryWay, _ := json["delivery_way"].(string)
  2671. advice.DeliveryWay = deliveryWay
  2672. }
  2673. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2674. executionFrequency, _ := json["execution_frequency"].(string)
  2675. advice.ExecutionFrequency = executionFrequency
  2676. }
  2677. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2678. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2679. advice.Price = price
  2680. }
  2681. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2682. med_list_codg, _ := json["medical_insurance_number"].(string)
  2683. advice.MedListCodg = med_list_codg
  2684. }
  2685. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2686. day := int64(json["day"].(float64))
  2687. advice.Day = day
  2688. }
  2689. return 0
  2690. }
  2691. func (c *HisApiController) setProjectWithJSONTwo(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  2692. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2693. id := int64(json["id"].(float64))
  2694. project.ID = id
  2695. historyProject, _ := service.GetHisProjectByID(id)
  2696. project.FeedetlSn = historyProject.FeedetlSn
  2697. }
  2698. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  2699. project_id := int64(json["project_id"].(float64))
  2700. project.ProjectId = project_id
  2701. }
  2702. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2703. // price := int64(json["price"].(float64))
  2704. // formatInt_price := strconv.FormatInt(price, 10)
  2705. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2706. // project.Price = float_price
  2707. // }
  2708. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2709. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2710. project.Price = price
  2711. }
  2712. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  2713. total, _ := json["total"].(string)
  2714. project.Count = total
  2715. }
  2716. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  2717. medical_code, _ := json["medical_code"].(string)
  2718. project.MedListCodg = medical_code
  2719. }
  2720. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2721. single_dose, _ := json["single_dose"].(string)
  2722. project.SingleDose = single_dose
  2723. }
  2724. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2725. delivery_way, _ := json["delivery_way"].(string)
  2726. project.DeliveryWay = delivery_way
  2727. }
  2728. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2729. execution_frequency, _ := json["execution_frequency"].(string)
  2730. project.ExecutionFrequency = execution_frequency
  2731. }
  2732. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2733. remark, _ := json["remark"].(string)
  2734. project.Remark = remark
  2735. }
  2736. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  2737. day, _ := json["number_days"].(string)
  2738. project.Day = day
  2739. }
  2740. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  2741. unit, _ := json["unit"].(string)
  2742. project.Unit = unit
  2743. }
  2744. return 0
  2745. }
  2746. func (c *HisApiController) setAddtionWithJSONTwo(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  2747. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2748. id := int64(json["id"].(float64))
  2749. historyAddtions, _ := service.GetHisAdditionByID(id)
  2750. additionalCharge.ID = id
  2751. additionalCharge.FeedetlSn = historyAddtions.FeedetlSn
  2752. }
  2753. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  2754. item_id := int64(json["item_id"].(float64))
  2755. additionalCharge.ItemId = item_id
  2756. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  2757. if config.ID > 0 {
  2758. if len(config.Code) > 0 {
  2759. additionalCharge.MedListCodg = config.Code
  2760. }
  2761. }
  2762. }
  2763. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2764. // price := int64(json["price"].(float64))
  2765. // formatInt_price := strconv.FormatInt(price, 10)
  2766. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2767. // additionalCharge.Price = float_price
  2768. // }
  2769. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  2770. // price := int64(json["price"].(float64))
  2771. // formatInt_price := strconv.FormatInt(price, 10)
  2772. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  2773. // additionalCharge.Price = float_price
  2774. //}
  2775. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  2776. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  2777. additionalCharge.Price = price
  2778. }
  2779. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  2780. count, _ := json["count"].(string)
  2781. counts, _ := strconv.ParseInt(count, 10, 64)
  2782. additionalCharge.Count = counts
  2783. }
  2784. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  2785. item_name, _ := json["item_name"].(string)
  2786. additionalCharge.ItemName = item_name
  2787. }
  2788. return 0
  2789. }
  2790. func (c *HisApiController) setAdviceWithJSON(advice *models.HisDoctorAdviceInfo, json map[string]interface{}) int {
  2791. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  2792. utils.ErrorLog("drug_name")
  2793. return enums.ErrorCodeParamWrong
  2794. }
  2795. adviceName, _ := json["drug_name"].(string)
  2796. if len(adviceName) == 0 {
  2797. utils.ErrorLog("len(advice_name) == 0")
  2798. return enums.ErrorCodeParamWrong
  2799. }
  2800. advice.AdviceName = adviceName
  2801. adviceDesc, _ := json["advice_desc"].(string)
  2802. advice.AdviceDesc = adviceDesc
  2803. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  2804. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  2805. advice.DrugSpec = drugSpec
  2806. }
  2807. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  2808. remark, _ := json["remark"].(string)
  2809. advice.Remark = remark
  2810. }
  2811. if json["id"] == nil {
  2812. advice.DrugId = 0
  2813. } else {
  2814. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  2815. drug_id := int64(json["id"].(float64))
  2816. advice.DrugId = drug_id
  2817. }
  2818. }
  2819. if json["groupno"] != nil || reflect.TypeOf(json["groupno"]).String() == "float64" {
  2820. groupno := int64(json["groupno"].(float64))
  2821. advice.Groupno = groupno
  2822. }
  2823. if json["hosp_appr_flag"] != nil && reflect.TypeOf(json["hosp_appr_flag"]).String() == "string" {
  2824. hosp_appr_flag, _ := strconv.ParseInt(json["hosp_appr_flag"].(string), 10, 64)
  2825. advice.HospApprFlag = hosp_appr_flag
  2826. }
  2827. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  2828. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  2829. advice.PrescribingNumber = prescribingNumber
  2830. }
  2831. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  2832. // frequency_type := int64(json["frequency_type"].(float64))
  2833. // advice.FrequencyType = frequency_type
  2834. //}
  2835. //
  2836. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  2837. // day_count := int64(json["day_count"].(float64))
  2838. // advice.DayCount = day_count
  2839. //}
  2840. //
  2841. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  2842. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  2843. // week_day, _ := json["week_day"].(string)
  2844. // advice.WeekDay = week_day
  2845. //}
  2846. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  2847. drugSpecUnit, _ := json["min_unit"].(string)
  2848. advice.DrugSpecUnit = drugSpecUnit
  2849. }
  2850. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  2851. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  2852. advice.SingleDose = singleDose
  2853. }
  2854. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  2855. singleDoseUnit, _ := json["single_dose_unit"].(string)
  2856. advice.SingleDoseUnit = singleDoseUnit
  2857. }
  2858. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  2859. deliveryWay, _ := json["delivery_way"].(string)
  2860. advice.DeliveryWay = deliveryWay
  2861. }
  2862. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  2863. executionFrequency, _ := json["execution_frequency"].(string)
  2864. advice.ExecutionFrequency = executionFrequency
  2865. }
  2866. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  2867. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  2868. advice.Price = price
  2869. }
  2870. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  2871. med_list_codg, _ := json["medical_insurance_number"].(string)
  2872. advice.MedListCodg = med_list_codg
  2873. }
  2874. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  2875. day := int64(json["day"].(float64))
  2876. advice.Day = day
  2877. }
  2878. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  2879. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  2880. advice.PrescribingNumberUnit = prescribingNumberUnit
  2881. }
  2882. if json["advice_id"] != nil && reflect.TypeOf(json["advice_id"]).String() == "float64" {
  2883. advice_id := int64(json["advice_id"].(float64))
  2884. advice.ID = advice_id
  2885. if advice.ID > 0 {
  2886. hisAdvice, err := service.GetHisDoctorAdvicesById(advice.ID)
  2887. if err == nil {
  2888. if hisAdvice.ID > 0 {
  2889. advice.ExecutionTime = hisAdvice.ExecutionTime
  2890. advice.ExecutionStaff = hisAdvice.ExecutionStaff
  2891. advice.ExecutionState = hisAdvice.ExecutionState
  2892. advice.CheckTime = hisAdvice.CheckTime
  2893. advice.Checker = hisAdvice.Checker
  2894. advice.CheckState = hisAdvice.CheckState
  2895. advice.StartTime = hisAdvice.StartTime
  2896. advice.HospApprFlag = hisAdvice.HospApprFlag
  2897. if hisAdvice.UserOrgId == 10028 {
  2898. 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 {
  2899. advice.ExecutionTime = 0
  2900. advice.ExecutionStaff = 0
  2901. advice.ExecutionState = 2
  2902. advice.CheckTime = 0
  2903. advice.Checker = 0
  2904. advice.CheckState = 2
  2905. }
  2906. } else {
  2907. 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 {
  2908. advice.ExecutionTime = 0
  2909. advice.ExecutionStaff = 0
  2910. advice.ExecutionState = 2
  2911. advice.CheckTime = 0
  2912. advice.Checker = 0
  2913. advice.CheckState = 2
  2914. }
  2915. }
  2916. //advice.Groupno = hisAdvice.Groupno
  2917. }
  2918. }
  2919. }
  2920. }
  2921. //_, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(advice.UserOrgId)
  2922. //
  2923. //if drugStockConfig.IsOpen == 1 {
  2924. //
  2925. // drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  2926. // if advice.ID == 0 { //医嘱不存在
  2927. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据单位与基础库一致为最小单位,直接计算
  2928. // drug.Total = drug.Total - advice.PrescribingNumber
  2929. // service.UpdateBaseDrugLib(&drug)
  2930. //
  2931. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据单位为最大单位,需要将最大单位转为最小单位
  2932. // num := advice.PrescribingNumber * float64(drug.MinNumber)
  2933. // drug.Total = drug.Total - num
  2934. // service.UpdateBaseDrugLib(&drug)
  2935. // }
  2936. //
  2937. // } else if advice.ID > 0 { //医嘱存在
  2938. // hisAdvice, _ := service.GetHisDoctorAdvicesById(advice.ID)
  2939. // var num float64
  2940. //
  2941. // if advice.PrescribingNumberUnit == drug.MinUnit { //当前数据为最小单位
  2942. // if hisAdvice.PrescribingNumberUnit == advice.PrescribingNumberUnit { //原数据为最小单位,三个单位一致为最小单位直接计算
  2943. // if hisAdvice.PrescribingNumber > advice.PrescribingNumber {
  2944. // num = hisAdvice.PrescribingNumber - advice.PrescribingNumber
  2945. // drug.Total = drug.Total + num
  2946. // service.UpdateBaseDrugLib(&drug)
  2947. // } else if hisAdvice.PrescribingNumber < advice.PrescribingNumber {
  2948. // num = advice.PrescribingNumber - hisAdvice.PrescribingNumber
  2949. // drug.Total = drug.Total - num
  2950. // service.UpdateBaseDrugLib(&drug)
  2951. // }
  2952. // } else { //原数据为最大单位,需要将最大单位数量转为最小单位数量
  2953. // num2 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  2954. // if num2 > advice.PrescribingNumber {
  2955. // num = num2 - advice.PrescribingNumber
  2956. // drug.Total = drug.Total + num
  2957. // service.UpdateBaseDrugLib(&drug)
  2958. // } else if num2 < advice.PrescribingNumber {
  2959. // num = advice.PrescribingNumber - num2
  2960. // drug.Total = drug.Total - num
  2961. // service.UpdateBaseDrugLib(&drug)
  2962. // }
  2963. //
  2964. // }
  2965. //
  2966. // } else if advice.PrescribingNumberUnit == drug.MaxUnit { //当前数据为最大单位
  2967. // if advice.PrescribingNumberUnit == hisAdvice.PrescribingNumberUnit { //原数据为最大单位, 当前数据单位和原数据单位都为最大单位,需要将两个数据转成最小单位
  2968. // num1 := hisAdvice.PrescribingNumber * float64(drug.MinNumber)
  2969. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2970. // if num1 > num2 {
  2971. // num = num1 - num2
  2972. // drug.Total = drug.Total + num
  2973. // service.UpdateBaseDrugLib(&drug)
  2974. // } else if num1 < num2 {
  2975. // num = num2 - num1
  2976. // drug.Total = drug.Total - num
  2977. // service.UpdateBaseDrugLib(&drug)
  2978. // }
  2979. //
  2980. // } else { //原数据为最小单位,当前数据为最大单位,需要将当前数据数量转为最小单位数量
  2981. // num2 := advice.PrescribingNumber * float64(drug.MinNumber)
  2982. // //num2 := hisAdvice.PrescribingNumber * (drug.Dose / float64(drug.MinNumber))
  2983. // if hisAdvice.PrescribingNumber > num2 {
  2984. // num = hisAdvice.PrescribingNumber - num2
  2985. // drug.Total = drug.Total + num
  2986. // service.UpdateBaseDrugLib(&drug)
  2987. // } else if num2 < advice.PrescribingNumber {
  2988. // num = num2 - hisAdvice.PrescribingNumber
  2989. // drug.Total = drug.Total - num
  2990. // service.UpdateBaseDrugLib(&drug)
  2991. // }
  2992. //
  2993. // }
  2994. // }
  2995. // }
  2996. //}
  2997. //
  2998. //if json["execution_time"] != nil && reflect.TypeOf(json["execution_time"]).String() == "string" {
  2999. // execution_time, _ := strconv.ParseInt(json["execution_time"].(string), 10,64)
  3000. // advice.ExecutionTime = execution_time
  3001. //}
  3002. //
  3003. //
  3004. //
  3005. //if json["execution_staff"] != nil && reflect.TypeOf(json["execution_staff"]).String() == "string" {
  3006. // execution_staff, _ := strconv.ParseInt(json["execution_staff"].(string), 10,64)
  3007. // advice.ExecutionStaff = execution_staff
  3008. //}
  3009. //
  3010. //
  3011. //
  3012. //if json["execution_state"] != nil && reflect.TypeOf(json["execution_state"]).String() == "string" {
  3013. // execution_state, _ := strconv.ParseInt(json["execution_state"].(string), 10,64)
  3014. // advice.ExecutionState = execution_state
  3015. //}
  3016. //
  3017. //
  3018. //if json["check_time"] != nil && reflect.TypeOf(json["check_time"]).String() == "string" {
  3019. // check_time, _ := strconv.ParseInt(json["check_time"].(string), 10,64)
  3020. // advice.CheckTime = check_time
  3021. //}
  3022. //
  3023. //
  3024. //if json["check_state"] != nil && reflect.TypeOf(json["check_state"]).String() == "string" {
  3025. // check_state, _ := strconv.ParseInt(json["check_state"].(string), 10,64)
  3026. // advice.CheckState = check_state
  3027. //}
  3028. //
  3029. //
  3030. //if json["checker"] != nil && reflect.TypeOf(json["checker"]).String() == "string" {
  3031. // checker, _ := strconv.ParseInt(json["checker"].(string), 10,64)
  3032. // advice.Checker = checker
  3033. //}
  3034. //
  3035. //if json["start_time"] != nil && reflect.TypeOf(json["start_time"]).String() == "string" {
  3036. // start_time, _ := strconv.ParseInt(json["start_time"].(string), 10,64)
  3037. // advice.StartTime = start_time
  3038. //}
  3039. return 0
  3040. }
  3041. func (c *HisApiController) setProjectWithJSON(project *models.HisPrescriptionProject, json map[string]interface{}) int {
  3042. project.ExecutionStaff = 0
  3043. project.ExecutionState = 2
  3044. project.ExecutionTime = 0
  3045. project.Checker = 0
  3046. project.CheckState = 2
  3047. project.CheckTime = 0
  3048. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3049. id := int64(json["id"].(float64))
  3050. project.ID = id
  3051. temp_project, _ := service.GetHisPrescriptionProjectByID(id)
  3052. project.ExecutionStaff = temp_project.ExecutionStaff
  3053. project.ExecutionState = temp_project.ExecutionState
  3054. project.ExecutionTime = temp_project.ExecutionTime
  3055. project.Checker = temp_project.Checker
  3056. project.CheckState = temp_project.CheckState
  3057. project.CheckTime = temp_project.CheckTime
  3058. project.TeamId = temp_project.TeamId
  3059. }
  3060. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3061. types := int64(json["type"].(float64))
  3062. project.Type = types
  3063. }
  3064. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3065. project_id := int64(json["project_id"].(float64))
  3066. project.ProjectId = project_id
  3067. }
  3068. if json["team_id"] != nil && reflect.TypeOf(json["team_id"]).String() == "float64" {
  3069. team_id := int64(json["team_id"].(float64))
  3070. project.TeamId = team_id
  3071. }
  3072. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3073. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3074. project.Price = price
  3075. }
  3076. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3077. total, _ := json["total"].(string)
  3078. //totals, _ := strconv.ParseInt(total, 10, 64)
  3079. project.Count = total
  3080. }
  3081. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3082. medical_code, _ := json["medical_code"].(string)
  3083. project.MedListCodg = medical_code
  3084. }
  3085. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3086. single_dose, _ := json["single_dose"].(string)
  3087. project.SingleDose = single_dose
  3088. }
  3089. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3090. delivery_way, _ := json["delivery_way"].(string)
  3091. project.DeliveryWay = delivery_way
  3092. }
  3093. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3094. execution_frequency, _ := json["execution_frequency"].(string)
  3095. project.ExecutionFrequency = execution_frequency
  3096. }
  3097. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3098. remark, _ := json["remark"].(string)
  3099. project.Remark = remark
  3100. }
  3101. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3102. day, _ := json["number_days"].(string)
  3103. project.Day = day
  3104. }
  3105. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3106. unit, _ := json["unit"].(string)
  3107. project.Unit = unit
  3108. }
  3109. //if json["frequency_type"] != nil || reflect.TypeOf(json["frequency_type"]).String() == "float64" {
  3110. // frequency_type := int64(json["frequency_type"].(float64))
  3111. // project.FrequencyType = frequency_type
  3112. //}
  3113. //
  3114. //if json["day_count"] != nil || reflect.TypeOf(json["day_count"]).String() == "float64" {
  3115. // day_count := int64(json["day_count"].(float64))
  3116. // project.DayCount = day_count
  3117. //}
  3118. //
  3119. //if json["week_day"] != nil && reflect.TypeOf(json["week_day"]).String() == "string" {
  3120. // //week_day, _ := strconv.ParseFloat(json["week_day"].(string), 64)
  3121. // week_day, _ := json["week_day"].(string)
  3122. // project.WeekDay = week_day
  3123. //}
  3124. //_, stockConfig := service.FindAutomaticReduceRecordByOrgId(project.UserOrgId)
  3125. //
  3126. //if project.ID == 0 {
  3127. // if stockConfig.IsOpen == 1 {
  3128. // if project.Type == 3 {
  3129. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3130. // f_count, _ := strconv.ParseFloat(project.Count, 64)
  3131. // good.Total = good.Total - f_count
  3132. // service.UpdateGoodInfo(&good)
  3133. // }
  3134. // }
  3135. //
  3136. //} else {
  3137. // temp_project, _ := service.GetHisPrescriptionProjectByID(project.ID)
  3138. //
  3139. // if stockConfig.IsOpen == 1 {
  3140. // if project.Type == 3 {
  3141. // good, _ := service.FindGoodInfoByIdTwo(project.ProjectId)
  3142. // if project.Count < temp_project.Count {
  3143. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3144. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3145. //
  3146. // other_count := f_count_two - f_count_one
  3147. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3148. // good.Total = good.Total + other_count_two
  3149. // service.UpdateGoodInfo(&good)
  3150. // } else if project.Count > temp_project.Count {
  3151. // f_count_one, _ := strconv.ParseFloat(project.Count, 64)
  3152. // f_count_two, _ := strconv.ParseFloat(temp_project.Count, 64)
  3153. //
  3154. // other_count := f_count_one - f_count_two
  3155. // other_count_two, _ := strconv.ParseFloat(strconv.FormatInt(int64(other_count), 10), 64)
  3156. // good.Total = good.Total - other_count_two
  3157. // service.UpdateGoodInfo(&good)
  3158. // }
  3159. //
  3160. // }
  3161. // }
  3162. //
  3163. //}
  3164. return 0
  3165. }
  3166. func (c *HisApiController) setAddtionWithJSON(additionalCharge *models.HisAdditionalCharge, json map[string]interface{}, org_id int64) int {
  3167. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3168. id := int64(json["id"].(float64))
  3169. additionalCharge.ID = id
  3170. }
  3171. if json["item_id"] != nil || reflect.TypeOf(json["item_id"]).String() == "float64" {
  3172. item_id := int64(json["item_id"].(float64))
  3173. additionalCharge.ItemId = item_id
  3174. config, _ := service.GetAdditionChargeByID(org_id, item_id)
  3175. if config.ID > 0 {
  3176. if len(config.Code) > 0 {
  3177. additionalCharge.MedListCodg = config.Code
  3178. }
  3179. }
  3180. }
  3181. // if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3182. // price := int64(json["price"].(float64))
  3183. // formatInt_price := strconv.FormatInt(price, 10)
  3184. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3185. // additionalCharge.Price = float_price
  3186. // }
  3187. //if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "float64" {
  3188. // price := int64(json["price"].(float64))
  3189. // formatInt_price := strconv.FormatInt(price, 10)
  3190. // float_price, _ := strconv.ParseFloat(formatInt_price, 64)
  3191. // additionalCharge.Price = float_price
  3192. //}
  3193. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3194. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3195. additionalCharge.Price = price
  3196. }
  3197. if json["count"] != nil && reflect.TypeOf(json["count"]).String() == "string" {
  3198. count, _ := json["count"].(string)
  3199. counts, _ := strconv.ParseInt(count, 10, 64)
  3200. additionalCharge.Count = counts
  3201. }
  3202. if json["item_name"] != nil && reflect.TypeOf(json["item_name"]).String() == "string" {
  3203. item_name, _ := json["item_name"].(string)
  3204. additionalCharge.ItemName = item_name
  3205. }
  3206. return 0
  3207. }
  3208. func (c *HisApiController) setAdviceTemplateWithJSON(advice *models.HisPrescriptionAdviceTemplate, json map[string]interface{}) int {
  3209. if json["drug_name"] == nil || reflect.TypeOf(json["drug_name"]).String() != "string" {
  3210. utils.ErrorLog("drug_name")
  3211. return enums.ErrorCodeParamWrong
  3212. }
  3213. adviceName, _ := json["drug_name"].(string)
  3214. if len(adviceName) == 0 {
  3215. utils.ErrorLog("len(advice_name) == 0")
  3216. return enums.ErrorCodeParamWrong
  3217. }
  3218. advice.AdviceName = adviceName
  3219. adviceDesc, _ := json["advice_desc"].(string)
  3220. advice.AdviceDesc = adviceDesc
  3221. if json["drug_spec"] != nil && reflect.TypeOf(json["drug_spec"]).String() == "string" {
  3222. drugSpec, _ := strconv.ParseFloat(json["drug_spec"].(string), 64)
  3223. advice.DrugSpec = drugSpec
  3224. }
  3225. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3226. remark, _ := json["remark"].(string)
  3227. advice.Remark = remark
  3228. }
  3229. if json["id"] == nil {
  3230. advice.DrugId = 0
  3231. } else {
  3232. if json["id"] != nil || reflect.TypeOf(json["id"]).String() == "float64" {
  3233. drug_id := int64(json["id"].(float64))
  3234. advice.DrugId = drug_id
  3235. }
  3236. }
  3237. if json["min_unit"] != nil && reflect.TypeOf(json["min_unit"]).String() == "string" {
  3238. drugSpecUnit, _ := json["min_unit"].(string)
  3239. advice.DrugSpecUnit = drugSpecUnit
  3240. }
  3241. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3242. singleDose, _ := strconv.ParseFloat(json["single_dose"].(string), 64)
  3243. advice.SingleDose = singleDose
  3244. }
  3245. if json["single_dose_unit"] != nil && reflect.TypeOf(json["single_dose_unit"]).String() == "string" {
  3246. singleDoseUnit, _ := json["single_dose_unit"].(string)
  3247. advice.SingleDoseUnit = singleDoseUnit
  3248. }
  3249. if json["prescribing_number"] != nil && reflect.TypeOf(json["prescribing_number"]).String() == "string" {
  3250. prescribingNumber, _ := strconv.ParseFloat(json["prescribing_number"].(string), 64)
  3251. advice.PrescribingNumber = prescribingNumber
  3252. }
  3253. if json["prescribing_number_unit"] != nil && reflect.TypeOf(json["prescribing_number_unit"]).String() == "string" {
  3254. prescribingNumberUnit, _ := json["prescribing_number_unit"].(string)
  3255. advice.PrescribingNumberUnit = prescribingNumberUnit
  3256. }
  3257. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3258. deliveryWay, _ := json["delivery_way"].(string)
  3259. advice.DeliveryWay = deliveryWay
  3260. }
  3261. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3262. executionFrequency, _ := json["execution_frequency"].(string)
  3263. advice.ExecutionFrequency = executionFrequency
  3264. }
  3265. if json["retail_price"] != nil || reflect.TypeOf(json["retail_price"]).String() == "string" {
  3266. price, _ := strconv.ParseFloat(json["retail_price"].(string), 64)
  3267. advice.Price = price
  3268. }
  3269. if json["medical_insurance_number"] != nil || reflect.TypeOf(json["medical_insurance_number"]).String() == "string" {
  3270. med_list_codg, _ := json["medical_insurance_number"].(string)
  3271. advice.MedListCodg = med_list_codg
  3272. }
  3273. if json["day"] != nil || reflect.TypeOf(json["day"]).String() == "float64" {
  3274. day := int64(json["day"].(float64))
  3275. advice.Day = day
  3276. }
  3277. return 0
  3278. }
  3279. func (c *HisApiController) setProjectTemplateWithJSON(project *models.HisPrescriptionProjectTemplate, json map[string]interface{}) int {
  3280. if json["type"] != nil || reflect.TypeOf(json["type"]).String() == "float64" {
  3281. types := int64(json["type"].(float64))
  3282. project.Type = types
  3283. }
  3284. if json["project_id"] != nil || reflect.TypeOf(json["project_id"]).String() == "float64" {
  3285. project_id := int64(json["project_id"].(float64))
  3286. project.ProjectId = project_id
  3287. }
  3288. if json["price"] != nil || reflect.TypeOf(json["price"]).String() == "string" {
  3289. price, _ := strconv.ParseFloat(json["price"].(string), 64)
  3290. project.Price = price
  3291. }
  3292. if json["total"] != nil && reflect.TypeOf(json["total"]).String() == "string" {
  3293. total, _ := json["total"].(string)
  3294. //totals, _ := strconv.ParseInt(total, 10, 64)
  3295. project.Count = total
  3296. }
  3297. if json["medical_code"] != nil && reflect.TypeOf(json["medical_code"]).String() == "string" {
  3298. medical_code, _ := json["medical_code"].(string)
  3299. project.MedListCodg = medical_code
  3300. }
  3301. if json["single_dose"] != nil && reflect.TypeOf(json["single_dose"]).String() == "string" {
  3302. single_dose, _ := json["single_dose"].(string)
  3303. project.SingleDose = single_dose
  3304. }
  3305. if json["delivery_way"] != nil && reflect.TypeOf(json["delivery_way"]).String() == "string" {
  3306. delivery_way, _ := json["delivery_way"].(string)
  3307. project.DeliveryWay = delivery_way
  3308. }
  3309. if json["execution_frequency"] != nil && reflect.TypeOf(json["execution_frequency"]).String() == "string" {
  3310. execution_frequency, _ := json["execution_frequency"].(string)
  3311. project.ExecutionFrequency = execution_frequency
  3312. }
  3313. if json["remark"] != nil && reflect.TypeOf(json["remark"]).String() == "string" {
  3314. remark, _ := json["remark"].(string)
  3315. project.Remark = remark
  3316. }
  3317. if json["number_days"] != nil && reflect.TypeOf(json["number_days"]).String() == "string" {
  3318. day, _ := json["number_days"].(string)
  3319. project.Day = day
  3320. }
  3321. if json["unit"] != nil && reflect.TypeOf(json["unit"]).String() == "string" {
  3322. unit, _ := json["unit"].(string)
  3323. project.Unit = unit
  3324. }
  3325. return 0
  3326. }
  3327. func (c *HisApiController) GetHisOrderList() {
  3328. page, _ := c.GetInt64("page", -1)
  3329. limit, _ := c.GetInt64("limit", -1)
  3330. start_time := c.GetString("start_time")
  3331. end_time := c.GetString("end_time")
  3332. types, _ := c.GetInt64("type", 0)
  3333. keywords := c.GetString("keywords")
  3334. p_type, _ := c.GetInt64("p_type", 0)
  3335. sort_type, _ := c.GetInt64("sort_type", 0)
  3336. timeLayout := "2006-01-02"
  3337. loc, _ := time.LoadLocation("Local")
  3338. var startTime int64
  3339. if len(start_time) > 0 {
  3340. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  3341. if err != nil {
  3342. fmt.Println(err)
  3343. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3344. return
  3345. }
  3346. startTime = theTime.Unix()
  3347. }
  3348. var endTime int64
  3349. if len(end_time) > 0 {
  3350. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  3351. if err != nil {
  3352. utils.ErrorLog(err.Error())
  3353. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3354. return
  3355. }
  3356. endTime = theTime.Unix()
  3357. }
  3358. adminUser := c.GetAdminUserInfo()
  3359. org_id := adminUser.CurrentOrgId
  3360. order, err, total := service.GetHisOrderList(org_id, page, limit, startTime, endTime, types, keywords, p_type, sort_type, start_time, end_time)
  3361. for _, item := range order {
  3362. info, _ := service.GetHisPrescriptionByPatientID(item.PatientId, item.UserOrgId)
  3363. item.DoctorName = info.Doctor
  3364. item.DepartmentName = info.XtHisDepartment.Name
  3365. }
  3366. if err == nil {
  3367. c.ServeSuccessJSON(map[string]interface{}{
  3368. "order": order,
  3369. "total": total,
  3370. })
  3371. } else {
  3372. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3373. return
  3374. }
  3375. }
  3376. func (c *HisApiController) GetHisOrder() {
  3377. patient_id, _ := c.GetInt64("patient_id", 0)
  3378. number := c.GetString("number")
  3379. adminInfo := c.GetAdminUserInfo()
  3380. order, err := service.GetHisOrder(adminInfo.CurrentOrgId, number, patient_id)
  3381. prescriptions, _ := service.GetHisPrescriptionThree(adminInfo.CurrentOrgId, patient_id, order.Number)
  3382. if err == nil {
  3383. c.ServeSuccessJSON(map[string]interface{}{
  3384. "order": order,
  3385. "prescription": prescriptions,
  3386. })
  3387. } else {
  3388. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3389. return
  3390. }
  3391. }
  3392. func (c *HisApiController) GetHisPrescriptionList() {
  3393. record_date := c.GetString("record_date")
  3394. keywords := c.GetString("keywords")
  3395. page, _ := c.GetInt64("page")
  3396. limit, _ := c.GetInt64("limit")
  3397. timeLayout := "2006-01-02"
  3398. loc, _ := time.LoadLocation("Local")
  3399. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  3400. if err != nil {
  3401. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3402. return
  3403. }
  3404. recordDateTime := theTime.Unix()
  3405. adminInfo := c.GetAdminUserInfo()
  3406. prescriptionOrder, err, total := service.GetNewHisPatientPrescriptionList(adminInfo.CurrentOrgId, keywords, recordDateTime, page, limit)
  3407. //adminInfo := c.GetAdminUserInfo()
  3408. //prescriptionOrder, err := service.GetHisPrescriptionOrderList(adminInfo.CurrentOrgId)
  3409. //fmt.Println(prescriptionOrder)
  3410. if err == nil {
  3411. c.ServeSuccessJSON(map[string]interface{}{
  3412. "order": prescriptionOrder,
  3413. "total": total,
  3414. })
  3415. } else {
  3416. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3417. return
  3418. }
  3419. }
  3420. func (c *HisApiController) GetHisPrescriptionInfo() {
  3421. id, _ := c.GetInt64("id")
  3422. adminInfo := c.GetAdminUserInfo()
  3423. prescriptionOrder, err := service.GetHisPrescriptionOrderInfo(id, adminInfo.CurrentOrgId)
  3424. prescription, err := service.GetHisPrescriptionFour(adminInfo.CurrentOrgId, prescriptionOrder.PatientId, prescriptionOrder.RecordDate, prescriptionOrder.PrescriptionNumber)
  3425. if err == nil {
  3426. c.ServeSuccessJSON(map[string]interface{}{
  3427. "order": prescriptionOrder,
  3428. "prescription": prescription,
  3429. })
  3430. } else {
  3431. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  3432. return
  3433. }
  3434. }
  3435. func (c *HisApiController) GetMedicalInsuranceConfig() {
  3436. adminUser := c.GetAdminUserInfo()
  3437. config, _ := service.GetMedicalInsuranceConfig(adminUser.CurrentOrgId)
  3438. c.ServeSuccessJSON(map[string]interface{}{
  3439. "config": config,
  3440. })
  3441. }
  3442. type ResultTwo struct {
  3443. ErrMsg interface{} `json:"err_msg"`
  3444. InfRefmsgid string `json:"inf_refmsgid"`
  3445. Infcode int64 `json:"infcode"`
  3446. Output struct {
  3447. Baseinfo struct {
  3448. Age float64 `json:"age"`
  3449. Brdy string `json:"brdy"`
  3450. Certno string `json:"certno"`
  3451. Gend string `json:"gend"`
  3452. Naty string `json:"naty"`
  3453. PsnCertType string `json:"psn_cert_type"`
  3454. PsnName string `json:"psn_name"`
  3455. PsnNo string `json:"psn_no"`
  3456. } `json:"baseinfo"`
  3457. Idetinfo []interface{} `json:"idetinfo"`
  3458. Iinfo []struct {
  3459. Balc float64 `json:"balc"`
  3460. CvlservFlag string `json:"cvlserv_flag"`
  3461. EmpName string `json:"emp_name"`
  3462. InsuplcAdmdvs string `json:"insuplc_admdvs"`
  3463. Insutype string `json:"insutype"`
  3464. PausInsuDansuplcAdmdvs string `json:"paus_insu_dansuplc_admdvs"`
  3465. PausInsuDate interface{} `json:"paus_insu_date"`
  3466. PsnInsuDate string `json:"psn_insu_date"`
  3467. PsnInsuStas string `json:"psn_insu_stas"`
  3468. PsnType string `json:"psn_type"`
  3469. } `json:"insuinfo"`
  3470. } `json:"output"`
  3471. RefmsgTime string `json:"refmsg_time"`
  3472. RespondTime string `json:"respond_time"`
  3473. Signtype interface{} `json:"signtype"`
  3474. WarnInfo interface{} `json:"warn_info"`
  3475. }
  3476. type ResultThree struct {
  3477. Cainfo interface{} `json:"cainfo"`
  3478. ErrMsg interface{} `json:"err_msg"`
  3479. InfRefmsgid string `json:"inf_refmsgid"`
  3480. Infcode int64 `json:"infcode"`
  3481. Output struct {
  3482. Data struct {
  3483. IptOtpNo string `json:"ipt_otp_no"`
  3484. MdtrtID string `json:"mdtrt_id"`
  3485. PsnNo string `json:"psn_no"`
  3486. } `json:"data"`
  3487. } `json:"output"`
  3488. RefmsgTime string `json:"refmsg_time"`
  3489. RespondTime string `json:"respond_time"`
  3490. Signtype interface{} `json:"signtype"`
  3491. WarnMsg interface{} `json:"warn_msg"`
  3492. }
  3493. type ResultFour struct {
  3494. Cainfo string `json:"cainfo"`
  3495. ErrMsg string `json:"err_msg"`
  3496. InfRefmsgid string `json:"inf_refmsgid"`
  3497. Infcode int64 `json:"infcode"`
  3498. Output struct {
  3499. Result []struct {
  3500. BasMednFlag string `json:"bas_medn_flag"`
  3501. ChldMedcFlag string `json:"chld_medc_flag"`
  3502. ChrgitmLv string `json:"chrgitm_lv"`
  3503. Cnt float64 `json:"cnt"`
  3504. DetItemFeeSumamt float64 `json:"det_item_fee_sumamt"`
  3505. DrtReimFlag string `json:"drt_reim_flag"`
  3506. FeedetlSn string `json:"feedetl_sn"`
  3507. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3508. HiNegoDrugFlag string `json:"hi_nego_drug_flag"`
  3509. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3510. ListSpItemFlag string `json:"list_sp_item_flag"`
  3511. LmtUsedFlag string `json:"lmt_used_flag"`
  3512. MedChrgitmType string `json:"med_chrgitm_type"`
  3513. Memo string `json:"memo"`
  3514. OverlmtAmt float64 `json:"overlmt_amt"`
  3515. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3516. Pric float64 `json:"pric"`
  3517. PricUplmtAmt float64 `json:"pric_uplmt_amt"`
  3518. SelfpayProp float64 `json:"selfpay_prop"`
  3519. } `json:"result"`
  3520. } `json:"output"`
  3521. RefmsgTime string `json:"refmsg_time"`
  3522. RespondTime string `json:"respond_time"`
  3523. Signtype string `json:"signtype"`
  3524. WarnMsg string `json:"warn_msg"`
  3525. }
  3526. type ResultFive struct {
  3527. Insutype string `json:"insutype"`
  3528. }
  3529. type ResultSix struct {
  3530. Cainfo interface{} `json:"cainfo"`
  3531. ErrMsg interface{} `json:"err_msg"`
  3532. InfRefmsgid string `json:"inf_refmsgid"`
  3533. Infcode int64 `json:"infcode"`
  3534. Output struct {
  3535. } `json:"output"`
  3536. RefmsgTime string `json:"refmsg_time"`
  3537. RespondTime string `json:"respond_time"`
  3538. Signtype interface{} `json:"signtype"`
  3539. WarnMsg interface{} `json:"warn_msg"`
  3540. }
  3541. type ResultSeven struct {
  3542. Cainfo string `json:"cainfo"`
  3543. ErrMsg string `json:"err_msg"`
  3544. InfRefmsgid string `json:"inf_refmsgid"`
  3545. Infcode int64 `json:"infcode"`
  3546. Output struct {
  3547. Setldetail []interface{} `json:"setldetail"`
  3548. Setlinfo struct {
  3549. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3550. AcctPay float64 `json:"acct_pay"`
  3551. ActPayDedc float64 `json:"act_pay_dedc"`
  3552. Age float64 `json:"age"`
  3553. Balc float64 `json:"balc"`
  3554. Brdy string `json:"brdy"`
  3555. Certno string `json:"certno"`
  3556. ClrOptins string `json:"clr_optins"`
  3557. ClrType string `json:"clr_type"`
  3558. ClrWay string `json:"clr_way"`
  3559. CvlservFlag string `json:"cvlserv_flag"`
  3560. CvlservPay float64 `json:"cvlserv_pay"`
  3561. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3562. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3563. Gend string `json:"gend"`
  3564. HifesPay float64 `json:"hifes_pay"`
  3565. HifmiPay float64 `json:"hifmi_pay"`
  3566. HifobPay float64 `json:"hifob_pay"`
  3567. HifpPay float64 `json:"hifp_pay"`
  3568. HospPartAmt float64 `json:"hosp_part_amt"`
  3569. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3570. Insutype string `json:"insutype"`
  3571. MafPay float64 `json:"maf_pay"`
  3572. MdtrtCertType string `json:"mdtrt_cert_type"`
  3573. MdtrtID string `json:"mdtrt_id"`
  3574. MedType string `json:"med_type"`
  3575. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3576. MedinsSetlID string `json:"medins_setl_id"`
  3577. Naty string `json:"naty"`
  3578. OthPay float64 `json:"oth_pay"`
  3579. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3580. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3581. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3582. PsnCashPay float64 `json:"psn_cash_pay"`
  3583. PsnCertType string `json:"psn_cert_type"`
  3584. PsnName string `json:"psn_name"`
  3585. PsnNo string `json:"psn_no"`
  3586. PsnPartAmt float64 `json:"psn_part_amt"`
  3587. PsnType string `json:"psn_type"`
  3588. SetlID string `json:"setl_id"`
  3589. SetlTime string `json:"setl_time"`
  3590. } `json:"setlinfo"`
  3591. } `json:"output"`
  3592. RefmsgTime string `json:"refmsg_time"`
  3593. RespondTime string `json:"respond_time"`
  3594. Signtype interface{} `json:"signtype"`
  3595. WarnMsg interface{} `json:"warn_msg"`
  3596. }
  3597. type ResultEight struct {
  3598. Cainfo string `json:"cainfo"`
  3599. ErrMsg string `json:"err_msg"`
  3600. InfRefmsgid string `json:"inf_refmsgid"`
  3601. Infcode int64 `json:"infcode"`
  3602. Output struct {
  3603. Stmtinfo struct {
  3604. SetlOptins string `json:"setl_optins"`
  3605. StmtRslt string `json:"stmt_rslt"`
  3606. StmtRsltDscr string `json:"stmt_rslt_dscr"`
  3607. } `json:"stmtinfo"`
  3608. } `json:"output"`
  3609. RefmsgTime string `json:"refmsg_time"`
  3610. RespondTime string `json:"respond_time"`
  3611. Signtype interface{} `json:"signtype"`
  3612. WarnMsg interface{} `json:"warn_msg"`
  3613. }
  3614. type ResultNine struct {
  3615. Cainfo string `json:"cainfo"`
  3616. ErrMsg string `json:"err_msg"`
  3617. InfRefmsgid string `json:"inf_refmsgid"`
  3618. Infcode int64 `json:"infcode"`
  3619. Output struct {
  3620. FileQuryNo string `json:"file_qury_no"`
  3621. } `json:"output"`
  3622. RefmsgTime string `json:"refmsg_time"`
  3623. RespondTime string `json:"respond_time"`
  3624. Signtype interface{} `json:"signtype"`
  3625. WarnMsg interface{} `json:"warn_msg"`
  3626. }
  3627. type ResultTen struct {
  3628. Cainfo string `json:"cainfo"`
  3629. ErrMsg string `json:"err_msg"`
  3630. InfRefmsgid string `json:"inf_refmsgid"`
  3631. Infcode int64 `json:"infcode"`
  3632. Output struct {
  3633. DldEndtime string `json:"dld_endtime"`
  3634. FileQuryNo string `json:"file_qury_no"`
  3635. Filename string `json:"filename"`
  3636. } `json:"output"`
  3637. RefmsgTime string `json:"refmsg_time"`
  3638. RespondTime string `json:"respond_time"`
  3639. Signtype interface{} `json:"signtype"`
  3640. WarnMsg interface{} `json:"warn_msg"`
  3641. }
  3642. type ResultEleven struct {
  3643. Cainfo string `json:"cainfo"`
  3644. ErrMsg string `json:"err_msg"`
  3645. InfRefmsgid string `json:"inf_refmsgid"`
  3646. Infcode int64 `json:"infcode"`
  3647. Output struct {
  3648. Setlinfo struct {
  3649. FixmedinsName string `json:"fixmedins_name"`
  3650. FixmedinsCode string `json:"fixmedins_code"`
  3651. PsnNo string `json:"psn_no"`
  3652. PsnName string `json:"psn_name"`
  3653. HifobPay float64 `json:"hifob_pay"`
  3654. Gend string `json:"gend"`
  3655. Brdy string `json:"brdy"`
  3656. PsnCertType string `json:"psn_cert_type"`
  3657. PsnType string `json:"psn_type"`
  3658. EmpName string `json:"emp_name"`
  3659. Certno string `json:"certno"`
  3660. Insutype string `json:"insutype"`
  3661. MedfeeSumamt float64 `json:"medfee_sumamt"`
  3662. FulamtOwnpayAmt float64 `json:"fulamt_ownpay_amt"`
  3663. OverlmtSelfpay float64 `json:"overlmt_selfpay"`
  3664. PreselfpayAmt float64 `json:"preselfpay_amt"`
  3665. InscpScpAmt float64 `json:"inscp_scp_amt"`
  3666. ActPayDedc float64 `json:"act_pay_dedc"`
  3667. HifpPay float64 `json:"hifp_pay"`
  3668. PoolPropSelfpay float64 `json:"pool_prop_selfpay"`
  3669. CvlservPay float64 `json:"cvlserv_pay"`
  3670. HifesPay float64 `json:"hifes_pay"`
  3671. HifmiPay float64 `json:"hifmi_pay"`
  3672. MafPay float64 `json:"maf_pay"`
  3673. OthPay float64 `json:"oth_pay"`
  3674. FundPaySumamt float64 `json:"fund_pay_sumamt"`
  3675. PsnPay float64 `json:"psn_pay"`
  3676. AcctPay float64 `json:"acct_pay"`
  3677. CashPayamt float64 `json:"cash_payamt"`
  3678. Balc float64 `json:"balc"`
  3679. AcctMulaidPay float64 `json:"acct_mulaid_pay"`
  3680. MedinsSetlId string `json:"medins_setl_id"`
  3681. RefdSetlFlag string `json:"refd_setl_flag"`
  3682. SetlTime string `json:"setl_time"`
  3683. MedType string `json:"med_type"`
  3684. } `json:"setlinfo"`
  3685. } `json:"output"`
  3686. RefmsgTime string `json:"refmsg_time"`
  3687. RespondTime string `json:"respond_time"`
  3688. Signtype interface{} `json:"signtype"`
  3689. WarnMsg interface{} `json:"warn_msg"`
  3690. }
  3691. type Custom struct {
  3692. DetItemFeeSumamt string
  3693. Cut string
  3694. FeedetlSn string
  3695. Price string
  3696. MedListCodg string
  3697. Type int64
  3698. AdviceId int64
  3699. ProjectId int64
  3700. ItemId int64
  3701. }
  3702. //获取个人信息----挂号-----上传就诊信息
  3703. func (c *HisApiController) GetRegisterInfo() {
  3704. id, _ := c.GetInt64("id")
  3705. record_time := c.GetString("record_time")
  3706. settlementValue, _ := c.GetInt64("settlement_value")
  3707. medical_insurance_card := c.GetString("medical_insurance_card")
  3708. name := c.GetString("name")
  3709. id_card_type, _ := c.GetInt64("id_card_type")
  3710. certificates, _ := c.GetInt64("certificates")
  3711. medical_care, _ := c.GetInt64("medical_care")
  3712. birthday := c.GetString("birthday")
  3713. age, _ := c.GetInt64("age")
  3714. id_card := c.GetString("id_card")
  3715. register_type, _ := c.GetInt64("register")
  3716. doctor, _ := c.GetInt64("doctor")
  3717. department, _ := c.GetInt64("department")
  3718. gender, _ := c.GetInt64("sex")
  3719. phone := c.GetString("phone")
  3720. registration_fee, _ := c.GetFloat("registration_fee")
  3721. medical_expenses, _ := c.GetFloat("medical_expenses")
  3722. social_type, _ := c.GetInt64("social_type")
  3723. //diagnosis_id, _ := c.GetInt64("diagnosis")
  3724. diagnosis_ids := c.GetString("diagnosis")
  3725. sick_type, _ := c.GetInt64("sick_type")
  3726. reg_type := c.GetString("p_type")
  3727. timeLayout := "2006-01-02"
  3728. loc, _ := time.LoadLocation("Local")
  3729. birthdays, _ := time.ParseInLocation(timeLayout+" 15:04:05", birthday+" 00:00:00", loc)
  3730. birthUnix := birthdays.Unix()
  3731. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3732. if err != nil {
  3733. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3734. return
  3735. }
  3736. recordDateTime := theTime.Unix()
  3737. adminInfo := c.GetAdminUserInfo()
  3738. tempPatient, _ := service.GetPatientByIDCardAndName(id_card, adminInfo.CurrentOrgId, name)
  3739. if tempPatient.ID == 0 {
  3740. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNoBloodPatientException)
  3741. return
  3742. }
  3743. var patient service.Patients
  3744. if id == 0 {
  3745. patient, _ = service.GetPatientByIDCard(id_card, adminInfo.CurrentOrgId)
  3746. } else {
  3747. patient, _ = service.GetPatientByIDTwo(adminInfo.CurrentOrgId, id)
  3748. }
  3749. if patient.ID == 0 {
  3750. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePatientNoExist)
  3751. return
  3752. }
  3753. if len(patient.IdCardNo) == 0 {
  3754. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeIDCartNo)
  3755. return
  3756. }
  3757. his, _ := service.GetHisPatientInfoTwo(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3758. if len(his) >= 1 {
  3759. order, _ := service.GetNewHisOrderTwo(adminInfo.CurrentOrgId, his[len(his)-1].Number, his[len(his)-1].PatientId, recordDateTime)
  3760. if len(his) >= 1 && order.ID == 0 {
  3761. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeHisPatientParamWrong)
  3762. return
  3763. }
  3764. }
  3765. timeStr := time.Now().Format("2006-01-02 15:04:05")
  3766. fmt.Println(timeStr)
  3767. timeArr := strings.Split(timeStr, " ")
  3768. fmt.Println(timeArr)
  3769. timeArrTwo := strings.Split(timeArr[0], "-")
  3770. timeArrThree := strings.Split(timeArr[1], ":")
  3771. var str = timeArrTwo[0] + timeArrTwo[1] + timeArrTwo[2] + timeArrThree[0] + timeArrThree[1] + timeArrThree[2] + strconv.FormatInt(patient.ID, 10)
  3772. lists, _ := service.GetHisPatientInfoList(adminInfo.CurrentOrgId, patient.ID, recordDateTime)
  3773. if len(lists) == 0 {
  3774. var hisPatient models.XtHisPatient
  3775. hisPatient = models.XtHisPatient{
  3776. Name: name,
  3777. Age: age,
  3778. Gender: gender,
  3779. Birthday: birthUnix,
  3780. Phone: phone,
  3781. MedicalTreatmentType: medical_care,
  3782. IdType: certificates,
  3783. IdCardNo: id_card,
  3784. BalanceAccountsType: settlementValue,
  3785. SocialType: social_type,
  3786. MedicalInsuranceNumber: medical_insurance_card,
  3787. RegisterType: register_type,
  3788. RegisterCost: registration_fee,
  3789. TreatmentCost: medical_expenses,
  3790. AdminUserId: adminInfo.AdminUser.Id,
  3791. UserOrgId: adminInfo.CurrentOrgId,
  3792. Status: 1,
  3793. RecordDate: recordDateTime,
  3794. IsReturn: 1,
  3795. PatientId: patient.ID,
  3796. Ctime: time.Now().Unix(),
  3797. Mtime: time.Now().Unix(),
  3798. Number: str,
  3799. IdCardType: id_card_type,
  3800. Departments: department,
  3801. Doctor: doctor,
  3802. PType: reg_type,
  3803. Diagnosis: diagnosis_ids,
  3804. SickType: sick_type,
  3805. }
  3806. service.CreateHisPatient(&hisPatient)
  3807. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3808. c.ServeSuccessJSON(map[string]interface{}{
  3809. "his_info": hisPatient,
  3810. })
  3811. } else {
  3812. //chrgBchno := rand.Intn(1000000) + 10000
  3813. var hisPatient models.XtHisPatient
  3814. hisPatient = models.XtHisPatient{
  3815. Name: name,
  3816. Age: age,
  3817. Gender: gender,
  3818. Birthday: birthUnix,
  3819. Phone: phone,
  3820. MedicalTreatmentType: medical_care,
  3821. IdType: certificates,
  3822. IdCardNo: id_card,
  3823. BalanceAccountsType: settlementValue,
  3824. SocialType: social_type,
  3825. MedicalInsuranceNumber: medical_insurance_card,
  3826. RegisterType: register_type,
  3827. RegisterCost: registration_fee,
  3828. TreatmentCost: medical_expenses,
  3829. AdminUserId: adminInfo.AdminUser.Id,
  3830. UserOrgId: adminInfo.CurrentOrgId,
  3831. Status: 1,
  3832. RecordDate: recordDateTime,
  3833. IsReturn: 1,
  3834. PatientId: patient.ID,
  3835. Ctime: time.Now().Unix(),
  3836. Mtime: time.Now().Unix(),
  3837. Number: str,
  3838. IdCardType: id_card_type,
  3839. Departments: department,
  3840. Doctor: doctor,
  3841. PType: reg_type,
  3842. Diagnosis: diagnosis_ids,
  3843. SickType: sick_type,
  3844. }
  3845. service.CreateHisPatient(&hisPatient)
  3846. service.UpdateHisPrescriptionHisID(hisPatient.ID, patient.ID, recordDateTime, adminInfo.CurrentOrgId)
  3847. c.ServeSuccessJSON(map[string]interface{}{
  3848. "his_info": hisPatient,
  3849. })
  3850. }
  3851. }
  3852. //上传明细----结算
  3853. func (c *HisApiController) GetUploadInfo() {
  3854. id, _ := c.GetInt64("id")
  3855. record_time := c.GetString("record_time")
  3856. his_patient_id, _ := c.GetInt64("his_patient_id")
  3857. pay_way, _ := c.GetInt64("pay_way")
  3858. pay_price, _ := c.GetFloat("pay_price")
  3859. pay_card_no := c.GetString("pay_card_no")
  3860. discount_price, _ := c.GetFloat("discount_price")
  3861. preferential_price, _ := c.GetFloat("preferential_price")
  3862. reality_price, _ := c.GetFloat("reality_price")
  3863. found_price, _ := c.GetFloat("found_price")
  3864. medical_insurance_price, _ := c.GetFloat("medical_insurance_price")
  3865. private_price, _ := c.GetFloat("private_price")
  3866. timeLayout := "2006-01-02"
  3867. loc, _ := time.LoadLocation("Local")
  3868. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  3869. fapiao_code := c.GetString("fapiao_code")
  3870. fapiao_number := c.GetString("fapiao_number")
  3871. diagnosis_id := c.GetString("diagnosis")
  3872. sick_type, _ := c.GetInt64("sick_type")
  3873. reg_type, _ := c.GetInt64("p_type")
  3874. order_id, _ := c.GetInt64("order_id")
  3875. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  3876. tempOrder, _ := service.GetHisOrderByID(order_id)
  3877. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  3878. if err != nil {
  3879. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3880. return
  3881. }
  3882. recordDateTime := theTime.Unix()
  3883. adminUser := c.GetAdminUserInfo()
  3884. var prescriptions []*models.HisPrescription
  3885. var start_time int64
  3886. var end_time int64
  3887. ids_str := c.GetString("ids")
  3888. ids_arr := strings.Split(ids_str, ",")
  3889. if tempOrder.ID == 0 {
  3890. if settle_accounts_type == 1 { //日结
  3891. fmt.Println(reg_type)
  3892. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  3893. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  3894. } else {
  3895. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  3896. }
  3897. } else { //月结
  3898. start_time_str := c.GetString("start_time")
  3899. end_time_str := c.GetString("end_time")
  3900. timeLayout := "2006-01-02"
  3901. loc, _ := time.LoadLocation("Local")
  3902. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  3903. if err != nil {
  3904. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3905. return
  3906. }
  3907. recordStartTime := theStartTime.Unix()
  3908. start_time = recordStartTime
  3909. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  3910. if err != nil {
  3911. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  3912. return
  3913. }
  3914. recordEndTime := theEndTime.Unix()
  3915. end_time = recordEndTime
  3916. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  3917. }
  3918. timestamp := time.Now().Unix()
  3919. tempTime := time.Unix(timestamp, 0)
  3920. timeFormat := tempTime.Format("20060102150405")
  3921. chrgBchno := rand.Intn(100000) + 10000
  3922. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  3923. strconv.FormatInt(his.PatientId, 10)
  3924. var ids []int64
  3925. for _, item := range prescriptions {
  3926. ids = append(ids, item.ID)
  3927. }
  3928. var total float64
  3929. for _, item := range prescriptions {
  3930. fmt.Println(item)
  3931. if item.Type == 1 { //药品
  3932. for _, subItem := range item.HisDoctorAdviceInfo {
  3933. total = total + (subItem.Price * subItem.PrescribingNumber)
  3934. }
  3935. }
  3936. if item.Type == 2 { //项目
  3937. for _, subItem := range item.HisPrescriptionProject {
  3938. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  3939. total = total + (subItem.Price * cnt)
  3940. }
  3941. }
  3942. for _, subItem := range item.HisAdditionalCharge {
  3943. total = total + (subItem.Price * float64(subItem.Count))
  3944. }
  3945. }
  3946. if reg_type == 1111 || reg_type == 1112 {
  3947. reg_type = 11
  3948. }
  3949. allTotal := fmt.Sprintf("%.4f", total)
  3950. totals, _ := strconv.ParseFloat(allTotal, 64)
  3951. order := &models.HisOrder{
  3952. UserOrgId: adminUser.CurrentOrgId,
  3953. HisPatientId: his.ID,
  3954. PatientId: id,
  3955. SettleAccountsDate: recordDateTime,
  3956. Ctime: time.Now().Unix(),
  3957. Mtime: time.Now().Unix(),
  3958. Status: 1,
  3959. OrderStatus: 2,
  3960. MdtrtId: his.Number,
  3961. Number: chrg_bchno,
  3962. MedfeeSumamt: totals,
  3963. PayWay: pay_way,
  3964. PayPrice: pay_price,
  3965. MedType: strconv.Itoa(int(reg_type)),
  3966. PayCardNo: pay_card_no,
  3967. DiscountPrice: discount_price,
  3968. PreferentialPrice: preferential_price,
  3969. RealityPrice: reality_price,
  3970. FoundPrice: found_price,
  3971. MedicalInsurancePrice: medical_insurance_price,
  3972. PrivatePrice: private_price,
  3973. SettleEndTime: end_time,
  3974. SettleStartTime: start_time,
  3975. SettleType: settle_accounts_type,
  3976. FaPiaoCode: fapiao_code,
  3977. FaPiaoNumber: fapiao_number,
  3978. Diagnosis: diagnosis_id,
  3979. PType: 2,
  3980. //SetlTime: t
  3981. }
  3982. err = service.CreateOrder(order)
  3983. if err != nil {
  3984. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  3985. return
  3986. }
  3987. var customs []*Custom
  3988. for _, item := range prescriptions {
  3989. if item.Type == 1 { //药品
  3990. for _, subItem := range item.HisDoctorAdviceInfo {
  3991. cus := &Custom{
  3992. AdviceId: subItem.ID,
  3993. ProjectId: 0,
  3994. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*subItem.PrescribingNumber),
  3995. Cut: fmt.Sprintf("%.4f", subItem.PrescribingNumber),
  3996. FeedetlSn: subItem.FeedetlSn,
  3997. Price: fmt.Sprintf("%.2f", subItem.Price),
  3998. MedListCodg: subItem.MedListCodg,
  3999. Type: 1,
  4000. }
  4001. customs = append(customs, cus)
  4002. }
  4003. }
  4004. if item.Type == 2 { //项目
  4005. for _, subItem := range item.HisPrescriptionProject {
  4006. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  4007. cus := &Custom{
  4008. AdviceId: 0,
  4009. ProjectId: subItem.ID,
  4010. DetItemFeeSumamt: fmt.Sprintf("%.4f", subItem.Price*cnt),
  4011. Cut: fmt.Sprintf("%.4f", cnt),
  4012. FeedetlSn: subItem.FeedetlSn,
  4013. Price: fmt.Sprintf("%.4f", float64(subItem.Price)),
  4014. MedListCodg: subItem.MedListCodg,
  4015. Type: 2,
  4016. }
  4017. customs = append(customs, cus)
  4018. }
  4019. }
  4020. for _, item := range item.HisAdditionalCharge {
  4021. cus := &Custom{
  4022. ItemId: item.ID,
  4023. AdviceId: 0,
  4024. ProjectId: 0,
  4025. DetItemFeeSumamt: fmt.Sprintf("%.4f", item.Price),
  4026. Cut: fmt.Sprintf("%.4f", float64(item.Count)),
  4027. FeedetlSn: item.FeedetlSn,
  4028. Price: fmt.Sprintf("%.4f", float64(item.Price)),
  4029. MedListCodg: item.XtHisAddtionConfig.Code,
  4030. Type: 3,
  4031. }
  4032. customs = append(customs, cus)
  4033. }
  4034. }
  4035. for _, item := range customs {
  4036. var advice_id int64 = 0
  4037. var project_id int64 = 0
  4038. var item_id int64 = 0
  4039. var types int64 = 0
  4040. if item.Type == 1 {
  4041. advice_id = item.AdviceId
  4042. project_id = 0
  4043. item_id = 0
  4044. } else if item.Type == 2 {
  4045. advice_id = 0
  4046. item_id = 0
  4047. project_id = item.ProjectId
  4048. } else if item.Type == 3 {
  4049. advice_id = 0
  4050. item_id = item.ItemId
  4051. project_id = 0
  4052. }
  4053. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  4054. cut, _ := strconv.ParseFloat(item.Cut, 32)
  4055. pric, _ := strconv.ParseFloat(item.Price, 32)
  4056. info := &models.HisOrderInfo{
  4057. OrderNumber: order.Number,
  4058. UploadDate: time.Now().Unix(),
  4059. AdviceId: advice_id,
  4060. DetItemFeeSumamt: detItemFeeSumamt,
  4061. Cnt: cut,
  4062. Pric: pric,
  4063. PatientId: id,
  4064. Status: 1,
  4065. Mtime: time.Now().Unix(),
  4066. Ctime: time.Now().Unix(),
  4067. UserOrgId: adminUser.CurrentOrgId,
  4068. HisPatientId: his.ID,
  4069. OrderId: order.ID,
  4070. ProjectId: project_id,
  4071. Type: types,
  4072. ItemId: item_id,
  4073. }
  4074. service.CreateOrderInfo(info)
  4075. }
  4076. his.Diagnosis = diagnosis_id
  4077. his.SickType = sick_type
  4078. his.RegisterType = reg_type
  4079. his.MedicalTreatmentType = reg_type
  4080. service.UpdataHisPateint(&his)
  4081. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  4082. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  4083. err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  4084. if err == nil {
  4085. c.ServeSuccessJSON(map[string]interface{}{
  4086. "msg": "结算成功",
  4087. })
  4088. }
  4089. } else {
  4090. if tempOrder.IsPre > 0 {
  4091. allTotal := fmt.Sprintf("%.2f", tempOrder.MedfeeSumamt)
  4092. totals, _ := strconv.ParseFloat(allTotal, 64)
  4093. tempOrder.OrderStatus = 2
  4094. tempOrder.PayWay = pay_way
  4095. tempOrder.PayPrice = pay_price
  4096. tempOrder.PayCardNo = pay_card_no
  4097. tempOrder.DiscountPrice = discount_price
  4098. tempOrder.PreferentialPrice = preferential_price
  4099. tempOrder.RealityPrice = reality_price
  4100. tempOrder.FoundPrice = found_price
  4101. tempOrder.MedicalInsurancePrice = medical_insurance_price
  4102. tempOrder.PrivatePrice = private_price
  4103. tempOrder.FaPiaoCode = fapiao_code
  4104. tempOrder.FaPiaoNumber = fapiao_number
  4105. tempOrder.PType = 2
  4106. tempOrder.MedfeeSumamt = totals
  4107. tempOrder.Diagnosis = diagnosis_id
  4108. err = service.SaveHisOrder(&tempOrder)
  4109. err = service.UpdataOrderStatusTwo(tempOrder.Number, adminUser.CurrentOrgId)
  4110. if err != nil {
  4111. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  4112. return
  4113. }
  4114. if err == nil {
  4115. c.ServeSuccessJSON(map[string]interface{}{
  4116. "msg": "结算成功",
  4117. })
  4118. }
  4119. }
  4120. }
  4121. }
  4122. //退款
  4123. func (c *HisApiController) Refund() {
  4124. order_id, _ := c.GetInt64("order_id")
  4125. order, _ := service.GetHisOrderByID(order_id)
  4126. adminUser := c.GetAdminUserInfo()
  4127. err := service.UpdataOrderStatus(order_id, order.Number, adminUser.CurrentOrgId)
  4128. if err == nil {
  4129. c.ServeSuccessJSON(map[string]interface{}{
  4130. "msg": "退费成功",
  4131. })
  4132. } else {
  4133. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4134. return
  4135. }
  4136. }
  4137. func (c *HisApiController) RefundNumber() {
  4138. his_patient_id, _ := c.GetInt64("id")
  4139. info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4140. info.Status = 0
  4141. count, _ := service.GetOrderCountByNumber(c.GetAdminUserInfo().CurrentOrgId, info.PatientId, info.RecordDate, info.Number)
  4142. if count > 0 {
  4143. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrongTwo)
  4144. return
  4145. }
  4146. err := service.SaveHisPatient(info)
  4147. if err == nil {
  4148. c.ServeSuccessJSON(map[string]interface{}{
  4149. "msg": "退号成功",
  4150. })
  4151. } else {
  4152. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4153. return
  4154. }
  4155. }
  4156. func (this *HisApiController) AdditionalCharge() {
  4157. dataBody := make(map[string]interface{}, 0)
  4158. err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  4159. fmt.Println(err)
  4160. his_patient_id := int64(dataBody["his_patient_id"].(float64))
  4161. patient_id := int64(dataBody["patient_id"].(float64))
  4162. medicineData, _ := dataBody["medicineData"].([]interface{})
  4163. adminUserInfo := this.GetAdminUserInfo()
  4164. orgId := adminUserInfo.CurrentOrgId
  4165. admin_user_id := adminUserInfo.AdminUser.Id
  4166. timeStr := time.Now().Format("2006-01-02")
  4167. timeLayout := "2006-01-02 15:04:05"
  4168. timeStringToTime, _ := utils.ParseTimeStringToTime(timeLayout, timeStr+" 00:00:00")
  4169. timenow := timeStringToTime.Unix()
  4170. var additionalCharges []*models.HisAdditionalCharge
  4171. for _, item := range medicineData {
  4172. var randNum int
  4173. randNum = rand.Intn(10000) + 1000
  4174. timestamp := time.Now().Unix()
  4175. tempTime := time.Unix(timestamp, 0)
  4176. timeFormat := tempTime.Format("20060102150405")
  4177. p_number := timeFormat + strconv.FormatInt(int64(randNum), 10) + strconv.FormatInt(int64(adminUserInfo.CurrentOrgId), 10) + strconv.FormatInt(int64(patient_id), 10)
  4178. items := item.(map[string]interface{})
  4179. money := items["price"].(string)
  4180. item_id_str := items["item_id"].(string)
  4181. name := items["name"].(string)
  4182. id_str := items["id"].(string)
  4183. moneys, _ := strconv.ParseInt(money, 10, 64)
  4184. monStr := strconv.FormatInt(moneys, 10)
  4185. monneyStr, _ := strconv.ParseFloat(monStr, 64)
  4186. item_id, _ := strconv.ParseInt(item_id_str, 10, 64)
  4187. id, _ := strconv.ParseInt(id_str, 10, 64)
  4188. additionalCharge := &models.HisAdditionalCharge{
  4189. ID: id,
  4190. HisPatientId: his_patient_id,
  4191. UserOrgId: orgId,
  4192. PatientId: patient_id,
  4193. RecordDate: timenow,
  4194. Price: monneyStr,
  4195. Status: 1,
  4196. ItemName: name,
  4197. ItemId: item_id,
  4198. AdminUserId: admin_user_id,
  4199. CreatedTime: time.Now().Unix(),
  4200. OrderStatus: 0,
  4201. PrescriptionNumber: "",
  4202. BatchNumber: "",
  4203. FeedetlSn: p_number,
  4204. }
  4205. service.CreateAdditionalCharge(additionalCharge)
  4206. additionalCharges = append(additionalCharges, additionalCharge)
  4207. }
  4208. this.ServeSuccessJSON(map[string]interface{}{
  4209. "msg": "添加成功",
  4210. "additional_charges": additionalCharges,
  4211. })
  4212. }
  4213. func (this *HisApiController) DeleteAddition() {
  4214. id, _ := this.GetInt64("id")
  4215. //TODO 需要判断是否已经结算
  4216. err := service.DelelteAddition(id, this.GetAdminUserInfo().CurrentOrgId)
  4217. if err == nil {
  4218. this.ServeSuccessJSON(map[string]interface{}{
  4219. "msg": "删除成功",
  4220. })
  4221. return
  4222. } else {
  4223. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4224. return
  4225. }
  4226. }
  4227. func (this *HisApiController) GetAdminUsers() {
  4228. adminUser := this.GetAdminUserInfo()
  4229. doctors, _ := service.GetAllHisDoctor(adminUser.CurrentOrgId)
  4230. this.ServeSuccessJSON(map[string]interface{}{
  4231. "doctors": doctors,
  4232. })
  4233. }
  4234. func (this *HisApiController) GetLastOrNextHisPrescription() {
  4235. change_type, _ := this.GetInt64("type", 0)
  4236. record_date := this.GetString("record_time")
  4237. patient_id, _ := this.GetInt64("patient_id", 0)
  4238. p_type, _ := this.GetInt64("p_type", 0)
  4239. timeLayout := "2006-01-02"
  4240. loc, _ := time.LoadLocation("Local")
  4241. theAdviceRecordTime, _ := time.ParseInLocation(timeLayout, record_date, loc)
  4242. record_time := theAdviceRecordTime.Unix()
  4243. adminUserInfo := this.GetAdminUserInfo()
  4244. prescriptions, err := service.GetHisPrescriptionByType(change_type, record_time, adminUserInfo.CurrentOrgId, patient_id, p_type)
  4245. if err == nil {
  4246. if len(prescriptions) == 0 {
  4247. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDoctorAdviceEmpty)
  4248. return
  4249. } else {
  4250. this.ServeSuccessJSON(map[string]interface{}{
  4251. "prescriptions": prescriptions,
  4252. })
  4253. return
  4254. }
  4255. } else {
  4256. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4257. return
  4258. }
  4259. }
  4260. func (this *HisApiController) GetCallHisPrescription() {
  4261. patient_id, _ := this.GetInt64("patient_id", 0)
  4262. timeLayout := "2006-01-02"
  4263. loc, _ := time.LoadLocation("Local")
  4264. start_time := this.GetString("start_time")
  4265. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4266. end_time := this.GetString("end_time")
  4267. p_type, _ := this.GetInt64("p_type")
  4268. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4269. adminUserInfo := this.GetAdminUserInfo()
  4270. prescriptions, err := service.GetCallHisPrescriptions(startime.Unix(), endtime.Unix(), adminUserInfo.CurrentOrgId, patient_id, p_type)
  4271. if err == nil {
  4272. this.ServeSuccessJSON(map[string]interface{}{
  4273. "prescriptions": prescriptions,
  4274. })
  4275. return
  4276. } else {
  4277. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4278. return
  4279. }
  4280. }
  4281. func (this *HisApiController) GetHisDayPrescription() {
  4282. timeLayout := "2006-01-02"
  4283. loc, _ := time.LoadLocation("Local")
  4284. start_time := this.GetString("start_time")
  4285. patient_id, _ := this.GetInt64("patient_id", 0)
  4286. startime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4287. end_time := this.GetString("end_time")
  4288. p_type, _ := this.GetInt64("p_type")
  4289. order_status, _ := this.GetInt64("type")
  4290. endtime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4291. adminUserInfo := this.GetAdminUserInfo()
  4292. var dayHisPrescription []*models.HisPrescription
  4293. var err error
  4294. if order_status == 1 || order_status == 0 {
  4295. dayHisPrescription, err = service.GetUnChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4296. } else if order_status == 2 {
  4297. dayHisPrescription, err = service.GetChargeMonthHisPrescriptionSix(adminUserInfo.CurrentOrgId, patient_id, startime.Unix(), endtime.Unix(), p_type)
  4298. }
  4299. if err == nil {
  4300. this.ServeSuccessJSON(map[string]interface{}{
  4301. "day_prescription": dayHisPrescription,
  4302. })
  4303. return
  4304. } else {
  4305. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  4306. return
  4307. }
  4308. }
  4309. func (c *HisApiController) GetHisChargePatientList() {
  4310. record_date := c.GetString("record_date")
  4311. order_status, _ := c.GetInt64("type")
  4312. timeLayout := "2006-01-02"
  4313. loc, _ := time.LoadLocation("Local")
  4314. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4315. if err != nil {
  4316. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4317. return
  4318. }
  4319. recordDateTime := theTime.Unix()
  4320. adminInfo := c.GetAdminUserInfo()
  4321. var tempPatients []*service.NewTempPatients
  4322. //tempPatients, _ := service.GetAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4323. if order_status != 2 {
  4324. tempPatients, _ = service.GetNewAllUnChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4325. } else {
  4326. tempPatients, _ = service.GetNewAllChargeHisPatientList(adminInfo.CurrentOrgId, "", recordDateTime)
  4327. }
  4328. var patients []*service.NewTempPatients
  4329. var patients_two []*service.NewTempPatients
  4330. for _, item := range tempPatients {
  4331. //过滤掉没挂号的和没开处方的
  4332. if len(item.HisPatient) > 0 || len(item.HisPrescription) > 0 {
  4333. patients = append(patients, item)
  4334. }
  4335. //过滤掉没挂号的
  4336. if len(item.HisPatient) > 0 {
  4337. patients_two = append(patients_two, item)
  4338. }
  4339. }
  4340. c.ServeSuccessJSON(map[string]interface{}{
  4341. "list": patients,
  4342. "list_two": patients_two,
  4343. })
  4344. }
  4345. func (c *HisApiController) GetHisUnRegisterPatientList() {
  4346. record_date := c.GetString("record_date")
  4347. timeLayout := "2006-01-02"
  4348. loc, _ := time.LoadLocation("Local")
  4349. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4350. if err != nil {
  4351. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4352. return
  4353. }
  4354. recordDateTime := theTime.Unix()
  4355. adminUser := c.GetAdminUserInfo()
  4356. tempPatients, _ := service.GetHisPatientList(adminUser.CurrentOrgId, "", recordDateTime)
  4357. var patients []*service.Patients
  4358. for _, item := range tempPatients {
  4359. if item.HisPatient.ID == 0 {
  4360. patients = append(patients, item)
  4361. }
  4362. }
  4363. c.ServeSuccessJSON(map[string]interface{}{
  4364. "list": patients,
  4365. //"list_two": patients_two,
  4366. })
  4367. }
  4368. func RemoveRepeatedPatient(patient []*service.Patients) (newArr []*service.Patients) {
  4369. newArr = make([]*service.Patients, 0)
  4370. for i := 0; i < len(patient); i++ {
  4371. repeat := false
  4372. for j := i + 1; j < len(patient); j++ {
  4373. if patient[i].ID == patient[j].ID {
  4374. repeat = true
  4375. break
  4376. }
  4377. }
  4378. if !repeat {
  4379. newArr = append(newArr, patient[i])
  4380. }
  4381. }
  4382. return
  4383. }
  4384. func (c *HisApiController) GetHisChargePatientInfo() {
  4385. patient_id, _ := c.GetInt64("patient_id")
  4386. his_patient_id, _ := c.GetInt64("his_patient_id")
  4387. record_date := c.GetString("record_date")
  4388. //start_time := c.GetString("start_time")
  4389. //end_time := c.GetString("end_time")
  4390. order_status, _ := c.GetInt64("type", 0)
  4391. p_type, _ := c.GetInt64("p_type", 0)
  4392. order_id, _ := c.GetInt64("order_id", 0)
  4393. timeLayout := "2006-01-02"
  4394. loc, _ := time.LoadLocation("Local")
  4395. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  4396. if err != nil {
  4397. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  4398. return
  4399. }
  4400. recordDateTime := theTime.Unix()
  4401. //startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4402. //if err != nil {
  4403. //
  4404. //}
  4405. //startRecordDateTime := startTime.Unix()
  4406. //
  4407. //endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4408. //if err != nil {
  4409. //
  4410. //}
  4411. //endRecordDateTime := endTime.Unix()
  4412. admin := c.GetAdminUserInfo()
  4413. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  4414. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  4415. var prescriptions []*models.HisPrescription
  4416. order, _ := service.GetHisOrderByID(order_id)
  4417. if order_status == 1 || order_status == 0 {
  4418. prescriptions, _ = service.GetUnChargeHisPrescriptionFive(admin.CurrentOrgId, patient_id, his_patient_id, recordDateTime, p_type)
  4419. } else if order_status == 2 {
  4420. prescriptions, _ = service.GetChargeHisPrescriptionSeven(admin.CurrentOrgId, patient_id, order.Number, p_type)
  4421. }
  4422. //var monthPrescriptions []*models.HisPrescription
  4423. //if order_status == 1 || order_status == 0 {
  4424. // monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  4425. //} else if order_status == 2 {
  4426. // monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, 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. //"month_prescriptions": monthPrescriptions,
  4442. "order": order,
  4443. "doctors": doctors,
  4444. "department": department,
  4445. })
  4446. return
  4447. }
  4448. func (c *HisApiController) GetAllOrderDetail() {
  4449. order_id, _ := c.GetInt64("id", 0)
  4450. order, _ := service.GetHisOrderByID(order_id)
  4451. if order.ID == 0 {
  4452. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4453. return
  4454. }
  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. })
  4465. return
  4466. }
  4467. func (c *HisApiController) GetAllOrderDetailCollect() {
  4468. order_id, _ := c.GetInt64("id", 0)
  4469. order, _ := service.GetHisOrderByID(order_id)
  4470. if order.ID == 0 {
  4471. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  4472. return
  4473. }
  4474. org_id := c.GetAdminUserInfo().CurrentOrgId
  4475. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  4476. order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  4477. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  4478. his, _ := service.GetHisPatientInfoThree(order.UserOrgId, order.MdtrtId)
  4479. //his, _ := service.Get(order.UserOrgId, order.MdtrtId)
  4480. record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4481. if his.BalanceAccountsType != 2 {
  4482. c.ServeSuccessJSON(map[string]interface{}{
  4483. "order": order,
  4484. "order_info": order_info,
  4485. "patient": patient,
  4486. "admin_info": adminInfo,
  4487. "his_hospital": record,
  4488. })
  4489. } else {
  4490. for _, item := range order_info {
  4491. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4492. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4493. item.MedChrgitmType = "09"
  4494. }
  4495. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4496. if item.HisPrescriptionProject.Type == 2 {
  4497. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4498. case 1:
  4499. item.MedChrgitmType = "14"
  4500. break
  4501. case 2:
  4502. item.MedChrgitmType = "05"
  4503. break
  4504. case 3:
  4505. item.MedChrgitmType = "04"
  4506. break
  4507. case 4:
  4508. item.MedChrgitmType = "14"
  4509. break
  4510. case 5:
  4511. item.MedChrgitmType = "08"
  4512. break
  4513. case 6:
  4514. item.MedChrgitmType = "14"
  4515. break
  4516. case 7:
  4517. item.MedChrgitmType = "14"
  4518. break
  4519. case 8:
  4520. item.MedChrgitmType = "03"
  4521. break
  4522. case 9:
  4523. item.MedChrgitmType = "14"
  4524. break
  4525. }
  4526. } else if item.HisPrescriptionProject.Type == 3 {
  4527. item.MedChrgitmType = "08"
  4528. }
  4529. }
  4530. }
  4531. c.ServeSuccessJSON(map[string]interface{}{
  4532. "order": order,
  4533. "order_info": order_info,
  4534. "patient": patient,
  4535. "admin_info": adminInfo,
  4536. "his_hospital": record,
  4537. })
  4538. }
  4539. return
  4540. }
  4541. func (c *HisApiController) GetMedicalInsuranceCostCompareList() {
  4542. page, _ := c.GetInt64("page")
  4543. limit, _ := c.GetInt64("limit")
  4544. keywords := c.GetString("keywords")
  4545. start_time := c.GetString("start_time")
  4546. end_time := c.GetString("end_time")
  4547. //clr_type := c.GetString("clr_type")
  4548. insutype := c.GetString("insutype")
  4549. timeLayout := "2006-01-02"
  4550. loc, _ := time.LoadLocation("Local")
  4551. var theStartTIme int64
  4552. if len(start_time) > 0 {
  4553. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4554. theStartTIme = theTime.Unix()
  4555. }
  4556. var theEndtTIme int64
  4557. if len(end_time) > 0 {
  4558. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4559. theEndtTIme = theTime.Unix()
  4560. }
  4561. if page <= 0 {
  4562. page = 1
  4563. }
  4564. if limit <= 0 {
  4565. limit = 10
  4566. }
  4567. list, total, _ := service.GetMedicalInsuranceCostCompareList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, insutype, theStartTIme, theEndtTIme)
  4568. c.ServeSuccessJSON(map[string]interface{}{
  4569. "total": total,
  4570. "list": list,
  4571. })
  4572. return
  4573. }
  4574. func (c *HisApiController) GetPutOnRecordList() {
  4575. page, _ := c.GetInt64("page")
  4576. limit, _ := c.GetInt64("limit")
  4577. keywords := c.GetString("keywords")
  4578. is_put_on_record, _ := c.GetInt64("is_put_on_record")
  4579. if page <= 0 {
  4580. page = 1
  4581. }
  4582. if limit <= 0 {
  4583. limit = 10
  4584. }
  4585. list, total, _ := service.GetGdybPsnNcdsRecordList(c.GetAdminUserInfo().CurrentOrgId, page, limit, keywords, is_put_on_record)
  4586. c.ServeSuccessJSON(map[string]interface{}{
  4587. "total": total,
  4588. "list": list,
  4589. })
  4590. return
  4591. }
  4592. func (c *HisApiController) GetCompareData() {
  4593. start_time := c.GetString("start_time")
  4594. end_time := c.GetString("end_time")
  4595. insutype := c.GetString("insutype")
  4596. clr_type := c.GetString("clr_type")
  4597. timeLayout := "2006-01-02"
  4598. loc, _ := time.LoadLocation("Local")
  4599. var theStartTIme int64
  4600. if len(start_time) > 0 {
  4601. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4602. if err != nil {
  4603. theStartTIme = 0
  4604. }
  4605. theStartTIme = theTime.Unix()
  4606. }
  4607. var theEndtTIme int64
  4608. if len(end_time) > 0 {
  4609. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4610. if err != nil {
  4611. theEndtTIme = 0
  4612. }
  4613. theEndtTIme = theTime.Unix()
  4614. }
  4615. formData, err := service.GetCheckAccountFormData(theStartTIme, theEndtTIme, c.GetAdminUserInfo().CurrentOrgId, insutype, clr_type)
  4616. fmt.Println(err)
  4617. if err == nil {
  4618. c.ServeSuccessJSON(map[string]interface{}{
  4619. "list": formData,
  4620. })
  4621. } else {
  4622. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  4623. return
  4624. }
  4625. }
  4626. func (c *HisApiController) GetFaPiaoData() {
  4627. order_id, _ := c.GetInt64("order_id")
  4628. patient_id, _ := c.GetInt64("patient_id")
  4629. number := c.GetString("number")
  4630. adminUser := c.GetAdminUserInfo()
  4631. order, _ := service.GetHisOrderByID(order_id)
  4632. orderInfos, _ := service.GetHisOrderInfoByNumber(order.Number)
  4633. patientPrescription, _ := service.FindLastPatientPrescriptionInfo(adminUser.CurrentOrgId, patient_id, order.SettleAccountsDate)
  4634. department, _ := service.GetDepartMentDetail(patientPrescription.Departments)
  4635. his, _ := service.GetHisPatientInfoThree(adminUser.CurrentOrgId, number)
  4636. his_hospital_record, _ := service.GetInHospitalRecordByNumber(order.MdtrtId)
  4637. //prescriptions, _ := service.GetHisPrescriptionThree(adminUser.CurrentOrgId, patient_id, order.Number)
  4638. var bedCostTotal float64 = 0 //床位总费
  4639. var bedCostSelfTotal float64 = 0 //床位自费
  4640. var bedCostPartSelfTotal float64 = 0 //床位部分项目自费
  4641. var operationCostTotal float64 = 0 //手术费
  4642. var operationCostSelfTotal float64 = 0 //手术费
  4643. var operationCostPartSelfTotal float64 = 0 //手术费
  4644. var otherCostTotal float64 = 0 //其他费用
  4645. var otherCostSelfTotal float64 = 0 //其他费用
  4646. var otherCostPartSelfTotal float64 = 0 //其他费用
  4647. var materialCostTotal float64 = 0 //材料费
  4648. var materialCostSelfTotal float64 = 0 //材料费
  4649. var materialCostPartSelfTotal float64 = 0 //材料费
  4650. var westernMedicineCostTotal float64 = 0 //西药费
  4651. var westernMedicineCostSelfTotal float64 = 0 //西药费
  4652. var westernMedicineCostPartSelfTotal float64 = 0 //西药费
  4653. var chineseTraditionalMedicineCostTotal float64 = 0 //中成药
  4654. var chineseTraditionalMedicineCostSelfTotal float64 = 0 //中成药
  4655. var chineseTraditionalMedicineCostPartSelfTotal float64 = 0 //中成药
  4656. var checkCostTotal float64 = 0 //检查费
  4657. var checkCostSelfTotal float64 = 0 //检查费
  4658. var checkCostPartSelfTotal float64 = 0 //检查费
  4659. var laboratoryCostTotal float64 = 0 //化验费
  4660. var laboratoryCostSelfTotal float64 = 0 //化验费
  4661. var laboratoryCostPartSelfTotal float64 = 0 //化验费
  4662. var treatCostTotal float64 = 0 //治疗费用
  4663. var treatCostSelfTotal float64 = 0 //治疗费用
  4664. var treatCostPartSelfTotal float64 = 0 //治疗费用
  4665. var zhenChaCostTotal float64 = 0 //其他费用
  4666. var zhenChaCostSelfTotal float64 = 0 //其他费用
  4667. var zhenChaCostPartSelfTotal float64 = 0 //其他费用
  4668. decimal.DivisionPrecision = 2
  4669. orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  4670. if his.BalanceAccountsType == 2 {
  4671. //orderInfos_two, _ := service.GetHisOrderDetailByNumber(order.Number, adminUser.CurrentOrgId)
  4672. for _, item := range orderInfos_two {
  4673. item.FulamtOwnpayAmt = item.DetItemFeeSumamt
  4674. if item.HisDoctorAdviceInfo.ID > 0 && item.HisPrescriptionProject.ID == 0 { //药品
  4675. item.MedChrgitmType = "09"
  4676. }
  4677. if item.HisPrescriptionProject.ID > 0 && item.HisDoctorAdviceInfo.ID == 0 {
  4678. if item.HisPrescriptionProject.Type == 2 {
  4679. switch item.HisPrescriptionProject.VMHisProject.CostClassify {
  4680. case 1:
  4681. item.MedChrgitmType = "14"
  4682. break
  4683. case 2:
  4684. item.MedChrgitmType = "05"
  4685. break
  4686. case 3:
  4687. item.MedChrgitmType = "04"
  4688. break
  4689. case 4:
  4690. item.MedChrgitmType = "14"
  4691. break
  4692. case 5:
  4693. item.MedChrgitmType = "08"
  4694. break
  4695. case 6:
  4696. item.MedChrgitmType = "14"
  4697. break
  4698. case 7:
  4699. item.MedChrgitmType = "14"
  4700. break
  4701. case 8:
  4702. item.MedChrgitmType = "03"
  4703. break
  4704. case 9:
  4705. item.MedChrgitmType = "14"
  4706. break
  4707. }
  4708. } else if item.HisPrescriptionProject.Type == 3 {
  4709. item.MedChrgitmType = "08"
  4710. }
  4711. }
  4712. }
  4713. for _, item := range orderInfos_two {
  4714. if item.MedChrgitmType == "01" { //床位费
  4715. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4716. bedCostSelfTotal = bedCostTotal
  4717. }
  4718. if item.MedChrgitmType == "03" { //检查费
  4719. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4720. checkCostSelfTotal = checkCostTotal
  4721. }
  4722. if item.MedChrgitmType == "04" { //化验费
  4723. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4724. laboratoryCostSelfTotal = laboratoryCostTotal
  4725. }
  4726. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" { //治疗费
  4727. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4728. treatCostSelfTotal = treatCostTotal
  4729. }
  4730. if item.MedChrgitmType == "06" { //手术费
  4731. treatCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4732. operationCostSelfTotal = treatCostTotal
  4733. }
  4734. if item.MedChrgitmType == "08" { //材料费
  4735. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4736. materialCostSelfTotal = materialCostTotal
  4737. }
  4738. if item.MedChrgitmType == "09" { //西药费
  4739. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4740. westernMedicineCostSelfTotal = westernMedicineCostTotal
  4741. }
  4742. if item.MedChrgitmType == "11" { //中成费
  4743. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4744. chineseTraditionalMedicineCostSelfTotal = chineseTraditionalMedicineCostTotal
  4745. }
  4746. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4747. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4748. otherCostSelfTotal = otherCostTotal
  4749. }
  4750. }
  4751. } else {
  4752. for _, item := range orderInfos {
  4753. if item.MedChrgitmType == "01" { //床位费
  4754. bedCostTotal, _ = decimal.NewFromFloat(bedCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4755. bedCostSelfTotal, _ = decimal.NewFromFloat(bedCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4756. bedCostPartSelfTotal, _ = decimal.NewFromFloat(bedCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4757. }
  4758. if item.MedChrgitmType == "02" { //诊察费
  4759. zhenChaCostTotal, _ = decimal.NewFromFloat(zhenChaCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4760. zhenChaCostSelfTotal, _ = decimal.NewFromFloat(zhenChaCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4761. zhenChaCostPartSelfTotal, _ = decimal.NewFromFloat(zhenChaCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4762. }
  4763. if item.MedChrgitmType == "03" { //检查费
  4764. checkCostTotal, _ = decimal.NewFromFloat(checkCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4765. checkCostSelfTotal, _ = decimal.NewFromFloat(checkCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4766. checkCostPartSelfTotal, _ = decimal.NewFromFloat(checkCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4767. }
  4768. if item.MedChrgitmType == "04" { //化验费
  4769. laboratoryCostTotal, _ = decimal.NewFromFloat(laboratoryCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4770. laboratoryCostSelfTotal, _ = decimal.NewFromFloat(laboratoryCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4771. laboratoryCostPartSelfTotal, _ = decimal.NewFromFloat(laboratoryCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4772. }
  4773. if item.MedChrgitmType == "05" || item.MedChrgitmType == "14" || item.MedChrgitmType == "1402" || item.MedChrgitmType == "1403" { //治疗费
  4774. treatCostTotal, _ = decimal.NewFromFloat(treatCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4775. treatCostSelfTotal, _ = decimal.NewFromFloat(treatCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4776. treatCostPartSelfTotal, _ = decimal.NewFromFloat(treatCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4777. }
  4778. if item.MedChrgitmType == "06" { //手术费
  4779. operationCostTotal, _ = decimal.NewFromFloat(operationCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4780. operationCostSelfTotal, _ = decimal.NewFromFloat(operationCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4781. operationCostPartSelfTotal, _ = decimal.NewFromFloat(operationCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4782. }
  4783. if item.MedChrgitmType == "08" { //材料费
  4784. materialCostTotal, _ = decimal.NewFromFloat(materialCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4785. materialCostSelfTotal, _ = decimal.NewFromFloat(materialCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4786. materialCostPartSelfTotal, _ = decimal.NewFromFloat(materialCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4787. }
  4788. if item.MedChrgitmType == "09" { //西药费
  4789. westernMedicineCostTotal, _ = decimal.NewFromFloat(westernMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4790. westernMedicineCostSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4791. westernMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(westernMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4792. }
  4793. if item.MedChrgitmType == "11" { //中成费
  4794. chineseTraditionalMedicineCostTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4795. chineseTraditionalMedicineCostSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4796. chineseTraditionalMedicineCostPartSelfTotal, _ = decimal.NewFromFloat(chineseTraditionalMedicineCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4797. }
  4798. if item.MedChrgitmType == "0" || item.MedChrgitmType == "12" { //其他费
  4799. otherCostTotal, _ = decimal.NewFromFloat(otherCostTotal).Add(decimal.NewFromFloat(item.DetItemFeeSumamt)).Float64()
  4800. otherCostSelfTotal, _ = decimal.NewFromFloat(otherCostSelfTotal).Add(decimal.NewFromFloat(item.OverlmtAmt)).Float64()
  4801. otherCostPartSelfTotal, _ = decimal.NewFromFloat(otherCostPartSelfTotal).Add(decimal.NewFromFloat(item.PreselfpayAmt)).Float64()
  4802. }
  4803. }
  4804. }
  4805. admin, _ := service.GetAdminUserInfoByID(adminUser.CurrentOrgId, adminUser.AdminUser.Id)
  4806. c.ServeSuccessJSON(map[string]interface{}{
  4807. "order_number": order.Number, //业务流水号
  4808. "id_card_no": his.IdCardNo, //社会保障号
  4809. "department_name": department.Name, //科室
  4810. "number": his.Number, //门诊号
  4811. "date": order.SettleAccountsDate, //结算日期
  4812. "name": order.PsnName, //姓名
  4813. "gender": order.Gend, //性别
  4814. "psn_cash_money": order.PsnCashPay, //个人支付
  4815. "pay_way": "门诊", //结算方式
  4816. "medfee_sumamt": order.MedfeeSumamt, //总费用
  4817. "admin_user_name": admin.UserName, //收款员
  4818. "order": order,
  4819. "order_info": orderInfos_two,
  4820. "his": his,
  4821. "bedCostTotal": bedCostTotal,
  4822. "bedCostSelfTotal": bedCostSelfTotal,
  4823. "bedCostPartSelfTotal": bedCostPartSelfTotal,
  4824. "operationCostTotal": operationCostTotal,
  4825. "operationCostSelfTotal": operationCostSelfTotal,
  4826. "operationCostPartSelfTotal": operationCostPartSelfTotal,
  4827. "otherCostTotal": otherCostTotal,
  4828. "otherCostSelfTotal": otherCostSelfTotal,
  4829. "otherCostPartSelfTotal": otherCostPartSelfTotal,
  4830. "materialCostTotal": materialCostTotal,
  4831. "materialCostSelfTotal": materialCostSelfTotal,
  4832. "materialCostPartSelfTotal": materialCostPartSelfTotal,
  4833. "westernMedicineCostTotal": westernMedicineCostTotal,
  4834. "westernMedicineCostSelfTotal": westernMedicineCostSelfTotal,
  4835. "westernMedicineCostPartSelfTotal": westernMedicineCostPartSelfTotal,
  4836. "chineseTraditionalMedicineCostTotal": chineseTraditionalMedicineCostTotal,
  4837. "chineseTraditionalMedicineCostSelfTotal": chineseTraditionalMedicineCostSelfTotal,
  4838. "chineseTraditionalMedicineCostPartSelfTotal": chineseTraditionalMedicineCostPartSelfTotal,
  4839. "checkCostTotal": checkCostTotal,
  4840. "checkCostSelfTotal": checkCostSelfTotal,
  4841. "checkCostPartSelfTotal": checkCostPartSelfTotal,
  4842. "laboratoryCostTotal": laboratoryCostTotal,
  4843. "laboratoryCostSelfTotal": laboratoryCostSelfTotal,
  4844. "laboratoryCostPartSelfTotal": laboratoryCostPartSelfTotal,
  4845. "treatCostTotal": treatCostTotal,
  4846. "treatCostSelfTotal": treatCostSelfTotal,
  4847. "treatCostPartSelfTotal": treatCostPartSelfTotal,
  4848. "zhenChaCostTotal": zhenChaCostTotal,
  4849. "zhenChaCostSelfTotal": zhenChaCostSelfTotal,
  4850. "zhenChaCostPartSelfTotal": zhenChaCostPartSelfTotal,
  4851. "his_hospital_record": his_hospital_record,
  4852. })
  4853. }
  4854. func (this *HisApiController) GetIncomeStatisticsData() {
  4855. start_time := this.GetString("start_time")
  4856. end_time := this.GetString("end_time")
  4857. key_words := this.GetString("key_words")
  4858. limit, _ := this.GetInt64("limit")
  4859. page, _ := this.GetInt64("page")
  4860. if page <= 0 {
  4861. page = 1
  4862. }
  4863. if limit <= 0 {
  4864. limit = 10
  4865. }
  4866. statistics_type, _ := this.GetInt64("statistics_type")
  4867. admin := this.GetAdminUserInfo()
  4868. timeLayout := "2006-01-02"
  4869. loc, _ := time.LoadLocation("Local")
  4870. var theStartTIme int64
  4871. if len(start_time) > 0 {
  4872. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  4873. if err != nil {
  4874. theStartTIme = 0
  4875. }
  4876. theStartTIme = theTime.Unix()
  4877. }
  4878. var theEndtTIme int64
  4879. if len(end_time) > 0 {
  4880. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  4881. if err != nil {
  4882. theEndtTIme = 0
  4883. }
  4884. theEndtTIme = theTime.Unix()
  4885. }
  4886. if statistics_type == 1 {
  4887. list, total, _ := service.GetDayIncomeStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  4888. this.ServeSuccessJSON(map[string]interface{}{
  4889. "list": list,
  4890. "total": total,
  4891. })
  4892. } else {
  4893. list, total, _ := service.GetDayIncomeDetailStatisticsData(admin.CurrentOrgId, key_words, theStartTIme, theEndtTIme, page, limit)
  4894. this.ServeSuccessJSON(map[string]interface{}{
  4895. "list": list,
  4896. "total": total,
  4897. })
  4898. }
  4899. }
  4900. func (c *HisApiController) PostProjectInformation() {
  4901. adminUser := c.GetAdminUserInfo()
  4902. orgId := adminUser.CurrentOrgId
  4903. dataBody := make(map[string]interface{}, 0)
  4904. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  4905. if err != nil {
  4906. utils.ErrorLog(err.Error())
  4907. return
  4908. }
  4909. utils.ErrorLog("%v", dataBody)
  4910. var projectList []*models.HisProject
  4911. var total_goods []interface{}
  4912. tempProjects := dataBody["projects"].([]interface{})
  4913. total_goods = tempProjects
  4914. for index, projectMap := range tempProjects {
  4915. projectM := projectMap.(map[string]interface{})
  4916. var project models.HisProject
  4917. if projectM["project_name"] == nil || reflect.TypeOf(projectM["project_name"]).String() != "string" {
  4918. utils.ErrorLog("project_name")
  4919. return
  4920. }
  4921. project_name, _ := projectM["project_name"].(string)
  4922. if len(project_name) == 0 { //名字为空则生成一条导入错误日志
  4923. err_log := models.ExportErrLog{
  4924. LogType: 6,
  4925. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4926. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的项目名称不能为空",
  4927. Status: 1,
  4928. CreateTime: time.Now().Unix(),
  4929. UpdateTime: time.Now().Unix(),
  4930. ExportTime: time.Now().Unix(),
  4931. }
  4932. service.CreateExportErrLog(&err_log)
  4933. continue
  4934. }
  4935. project.ProjectName = project_name
  4936. prices := projectM["price"].(string)
  4937. price, _ := strconv.ParseFloat(prices, 64)
  4938. if price <= 0 { //名字为空则生成一条导入错误日志
  4939. err_log := models.ExportErrLog{
  4940. LogType: 6,
  4941. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4942. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的零价不能为空",
  4943. Status: 1,
  4944. CreateTime: time.Now().Unix(),
  4945. UpdateTime: time.Now().Unix(),
  4946. ExportTime: time.Now().Unix(),
  4947. }
  4948. service.CreateExportErrLog(&err_log)
  4949. continue
  4950. }
  4951. project.Price = price
  4952. if projectM["unit"] == nil || reflect.TypeOf(projectM["unit"]).String() != "string" {
  4953. utils.ErrorLog("unit_id")
  4954. return
  4955. }
  4956. unit := projectM["unit"].(string)
  4957. if len(unit) == 0 { //名字为空则生成一条导入错误日志
  4958. err_log := models.ExportErrLog{
  4959. LogType: 6,
  4960. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4961. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的单位不能为空",
  4962. Status: 1,
  4963. CreateTime: time.Now().Unix(),
  4964. UpdateTime: time.Now().Unix(),
  4965. ExportTime: time.Now().Unix(),
  4966. }
  4967. service.CreateExportErrLog(&err_log)
  4968. continue
  4969. }
  4970. project.Unit = unit
  4971. cost_classify := projectM["cost_classify"].(string)
  4972. if len(cost_classify) == 0 { //名字为空则生成一条导入错误日志
  4973. err_log := models.ExportErrLog{
  4974. LogType: 6,
  4975. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  4976. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  4977. Status: 1,
  4978. CreateTime: time.Now().Unix(),
  4979. UpdateTime: time.Now().Unix(),
  4980. ExportTime: time.Now().Unix(),
  4981. }
  4982. service.CreateExportErrLog(&err_log)
  4983. continue
  4984. }
  4985. var costClassify = "费用类别"
  4986. var cost_classify_id int64
  4987. costClassifyConfig, _ := service.GetDrugDataConfig(0, costClassify)
  4988. if len(cost_classify) != 0 {
  4989. _, errcode := service.IsExistDicConfig(costClassifyConfig.ID, cost_classify, orgId)
  4990. if errcode == gorm.ErrRecordNotFound {
  4991. costConfig, _ := service.GetLastDicConfig(costClassifyConfig.ID, orgId)
  4992. dataconfig := models.DictDataconfig{
  4993. ParentId: costClassifyConfig.ID,
  4994. Module: "system",
  4995. OrgId: orgId,
  4996. Name: cost_classify,
  4997. FieldName: "",
  4998. Value: costConfig.Value + 1,
  4999. CreatedTime: "",
  5000. UpdatedTime: "",
  5001. CreateUserId: adminUser.AdminUser.Id,
  5002. Status: 1,
  5003. Remark: "",
  5004. DeleteIdSystem: 0,
  5005. Title: "",
  5006. Content: "",
  5007. Order: 0,
  5008. Code: "",
  5009. }
  5010. service.CreatedDicConfig(&dataconfig)
  5011. }
  5012. }
  5013. costClassList, _ := service.GetParentDataConfig(costClassifyConfig.ID, orgId)
  5014. for _, it := range costClassList {
  5015. if cost_classify == it.Name {
  5016. cost_classify_id = int64(it.Value)
  5017. }
  5018. }
  5019. project.CostClassify = cost_classify_id
  5020. executive_section := projectM["executive_section"].(string)
  5021. if len(executive_section) == 0 { //名字为空则生成一条导入错误日志
  5022. err_log := models.ExportErrLog{
  5023. LogType: 6,
  5024. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5025. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空或内容与系统不匹配",
  5026. Status: 1,
  5027. CreateTime: time.Now().Unix(),
  5028. UpdateTime: time.Now().Unix(),
  5029. ExportTime: time.Now().Unix(),
  5030. }
  5031. service.CreateExportErrLog(&err_log)
  5032. continue
  5033. }
  5034. if len(executive_section) != 0 {
  5035. //查找科室是否有内容
  5036. _, errcodedepart := service.GetDepartMentByName(executive_section, orgId)
  5037. if errcodedepart == gorm.ErrRecordNotFound {
  5038. department := models.XtHisDepartment{
  5039. Name: executive_section,
  5040. Status: 1,
  5041. UserOrgId: adminUser.CurrentOrgId,
  5042. CreatedTime: time.Now().Unix(),
  5043. }
  5044. service.CreateDePartment(&department)
  5045. }
  5046. }
  5047. var executive_section_id int64
  5048. departMentList, _ := service.GetAllDepartMent(orgId)
  5049. for _, it := range departMentList {
  5050. if executive_section == it.Name {
  5051. executive_section_id = it.ID
  5052. }
  5053. }
  5054. project.ExecutiveSection = executive_section_id
  5055. medical_coverage := projectM["medical_coverage"].(string)
  5056. if len(medical_coverage) == 0 { //名字为空则生成一条导入错误日志
  5057. err_log := models.ExportErrLog{
  5058. LogType: 6,
  5059. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5060. ErrMsg: "第" + strconv.Itoa(index+3) + "行" + "的费用类别不能为空",
  5061. Status: 1,
  5062. CreateTime: time.Now().Unix(),
  5063. UpdateTime: time.Now().Unix(),
  5064. ExportTime: time.Now().Unix(),
  5065. }
  5066. service.CreateExportErrLog(&err_log)
  5067. continue
  5068. }
  5069. var medicalCoverage = "医保等级"
  5070. var medical_coverage_id int64
  5071. medicalCoverageConfig, _ := service.GetDrugDataConfig(0, medicalCoverage)
  5072. if len(medical_coverage) != 0 {
  5073. _, errormedicalcoverage := service.IsExistDicConfig(medicalCoverageConfig.ID, medical_coverage, orgId)
  5074. if errormedicalcoverage == gorm.ErrRecordNotFound {
  5075. medicalCoverageConfig, _ := service.GetLastDicConfig(medicalCoverageConfig.ID, orgId)
  5076. dataconfig := models.DictDataconfig{
  5077. ParentId: medicalCoverageConfig.ID,
  5078. Module: "system",
  5079. OrgId: orgId,
  5080. Name: medical_coverage,
  5081. FieldName: "",
  5082. Value: medicalCoverageConfig.Value + 1,
  5083. CreatedTime: "",
  5084. UpdatedTime: "",
  5085. CreateUserId: adminUser.AdminUser.Id,
  5086. Status: 1,
  5087. Remark: "",
  5088. DeleteIdSystem: 0,
  5089. Title: "",
  5090. Content: "",
  5091. Order: 0,
  5092. Code: "",
  5093. }
  5094. service.CreatedDicConfig(&dataconfig)
  5095. }
  5096. }
  5097. medicalCoverageList, _ := service.GetParentDataConfig(medicalCoverageConfig.ID, orgId)
  5098. for _, it := range medicalCoverageList {
  5099. if medical_coverage == it.Name {
  5100. medical_coverage_id = int64(it.Value)
  5101. }
  5102. }
  5103. project.MedicalCoverage = medical_coverage_id
  5104. pinyin := projectM["pinyin"].(string)
  5105. project.Pinyin = pinyin
  5106. wubi := projectM["wubi"].(string)
  5107. project.Wubi = wubi
  5108. statistical_classification := projectM["statistical_classification"].(string)
  5109. var statisticalClassification = "统计分类"
  5110. var statistical_classification_id int64
  5111. classiFication, _ := service.GetDrugDataConfig(0, statisticalClassification)
  5112. if len(statistical_classification) != 0 {
  5113. _, classificationerrcodes := service.IsExistDicConfig(classiFication.ID, statistical_classification, orgId)
  5114. if classificationerrcodes == gorm.ErrRecordNotFound {
  5115. classiFicationConfig, _ := service.GetLastDicConfig(classiFication.ID, orgId)
  5116. dataconfig := models.DictDataconfig{
  5117. ParentId: classiFication.ID,
  5118. Module: "system",
  5119. OrgId: orgId,
  5120. Name: statistical_classification,
  5121. FieldName: "",
  5122. Value: classiFicationConfig.Value + 1,
  5123. CreatedTime: "",
  5124. UpdatedTime: "",
  5125. CreateUserId: adminUser.AdminUser.Id,
  5126. Status: 1,
  5127. Remark: "",
  5128. DeleteIdSystem: 0,
  5129. Title: "",
  5130. Content: "",
  5131. Order: 0,
  5132. Code: "",
  5133. }
  5134. service.CreatedDicConfig(&dataconfig)
  5135. }
  5136. }
  5137. classiFicationList, _ := service.GetParentDataConfig(classiFication.ID, orgId)
  5138. for _, it := range classiFicationList {
  5139. if statistical_classification == it.Name {
  5140. statistical_classification_id = int64(it.Value)
  5141. }
  5142. }
  5143. project.StatisticalClassification = statistical_classification_id
  5144. disease_directory := int64(projectM["disease_directory"].(float64))
  5145. project.DiseaseDirectory = disease_directory
  5146. is_record := int64(projectM["is_record"].(float64))
  5147. project.IsRecord = is_record
  5148. medical_code := projectM["medical_code"].(string)
  5149. project.MedicalCode = medical_code
  5150. tube_color := projectM["tube_color"].(string)
  5151. var tubeColor = "试管颜色"
  5152. var tube_color_id int64
  5153. tubeColorConfig, _ := service.GetDrugDataConfig(0, tubeColor)
  5154. if len(tube_color) != 0 {
  5155. _, errcodetube := service.IsExistDicConfig(tubeColorConfig.ID, tube_color, orgId)
  5156. if errcodetube == gorm.ErrRecordNotFound {
  5157. tubeConfig, _ := service.GetLastDicConfig(tubeColorConfig.ID, orgId)
  5158. dataconfig := models.DictDataconfig{
  5159. ParentId: tubeColorConfig.ID,
  5160. Module: "system",
  5161. OrgId: orgId,
  5162. Name: tube_color,
  5163. FieldName: "",
  5164. Value: tubeConfig.Value + 1,
  5165. CreatedTime: "",
  5166. UpdatedTime: "",
  5167. CreateUserId: adminUser.AdminUser.Id,
  5168. Status: 1,
  5169. Remark: "",
  5170. DeleteIdSystem: 0,
  5171. Title: "",
  5172. Content: "",
  5173. Order: 0,
  5174. Code: "",
  5175. }
  5176. service.CreatedDicConfig(&dataconfig)
  5177. }
  5178. }
  5179. tubeColorList, _ := service.GetParentDataConfig(tubeColorConfig.ID, orgId)
  5180. for _, it := range tubeColorList {
  5181. if tube_color == it.Name {
  5182. tube_color_id = int64(it.Value)
  5183. }
  5184. }
  5185. project.TubeColor = tube_color_id
  5186. single_dose := projectM["single_dose"].(string)
  5187. project.SingleDose = single_dose
  5188. execution_frequency := projectM["execution_frequency"].(string)
  5189. project.ExecutionFrequency = execution_frequency
  5190. delivery_way := projectM["delivery_way"].(string)
  5191. project.DeliveryWay = delivery_way
  5192. number_days := projectM["number_days"].(string)
  5193. project.NumberDays = number_days
  5194. total := projectM["total"].(string)
  5195. project.Total = total
  5196. medical_status := int64(projectM["medical_status"].(float64))
  5197. project.MedicalStatus = medical_status
  5198. category := int64(projectM["category"].(float64))
  5199. project.Category = category
  5200. specail_project := int64(projectM["specail_project"].(float64))
  5201. project.SpecailProject = specail_project
  5202. social_security_directory_code := projectM["social_security_directory_code"].(string)
  5203. project.SocialSecurityDirectoryCode = social_security_directory_code
  5204. remark := projectM["remark"].(string)
  5205. project.Remark = remark
  5206. record_date := projectM["record_date"].(string)
  5207. timeLayout := "2006-01-02"
  5208. loc, _ := time.LoadLocation("Local")
  5209. theTime, _ := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5210. project.RecordDate = theTime.Unix()
  5211. projectList = append(projectList, &project)
  5212. }
  5213. export_time := time.Now().Unix()
  5214. errLogs, _ := service.FindPatientExportLog(c.GetAdminUserInfo().CurrentOrgId, export_time)
  5215. if len(projectList) > 0 {
  5216. for _, item := range projectList {
  5217. project := models.HisProject{
  5218. ProjectName: item.ProjectName,
  5219. Price: item.Price,
  5220. Unit: item.Unit,
  5221. CostClassify: item.CostClassify,
  5222. ExecutiveSection: item.ExecutiveSection,
  5223. MedicalCoverage: item.MedicalCoverage,
  5224. UserOrgId: orgId,
  5225. Status: 1,
  5226. CreatedTime: time.Now().Unix(),
  5227. Pinyin: item.Pinyin,
  5228. Wubi: item.Wubi,
  5229. StatisticalClassification: item.StatisticalClassification,
  5230. DiseaseDirectory: item.DiseaseDirectory,
  5231. IsRecord: item.IsRecord,
  5232. MedicalCode: item.MedicalCode,
  5233. TubeColor: item.TubeColor,
  5234. SingleDose: item.SingleDose,
  5235. DeliveryWay: item.DeliveryWay,
  5236. NumberDays: item.NumberDays,
  5237. Total: item.Total,
  5238. Category: item.Category,
  5239. MedicalStatus: item.MedicalStatus,
  5240. SpecailProject: item.SpecailProject,
  5241. RecordDate: item.RecordDate,
  5242. Remark: item.Remark,
  5243. SocialSecurityDirectoryCode: item.SocialSecurityDirectoryCode,
  5244. ExecutionFrequency: item.ExecutionFrequency,
  5245. }
  5246. _, errcodeproject := service.GetProjectByNameIsExsit(item.ProjectName, orgId)
  5247. if errcodeproject == gorm.ErrRecordNotFound {
  5248. service.CreateProjectInfomation(&project)
  5249. } else if errcodeproject == nil {
  5250. service.UpdateProjectByName(&project, item.ProjectName, orgId)
  5251. }
  5252. log := models.ExportLog{
  5253. LogType: 6,
  5254. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5255. TotalNum: int64(len(total_goods)),
  5256. FailNum: int64(len(errLogs)),
  5257. SuccessNum: int64(len(projectList)),
  5258. CreateTime: time.Now().Unix(),
  5259. UpdateTime: time.Now().Unix(),
  5260. ExportTime: export_time,
  5261. Status: 1,
  5262. }
  5263. service.CreateExportLog(&log)
  5264. c.ServeSuccessJSON(map[string]interface{}{
  5265. "msg": "导入成功",
  5266. "total_num": len(total_goods),
  5267. "success_num": len(projectList),
  5268. "fail_num": int64(len(errLogs)),
  5269. })
  5270. }
  5271. } else {
  5272. log := models.ExportLog{
  5273. LogType: 6,
  5274. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5275. TotalNum: int64(len(total_goods)),
  5276. FailNum: int64(len(errLogs)),
  5277. SuccessNum: int64(len(projectList)),
  5278. CreateTime: time.Now().Unix(),
  5279. UpdateTime: time.Now().Unix(),
  5280. ExportTime: export_time,
  5281. Status: 1,
  5282. }
  5283. service.CreateExportLog(&log)
  5284. c.ServeSuccessJSON(map[string]interface{}{
  5285. "msg": "导入成功",
  5286. "total_num": len(total_goods),
  5287. "success_num": len(projectList),
  5288. "fail_num": int64(len(errLogs)),
  5289. })
  5290. }
  5291. }
  5292. //func (this *HisApiController) EditProjectInformation(){
  5293. //
  5294. // id, _ := this.GetInt64("id")
  5295. // project_team := this.GetString("project_team")
  5296. // price := this.GetString("price")
  5297. // price_float, _ := strconv.ParseFloat(price, 64)
  5298. // pinyin := this.GetString("pinyin")
  5299. // wubi := this.GetString("wubi")
  5300. // tube_color, _ := this.GetInt64("tube_color")
  5301. // team_type, _ := this.GetInt64("team_type")
  5302. // remark := this.GetString("remark")
  5303. // ids := this.GetString("ids")
  5304. // item_id := this.GetString("item_id")
  5305. // projectTeam := models.XtHisProjectTeam{
  5306. // ProjectTeam: project_team,
  5307. // Price: price_float,
  5308. // Pinyin: pinyin,
  5309. // Wubi: wubi,
  5310. // TubeColor: tube_color,
  5311. // TeamType: team_type,
  5312. // Remark: remark,
  5313. // ProjectId: ids,
  5314. // ItemId: item_id,
  5315. // }
  5316. //
  5317. //
  5318. // dataBody := make(map[string]interface{}, 0)
  5319. // err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
  5320. // if err != nil {
  5321. // utils.ErrorLog(err.Error())
  5322. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5323. // return
  5324. // }
  5325. //
  5326. // err = service.UpdatedProjectTeam(id, &projectTeam)
  5327. //
  5328. //
  5329. // if err != nil {
  5330. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeUpdateConfig)
  5331. // return
  5332. // }
  5333. //
  5334. // if dataBody["info"] != nil && reflect.TypeOf(dataBody["info"]).String() == "[]interface {}" {
  5335. // infos, _ := dataBody["info"].([]interface{})
  5336. // if len(infos) > 0 {
  5337. // var ids []string
  5338. //
  5339. // for _, item := range infos {
  5340. // items := item.(map[string]interface{})
  5341. // if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
  5342. // utils.ErrorLog("id")
  5343. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5344. // return
  5345. // }
  5346. // id := int64(items["id"].(float64))
  5347. //
  5348. // if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5349. // utils.ErrorLog("type")
  5350. // this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5351. // return
  5352. // }
  5353. // types := int64(items["type"].(float64))
  5354. //
  5355. // if items["number"] == nil || reflect.TypeOf(items["number"]).String() != "string" {
  5356. // utils.ErrorLog("number")
  5357. // }
  5358. //
  5359. // number, _ := strconv.ParseInt(items["number"].(string), 10, 64)
  5360. //
  5361. // projectList := models.XtHisProjectList{
  5362. // Number: number,
  5363. // UserOrgId: this.GetAdminUserInfo().CurrentOrgId,
  5364. // ProjectId: id,
  5365. // Status: 1,
  5366. // CreatedTime: time.Now().Unix(),
  5367. // UpdatedTime: time.Now().Unix(),
  5368. // TeamId: projectTeam.ID,
  5369. // Type: types,
  5370. // }
  5371. // list := projectList
  5372. //
  5373. // service.CreateProjectList(&list)
  5374. //
  5375. // ids = append(ids, strconv.FormatInt(list.ID, 10))
  5376. //
  5377. // }
  5378. // ids_str := strings.Join(ids, ",")
  5379. // projectTeam.ProjectId = projectTeam.ProjectId+"," + ids_str
  5380. // service.SaveProjectTeam(&projectTeam)
  5381. // this.ServeSuccessJSON(map[string]interface{}{
  5382. // "projectTeam": projectTeam,
  5383. // })
  5384. // }
  5385. // }
  5386. //}
  5387. func (c *HisApiController) CreateHisPrescriptionTemplate() {
  5388. name := c.GetString("name")
  5389. mode_id, _ := c.GetInt64("mode", 0)
  5390. types, _ := c.GetInt64("type", 0)
  5391. patient_id, _ := c.GetInt64("patient_id", 0)
  5392. types = 1
  5393. adminInfo := c.GetAdminUserInfo()
  5394. template := &models.HisPrescriptionTemplate{
  5395. UserOrgId: c.GetAdminUserInfo().CurrentOrgId,
  5396. PatientId: patient_id,
  5397. Type: types,
  5398. Status: 1,
  5399. Ctime: time.Now().Unix(),
  5400. Mtime: time.Now().Unix(),
  5401. Name: name,
  5402. Mode: mode_id,
  5403. }
  5404. dataBody := make(map[string]interface{}, 0)
  5405. err := json.Unmarshal(c.Ctx.Input.RequestBody, &dataBody)
  5406. if err != nil {
  5407. utils.ErrorLog(err.Error())
  5408. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5409. return
  5410. }
  5411. err = service.CreateHisPrescriptionTemplate(template)
  5412. if dataBody["prescriptions"] != nil && reflect.TypeOf(dataBody["prescriptions"]).String() == "[]interface {}" {
  5413. prescriptions, _ := dataBody["prescriptions"].([]interface{})
  5414. if len(prescriptions) > 0 {
  5415. for _, item := range prescriptions {
  5416. items := item.(map[string]interface{})
  5417. if items["type"] == nil || reflect.TypeOf(items["type"]).String() != "float64" {
  5418. utils.ErrorLog("type")
  5419. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5420. return
  5421. }
  5422. types := int64(items["type"].(float64))
  5423. if items["med_type"] == nil || reflect.TypeOf(items["med_type"]).String() != "float64" {
  5424. utils.ErrorLog("med_type")
  5425. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5426. return
  5427. }
  5428. med_type := strconv.Itoa(int(items["med_type"].(float64)))
  5429. ctime := time.Now().Unix()
  5430. prescription := &models.HisPrescriptionInfoTemplate{
  5431. PatientId: patient_id,
  5432. UserOrgId: adminInfo.CurrentOrgId,
  5433. Ctime: ctime,
  5434. Mtime: ctime,
  5435. Type: types,
  5436. Modifier: adminInfo.AdminUser.Id,
  5437. Creator: adminInfo.AdminUser.Id,
  5438. Status: 1,
  5439. PTemplateId: template.ID,
  5440. MedType: med_type,
  5441. }
  5442. service.CreateHisPrescriptionInfoTemplate(prescription)
  5443. if items["advices"] != nil && reflect.TypeOf(items["advices"]).String() == "[]interface {}" {
  5444. advices := items["advices"].([]interface{})
  5445. //group := service.GetMaxAdviceGroupID(adminInfo.CurrentOrgId)
  5446. ctime := time.Now().Unix()
  5447. mtime := ctime
  5448. if len(advices) > 0 {
  5449. for _, advice := range advices {
  5450. var s models.HisPrescriptionAdviceTemplate
  5451. s.PrescriptionId = prescription.ID
  5452. s.AdviceType = 2
  5453. s.StopState = 2
  5454. s.ExecutionState = 2
  5455. s.Status = 1
  5456. s.UserOrgId = adminInfo.CurrentOrgId
  5457. s.CreatedTime = ctime
  5458. s.UpdatedTime = mtime
  5459. s.PatientId = patient_id
  5460. errcode := c.setAdviceTemplateWithJSON(&s, advice.(map[string]interface{}))
  5461. if errcode > 0 {
  5462. c.ServeFailJSONWithSGJErrorCode(errcode)
  5463. return
  5464. }
  5465. service.CreateHisPrescriptionAdviceTemplate(&s)
  5466. }
  5467. }
  5468. }
  5469. if items["project"] != nil && reflect.TypeOf(items["project"]).String() == "[]interface {}" {
  5470. projects := items["project"].([]interface{})
  5471. if len(projects) > 0 {
  5472. for _, project := range projects {
  5473. var p models.HisPrescriptionProjectTemplate
  5474. p.PrescriptionId = prescription.ID
  5475. p.Ctime = time.Now().Unix()
  5476. p.Mtime = time.Now().Unix()
  5477. p.PatientId = patient_id
  5478. p.UserOrgId = adminInfo.CurrentOrgId
  5479. p.Status = 1
  5480. errcode := c.setProjectTemplateWithJSON(&p, project.(map[string]interface{}))
  5481. if errcode > 0 {
  5482. c.ServeFailJSONWithSGJErrorCode(errcode)
  5483. return
  5484. }
  5485. service.CreateHisPrescriptionProjectTemplate(&p)
  5486. }
  5487. }
  5488. }
  5489. }
  5490. c.ServeSuccessJSON(map[string]interface{}{
  5491. "msg": "创建成功",
  5492. })
  5493. }
  5494. }
  5495. }
  5496. func (c *HisApiController) PreSettle() {
  5497. id, _ := c.GetInt64("id")
  5498. record_time := c.GetString("record_time")
  5499. his_patient_id, _ := c.GetInt64("his_patient_id")
  5500. timeLayout := "2006-01-02"
  5501. loc, _ := time.LoadLocation("Local")
  5502. settle_accounts_type, _ := c.GetInt64("settle_accounts_type")
  5503. diagnosis_id := c.GetString("diagnosis")
  5504. sick_type, _ := c.GetInt64("sick_type")
  5505. reg_type, _ := c.GetInt64("p_type")
  5506. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5507. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_time+" 00:00:00", loc)
  5508. if err != nil {
  5509. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5510. return
  5511. }
  5512. recordDateTime := theTime.Unix()
  5513. adminUser := c.GetAdminUserInfo()
  5514. var prescriptions []*models.HisPrescription
  5515. var start_time int64
  5516. var end_time int64
  5517. ids_str := c.GetString("ids")
  5518. ids_arr := strings.Split(ids_str, ",")
  5519. fmt.Println(reg_type)
  5520. if settle_accounts_type == 1 { //日结
  5521. if reg_type == 11 || reg_type == 1111 || reg_type == 1112 {
  5522. prescriptions, _ = service.GetPrescriptionByIds(ids_arr, adminUser.CurrentOrgId)
  5523. } else {
  5524. prescriptions, _ = service.GetSettleHisPrescription(adminUser.CurrentOrgId, id, his_patient_id, recordDateTime, reg_type)
  5525. }
  5526. fmt.Println(prescriptions)
  5527. } else { //月结
  5528. start_time_str := c.GetString("start_time")
  5529. end_time_str := c.GetString("end_time")
  5530. timeLayout := "2006-01-02"
  5531. loc, _ := time.LoadLocation("Local")
  5532. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time_str+" 00:00:00", loc)
  5533. if err != nil {
  5534. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5535. return
  5536. }
  5537. recordStartTime := theStartTime.Unix()
  5538. start_time = recordStartTime
  5539. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time_str+" 00:00:00", loc)
  5540. if err != nil {
  5541. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5542. return
  5543. }
  5544. recordEndTime := theEndTime.Unix()
  5545. end_time = recordEndTime
  5546. prescriptions, _ = service.GetMonthHisPrescription(adminUser.CurrentOrgId, id, recordStartTime, recordEndTime, reg_type)
  5547. }
  5548. if reg_type == 1111 || reg_type == 1112 {
  5549. reg_type = 11
  5550. }
  5551. timestamp := time.Now().Unix()
  5552. tempTime := time.Unix(timestamp, 0)
  5553. timeFormat := tempTime.Format("20060102150405")
  5554. chrgBchno := rand.Intn(100000) + 10000
  5555. chrg_bchno := timeFormat + strconv.FormatInt(int64(chrgBchno), 10) + strconv.FormatInt(his.PatientId, 10)
  5556. strconv.FormatInt(his.PatientId, 10)
  5557. var ids []int64
  5558. for _, item := range prescriptions {
  5559. ids = append(ids, item.ID)
  5560. }
  5561. fmt.Println(ids)
  5562. var total float64
  5563. for _, item := range prescriptions {
  5564. fmt.Println(item)
  5565. if item.Type == 1 { //药品
  5566. for _, subItem := range item.HisDoctorAdviceInfo {
  5567. total = total + (subItem.Price * subItem.PrescribingNumber)
  5568. }
  5569. }
  5570. if item.Type == 2 { //项目
  5571. for _, subItem := range item.HisPrescriptionProject {
  5572. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5573. total = total + (subItem.Price * cnt)
  5574. }
  5575. }
  5576. for _, subItem := range item.HisAdditionalCharge {
  5577. total = total + (subItem.Price * float64(subItem.Count))
  5578. }
  5579. }
  5580. allTotal := fmt.Sprintf("%.2f", total)
  5581. totals, _ := strconv.ParseFloat(allTotal, 64)
  5582. order := &models.HisOrder{
  5583. UserOrgId: adminUser.CurrentOrgId,
  5584. HisPatientId: his.ID,
  5585. PatientId: id,
  5586. SettleAccountsDate: recordDateTime,
  5587. Ctime: time.Now().Unix(),
  5588. Mtime: time.Now().Unix(),
  5589. Status: 1,
  5590. OrderStatus: 1,
  5591. MdtrtId: his.Number,
  5592. Number: chrg_bchno,
  5593. MedfeeSumamt: totals,
  5594. SettleEndTime: end_time,
  5595. SettleStartTime: start_time,
  5596. SettleType: settle_accounts_type,
  5597. PType: 2,
  5598. IsPre: 1,
  5599. MedType: strconv.Itoa(int(reg_type)),
  5600. Diagnosis: diagnosis_id,
  5601. }
  5602. err = service.CreateOrder(order)
  5603. if err != nil {
  5604. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCreateOrderException)
  5605. return
  5606. }
  5607. var customs []*Custom
  5608. for _, item := range prescriptions {
  5609. fmt.Println(item.Type)
  5610. if item.Type == 1 { //药品
  5611. for _, subItem := range item.HisDoctorAdviceInfo {
  5612. cus := &Custom{
  5613. AdviceId: subItem.ID,
  5614. ProjectId: 0,
  5615. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*subItem.PrescribingNumber),
  5616. Cut: fmt.Sprintf("%.2f", subItem.PrescribingNumber),
  5617. FeedetlSn: subItem.FeedetlSn,
  5618. Price: fmt.Sprintf("%.2f", subItem.Price),
  5619. MedListCodg: subItem.MedListCodg,
  5620. Type: 1,
  5621. }
  5622. customs = append(customs, cus)
  5623. }
  5624. }
  5625. if item.Type == 2 { //项目
  5626. for _, subItem := range item.HisPrescriptionProject {
  5627. cnt, _ := strconv.ParseFloat(subItem.Count, 64)
  5628. cus := &Custom{
  5629. AdviceId: 0,
  5630. ProjectId: subItem.ID,
  5631. DetItemFeeSumamt: fmt.Sprintf("%.2f", subItem.Price*cnt),
  5632. Cut: fmt.Sprintf("%.2f", cnt),
  5633. FeedetlSn: subItem.FeedetlSn,
  5634. Price: fmt.Sprintf("%.2f", float64(subItem.Price)),
  5635. MedListCodg: subItem.MedListCodg,
  5636. Type: 2,
  5637. }
  5638. customs = append(customs, cus)
  5639. }
  5640. }
  5641. for _, item := range item.HisAdditionalCharge {
  5642. cus := &Custom{
  5643. ItemId: item.ID,
  5644. AdviceId: 0,
  5645. ProjectId: 0,
  5646. DetItemFeeSumamt: fmt.Sprintf("%.2f", item.Price),
  5647. Cut: fmt.Sprintf("%.2f", float64(item.Count)),
  5648. FeedetlSn: item.FeedetlSn,
  5649. Price: fmt.Sprintf("%.2f", float64(item.Price)),
  5650. MedListCodg: item.XtHisAddtionConfig.Code,
  5651. Type: 3,
  5652. }
  5653. customs = append(customs, cus)
  5654. }
  5655. }
  5656. fmt.Println(customs)
  5657. for _, item := range customs {
  5658. var advice_id int64 = 0
  5659. var project_id int64 = 0
  5660. var item_id int64 = 0
  5661. var types int64 = 0
  5662. if item.Type == 1 {
  5663. advice_id = item.AdviceId
  5664. project_id = 0
  5665. item_id = 0
  5666. } else if item.Type == 2 {
  5667. advice_id = 0
  5668. item_id = 0
  5669. project_id = item.ProjectId
  5670. } else if item.Type == 3 {
  5671. advice_id = 0
  5672. item_id = item.ItemId
  5673. project_id = 0
  5674. }
  5675. detItemFeeSumamt, _ := strconv.ParseFloat(item.DetItemFeeSumamt, 32)
  5676. cut, _ := strconv.ParseFloat(item.Cut, 32)
  5677. pric, _ := strconv.ParseFloat(item.Price, 32)
  5678. info := &models.HisOrderInfo{
  5679. OrderNumber: order.Number,
  5680. UploadDate: time.Now().Unix(),
  5681. AdviceId: advice_id,
  5682. DetItemFeeSumamt: detItemFeeSumamt,
  5683. Cnt: cut,
  5684. Pric: pric,
  5685. PatientId: id,
  5686. Status: 1,
  5687. Mtime: time.Now().Unix(),
  5688. Ctime: time.Now().Unix(),
  5689. UserOrgId: adminUser.CurrentOrgId,
  5690. HisPatientId: his.ID,
  5691. OrderId: order.ID,
  5692. ProjectId: project_id,
  5693. Type: types,
  5694. ItemId: item_id,
  5695. }
  5696. service.CreateOrderInfo(info)
  5697. }
  5698. his.SickType = sick_type
  5699. service.UpdataHisPateint(&his)
  5700. err = service.UpDatePrescriptionNumber(adminUser.CurrentOrgId, ids, chrg_bchno)
  5701. err = service.UpDateHisPrescriptionInfoNumber(adminUser.CurrentOrgId, id, chrg_bchno, recordDateTime, his_patient_id)
  5702. //err = service.UpdataOrderStatusTwo(chrg_bchno, adminUser.CurrentOrgId)
  5703. if err == nil {
  5704. c.ServeSuccessJSON(map[string]interface{}{
  5705. "msg": "结算成功",
  5706. })
  5707. }
  5708. }
  5709. type CustomOrderInfo struct {
  5710. Name string
  5711. Spec string
  5712. Unit string
  5713. Count float64
  5714. Price float64
  5715. Total float64
  5716. }
  5717. func (c *HisApiController) GetPrivateExpensesInfo() {
  5718. order_id, _ := c.GetInt64("id", 0)
  5719. his_patient_id, _ := c.GetInt64("his_patient_id", 0)
  5720. order, _ := service.GetHisOrderByID(order_id)
  5721. role, _ := service.GetAdminUserInfoByID(c.GetAdminUserInfo().CurrentOrgId, c.GetAdminUserInfo().AdminUser.Id)
  5722. if order.ID == 0 {
  5723. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrderParamWrong)
  5724. return
  5725. }
  5726. miConfig, _ := service.FindMedicalInsuranceInfo(c.GetAdminUserInfo().CurrentOrgId)
  5727. his, _ := service.GetHisPatientByIdThree(his_patient_id)
  5728. org_id := c.GetAdminUserInfo().CurrentOrgId
  5729. adminInfo, _ := service.GetAdminUserInfoByID(org_id, order.Creator)
  5730. //order_info, _ := service.GetHisOrderDetailByNumber(order.Number, org_id)
  5731. orderInfos, _ := service.GetHisOrderInfoByNumberOne(order.Number)
  5732. orderInfos_two, _ := service.GetHisOrderInfoByNumberTwo(order.Number)
  5733. orderInfos_three, _ := service.GetHisOrderInfoByNumberThree(order.Number)
  5734. var orderInfos_four []*models.HisOrderInfoTwo
  5735. for _, item := range orderInfos_three {
  5736. if item.HisPrescriptionProject.HisProject.CostClassify == 3 {
  5737. item.HisPrescriptionProject.IsCheckTeam = 1
  5738. orderInfos_four = append(orderInfos_four, item)
  5739. }
  5740. if item.HisPrescriptionProject.HisProject.CostClassify != 3 {
  5741. item.HisPrescriptionProject.IsCheckTeam = 2
  5742. orderInfos_two = append(orderInfos_two, item)
  5743. }
  5744. }
  5745. new_order_info := RemoveRepeatedTeam(orderInfos_four)
  5746. var cus_slice []CustomOrderInfo
  5747. for _, item := range new_order_info {
  5748. var cus CustomOrderInfo
  5749. cus.Name = item.HisPrescriptionProject.XtHisProjectTeam.ProjectTeam
  5750. cus.Unit = ""
  5751. cus.Spec = ""
  5752. var total float64
  5753. for _, subItem := range orderInfos_four {
  5754. if item.HisPrescriptionProject.TeamId == subItem.HisPrescriptionProject.TeamId {
  5755. total = total + subItem.DetItemFeeSumamt
  5756. fmt.Println(subItem.DetItemFeeSumamt)
  5757. }
  5758. }
  5759. cus.Count = 1
  5760. cus.Total = total
  5761. cus_slice = append(cus_slice, cus)
  5762. }
  5763. orderInfos = append(orderInfos, orderInfos_two...)
  5764. if c.GetAdminUserInfo().CurrentOrgId != 10138 {
  5765. orderInfos = append(orderInfos, orderInfos_three...)
  5766. }
  5767. patient, _ := service.GetPatientByID(org_id, order.PatientId)
  5768. c.ServeSuccessJSON(map[string]interface{}{
  5769. "order": order,
  5770. "order_info": orderInfos,
  5771. "patient": patient,
  5772. "admin_info": adminInfo,
  5773. "his": his,
  5774. "current_admin": role,
  5775. "org_config": miConfig,
  5776. "new_order_info": cus_slice,
  5777. })
  5778. }
  5779. func (this *HisApiController) ChangeMedType() {
  5780. med_type := this.GetString("med_type")
  5781. old_med_type := this.GetString("old_med_type")
  5782. ids := this.GetString("ids")
  5783. settle_type, _ := this.GetInt64("settle_type")
  5784. start_time := this.GetString("start_time")
  5785. end_time := this.GetString("end_time")
  5786. ids_arr := strings.Split(ids, ",")
  5787. if settle_type == 1 { //日结
  5788. id, _ := strconv.ParseInt(ids_arr[0], 10, 64)
  5789. prescription, _ := service.GetPrescriptionById(id, this.GetAdminUserInfo().CurrentOrgId)
  5790. prescription.MedType = med_type
  5791. err := service.SaveHisPrescription(&prescription)
  5792. if err == nil {
  5793. this.ServeSuccessJSON(map[string]interface{}{
  5794. "msg": "修改成功",
  5795. })
  5796. } else {
  5797. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5798. return
  5799. }
  5800. } else if settle_type == 2 {
  5801. timeLayout := "2006-01-02"
  5802. loc, _ := time.LoadLocation("Local")
  5803. theStartTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5804. if err != nil {
  5805. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5806. return
  5807. }
  5808. recordStartTime := theStartTime.Unix()
  5809. start_time_timestamp := recordStartTime
  5810. theEndTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 00:00:00", loc)
  5811. if err != nil {
  5812. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5813. return
  5814. }
  5815. recordEndTime := theEndTime.Unix()
  5816. end_time_timestamp := recordEndTime
  5817. updateErr := service.UpdateBatchHisPrescriptionMedType(ids_arr, med_type, start_time_timestamp, end_time_timestamp, this.GetAdminUserInfo().CurrentOrgId, old_med_type)
  5818. if updateErr == nil {
  5819. this.ServeSuccessJSON(map[string]interface{}{
  5820. "msg": "修改成功",
  5821. })
  5822. } else {
  5823. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  5824. return
  5825. }
  5826. }
  5827. }
  5828. func (c *HisApiController) GetHisMonthChargePatientInfo() {
  5829. patient_id, _ := c.GetInt64("patient_id")
  5830. his_patient_id, _ := c.GetInt64("his_patient_id")
  5831. record_date := c.GetString("record_date")
  5832. start_time := c.GetString("start_time")
  5833. end_time := c.GetString("end_time")
  5834. order_status, _ := c.GetInt64("type", 0)
  5835. p_type, _ := c.GetInt64("p_type", 0)
  5836. order_id, _ := c.GetInt64("order_id", 0)
  5837. timeLayout := "2006-01-02"
  5838. loc, _ := time.LoadLocation("Local")
  5839. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5840. if err != nil {
  5841. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5842. return
  5843. }
  5844. recordDateTime := theTime.Unix()
  5845. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5846. if err != nil {
  5847. }
  5848. startRecordDateTime := startTime.Unix()
  5849. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5850. if err != nil {
  5851. }
  5852. endRecordDateTime := endTime.Unix()
  5853. admin := c.GetAdminUserInfo()
  5854. his_patient_info, _ := service.GetNewHisPatientInfo(his_patient_id)
  5855. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5856. order, _ := service.GetHisOrderByID(order_id)
  5857. var monthPrescriptions []*models.HisPrescription
  5858. if order_status == 1 || order_status == 0 {
  5859. monthPrescriptions, _ = service.GetUnChargeMonthHisPrescriptionThree(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5860. } else if order_status == 2 {
  5861. monthPrescriptions, _ = service.GetChargeMonthHisPrescriptionFive(admin.CurrentOrgId, patient_id, order.Number, p_type)
  5862. }
  5863. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5864. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5865. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5866. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5867. //获取所有科室信息
  5868. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5869. c.ServeSuccessJSON(map[string]interface{}{
  5870. "his_info": his_patient_info,
  5871. "xt_info": xt_patient_info,
  5872. "case_history": case_history,
  5873. "info": patientPrescriptionInfo,
  5874. "last_info": lastPatientPrescriptionInfo,
  5875. "month_prescriptions": monthPrescriptions,
  5876. "order": order,
  5877. "doctors": doctors,
  5878. "department": department,
  5879. })
  5880. return
  5881. }
  5882. func (c *HisApiController) GetHisMonthPatientInfo() {
  5883. patient_id, _ := c.GetInt64("patient_id")
  5884. his_patient_id, _ := c.GetInt64("his_patient_id")
  5885. record_date := c.GetString("record_date")
  5886. number := c.GetString("number")
  5887. start_time := c.GetString("start_time")
  5888. end_time := c.GetString("end_time")
  5889. p_type, _ := c.GetInt64("p_type")
  5890. timeLayout := "2006-01-02"
  5891. loc, _ := time.LoadLocation("Local")
  5892. theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", record_date+" 00:00:00", loc)
  5893. if err != nil {
  5894. c.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  5895. return
  5896. }
  5897. recordDateTime := theTime.Unix()
  5898. startTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
  5899. if err != nil {
  5900. }
  5901. startRecordDateTime := startTime.Unix()
  5902. endTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
  5903. if err != nil {
  5904. }
  5905. endRecordDateTime := endTime.Unix()
  5906. admin := c.GetAdminUserInfo()
  5907. his_patient_info, _ := service.GetNewHisPatientInfoTwo(admin.CurrentOrgId, his_patient_id, recordDateTime)
  5908. xt_patient_info, _ := service.GetXTPatientInfo(admin.CurrentOrgId, patient_id)
  5909. count, _ := service.GetHisPatientCount(admin.CurrentOrgId, patient_id, recordDateTime)
  5910. monthPrescriptions, _ := service.GetMonthHisPrescriptionTwo(admin.CurrentOrgId, patient_id, startRecordDateTime, endRecordDateTime, p_type)
  5911. case_history, _ := service.GetHisPatientCaseHistoryInfo(admin.CurrentOrgId, patient_id, recordDateTime)
  5912. patientPrescriptionInfo, _ := service.FindPatientPrescriptionInfo(admin.CurrentOrgId, patient_id, recordDateTime, p_type, his_patient_id)
  5913. lastPatientPrescriptionInfo, _ := service.FindLastPatientPrescriptionInfoTwo(admin.CurrentOrgId, patient_id, recordDateTime, p_type)
  5914. order, _ := service.GetHisOrder(admin.CurrentOrgId, number, patient_id)
  5915. doctors, _ := service.GetHisAdminUserDoctors(admin.CurrentOrgId)
  5916. _, drugStockConfig := service.FindDrugStockAutomaticReduceRecordByOrgId(admin.CurrentOrgId)
  5917. //获取所有科室信息
  5918. department, _ := service.GetAllDepartMent(admin.CurrentOrgId)
  5919. c.ServeSuccessJSON(map[string]interface{}{
  5920. "his_info": his_patient_info,
  5921. "xt_info": xt_patient_info,
  5922. "case_history": case_history,
  5923. "info": patientPrescriptionInfo,
  5924. "month_prescriptions": monthPrescriptions,
  5925. "order": order,
  5926. "doctors": doctors,
  5927. "department": department,
  5928. "count": count,
  5929. "drugStockConfig": drugStockConfig,
  5930. "last_info": lastPatientPrescriptionInfo,
  5931. })
  5932. return
  5933. }
  5934. func (c *HisApiController) GetAllOrder() {
  5935. org_id := c.GetAdminUserInfo().CurrentOrgId
  5936. orders, _ := service.GetNewHisOrderList(org_id)
  5937. c.ServeSuccessJSON(map[string]interface{}{
  5938. "order": orders,
  5939. })
  5940. return
  5941. }
  5942. func RemoveRepeatedTeam(arr []*models.HisOrderInfoTwo) (newArr []*models.HisOrderInfoTwo) {
  5943. newArr = make([]*models.HisOrderInfoTwo, 0)
  5944. for i := 0; i < len(arr); i++ {
  5945. repeat := false
  5946. for j := i + 1; j < len(arr); j++ {
  5947. if arr[i].HisPrescriptionProject.TeamId == arr[j].HisPrescriptionProject.TeamId {
  5948. repeat = true
  5949. break
  5950. }
  5951. }
  5952. if !repeat {
  5953. newArr = append(newArr, arr[i])
  5954. }
  5955. }
  5956. return
  5957. }
  5958. //修改处方退库操作 参数传修改之前的处方数据
  5959. func DeleteDrugWarehosueInfo(advice models.HisDoctorAdviceInfo) (err error) {
  5960. if advice.ExecutionState == 1 {
  5961. //查询该病人该药品是否有库存记录
  5962. info, errcode := service.GetDrugAutoWarehouseOut(advice.PatientId, advice.AdviceDate, advice.DrugId)
  5963. if errcode == gorm.ErrRecordNotFound {
  5964. } else {
  5965. //退库
  5966. drug, _ := service.FindBaseDrugLibRecord(advice.UserOrgId, advice.DrugId)
  5967. if advice.PrescribingNumberUnit == drug.MinUnit {
  5968. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  5969. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  5970. //退库
  5971. warehouseInfo := models.DrugWarehouseInfo{
  5972. StockMinNumber: prescribingNumber,
  5973. }
  5974. service.UpdateDrugWarehouse(info.WarehouseInfoId, warehouseInfo)
  5975. operation_time := time.Now().Unix()
  5976. creater := advice.AdviceDoctor
  5977. ctime := time.Now().Unix()
  5978. timeStr := time.Now().Format("2006-01-02")
  5979. timeArr := strings.Split(timeStr, "-")
  5980. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  5981. total = total + 1
  5982. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  5983. cancelStock := models.DrugCancelStock{
  5984. OrderNumber: orderNumber,
  5985. OperaTime: operation_time,
  5986. OrgId: advice.UserOrgId,
  5987. Creater: creater,
  5988. Ctime: ctime,
  5989. Status: 1,
  5990. ReturnTime: advice.AdviceDate,
  5991. Dealer: info.Dealer,
  5992. Manufacturer: info.Manufacturer,
  5993. Type: 1,
  5994. }
  5995. service.AddSigleDrugCancelStock(&cancelStock)
  5996. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  5997. dealer, _ := service.GetDealerById(info.Dealer)
  5998. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  5999. cancelStockInfo := models.DrugCancelStockInfo{
  6000. OrderNumber: cancelInfo.OrderNumber,
  6001. CancelStockId: cancelInfo.ID,
  6002. DrugId: info.DrugId,
  6003. Count: info.Count,
  6004. Status: 1,
  6005. Ctime: ctime,
  6006. OrgId: advice.UserOrgId,
  6007. Type: 1,
  6008. Manufacturer: manufactureName.ManufacturerName,
  6009. Dealer: dealer.DealerName,
  6010. Total: 0,
  6011. RetailPrice: info.RetailPrice,
  6012. RetailTotalPrice: info.RetailTotalPrice,
  6013. Price: info.Price,
  6014. RegisterAccount: "",
  6015. Remark: info.Remark,
  6016. BatchNumber: info.BatchNumber,
  6017. MaxUnit: info.CountUnit,
  6018. ProductDate: info.ProductDate,
  6019. ExpiryDate: info.ExpiryDate,
  6020. BatchNumberId: info.WarehouseInfoId,
  6021. }
  6022. flow := models.DrugFlow{
  6023. WarehousingId: 0,
  6024. DrugId: info.DrugId,
  6025. Number: "",
  6026. BatchNumber: info.BatchNumber,
  6027. Count: info.Count,
  6028. UserOrgId: advice.UserOrgId,
  6029. PatientId: 0,
  6030. SystemTime: ctime,
  6031. ConsumableType: 4,
  6032. IsSys: 0,
  6033. WarehousingOrder: "",
  6034. WarehouseOutId: 0,
  6035. WarehouseOutOrderNumber: "",
  6036. IsEdit: 0,
  6037. CancelStockId: cancelStock.ID,
  6038. CancelOrderNumber: cancelStock.OrderNumber,
  6039. Manufacturer: info.Manufacturer,
  6040. Dealer: info.Dealer,
  6041. Creator: advice.UserOrgId,
  6042. UpdateCreator: 0,
  6043. Status: 1,
  6044. Ctime: time.Now().Unix(),
  6045. Mtime: 0,
  6046. Price: info.Price,
  6047. WarehousingDetailId: 0,
  6048. WarehouseOutDetailId: 0,
  6049. CancelOutDetailId: 0,
  6050. ExpireDate: info.ExpiryDate,
  6051. ProductDate: info.ProductDate,
  6052. MaxUnit: info.CountUnit,
  6053. MinUnit: "",
  6054. }
  6055. service.CreatedCancelStock(cancelStockInfo)
  6056. service.CreateDrugFlowOne(flow)
  6057. } else {
  6058. floatPrescrip := strconv.FormatFloat(advice.PrescribingNumber, 'f', -1, 32)
  6059. prescribingNumber, _ := strconv.ParseInt(floatPrescrip, 10, 64)
  6060. if advice.PrescribingNumberUnit == drug.MaxUnit {
  6061. warehouseInfo := models.DrugWarehouseInfo{
  6062. StockMinNumber: prescribingNumber,
  6063. }
  6064. service.UpdateDrugWarehouseOne(info.WarehouseInfoId, warehouseInfo)
  6065. }
  6066. operation_time := time.Now().Unix()
  6067. creater := advice.AdviceDoctor
  6068. ctime := time.Now().Unix()
  6069. timeStr := time.Now().Format("2006-01-02")
  6070. timeArr := strings.Split(timeStr, "-")
  6071. total, _ := service.FindAllDrugCancelStockTotal(advice.UserOrgId)
  6072. total = total + 1
  6073. orderNumber := "CKTKD" + strconv.FormatInt(advice.UserOrgId, 10) + timeArr[0] + timeArr[1] + timeArr[2] + "000" + strconv.FormatInt(total, 10)
  6074. cancelStock := models.DrugCancelStock{
  6075. OrderNumber: orderNumber,
  6076. OperaTime: operation_time,
  6077. OrgId: advice.UserOrgId,
  6078. Creater: creater,
  6079. Ctime: ctime,
  6080. Status: 1,
  6081. ReturnTime: advice.AdviceDate,
  6082. Dealer: info.Dealer,
  6083. Manufacturer: info.Manufacturer,
  6084. Type: 1,
  6085. }
  6086. service.AddSigleDrugCancelStock(&cancelStock)
  6087. manufactureName, _ := service.GetManufactureById(info.Manufacturer)
  6088. dealer, _ := service.GetDealerById(info.Dealer)
  6089. cancelInfo, _ := service.GetLastDrugCancelStockById(advice.UserOrgId)
  6090. cancelStockInfo := models.DrugCancelStockInfo{
  6091. OrderNumber: cancelInfo.OrderNumber,
  6092. CancelStockId: cancelInfo.ID,
  6093. DrugId: info.DrugId,
  6094. Count: info.Count,
  6095. Status: 1,
  6096. Ctime: ctime,
  6097. OrgId: advice.UserOrgId,
  6098. Type: 1,
  6099. Manufacturer: manufactureName.ManufacturerName,
  6100. Dealer: dealer.DealerName,
  6101. Total: 0,
  6102. RetailPrice: info.RetailPrice,
  6103. RetailTotalPrice: info.RetailTotalPrice,
  6104. Price: info.Price,
  6105. RegisterAccount: "",
  6106. Remark: info.Remark,
  6107. BatchNumber: info.BatchNumber,
  6108. MaxUnit: info.CountUnit,
  6109. ProductDate: info.ProductDate,
  6110. ExpiryDate: info.ExpiryDate,
  6111. BatchNumberId: info.WarehouseInfoId,
  6112. }
  6113. flow := models.DrugFlow{
  6114. WarehousingId: 0,
  6115. DrugId: info.DrugId,
  6116. Number: "",
  6117. BatchNumber: info.BatchNumber,
  6118. Count: info.Count,
  6119. UserOrgId: advice.UserOrgId,
  6120. PatientId: 0,
  6121. SystemTime: ctime,
  6122. ConsumableType: 4,
  6123. IsSys: 0,
  6124. WarehousingOrder: "",
  6125. WarehouseOutId: 0,
  6126. WarehouseOutOrderNumber: "",
  6127. IsEdit: 0,
  6128. CancelStockId: cancelStock.ID,
  6129. CancelOrderNumber: cancelStock.OrderNumber,
  6130. Manufacturer: info.Manufacturer,
  6131. Dealer: info.Dealer,
  6132. Creator: advice.AdviceDoctor,
  6133. UpdateCreator: 0,
  6134. Status: 1,
  6135. Ctime: time.Now().Unix(),
  6136. Mtime: 0,
  6137. Price: info.Price,
  6138. WarehousingDetailId: 0,
  6139. WarehouseOutDetailId: 0,
  6140. CancelOutDetailId: 0,
  6141. ExpireDate: info.ExpiryDate,
  6142. ProductDate: info.ProductDate,
  6143. MaxUnit: info.CountUnit,
  6144. MinUnit: "",
  6145. }
  6146. service.CreatedCancelStock(cancelStockInfo)
  6147. service.CreateDrugFlowOne(flow)
  6148. }
  6149. }
  6150. }
  6151. return err
  6152. }
  6153. func (this *HisApiController) DeleteNCDS() {
  6154. id, _ := this.GetInt64("id", 0)
  6155. if id > 0 {
  6156. service.DeletePsnNCDSRecordById(id)
  6157. this.ServeSuccessJSON(map[string]interface{}{
  6158. "msg": "删除成功",
  6159. })
  6160. } else {
  6161. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRecordFailedException)
  6162. return
  6163. }
  6164. }
  6165. func (c *HisApiController) GetHisDoctorAdviceInfo() {
  6166. id, _ := c.GetInt64("id")
  6167. advice, _ := service.GetHisDoctorAdviceInfo(id)
  6168. c.ServeSuccessJSON(map[string]interface{}{
  6169. "advice": advice,
  6170. })
  6171. return
  6172. }