his_api_controller.go 179KB

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