his_api_controller.go 246KB

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