his_api_controller.go 237KB

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