123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989 |
- package statistics_service
-
- import (
- "XT_New/models"
- "XT_New/service"
- "fmt"
- "github.com/jinzhu/gorm"
- "math"
- "strconv"
- "strings"
- )
-
- func GetOrgFirstPatientInfo(user_org_id int64) (patient *models.Patients, err error) {
- db := service.XTReadDB()
- var tempPatient models.Patients
- findErr := db.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", user_org_id).Last(&tempPatient).Error
- if findErr == gorm.ErrRecordNotFound {
- return nil, nil
- }
- if findErr != nil {
- return nil, findErr
- }
- return &tempPatient, nil
- }
-
- type ProcessIndexDataStruct struct {
- Date string `json:"date"`
- Value float64 `json:"value"`
- }
-
- // 透析过程统计
- func GetDialysisProcessIndexChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (datas []*ProcessIndexDataStruct, err error) {
- db := service.XTReadDB()
- switch statistics_type {
- case 1:
- err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, weight_before as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- break
- case 2:
- err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, weight_after as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- break
- case 3:
- err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, systolic_blood_pressure as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? AND systolic_blood_pressure <> 0 ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- break
- case 4:
- err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, diastolic_blood_pressure as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? AND diastolic_blood_pressure <> 0", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- break
- case 5:
- err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, pulse_frequency as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- break
- case 6:
- err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, systolic_blood_pressure as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? AND systolic_blood_pressure <> 0", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- break
- case 7:
- err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, diastolic_blood_pressure as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? AND diastolic_blood_pressure <> 0 ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- break
- case 8:
- err = db.Raw("select from_unixtime(assessment_date,'%Y-%m-%d') as date, pulse_frequency as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND assessment_date <= ? AND assessment_date >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- break
-
- }
- if err != nil {
- return nil, err
- }
- return datas, nil
-
- }
-
- type otherItemAmount struct {
- Total int64 `json:"total"`
- Name string `json:"name"`
- Ratio string `json:"ratio"`
- }
-
- func GetDialysisProcessIndexOtherChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (item []*otherItemAmount, err error) {
- db := service.XTReadDB()
- var items []*otherItemAmount
- var tempErr error
- var total int64
- switch statistics_type {
- case 9:
- tempErr = db.Table("xt_dialysis_prescription as p").Where("p.user_org_id=? and p.status=1 and p.record_date >= ? and p.record_date <= ? AND p.patient_id = ? ", user_org_id, start_time, end_time, patient_id).
- Select("CASE WHEN p.mode_id = 1 THEN 'HD'" +
- " WHEN p.mode_id = 2 THEN 'HDF'" +
- " WHEN p.mode_id = 3 THEN 'HD+HP'" +
- " WHEN p.mode_id = 4 THEN 'HP'" +
- " WHEN p.mode_id = 5 THEN 'HF'" +
- " WHEN p.mode_id = 6 THEN 'SCUF'" +
- " WHEN p.mode_id = 7 THEN 'IUF'" +
- " WHEN p.mode_id = 8 THEN 'HFHD'" +
- " WHEN p.mode_id = 9 THEN 'HFHD+HP'" +
- " WHEN p.mode_id = 10 THEN 'PHF'" +
- " WHEN p.mode_id = 11 THEN 'HFR'" +
- " WHEN p.mode_id = 12 THEN 'HDF+HP'" +
- " WHEN p.mode_id = 13 THEN 'CRRT'" +
- " WHEN p.mode_id = 14 THEN '腹水回输'" +
- " WHEN p.mode_id = 19 THEN 'IUF+HD'" +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("p.mode_id").Scan(&items).Error
-
- break
- case 10:
- tempErr = db.Table("xt_dialysis_prescription as p").Where("p.user_org_id=? and p.status=1 and p.record_date >= ? and p.record_date <= ? AND p.patient_id = ? ", user_org_id, start_time, end_time, patient_id).
- Select("CASE WHEN p.anticoagulant = 1 THEN '无肝素'" +
- " WHEN p.anticoagulant = 2 THEN '普通肝素'" +
- " WHEN p.anticoagulant = 3 THEN '低分子肝素'" +
- " WHEN p.anticoagulant = 4 THEN '阿加曲班'" +
- " WHEN p.anticoagulant = 5 THEN '枸橼酸钠'" +
- " WHEN p.anticoagulant = 6 THEN '低分子肝素钙'" +
- " WHEN p.anticoagulant = 7 THEN '低分子肝素钠'" +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("p.anticoagulant").Scan(&items).Error
-
- break
- }
-
- db.Table("xt_dialysis_prescription as p").Where("p.user_org_id=? AND p.status = 1 AND p.patient_id = ? AND p.record_date >= ? and p.record_date <= ? ", user_org_id, patient_id, start_time, end_time).Count(&total)
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
- if tempErr != nil {
- return nil, err
- }
- return items, nil
- }
-
- type PatientDialysisRecord struct {
- models.VMSchedule
- DeviceNumber VMDeviceNumber `gorm:"foreignkey:ID;AssociationForeignKey:BedId;" json:"device_number"`
- DialysisPrescription VMDialysisPrescription `json:"prescription" gorm:"foreignkey:RecordDate;AssociationForeignKey:ScheduleDate;"`
- PredialysisEvaluation VMPredialysisEvaluation `json:"predialysis_evaluation" gorm:"foreignkey:AssessmentDate;AssociationForeignKey:ScheduleDate;"`
- AssessmentAfterDislysis models.AssessmentAfterDislysis `json:"assessment_after_dislysis" gorm:"foreignkey:AssessmentDate;AssociationForeignKey:ScheduleDate;"`
- Patient VMPatients `json:"patient" gorm:"foreignkey:ID;AssociationForeignKey:PatientID;"`
- }
-
- func GetDialysisProcessIndexTableData(orgID, patientID int64, page, limit, start, end int64) ([]*PatientDialysisRecord, int64, error) {
- offset := (page - 1) * limit
- var total int64
- var err error
- var orders []*PatientDialysisRecord
- readDb := service.XTReadDB()
- db := readDb.Table("xt_schedule as sch").
- Preload("DeviceNumber", "org_id=? and status=1", orgID).
- Preload("DialysisPrescription", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("PredialysisEvaluation", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("AssessmentAfterDislysis", "patient_id=? and user_org_id=? and status=1", patientID, orgID).
- Preload("Patient", "user_org_id=? and status=1", orgID).
- Where("sch.patient_id=? and sch.user_org_id=? and sch.status=1", patientID, orgID).Group("sch.schedule_date")
- if start != 0 {
- db = db.Where("sch.schedule_date>=?", start)
- }
- if end != 0 {
- db = db.Where("sch.schedule_date<=?", end)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("sch.schedule_date desc").Select("sch.patient_id,sch.schedule_date,sch.bed_id,sch.user_org_id").Find(&orders).Error
- return orders, total, err
- }
- func GetAnticoagulantData(user_org_id int64) (config []*models.Dataconfig, tempErr error) {
- var tempDataConfig []*models.Dataconfig
- var tempConfig models.Dataconfig
- db := service.XTReadDB()
- db.Model(&models.Dataconfig{}).Where("name = '抗凝剂' AND field_name = 'anticoagulant' AND parent_id = 0").First(&tempConfig)
- err := db.Model(&models.Dataconfig{}).Where("(org_id = 0 OR org_id = ?) AND parent_id = ?", user_org_id, tempConfig.ID).Find(&tempDataConfig).Error
- return tempDataConfig, err
- }
-
- //透析过程统计
-
- // 透析监测统计
- func GetDialysisWatchChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (datas []*ProcessIndexDataStruct, err error) {
- db := service.XTReadDB()
- switch statistics_type {
- case 1:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.systolic_blood_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? AND systolic_blood_pressure <> 0 Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.systolic_blood_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? AND systolic_blood_pressure <> 0 Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- }
- break
- case 2:
-
- if patient_id == 0 {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.diastolic_blood_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? AND diastolic_blood_pressure <> 0 Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.diastolic_blood_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? AND diastolic_blood_pressure <> 0 Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
-
- break
- case 3:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.pulse_frequency as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.pulse_frequency as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
- break
- case 4:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.breathing_rate as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.breathing_rate as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
- break
- case 5:
- if patient_id == 0 {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.temperature as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.temperature as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ?Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
- break
- case 6:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.blood_flow_volume as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.blood_flow_volume as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
- break
- case 7:
- if patient_id == 0 {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.venous_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.venous_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
- break
- case 8:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.arterial_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.arterial_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- }
- break
- case 9:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.transmembrane_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.transmembrane_pressure as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
-
- break
- case 10:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.dialysate_temperature as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.dialysate_temperature as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
-
- break
- case 11:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.ultrafiltration_rate as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.ultrafiltration_rate as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
-
- break
- case 12:
- if patient_id == 0 {
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.ultrafiltration_volume as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, end_time, start_time).Scan(&datas).Error
-
- } else {
-
- err = db.Raw("select from_unixtime(monitor.operate_time,'%Y-%m-%d') as date, monitor.ultrafiltration_volume as value from xt_monitoring_record as monitor Where status = 1 AND user_org_id = ? AND patient_id = ? AND operate_time <= ? AND operate_time >= ? Order by operate_time asc", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
-
- }
-
- break
- }
-
- if err != nil {
- return nil, err
- }
- return datas, nil
-
- }
- func GetDialysisWatchTableData(orgID, patientID int64, page, limit, start, end int64) ([]*VMMonitoringRecord, int64, error) {
- offset := (page - 1) * limit
- var total int64
- var err error
- var orders []*VMMonitoringRecord
- readDb := service.XTReadDB()
- db := readDb.Table("xt_monitoring_record as mo").
- Where(" mo.user_org_id=? and mo.status=1", orgID)
- if patientID != 0 {
- db = db.Where("mo.patient_id =?", patientID)
- }
- if start != 0 {
- db = db.Where("mo.operate_time>=?", start)
- }
- if end != 0 {
- db = db.Where("mo.operate_time<=?", end)
- }
- err = db.Count(&total).Offset(offset).Limit(limit).Order("mo.operate_time desc").Select("mo.patient_id,mo.operate_time,mo.systolic_blood_pressure, mo.diastolic_blood_pressure, mo.pulse_frequency,mo.breathing_rate,mo.temperature,mo.blood_flow_volume,mo.venous_pressure,mo.arterial_pressure,mo.transmembrane_pressure,mo.dialysate_temperature,mo.ultrafiltration_rate,mo.ultrafiltration_volume").Find(&orders).Error
- return orders, total, err
- }
-
- //透析监测统计
-
- // 透析体重统计
- func GetDialysisWeightChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int) (item []*otherItemAmount, err error) {
- db := service.XTReadDB()
- var items []*otherItemAmount
- var tempErr error
- var Total int64
- switch statistics_type {
- case 1:
- db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).Count(&Total)
- tempErr = db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).
- Select("CASE WHEN dry_weight < 40 THEN '小于40kg'" +
- " WHEN dry_weight >= 40 AND dry_weight < 50 THEN '40~50kg'" +
- " WHEN dry_weight >= 50 AND dry_weight < 60 THEN '50~60kg'" +
- " WHEN dry_weight >= 60 AND dry_weight < 70 THEN '60~70kg'" +
- " WHEN dry_weight >= 70 THEN '大于70kg'" +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
-
- var isHasConditionOne bool = false
- var isHasConditionTwo bool = false
- var isHasConditionThree bool = false
- var isHasConditionFour bool = false
- var isHasConditionFive bool = false
-
- for _, item := range items {
- if item.Name == "小于40kg" {
- isHasConditionOne = true
- }
- if item.Name == "40~50kg" {
- isHasConditionTwo = true
- }
- if item.Name == "60~70kg" {
- isHasConditionThree = true
- }
- if item.Name == "大于70kg" {
- isHasConditionFour = true
- }
- if item.Name == "待定/卧床" {
- isHasConditionFive = true
- }
- }
- if !isHasConditionOne {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "小于40kg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- if !isHasConditionTwo {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "40~50kg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
- if !isHasConditionThree {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "60~70kg",
- Ratio: "0",
- }
- items = append(items, newItem)
-
- }
-
- if !isHasConditionFour {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "大于70kg",
- Ratio: "0",
- }
- items = append(items, newItem)
-
- }
-
- if !isHasConditionFive {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "未知",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
-
- break
- case 2:
- db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).Count(&Total)
-
- tempErr = db.Table("xt_assessment_before_dislysis").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).
- Select("CASE WHEN weight_before < 40 THEN '小于40kg'" +
- " WHEN weight_before >= 40 AND weight_before < 50 THEN '40~50kg'" +
- " WHEN weight_before >= 50 AND weight_before < 60 THEN '50~60kg'" +
- " WHEN weight_before >= 60 AND weight_before < 70 THEN '60~70kg'" +
- " WHEN weight_before >= 70 THEN '大于70kg'" +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
-
- var isHasConditionOne bool = false
- var isHasConditionTwo bool = false
- var isHasConditionThree bool = false
- var isHasConditionFour bool = false
- var isHasConditionFive bool = false
-
- for _, item := range items {
- if item.Name == "小于40kg" {
- isHasConditionOne = true
- }
- if item.Name == "40~50kg" {
- isHasConditionTwo = true
- }
-
- if item.Name == "60~70kg" {
- isHasConditionThree = true
- }
-
- if item.Name == "大于70kg" {
- isHasConditionFour = true
- }
-
- if item.Name == "未知" {
- isHasConditionFive = true
- }
- }
- if !isHasConditionOne {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "小于40kg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- if !isHasConditionTwo {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "40~50kg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
- if !isHasConditionThree {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "60~70kg",
- Ratio: "0",
- }
- items = append(items, newItem)
-
- }
-
- if !isHasConditionFour {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "大于70kg",
- Ratio: "0",
- }
- items = append(items, newItem)
-
- }
-
- if !isHasConditionFive {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "未知",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
-
- break
- case 3:
-
- //db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).Count(&Total)
-
- //db.Raw("Select count(*) from `xt_assessment_before_dislysis` LEFT JOIN `xt_assessment_after_dislysis` On xt_assessment_before_dislysis.`patient_id` = xt_assessment_after_dislysis.`patient_id` AND xt_assessment_before_dislysis.assessment_date = xt_assessment_after_dislysis.assessment_date AND xt_assessment_after_dislysis.weight_after != 0 Where xt_assessment_before_dislysis.user_org_id = ? AND xt_assessment_before_dislysis.created_time >= ? AND xt_assessment_before_dislysis.created_time <= ? Order by xt_assessment_before_dislysis.assessment_date desc", user_org_id, start_time, end_time).Count(&Total)
-
- var newTotal int64
- type weight struct {
- WeightAfter float64 `json:"weight_after"`
- WeightBefore float64 `json:"weight_before"`
- }
- var weights []*weight
- var weightAdd []float64
- db.Raw("Select xt_assessment_after_dislysis.weight_after as weight_after ,xt_assessment_before_dislysis.weight_before as weight_before from `xt_assessment_before_dislysis` LEFT JOIN `xt_assessment_after_dislysis` On xt_assessment_before_dislysis.`patient_id` = xt_assessment_after_dislysis.`patient_id` AND xt_assessment_before_dislysis.assessment_date = xt_assessment_after_dislysis.assessment_date AND xt_assessment_after_dislysis.weight_after <> 0 AND xt_assessment_after_dislysis.user_org_id = ? Where xt_assessment_before_dislysis.user_org_id = ? AND xt_assessment_before_dislysis.created_time >= ? AND xt_assessment_before_dislysis.created_time <= ? Order by xt_assessment_before_dislysis.assessment_date desc", user_org_id, user_org_id, start_time, end_time).Scan(&weights)
- for index, _ := range weights {
- if index+1 < len(weights) {
- if weights[index+1].WeightAfter == 0 || weights[index].WeightBefore == 0 {
- continue
- }
- weightAdd = append(weightAdd, weights[index].WeightBefore-weights[index+1].WeightAfter)
- }
- }
-
- var total_one int64
- var total_two int64
- var total_three int64
- var total_four int64
- var total_five int64
-
- for _, item := range weightAdd {
- if item < 1 {
- total_one++
-
- }
-
- if item >= 1 && item < 2 {
- total_two++
-
- }
-
- if item >= 2 && item < 3 {
- total_three++
-
- }
-
- if item >= 3 && item <= 4 {
- total_four++
-
- }
-
- if item > 4 {
- total_five++
-
- }
- }
-
- newTotal = total_one + total_two + total_three + total_four + total_five
-
- newItem := &otherItemAmount{
- Total: total_one,
- Name: "小于1kg",
- Ratio: "0",
- }
- newItem1 := &otherItemAmount{
- Total: total_two,
- Name: "1-2kg",
- Ratio: "0",
- }
- newItem2 := &otherItemAmount{
- Total: total_three,
- Name: "2-3kg",
- Ratio: "0",
- }
- newItem3 := &otherItemAmount{
- Total: total_four,
- Name: "3-4kg",
- Ratio: "0",
- }
- newItem4 := &otherItemAmount{
- Total: total_five,
- Name: "大于4kg",
- Ratio: "0",
- }
-
- items = append(items, newItem)
- items = append(items, newItem1)
- items = append(items, newItem2)
- items = append(items, newItem3)
- items = append(items, newItem4)
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(newTotal)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(newTotal))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
-
- break
- case 4:
-
- db.Table("xt_assessment_after_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).Count(&Total)
-
- tempErr = db.Table("xt_assessment_after_dislysis").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ?", user_org_id, start_time, end_time).
- Select("CASE WHEN weight_after < 40 THEN '小于40kg'" +
- " WHEN weight_after >= 40 AND weight_after < 50 THEN '40~50kg'" +
- " WHEN weight_after >= 50 AND weight_after < 60 THEN '50~60kg'" +
- " WHEN weight_after >= 60 AND weight_after < 70 THEN '60~70kg'" +
- " WHEN weight_after >= 70 THEN '大于70kg'" +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
-
- var isHasConditionOne bool = false
- var isHasConditionTwo bool = false
- var isHasConditionThree bool = false
- var isHasConditionFour bool = false
- var isHasConditionFive bool = false
-
- for _, item := range items {
- if item.Name == "小于40kg" {
- isHasConditionOne = true
- }
- if item.Name == "40~50kg" {
- isHasConditionTwo = true
- }
-
- if item.Name == "60~70kg" {
- isHasConditionThree = true
- }
-
- if item.Name == "大于70kg" {
- isHasConditionFour = true
- }
-
- if item.Name == "未知" {
- isHasConditionFive = true
- }
- }
- if !isHasConditionOne {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "小于40kg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- if !isHasConditionTwo {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "40~50kg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
- if !isHasConditionThree {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "60~70kg",
- Ratio: "0",
- }
- items = append(items, newItem)
-
- }
-
- if !isHasConditionFour {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "大于70kg",
- Ratio: "0",
- }
- items = append(items, newItem)
-
- }
-
- if !isHasConditionFive {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "未知",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
-
- break
- }
- if tempErr != nil {
- return nil, err
- }
-
- fmt.Println(items)
- return items, nil
- }
- func GetDialysisWeightTableData(orgID, patientID int64, page, limit, start, end int64) ([]*VMPredialysisEvaluation, int64, error) {
- offset := (page - 1) * limit
- var total int64
- var err error
- var orders []*VMPredialysisEvaluation
- readDb := service.XTReadDB()
- db := readDb.Table("xt_assessment_before_dislysis")
- db = db.Where(" user_org_id=? and status=1", orgID)
- if patientID > 0 {
- db = db.Where("patient_id=?", patientID)
- }
-
- if start != 0 {
- db = db.Where("assessment_date>=?", start)
- }
- if end != 0 {
- db = db.Where("assessment_date<=?", end)
- }
- db = db.Preload("VMAssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).Preload("VMPatients", "status = 1 AND user_org_id = ?", orgID)
- err = db.Count(&total).Offset(offset).Limit(limit).Order("assessment_date desc").Select("dry_weight, weight_before, patient_id, assessment_date").Find(&orders).Error
-
- for _, item := range orders {
- after, _ := GetLastAfterWeight(orgID, item.AssessmentDate, item.PatientId)
- if after.ID > 0 {
- fmt.Println(after.WeightAfter)
- item.LastAfterWeight = after.WeightAfter
- }
- }
- return orders, total, err
- }
-
- type LastAfter struct {
- ID int64 `json:"id"`
- WeightAfter float64 `json:"weight_after"`
- }
-
- func GetLastAfterWeight(user_org_id int64, before_assessment_date int64, patient_id int64) (after LastAfter, err error) {
- readDb := service.XTReadDB()
- err = readDb.Raw("SELECT weight_after as weight_after,id as id from xt_assessment_after_dislysis WHERE (user_org_id = ? AND patient_id = ? AND assessment_date < ?) ORDER BY id desc,`xt_assessment_after_dislysis`.`id` ASC LIMIT 1 ", user_org_id, patient_id, before_assessment_date).Scan(&after).Error
- return
- }
-
- func GetPatientDialysisWeightChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (datas []*ProcessIndexDataStruct, err error) {
- db := service.XTReadDB()
- switch statistics_type {
- case 1:
- err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, dry_weight as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- break
- case 2:
- err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, weight_before as value from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- break
- case 3:
-
- type weight struct {
- WeightAfter float64 `json:"weight_after"`
- WeightBefore float64 `json:"weight_before"`
- Date string `json:"date"`
- }
-
- var weights []*weight
- db.Raw("Select xt_assessment_after_dislysis.weight_after as weight_after ,xt_assessment_before_dislysis.weight_before as weight_before,from_unixtime(xt_assessment_before_dislysis.assessment_date,'%Y-%m-%d') as date from `xt_assessment_before_dislysis` LEFT JOIN `xt_assessment_after_dislysis` On xt_assessment_before_dislysis.`patient_id` = xt_assessment_after_dislysis.`patient_id` AND xt_assessment_before_dislysis.assessment_date = xt_assessment_after_dislysis.assessment_date AND xt_assessment_after_dislysis.weight_after <> 0 Where xt_assessment_before_dislysis.user_org_id = ? AND xt_assessment_before_dislysis.created_time >= ? AND xt_assessment_before_dislysis.created_time <= ? AND xt_assessment_before_dislysis.patient_id = ? Order by date desc", user_org_id, start_time, end_time, patient_id).Scan(&weights)
- fmt.Println(len(weights))
- for index, _ := range weights {
-
- if index+1 < len(weights) {
- var weight_add ProcessIndexDataStruct
- fmt.Println(weights[index+1].WeightAfter)
- fmt.Println(weights[index].WeightBefore)
-
- if weights[index+1].WeightAfter == 0 || weights[index].WeightBefore == 0 {
- continue
- }
- add := weights[index].WeightBefore - weights[index+1].WeightAfter
- weight_add.Value = add
- weight_add.Date = weights[index].Date
- datas = append(datas, &weight_add)
-
- }
- }
-
- break
- case 4:
- err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, weight_after as value from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- break
-
- }
- if err != nil {
- return nil, err
- }
- return datas, nil
-
- }
-
- //透析体重统计
-
- // 透析血压统计
- func GetBloodPressureChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, patient_id int64) (item []*otherItemAmount, err error) {
- db := service.XTReadDB()
- var items []*otherItemAmount
- var tempErr error
- var TotalOne int64
- var TotalTwo int64
- var Total int64
-
- switch statistics_type {
- case 1:
- type bp struct {
- SystolicBloodPressure float64 `json:"systolic_blood_pressure"`
- DiastolicBloodPressure float64 `json:"diastolic_blood_pressure"`
- }
- var bps []*bp
-
- if patient_id == 0 {
- db.Raw("SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_before_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 UNION ALL SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, user_org_id, start_time, end_time).Scan(&bps)
- db.Raw("SELECT count(id) FROM xt_assessment_before_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).Count(&TotalOne)
- db.Raw("SELECT count(id) FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).Count(&TotalTwo)
- Total = TotalOne + TotalTwo
- fmt.Println("----Total-----")
- fmt.Println(TotalOne)
- fmt.Println(TotalTwo)
- fmt.Println(Total)
-
- } else {
- db.Raw("SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_before_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ? AND AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 UNION ALL SELECT systolic_blood_pressure,diastolic_blood_pressure FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ? AND AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id, user_org_id, start_time, end_time, patient_id).Scan(&bps)
- db.Raw("SELECT count(id) FROM xt_assessment_before_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id).Count(&TotalOne)
- db.Raw("SELECT count(id) FROM xt_assessment_after_dislysis Where user_org_id = ? AND created_time >= ? AND created_time <= ? AND patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id).Count(&TotalTwo)
- Total = TotalOne + TotalTwo
- fmt.Println(TotalOne)
- fmt.Println(TotalTwo)
- fmt.Println(Total)
-
- }
-
- var total_one int64
- var total_two int64
- var total_three int64
- var total_four int64
-
- for _, item := range bps {
- if item.SystolicBloodPressure > 160 && item.DiastolicBloodPressure > 100 {
- total_one++
- } else if item.SystolicBloodPressure < 140 && item.DiastolicBloodPressure < 90 {
- total_two++
-
- } else if item.SystolicBloodPressure >= 140 && item.SystolicBloodPressure <= 160 && item.DiastolicBloodPressure >= 90 && item.DiastolicBloodPressure <= 100 {
- total_three++
- } else {
-
- total_four++
- }
- }
-
- newItem := &otherItemAmount{
- Total: total_one,
- Name: "大于160/100mmHg",
- Ratio: "0",
- }
- newItem1 := &otherItemAmount{
- Total: total_two,
- Name: "小于140/90mmHg",
- Ratio: "0",
- }
- newItem2 := &otherItemAmount{
- Total: total_three,
- Name: "140-160mmHg/90-100mmHg",
- Ratio: "0",
- }
- newItem3 := &otherItemAmount{
- Total: total_four,
- Name: "其他",
- Ratio: "0",
- }
-
- items = append(items, newItem)
- items = append(items, newItem1)
- items = append(items, newItem2)
- items = append(items, newItem3)
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
- break
- case 2:
- if patient_id == 0 {
- tempErr = db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).
- Select("CASE WHEN systolic_blood_pressure > 160 AND diastolic_blood_pressure > 100 THEN '大于160/100mmHg'" +
- " WHEN systolic_blood_pressure < 140 AND diastolic_blood_pressure < 90 THEN '小于140/90mmHg'" +
- " WHEN systolic_blood_pressure >= 140 AND systolic_blood_pressure <= 160 AND diastolic_blood_pressure >= 90 AND diastolic_blood_pressure <= 100 THEN '140-160mmHg/90-100mmHg'" +
- " ELSE '其他' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
- db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? AND status = 1 AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).Count(&Total)
-
- } else {
-
- tempErr = db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ? and patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id).
- Select("CASE WHEN systolic_blood_pressure > 160 AND diastolic_blood_pressure > 100 THEN '大于160/100mmHg'" +
- " WHEN systolic_blood_pressure < 140 AND diastolic_blood_pressure < 90 THEN '小于140/90mmHg'" +
- " WHEN systolic_blood_pressure >= 140 AND systolic_blood_pressure <= 160 AND diastolic_blood_pressure >= 90 AND diastolic_blood_pressure <= 100 THEN '140-160mmHg/90-100mmHg'" +
- " ELSE '其他' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
-
- db.Table("xt_assessment_before_dislysis ").Where("user_org_id=? AND status = 1 AND created_time >= ? AND created_time <= ? AND patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0", user_org_id, start_time, end_time, patient_id).Count(&Total)
-
- }
-
- var isHasConditionOne bool = false
- var isHasConditionTwo bool = false
- var isHasConditionThree bool = false
- var isHasConditionFour bool = false
-
- for _, item := range items {
- if item.Name == "大于160/100mmHg" {
- isHasConditionOne = true
- }
- if item.Name == "小于140/90mmHg" {
- isHasConditionTwo = true
- }
-
- if item.Name == "140-160mmHg/90-100mmHg" {
- isHasConditionThree = true
- }
- if item.Name == "其他" {
- isHasConditionFour = true
- }
- }
- if !isHasConditionOne {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "大于160/100mmHg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- if !isHasConditionTwo {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "小于140/90mmHg",
- Ratio: "0",
- }
- items = append(items, newItem)
-
- }
-
- if !isHasConditionThree {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "140-160mmHg/90-100mmHg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- if !isHasConditionFour {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "其他",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
- break
- case 3:
- if patient_id == 0 {
- tempErr = db.Table("xt_assessment_after_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).
- Select("CASE WHEN systolic_blood_pressure > 160 AND diastolic_blood_pressure > 100 THEN '大于160/100mmHg'" +
- " WHEN systolic_blood_pressure < 140 AND diastolic_blood_pressure < 90 THEN '小于140/90mmHg'" +
- " WHEN systolic_blood_pressure >= 140 AND systolic_blood_pressure <= 160 AND diastolic_blood_pressure >= 90 AND diastolic_blood_pressure <= 100 THEN '140-160mmHg/90-100mmHg'" +
- " ELSE '其他' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
- db.Table("xt_assessment_after_dislysis").Where("user_org_id=? AND status = 1 AND created_time >= ? AND created_time <= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time).Count(&Total)
-
- } else {
- tempErr = db.Table("xt_assessment_after_dislysis ").Where("user_org_id=? and status=1 and created_time >= ? and created_time <= ? and patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0", user_org_id, start_time, end_time, patient_id).
- Select("CASE WHEN systolic_blood_pressure > 160 AND diastolic_blood_pressure > 100 THEN '大于160/100mmHg'" +
- " WHEN systolic_blood_pressure < 140 AND diastolic_blood_pressure < 90 THEN '小于140/90mmHg'" +
- " WHEN systolic_blood_pressure >= 140 AND systolic_blood_pressure <= 160 AND diastolic_blood_pressure >= 90 AND diastolic_blood_pressure <= 100 THEN '140-160mmHg/90-100mmHg'" +
- " ELSE '其他' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
-
- db.Table("xt_assessment_after_dislysis ").Where("user_org_id=? AND status = 1 AND created_time >= ? AND created_time <= ? AND patient_id = ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, start_time, end_time, patient_id).Count(&Total)
-
- }
-
- var isHasConditionOne bool = false
- var isHasConditionTwo bool = false
- var isHasConditionThree bool = false
- var isHasConditionFour bool = false
-
- for _, item := range items {
- if item.Name == "大于160/100mmHg" {
- isHasConditionOne = true
- }
- if item.Name == "小于140/90mmHg" {
- isHasConditionTwo = true
- }
-
- if item.Name == "140-160mmHg/90-100mmHg" {
- isHasConditionThree = true
- }
- if item.Name == "其他" {
- isHasConditionFour = true
- }
- }
- if !isHasConditionOne {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "大于160/100mmHg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- if !isHasConditionTwo {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "小于140/90mmHg",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
- if !isHasConditionThree {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "140-160mmHg/90-100mmHg",
- Ratio: "0",
- }
- items = append(items, newItem)
-
- }
-
- if !isHasConditionFour {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "其他",
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
- break
- }
- if tempErr != nil {
- return nil, err
- }
- return items, nil
- }
- func GetBloodPressureTableData(orgID, patientID int64, page, limit, start, end int64) ([]*VMSchedule, int64, error) {
- offset := (page - 1) * limit
- var total int64
- var err error
- var orders []*VMSchedule
- readDb := service.XTReadDB()
- db := readDb.Table("xt_schedule as sch")
- db = db.Where(" sch.user_org_id=? and sch.status=1", orgID)
- if patientID > 0 {
- db = db.Where("sch.patient_id=?", patientID)
- }
- if start != 0 {
- db = db.Where("sch.schedule_date>=?", start)
- }
- if end != 0 {
- db = db.Where("sch.schedule_date<=?", end)
- }
- db = db.Preload("VMPredialysisEvaluation", "status = 1 AND user_org_id = ?", orgID).
- Preload("VMAssessmentAfterDislysis", "status = 1 AND user_org_id = ?", orgID).
- Preload("VMMinMonitoringRecord", func(db *gorm.DB) *gorm.DB {
- return db.Where("user_org_id = ? AND status = 1", orgID).Order("diastolic_blood_pressure ASC")
- }).
- Preload("VMMaxMonitoringRecord", func(db *gorm.DB) *gorm.DB {
- return db.Where("user_org_id = ? AND status = 1 ", orgID).Order("systolic_blood_pressure DESC")
- }).
- Preload("VMPatients", "status = 1 AND user_org_id = ?", orgID)
- err = db.Count(&total).Offset(offset).Limit(limit).Order("sch.schedule_date desc").Select(" sch.schedule_date,sch.patient_id,sch.user_org_id").Find(&orders).Error
- return orders, total, err
-
- }
-
- type BPDataStruct struct {
- Date string `json:"date"`
- SystolicBloodPressure float64 `json:"systolic_blood_pressure"`
- DiastolicBloodPressure float64 `json:"diastolic_blood_pressure"`
- }
-
- func GetPatientBloodPressureChartData(user_org_id int64, patient_id int64, start_time int64, end_time int64, statistics_type int) (datas []*BPDataStruct, err error) {
- db := service.XTReadDB()
- switch statistics_type {
- case 1:
- err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, systolic_blood_pressure as systolic_blood_pressure, diastolic_blood_pressure as diastolic_blood_pressure from xt_assessment_before_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- break
- case 2:
- err = db.Raw("select from_unixtime(assessment_date, '%Y-%m-%d') as date, systolic_blood_pressure as systolic_blood_pressure, diastolic_blood_pressure as diastolic_blood_pressure from xt_assessment_after_dislysis Where status = 1 AND user_org_id = ? AND patient_id = ? AND created_time <= ? AND created_time >= ? AND systolic_blood_pressure <> 0 AND diastolic_blood_pressure <> 0 ", user_org_id, patient_id, end_time, start_time).Scan(&datas).Error
- break
-
- }
- if err != nil {
- return nil, err
- }
- return datas, nil
-
- }
-
- //透析血压统计
-
- // 工作量统计
- func GetDoctorWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
- userDb := service.UserReadDB()
- db := service.XTReadDB()
- if admin_user_id == 0 {
- userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where status = 1 AND org_id = ? AND user_type = 2 ", user_org_id).Scan(&datas)
- } else {
- userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where status = 1 AND org_id = ? AND user_type = 2 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
- }
- var sys_datas VMUserAdminRole
- sys_datas.AdminUserId = 0
- sys_datas.PCount = 0
- sys_datas.UserName = "系统"
- datas = append(datas, &sys_datas)
-
- switch statistics_type {
- case 1:
- var Total int64
- db.Table("xt_dialysis_prescription as p").Joins("join xt_dialysis_order o On o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND o.status = 1").Where("p.user_org_id = ? AND p.status = 1 AND p.record_date >= ? AND p.record_date <= ? AND p.mode_id > 0 ", user_org_id, start_time, end_time).Count(&Total)
- for _, item := range datas {
- var total int64
- db.Table("xt_dialysis_prescription as p").Joins("join xt_dialysis_order o On o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND o.status = 1").Where("p.user_org_id = ? AND p.status = 1 AND p.creater = ? AND p.record_date >= ? AND p.record_date <= ? AND p.mode_id > 0", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
- item.PCount = total
-
- if math.IsNaN(float64(item.PCount) / float64(Total)) {
- item.PRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.PCount)/float64(Total))*100), 64)
- item.PRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
- case 2:
- var Total int64
- db.Table("xt_patient_course_of_disease as course").Where("org_id = ? AND status = 1 AND record_time >= ? AND record_time <= ?", user_org_id, start_time, end_time).Count(&Total)
-
- for _, item := range datas {
- var total int64
- db.Table("xt_patient_course_of_disease as course").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
- item.CourseCount = total
-
- if math.IsNaN(float64(item.CourseCount) / float64(Total)) {
- item.CourseRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.CourseCount)/float64(Total))*100), 64)
- item.CourseRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
-
- break
- case 3:
- var Total int64
-
- db.Table("xt_patient_rescue_record as rescue").Where("org_id = ? AND status = 1 AND record_time >= ? AND record_time <= ?", user_org_id, start_time, end_time).Count(&Total)
-
- for _, item := range datas {
- var total int64
- db.Table("xt_patient_rescue_record as rescue").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&total)
- item.RescueCount = total
-
- if math.IsNaN(float64(item.RescueCount) / float64(Total)) {
- item.RescueRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.RescueCount)/float64(Total))*100), 64)
- item.RescueRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
- }
- if err != nil {
- return nil, err
- }
-
- fmt.Println(datas)
- return datas, nil
-
- }
- func GetDoctorWorkloadTableData(user_org_id int64, start_time int64, end_time int64, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
- userDb := service.UserReadDB()
- db := service.XTReadDB()
- if admin_user_id == 0 {
- userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 2 ", user_org_id).Scan(&datas)
- } else {
- userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 2 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
- }
- var sys_datas VMUserAdminRole
- sys_datas.AdminUserId = 0
- sys_datas.PCount = 0
- sys_datas.UserName = "系统"
- datas = append(datas, &sys_datas)
-
- for _, item := range datas {
- var Total int64
- var TotalOne int64
- var TotalTwo int64
- db.Table("xt_dialysis_prescription as p").Joins("join xt_dialysis_order o On o.dialysis_date = p.record_date AND o.patient_id = p.patient_id AND o.user_org_id = ? AND o.status = 1", user_org_id).Where("p.user_org_id = ? AND p.status = 1 AND p.creater = ? AND p.record_date >= ? AND p.record_date <= ? AND p.mode_id > 0", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
- db.Table("xt_patient_course_of_disease as course").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
- db.Table("xt_patient_rescue_record as rescue").Where("org_id = ? AND status = 1 AND recorder = ? AND record_time >= ? AND record_time <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
- item.PCount = Total
- item.CourseCount = TotalOne
- item.RescueCount = TotalTwo
- }
- if err != nil {
- return nil, err
- }
- return datas, nil
-
- }
- func GetNurseWorkloadChartData(user_org_id int64, start_time int64, end_time int64, statistics_type int, admin_user_id int64) (datas []*VMUserAdminRole, err error) {
- userDb := service.UserReadDB()
- db := service.XTReadDB()
-
- if admin_user_id == 0 {
- userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 ", user_org_id).Scan(&datas)
- } else {
- userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
- }
-
- var NewTotalOne int64
- var NewTotalThree int64
- var NewTotalFour int64
-
- var NewTotalFive int64
- var NewTotalSix int64
- var NewTotalSeven int64
- var NewTotalEight int64
- var NewTotalNight int64
- var NewTotalTen int64
-
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalOne)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalFive)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalSix)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalSeven)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalEight)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalNight)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalTen)
- db.Table("xt_monitoring_record as monitor ").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalThree)
- db.Table("xt_treatment_summary as summary").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, start_time, end_time).Count(&NewTotalFour)
-
- switch statistics_type {
- case 2:
- for _, item := range datas {
- var Total int64
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- item.PunctureCount = Total
- if math.IsNaN(float64(item.PunctureCount) / float64(NewTotalOne)) {
- item.PunctureRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.PunctureCount)/float64(NewTotalOne))*100), 64)
- item.PunctureRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
- case 1:
- for _, item := range datas {
- var Total int64
- db.Table("xt_monitoring_record as monitor").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_nurse = ? AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
- item.CureCount = Total
- if math.IsNaN(float64(item.CureCount) / float64(NewTotalThree)) {
- item.CureRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.CureCount)/float64(NewTotalThree))*100), 64)
- item.CureRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
-
- case 3:
- for _, item := range datas {
- var Total int64
- db.Table("xt_treatment_summary as summary ").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.creater = ? AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
- item.MissionCount = Total
- if math.IsNaN(float64(item.MissionCount) / float64(NewTotalFour)) {
- item.MissionRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.MissionCount)/float64(NewTotalFour))*100), 64)
- item.MissionRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
- break
-
- case 4:
- for _, item := range datas {
- var Total int64
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.change_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- item.ChangeNuserCount = Total
- if math.IsNaN(float64(item.ChangeNuserCount) / float64(NewTotalFive)) {
- item.ChangeRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.ChangeNuserCount)/float64(NewTotalFive))*100), 64)
- item.ChangeRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
-
- break
-
- case 5:
- for _, item := range datas {
- var Total int64
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.difficult_puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- item.DiffiCultPuntureNuserCount = Total
- if math.IsNaN(float64(item.DiffiCultPuntureNuserCount) / float64(NewTotalSix)) {
- item.DiffiCultNuserRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.DiffiCultPuntureNuserCount)/float64(NewTotalSix))*100), 64)
- item.DiffiCultNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
-
- case 6:
- for _, item := range datas {
- var Total int64
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.new_fistula_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- item.NewNuserCount = Total
- if math.IsNaN(float64(item.NewNuserCount) / float64(NewTotalSeven)) {
- item.NewNuserRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.NewNuserCount)/float64(NewTotalSeven))*100), 64)
- item.NewNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
-
- case 7:
- for _, item := range datas {
- var Total int64
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.start_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- item.StartNuserCount = Total
- if math.IsNaN(float64(item.StartNuserCount) / float64(NewTotalEight)) {
- item.StartNuserRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.StartNuserCount)/float64(NewTotalEight))*100), 64)
- item.StartNuserRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
- case 8:
- for _, item := range datas {
- var Total int64
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.finish_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- item.FinshNurserCount = Total
- if math.IsNaN(float64(item.FinshNurserCount) / float64(NewTotalNight)) {
- item.FinshNurseRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.FinshNurserCount)/float64(NewTotalNight))*100), 64)
- item.FinshNurseRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
- case 9:
- for _, item := range datas {
- var Total int64
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.washpipe_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- item.WashpipeNurserCount = Total
- if math.IsNaN(float64(item.WashpipeNurserCount) / float64(NewTotalTen)) {
- item.WashpipeNurseRatio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.WashpipeNurserCount)/float64(NewTotalTen))*100), 64)
- item.WashpipeNurseRatio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
-
- }
- break
-
- }
-
- if err != nil {
- return nil, err
- }
- return datas, nil
-
- }
- func GetNurseWorkloadTableData(user_org_id int64, start_time int64, end_time int64, admin_user_id int64, page int64, limit int64) (datas []*VMUserAdminRole, AdminTotal int64, err error) {
- userDb := service.UserReadDB()
- db := service.XTReadDB()
- //var tempConfig models.Dataconfig
- //offset := (page - 1) * limit
-
- //db.Model(&models.Dataconfig{}).Where("name = '血管通路' AND module = 'hemodialysis' AND field_name = 'vascular_access_desc' AND parent_id = 0").First(&tempConfig)
-
- if admin_user_id == 0 {
- userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 ", user_org_id).Scan(&datas)
- } else {
- userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
- }
-
- for _, item := range datas {
- var Total int64
- var TotalTwo int64
- var TotalThree int64
- var TotalFour int64
- var TotalFive int64
- var TotalSix int64
- var TotalSeven int64
- var TotalEghit int64
- var TotalNight int64
- //db.Raw("select count(*) as total from (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from xt_assessment_before_dislysis as d JOIN `xt_data_config` config on d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('内瘘',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ? Group by d.id) b JOIN `xt_dialysis_order` on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1 AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
- //db.Raw("select count(*) as total_one from (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from xt_assessment_before_dislysis as d JOIN `xt_data_config` config on d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('导管',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ? Group by d.id) b JOIN `xt_dialysis_order` on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1 AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
- db.Table("xt_monitoring_record as monitor ").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_nurse = ? AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- db.Table("xt_treatment_summary as summary").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.creater = ? AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalThree)
-
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.change_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFour)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.difficult_puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFive)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.new_fistula_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalSix)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.start_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalSeven)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.finish_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalEghit)
- db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.washpipe_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalNight)
-
- item.PunctureCount = Total
- item.CureCount = TotalTwo
- item.MissionCount = TotalThree
- item.ChangeNuserCount = TotalFour
- item.DiffiCultPuntureNuserCount = TotalFive
- item.NewNuserCount = TotalSix
- item.StartNuserCount = TotalSeven
- item.FinshNurserCount = TotalEghit
- item.WashpipeNurserCount = TotalNight
- }
-
- if err != nil {
- return nil, AdminTotal, err
- }
- return datas, AdminTotal, nil
-
- }
-
- //func GetMobilNurseWorkloadTableData(user_org_id int64, start_time int64, end_time int64, admin_user_id int64, page int64, limit int64) (datas []*VMUserAdminRole, AdminTotal int64, err error) {
- // userDb := service.UserReadDB()
- // db := service.XTReadDB()
- // //var tempConfig models.Dataconfig
- // //offset := (page - 1) * limit
- //
- // //db.Model(&models.Dataconfig{}).Where("name = '血管通路' AND module = 'hemodialysis' AND field_name = 'vascular_access_desc' AND parent_id = 0").First(&tempConfig)
- //
- // if admin_user_id == 0 {
- // userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 ", user_org_id).Scan(&datas)
- // } else {
- // userDb.Raw("select admin_user_id, user_name,org_id from sgj_user_admin_role Where org_id = ? AND user_type = 3 AND admin_user_id = ?", user_org_id, admin_user_id).Scan(&datas)
- // }
- //
- // for _, item := range datas {
- // var Total int64
- // var TotalTwo int64
- // var TotalThree int64
- // var TotalFour int64
- // var TotalFive int64
- // var TotalSix int64
- // var TotalSeven int64
- // var TotalEghit int64
- // var TotalNight int64
- // //db.Raw("select count(*) as total from (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from xt_assessment_before_dislysis as d JOIN `xt_data_config` config on d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('内瘘',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ? Group by d.id) b JOIN `xt_dialysis_order` on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1 AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&Total)
- // //db.Raw("select count(*) as total_one from (select d.patient_id as patient, d.id, d.`assessment_date` as date,config.name as name from xt_assessment_before_dislysis as d JOIN `xt_data_config` config on d.`blood_access_part_opera_id` = config.value AND config.org_id = ? AND config.parent_id = ? AND FIND_IN_SET('导管',config.name) > 0 Where d.user_org_id = ? AND d.assessment_date >=? AND d.assessment_date <= ? Group by d.id) b JOIN `xt_dialysis_order` on xt_dialysis_order.`dialysis_date` = b.date AND xt_dialysis_order.user_org_id = ? AND xt_dialysis_order.status = 1 AND xt_dialysis_order.start_nurse = ? AND xt_dialysis_order.dialysis_date >= ? AND xt_dialysis_order.dialysis_date <= ? ", user_org_id, tempConfig.ID, user_org_id, start_time, end_time, user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalOne)
- // db.Table("xt_monitoring_record as monitor ").Joins("join xt_schedule sch On sch.schedule_date = monitor.monitoring_date AND sch.patient_id = monitor.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("monitor.user_org_id = ? AND monitor.status = 1 AND monitor.monitoring_nurse = ? AND monitor.monitoring_date >= ? AND monitor.monitoring_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalTwo)
- // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&Total)
- // db.Table("xt_treatment_summary as summary").Joins("join xt_schedule sch On sch.schedule_date = summary.assessment_date AND sch.patient_id = summary.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("summary.user_org_id = ? AND summary.status = 1 AND summary.creater = ? AND summary.assessment_date >= ? AND summary.assessment_date <= ?", user_org_id, item.AdminUserId, start_time, end_time).Count(&TotalThree)
- //
- // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.change_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFour)
- // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.difficult_puncture_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalFive)
- // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.new_fistula_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalSix)
- // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.start_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalSeven)
- // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.finish_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalEghit)
- // db.Table("xt_dialysis_order as o").Joins("join xt_schedule sch On sch.schedule_date = o.dialysis_date AND sch.patient_id = o.patient_id AND sch.user_org_id = ? AND sch.status = 1", user_org_id).Where("o.user_org_id = ? AND o.status = 1 AND o.dialysis_date >= ? AND o.dialysis_date <= ? AND o.washpipe_nurse = ?", user_org_id, start_time, end_time, item.AdminUserId).Count(&TotalNight)
- //
- // item.PunctureCount = Total
- // item.CureCount = TotalTwo
- // item.MissionCount = TotalThree
- // item.ChangeNuserCount = TotalFour
- // item.DiffiCultPuntureNuserCount = TotalFive
- // item.NewNuserCount = TotalSix
- // item.StartNuserCount = TotalSeven
- // item.FinshNurserCount = TotalEghit
- // item.WashpipeNurserCount = TotalNight
- // }
- //
- // if err != nil {
- // return nil, AdminTotal, err
- // }
- // return datas, AdminTotal, nil
- //
- //}
-
- // 工作量统计
- type AdminUser struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- AdminUserId int64 `gorm:"column:admin_user_id" json:"admin_user_id" form:"admin_user_id"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- UserName string `gorm:"column:user_name" json:"user_name" form:"user_name"`
- UserType int64 `gorm:"column:user_type" json:"user_type" form:"user_type"`
- }
-
- func GetAllAdminUser(user_org_id int64) (datas []*AdminUser, err error) {
- userDb := service.UserReadDB()
- userDb.Raw("select id, admin_user_id, user_name,org_id, user_type from sgj_user_admin_role Where status = 1 AND org_id = ?", user_org_id).Scan(&datas)
- return datas, nil
-
- }
-
- //func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
- // db := service.XTReadDB()
- // err = db.Model(&models.QualityControlStandard{}).Where("status = 1 AND org_id = ? ", user_org_id).Count(&count).Error
- // return
- //}
-
- type InspectionReference struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
- Project string `gorm:"column:project" json:"project" form:"project"`
- ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
- ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
- RangeType int64 `gorm:"column:range_type" json:"range_type" form:"range_type"`
- RangeMin string `gorm:"column:range_min" json:"range_min" form:"range_min"`
- RangeMax string `gorm:"column:range_max" json:"range_max" form:"range_max"`
- RangeValue string `gorm:"column:range_value" json:"range_value" form:"range_value"`
- Unit string `gorm:"column:unit" json:"unit" form:"unit"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- }
-
- func FindOrgQualityControlStandardInspectionReference(user_org_id int64) (references []*InspectionReference, err error) {
- db := service.XTReadDB()
- err = db.Raw("SELECT reference.project_name AS project_name,qcs.inspection_major AS project_id, qcs.inspection_minor AS id,reference.item_name AS item_name,qcs.range_type AS range_type,reference.range_min AS range_min,reference.range_max AS range_max,reference.unit AS unit,qcs.range_value AS range_value FROM xt_quality_control_standard qcs LEFT JOIN xt_inspection_reference reference ON qcs.inspection_major = reference.project_id AND ( qcs.inspection_minor = reference.item_id AND reference.org_id = ?) OR (org_id = 0 AND qcs.inspection_minor = reference.id ) WHERE qcs.user_org_id = ? AND qcs.status = 1 AND reference.status = 1", user_org_id, user_org_id).Scan(&references).Error
- return
- }
-
- func FindOrgInspectionReference(user_org_id int64, range_type int) (references []*models.InspectionReference, err error) {
- db := service.XTReadDB()
- if range_type == 1 {
-
- err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND range_type = 1 AND (range_min REGEXP '[^0-9.]') = 0 AND (range_max REGEXP '[^0-9.]') = 0 ", user_org_id).Find(&references).Error
-
- } else {
- err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND range_type = 2", user_org_id).Find(&references).Error
-
- }
- return
- }
-
- func FindProcjectInspectionReference(user_org_id int64, project_id int64, item_id int64) (references models.InspectionReference, err error) {
- db := service.XTReadDB()
- err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND project_id = ? AND id = ?", user_org_id, project_id, item_id).First(&references).Error
- return
- }
-
- func FindOrgInspectionReferenceRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (inspection []*models.Inspection, err error) {
- db := service.XTReadDB()
- err = db.Model(&models.Inspection{}).Where("status = 1 AND org_id = ? AND project_id = ? AND item_id = ? ", user_org_id, project_id, item_id).Group("inspect_value").Find(&inspection).Error
- return
- }
-
- func FindOrgConfigRangeTypeValue(user_org_id int64, project_id int64, item_id int64) (qcs models.InspectionReference, err error) {
- db := service.XTReadDB()
- err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND project_id = ? AND item_id = ?", user_org_id, project_id, item_id).First(&qcs).Error
- return
- }
-
- func FindOrgConfigRangeTypeValueTwo(user_org_id int64, project_id int64, item_id int64) (qcs models.InspectionReference, err error) {
- db := service.XTReadDB()
- err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ? AND project_id = ? AND id = ?", user_org_id, project_id, item_id).First(&qcs).Error
- return
- }
-
- func GetInspectionChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, range_type int, range_value string) (item []*otherItemAmount, err error) {
- db := service.XTReadDB()
- var items []*otherItemAmount
- var tempErr error
- var Total int64
- selectContent := "CASE"
- range_value_arr := strings.Split(range_value, ",")
-
- db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND inspect_value <> '' ", user_org_id, start_time, end_time, project_id, item_id).Count(&Total)
-
- if range_type == 1 {
-
- tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND inspect_value <> ''", user_org_id, start_time, end_time, project_id, item_id).
- Select("CASE WHEN inspect_value < " + range_value_arr[0] + " THEN " + "'" + "小于" + range_value_arr[0] + "'" +
- " WHEN inspect_value >= " + range_value_arr[0] + " AND inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
- " WHEN inspect_value > " + range_value_arr[1] + " THEN " + "'" + "大于" + range_value_arr[1] + "'" +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
-
- var isHasConditionOne bool = false
- var isHasConditionTwo bool = false
- var isHasConditionThree bool = false
-
- for _, item := range items {
- if item.Name == "大于"+range_value_arr[1] {
- isHasConditionOne = true
- }
- if item.Name == "小于"+range_value_arr[0] {
- isHasConditionTwo = true
- }
- if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
- isHasConditionThree = true
- }
- }
- if !isHasConditionOne {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "大于" + range_value_arr[1],
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- if !isHasConditionTwo {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "小于" + range_value_arr[0],
- Ratio: "0",
- }
- items = append(items, newItem)
- }
- if !isHasConditionThree {
- newItem := &otherItemAmount{
- Total: 0,
- Name: range_value_arr[0] + "~" + range_value_arr[1],
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
- return items, tempErr
-
- } else {
- for _, item := range range_value_arr {
- //selectContent = selectContent + " WHEN inspect_value =" + item + " THEN " + "'" + item + "'"
- selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
-
- }
- tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND inspect_value <> '' ", user_org_id, start_time, end_time, project_id, item_id).
- Select(selectContent +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
-
- return items, tempErr
- }
-
- }
-
- type Inspection struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- PatientId int64 `gorm:"column:patient_id" json:"patient_id" form:"patient_id"`
- OrgId int64 `gorm:"column:org_id" json:"org_id" form:"org_id"`
- ProjectId int64 `gorm:"column:project_id" json:"project_id" form:"project_id"`
- ItemId int64 `gorm:"column:item_id" json:"item_id" form:"item_id"`
- ItemName string `gorm:"column:item_name" json:"item_name" form:"item_name"`
- ProjectName string `gorm:"column:project_name" json:"project_name" form:"project_name"`
- InspectType int64 `gorm:"column:inspect_type" json:"inspect_type" form:"inspect_type"`
- InspectValue string `gorm:"column:inspect_value" json:"inspect_value" form:"inspect_value"`
- InspectDate int64 `gorm:"column:inspect_date" json:"inspect_date" form:"inspect_date"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- CreatedTime int64 `gorm:"column:created_time" json:"created_time" form:"created_time"`
- UpdatedTime int64 `gorm:"column:updated_time" json:"updated_time" form:"updated_time"`
- Patient models.Patients `gorm:"ForeignKey:ID;AssociationForeignKey:PatientId" json:"patient"`
- }
-
- func (Inspection) TableName() string {
- return "xt_inspection"
- }
-
- func GetInspectionChartTableData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, patient_id int64, page, limit int64, range_type int, range_value string) (datas []*Inspection, total int64, err error) {
-
- if range_type == 1 {
-
- index := strings.Index(range_value, "小于")
- indexTwo := strings.Index(range_value, "大于")
- indexThree := strings.Index(range_value, "~")
-
- if index != -1 {
- value, _ := strconv.ParseFloat(strings.Replace(range_value, "小于", "", 1), 64)
- db := service.XTReadDB()
- offset := (page - 1) * limit
- err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 AND inspect_value < ?", user_org_id, start_time, end_time, project_id, item_id, value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", user_org_id)
- }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
- return datas, total, err
- } else if indexTwo != -1 {
- value, _ := strconv.ParseFloat(strings.Replace(range_value, "大于", "", 1), 64)
-
- db := service.XTReadDB()
- offset := (page - 1) * limit
- err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 AND inspect_value > ?", user_org_id, start_time, end_time, project_id, item_id, value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", user_org_id)
- }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
- return datas, total, err
- } else if indexThree != -1 {
- range_value_arr := strings.Split(range_value, "~")
- fmt.Println(range_value_arr)
-
- float1, err := strconv.ParseFloat(range_value_arr[0], 64)
- float2, err := strconv.ParseFloat(range_value_arr[1], 64)
- fmt.Println(err)
- fmt.Println(float1)
-
- fmt.Println(float2)
-
- db := service.XTReadDB()
- offset := (page - 1) * limit
- err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 AND inspect_value >= ? AND inspect_value <= ?", user_org_id, start_time, end_time, project_id, item_id, float1, float2).Preload("Patient", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", user_org_id)
- }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
- return datas, total, err
- } else {
- db := service.XTReadDB()
- offset := (page - 1) * limit
- err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 ", user_org_id, start_time, end_time, project_id, item_id).Preload("Patient", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", user_org_id)
- }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
- return datas, total, err
- }
-
- } else {
-
- if range_value == "全部" {
- db := service.XTReadDB()
- offset := (page - 1) * limit
- err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 ", user_org_id, start_time, end_time, project_id, item_id).Preload("Patient", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", user_org_id)
- }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
- return datas, total, err
-
- } else {
-
- db := service.XTReadDB()
- offset := (page - 1) * limit
- err = db.Model(&Inspection{}).Where("org_id = ? AND status = 1 AND inspect_date >= ? AND inspect_date <= ? AND project_id = ? AND item_id = ? AND status = 1 AND inspect_value = ?", user_org_id, start_time, end_time, project_id, item_id, range_value).Preload("Patient", func(db *gorm.DB) *gorm.DB {
- return db.Where("status = 1 AND user_org_id = ?", user_org_id)
- }).Count(&total).Offset(offset).Limit(limit).Find(&datas).Error
- return datas, total, err
-
- }
-
- }
-
- }
-
- type NewIndexDataStruct struct {
- Date string `json:"date"`
- Value string `json:"value"`
- }
-
- func GetPatientInspectionChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, patient_id int64) (datas []*NewIndexDataStruct, err error) {
- db := service.XTReadDB()
- err = db.Raw("select from_unixtime(inspect_date, '%Y-%m-%d') as date, inspect_value as value from xt_inspection Where status = 1 AND org_id = ? AND patient_id = ? AND project_id = ? AND item_id = ? AND inspect_date <= ? AND inspect_date >= ? Order by inspect_date asc ", user_org_id, patient_id, project_id, item_id, end_time, start_time).Scan(&datas).Error
- if err != nil {
- return nil, err
- }
- return datas, nil
-
- }
-
- func GetPatientInspectionBarChartData(user_org_id int64, start_time int64, end_time int64, project_id int64, item_id int64, range_type int, range_value string, patient_id int64) (item []*otherItemAmount, err error) {
- db := service.XTReadDB()
- var items []*otherItemAmount
- var tempErr error
- selectContent := "CASE"
- range_value_arr := strings.Split(range_value, ",")
- var Total int64
-
- db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND patient_id = ? AND inspect_value <> ''", user_org_id, start_time, end_time, project_id, item_id, patient_id).Count(&Total)
-
- if range_type == 1 {
- tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND project_id = ? AND item_id = ? AND patient_id = ? AND inspect_value <> ''", user_org_id, start_time, end_time, project_id, item_id, patient_id).
- Select("CASE WHEN inspect_value < " + range_value_arr[0] + " THEN " + "'" + "小于" + range_value_arr[0] + "'" +
- " WHEN inspect_value >= " + range_value_arr[0] + " AND inspect_value <= " + range_value_arr[1] + " THEN " + "'" + range_value_arr[0] + "~" + range_value_arr[1] + "'" +
- " WHEN inspect_value > " + range_value_arr[1] + " THEN " + "'" + "大于" + range_value_arr[1] + "'" +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
-
- var isHasConditionOne bool = false
- var isHasConditionTwo bool = false
- var isHasConditionThree bool = false
-
- for _, item := range items {
-
- if item.Name == "大于"+range_value_arr[1] {
- isHasConditionOne = true
- }
-
- if item.Name == "小于"+range_value_arr[0] {
- isHasConditionTwo = true
- }
-
- if item.Name == range_value_arr[0]+"~"+range_value_arr[1] {
- isHasConditionThree = true
- }
- }
- if !isHasConditionOne {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "大于" + range_value_arr[1],
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- if !isHasConditionTwo {
- newItem := &otherItemAmount{
- Total: 0,
- Name: "小于" + range_value_arr[0],
- Ratio: "0",
- }
- items = append(items, newItem)
- }
- if !isHasConditionThree {
- newItem := &otherItemAmount{
- Total: 0,
- Name: range_value_arr[0] + "~" + range_value_arr[1],
- Ratio: "0",
- }
- items = append(items, newItem)
- }
-
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
-
- return items, tempErr
-
- } else {
-
- for _, item := range range_value_arr {
- selectContent = selectContent + " WHEN inspect_value =" + "'" + item + "'" + " THEN " + "'" + item + "'"
- }
- tempErr = db.Table("xt_inspection").Where("org_id=? and status=1 and inspect_date >= ? and inspect_date <= ? AND patient_id = ? AND inspect_value <> '' AND project_id = ? AND item_id = ?", user_org_id, start_time, end_time, patient_id, project_id, item_id).
- Select(selectContent +
- " ELSE '未知' END AS name, COUNT(*) AS total",
- ).Group("name").Scan(&items).Error
- for _, item := range items {
- if math.IsNaN(float64(item.Total) / float64(Total)) {
- item.Ratio = "0.0"
- } else {
- float_value, _ := strconv.ParseFloat(fmt.Sprintf("%.1f", (float64(item.Total)/float64(Total))*100), 64)
- item.Ratio = strconv.FormatFloat(float_value, 'f', 1, 32)
- }
- }
- return items, tempErr
- }
-
- }
-
- type VMPatient struct {
- ID int64 `gorm:"column:id" json:"id" form:"id"`
- UserOrgId int64 `gorm:"column:user_org_id" json:"user_org_id" form:"user_org_id"`
- UserId int64 `gorm:"column:user_id" json:"user_id" form:"user_id"`
- Name string `gorm:"column:name" json:"name" form:"name"`
- Lapseto int64 `gorm:"column:lapseto" json:"lapseto" form:"lapseto"`
- Status int64 `gorm:"column:status" json:"status" form:"status"`
- }
-
- func (VMPatient) TableName() string {
- return "xt_patients"
- }
-
- func GetOrgPatients(user_org_id int64) (patient *[]VMPatient, err error) {
- db := service.XTReadDB()
- var tempPatient []VMPatient
- findErr := db.Model(&models.Patients{}).Where("user_org_id = ? AND status = 1 AND lapseto = 1", user_org_id).Find(&tempPatient).Error
- if findErr == gorm.ErrRecordNotFound {
- return nil, nil
- }
- if findErr != nil {
- return nil, findErr
- }
- return &tempPatient, nil
- }
-
- func FindOrgQualityControlStandardInspectionReferenceById(user_org_id int64, project_id int64, item_id int64) (references InspectionReference, err error) {
- db := service.XTReadDB()
- err = db.Raw("Select reference.project_name as project_name,qcs.inspection_major as project_id, qcs.inspection_minor as id,reference.item_name as item_name,qcs.range_type as range_type,reference.range_min as range_min, reference.range_max as range_max,reference.unit as unit,qcs.range_value as range_value from xt_quality_control_standard qcs Left JOIN xt_inspection_reference reference ON qcs.inspection_major = reference.project_id and qcs.inspection_minor = reference.id and (reference.org_id = ? OR org_id = 0) Where qcs.user_org_id = ? AND qcs.status = 1 AND qcs.inspection_major = ? AND qcs.inspection_minor = ?", user_org_id, user_org_id, project_id, item_id).Scan(&references).Error
- return
- }
-
- func FindOrgInspectionCount(user_org_id int64) (count int64, err error) {
- db := service.XTReadDB()
- err = db.Model(&models.InspectionReference{}).Where("status = 1 AND org_id = ?", user_org_id).Count(&count).Error
- return
- }
-
- func GetOrderDialysisCount(orgid int64, startime int64, endtime int64) (order []*models.BloodDialysisOrderOne, err error) {
- db := service.XTReadDB()
- table := db.Table("xt_schedule as s")
- fmt.Println(table)
- d := db.Table("xt_patients as p")
- fmt.Println(d)
- db = db.Table("xt_dialysis_order as o").Where("o.status = 1")
- if orgid > 0 {
- db = db.Where("o.user_org_id = ?", orgid)
- }
- if startime > 0 {
- db = db.Where("o.dialysis_date>=?", startime)
- }
- if endtime > 0 {
- db = db.Where("o.dialysis_date<=?", endtime)
- }
- err = db.Group("o.start_nurse,s.mode_id").Select("s.mode_id,s.patient_id,count(s.mode_id) as count,o.start_nurse").Joins("left join xt_schedule as s on s.patient_id = o.patient_id").Joins("left join xt_patients as p on p.id = o.patient_id ").Where("s.schedule_date = o.dialysis_date and s.status = 1 and o.user_org_id = ?", orgid).Scan(&order).Error
- return order, err
- }
|