his_api_controller.go 190KB

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