zoukankan      html  css  js  c++  java
  • 海南挂号报表

    挂号信息表1

    CREATE TABLE `bpm_appointment` (
      `id` varchar(40) NOT NULL,
      `patient_id` varchar(40) NOT NULL,
      `patient_name` varchar(255) DEFAULT NULL COMMENT '患者名称',
      `patient_phone` varchar(45) DEFAULT NULL COMMENT '患者手机号',
      `patient_sex` varchar(40) DEFAULT NULL COMMENT '患者性别',
      `service_name` varchar(255) DEFAULT NULL,
      `service_classification` varchar(40) DEFAULT NULL COMMENT '物资分类',
      `symptom` varchar(256) DEFAULT NULL COMMENT '症状描述',
      `appointment_date` date NOT NULL COMMENT '预约日期',
      `appointment_starttime` time DEFAULT NULL COMMENT '预约时段开始时间',
      `appointment_endtime` time DEFAULT NULL COMMENT '预约时段结束时间',
      `appointment_ArrangeId` varchar(40) DEFAULT NULL,
      `appointment_doctor_id` varchar(40) DEFAULT NULL,
      `appointment_doctor_name` varchar(255) DEFAULT NULL COMMENT '预约医生名称',
      `visit_number` varchar(45) NOT NULL COMMENT '看诊序号,每次看诊过程只生成一个序号',
      `appointment_state` int(11) NOT NULL COMMENT '预约状态 0:已预约 1:已确认 2:已就诊  -1:已取消 -2:迟到 -3:爽约 ',
      `orderId` varchar(40) DEFAULT NULL,
      `order_item_id` varchar(40) DEFAULT NULL,
      `medical_insurance_type` int(11) DEFAULT NULL COMMENT '医疗保险类型:0. 自费 1. 社保 2.商保 3.新农合 4.社保(未带卡)',
      `medical_card_number` varchar(100) DEFAULT NULL COMMENT '医保卡号',
      `is_medical_insurance` int(11) NOT NULL DEFAULT '0' COMMENT '是否医保:0 无,1 医保 ',
      `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `updater` varchar(40) DEFAULT NULL,
      `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
      `del_flag` int(11) NOT NULL DEFAULT '0' COMMENT '是否删除:0:否 1.是',
      `is_valid` int(11) DEFAULT '1',
      `description` text COMMENT '备注',
      `org_id` varchar(40) DEFAULT NULL COMMENT '机构id',
      `referrer` varchar(40) DEFAULT NULL COMMENT '推荐人',
      `referrer_name` varchar(100) DEFAULT NULL COMMENT '推荐人姓名',
      `referrer_dept_id` varchar(40) DEFAULT NULL COMMENT '推荐人部门',
      `referrer_dept_name` varchar(100) DEFAULT NULL COMMENT '推荐人部门名称',
      `shop_set_item_id` varchar(40) DEFAULT NULL COMMENT '商城套餐明细id(套餐预约挂号使用)',
      `payment_deadline` datetime DEFAULT NULL COMMENT '互联网医院 挂号 支付截止时间',
      `cancel_reason` varchar(100) DEFAULT NULL COMMENT '取消原因',
      `cancel_type` int(1) DEFAULT '1' COMMENT '取消挂号类别:1.患者自己取消 2. 换号取消 3. APP超时未支付取消',
      `is_urgent` int(1) DEFAULT '0' COMMENT '是否 加急:0.否  1.是',
      `tenant_id` varchar(40) DEFAULT NULL COMMENT '租户id',
      `is_scene_appoint` int(11) NOT NULL DEFAULT '0' COMMENT '现场挂号:0/否,1/是',
      `is_physical_examination` int(11) NOT NULL DEFAULT '0' COMMENT '是否预检:0/否,1/是',
      `medical_record_book` int(11) NOT NULL DEFAULT '0' COMMENT '使用病历本:1/使用,0/未使用',
      `insurance_id` varchar(40) DEFAULT NULL,
      `insurance_org_id` varchar(40) DEFAULT NULL,
      `product_id` varchar(40) DEFAULT NULL,
      `channel_id` varchar(40) DEFAULT NULL,
      `medical_insurance_org_id` varchar(40) DEFAULT NULL COMMENT '基本医疗保险机构id',
      `icno` varchar(40) DEFAULT NULL COMMENT '患者社保卡号',
      `persontype` varchar(40) DEFAULT NULL COMMENT '医保参保人员类型:11-在职职工',
      `patient_age` int(11) DEFAULT NULL,
      `providerId` varchar(40) DEFAULT NULL,
      `provider_name` varchar(255) DEFAULT '' COMMENT '科室名称',
      `subsequent_visit` int(11) NOT NULL COMMENT '是否复诊 0:否,1:是',
      `serviceId` varchar(40) DEFAULT NULL,
      `organ_id` varchar(40) NOT NULL,
      `organ_name` varchar(255) DEFAULT NULL,
      `dept_type` varchar(40) DEFAULT '1' COMMENT '部门类别: 1-科室,2-病区',
      `dept_id` varchar(40) NOT NULL COMMENT '部门id:科室id,病区id',
      `dept_name` varchar(255) DEFAULT NULL COMMENT '部门名称:科室名称,病区名称',
      `appointment_resource_id` varchar(40) DEFAULT NULL COMMENT '预约的资源id',
      `appointment_relate_id` varchar(40) DEFAULT NULL COMMENT '预约的资源引用id',
      `appointment_resource_name` varchar(255) DEFAULT NULL COMMENT '预约的资源名称',
      `appointment_resource_type` varchar(48) DEFAULT NULL COMMENT '预约的资源类型',
      `is_pregnancy` int(11) DEFAULT '0' COMMENT '是否孕妇:0:否 1.是',
      `is_appoint_resource` int(11) NOT NULL DEFAULT '0' COMMENT '是否指定的医生:0.否 1.是 (用于区分是否是患者自己指定的医生)',
      `transfer_from` varchar(255) DEFAULT NULL COMMENT '转诊来源',
      `data_source` varchar(255) DEFAULT '1' COMMENT '数据来源:1-网站;2-app;...',
      `occupy_volume` int(11) DEFAULT '1' COMMENT '预约时占用的数量',
      `is_sms_remind` int(11) DEFAULT '1' COMMENT '是否为短信提醒:1-是:0-否',
      `is_app_remind` int(11) DEFAULT '1' COMMENT '是否为app提醒:1-是:0-否',
      `sort` int(11) DEFAULT NULL COMMENT '等待列表排序',
      `is_plus` int(11) DEFAULT '0' COMMENT '是否是加号:0:否 1.是',
      `register_type` int(11) DEFAULT '0' COMMENT '挂号方式:0.预约转挂号 1.挂号',
      `arrival_time` datetime DEFAULT NULL COMMENT '到诊时间',
      `is_unusual_status` int(11) DEFAULT NULL COMMENT '是否 异常状态(排班删除引起):0.否 1.是',
      `creator` varchar(40) DEFAULT NULL,
      `cancel_time` datetime DEFAULT NULL COMMENT '取消操作操作时间',
      `reception_time` datetime DEFAULT NULL COMMENT '接诊时间',
      `cancel_user` varchar(255) DEFAULT NULL COMMENT '取消操作操作人',
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='预约挂号表';

      患者挂号信息查询

    select distinct
        CASE a.appointment_state WHEN -1 THEN '退号' ELSE '未退' END AS returnFlag, 
        CASE a.is_appoint_resource WHEN 0 THEN '未指定医生' WHEN 1 THEN '指定医生' END as isAppointResource,        -- 是否指定医生
        a.create_time as guaHaoTime,                   -- 挂号时间
        p.create_time as createDocTime,                -- '建档时间'
        '挂号实收金额' as guaHaoRealMoney,
        '门诊实收金额' as menZenRealMoney,
        d.outpatient_number as blNumber,
        p.name as patientName,                          -- 患者姓名
        a.dept_name,                                 -- 科室名称
        a.appointment_doctor_name as doctorName,     -- 医生
        CASE a.subsequent_visit 
            WHEN 0 THEN '初诊' 
            WHEN 1 THEN '复诊' 
            WHEN 2 THEN '转诊' 
            WHEN 3 THEN '急诊' 
            WHEN 4 THEN '体检'
            WHEN 5 THEN '简易'
            WHEN 6 THEN '疫苗'  
        END AS isReVisit,                            -- 初复诊
        channel.name as sourceName,                                 -- 信息(渠道)来源
        p.birthday,                                     -- 出生日期
        if(c.id_no is null, if(c.other_type is null, null,
            (select e.name from  `thc_warehouse`.`sys_type_info` e 
             JOIN `thc_warehouse`.`sys_type` f ON e.sys_type_id = f.id
             WHERE f.`code` = 'THC_WH_PERSON_CARD' and e.value = c.other_type)
            ), '身份证') as cardType,                                    -- 证件类型
        if(c.id_no is null,c.other_no,c.id_no) as cardNo,        -- 证件号码
        p.address,    -- 住址
        p.household, -- 户籍
        p.household_address, -- 户口所在地
        a.patient_phone,    -- 患者电话号
        a.appointment_date, -- 预约日期
        a.appointment_starttime, -- 预约开始时间
        a.appointment_endtime,    -- 预约结束时间
        a.creator,                    -- 挂号员
    
        a.dept_id,        -- 部门ID
        a.orderId,    -- 订单ID
        a.order_item_id, -- 订单明细id
        a.medical_card_number,    -- 社保卡号  
        a.description,    -- 备注
        
    
    --    p.birth_address, -- 出生地
    --    CONCAT(p.household_address->'$.householdAddressDetail',p.household_address->'$.province'),
        CASE a.data_source WHEN 1 THEN '网站' WHEN 2 THEN 'APP' END as dataSource  -- 数据来源
    from `thc_arrange`.`bpm_appointment` a
    left join `thc_passport`.`patient` p on a.patient_id = p.id
    left join `thc_passport`.`contact` c on a.patient_id = c.patient_id
    left join `thc_passport`.`patient_org` d on a.patient_id = d.patient_id
    left join `thc_c_union`.`member_channel` channel on a.channel_id = channel.id
    
    limit 10;

    按照医生统计,(只统计了数量,尚未统计金额 )

    -- ------------
    -- 总挂号数
    -- ------------
    select 
        t1.dept_name, 
        t1.doctorName, 
        t1.startTime,
        t1.endTime,
        IFNULL(t1.num,0) as num1,
        IFNULL(t2.num,0) as num2,
        IFNULL(t3.num,0) as num3,
        IFNULL(t4.num,0) as num4,
        IFNULL(t5.num,0) as num5,
        IFNULL(t6.num,0) as num6,
        IFNULL(t7.num,0) as num7,
        IFNULL(t8.num,0) as num8,
        IFNULL(t9.num,0) as num9,
        IFNULL(t10.num,0) as num10,
        IFNULL(t11.num,0) as num11,
        IFNULL(t12.num,0) as num12,
        IFNULL(t14.num,0) as num14,
        IFNULL(t15.num,0) as num15,
        IFNULL(t15.num,0) as num16,
        IFNULL(t15.num,0) as num17,
        IFNULL(t15.num,0) as num18,
        IFNULL(t15.num,0) as num19
    from
    -- ------------
    -- 总挂号数
    -- ------------
    (
        select 
            a.dept_name,
            a.appointment_doctor_name as doctorName,
            a.dept_id,
            a.appointment_doctor_id,
            count(1)  as num,
            CONCAT(a.`appointment_date`," ",a.appointment_starttime) as startTime,
            CONCAT(a.`appointment_date`," ",a.appointment_endtime) as endTime
        from `thc_arrange`.`bpm_appointment` a
        group by a.dept_name,a.appointment_doctor_name
    ) t1 
    -- ------------
    -- 退号
    -- ------------
    left join (
        select a.dept_name,a.appointment_doctor_name as doctorName,count(1)  as num 
        from `thc_arrange`.`bpm_appointment` a
        where a.appointment_state = -1
        group by a.dept_name,a.appointment_doctor_name
    ) t2 on t1.dept_name = t2.dept_name and t1.doctorName = t2.doctorName
    
    -- ------------
    -- 实际挂号数   =    初诊数 + 复诊数 + 转诊数
    -- ------------
    left join (
        select a.dept_name,a.appointment_doctor_name as doctorName, count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.subsequent_visit in (0,1,2)
        group by a.dept_name,a.appointment_doctor_name
    ) t3  on t1.dept_name = t3.dept_name and t1.doctorName = t3.doctorName
    
    -- ------------
    -- 指定
    -- ------------
    left join (
        select 
            a.dept_name,     -- 科室名称
            a.appointment_doctor_name as doctorName,     -- 医生
            count(1)   as num
        from `thc_arrange`.`bpm_appointment` a
        where a.is_appoint_resource = 1
        group by a.dept_name,a.appointment_doctor_name
    ) t4  on t1.dept_name = t4.dept_name and t1.doctorName = t4.doctorName
    
    -- ------------
    -- 初诊
    -- ------------
    left join (
        select 
            a.dept_name,     -- 科室名称
            a.appointment_doctor_name as doctorName,     -- 医生
            count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.subsequent_visit = 0
        group by a.dept_name,a.appointment_doctor_name
    ) t5 on t1.dept_name = t5.dept_name and t1.doctorName = t5.doctorName
    
    -- ------------
    -- 复诊
    -- ------------
    left join (
        select 
            a.dept_name,     -- 科室名称
            a.appointment_doctor_name as doctorName,     -- 医生
            count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.subsequent_visit = 1
        group by a.dept_name,a.appointment_doctor_name
    ) t6  on t1.dept_name = t6.dept_name and t1.doctorName = t6.doctorName
    
    -- ------------
    -- 体检
    -- ------------
    left join (
        select 
        a.dept_name,     -- 科室名称
        a.appointment_doctor_name as doctorName,     -- 医生
        count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.subsequent_visit = 4
        group by a.dept_name,a.appointment_doctor_name
    ) t7 on t1.dept_name = t7.dept_name and t1.doctorName = t7.doctorName
    
    
    -- ------------
    -- 团队
    -- ------------
    left join (
        select 
        a.dept_name,     -- 科室名称
        a.appointment_doctor_name as doctorName,     -- 医生
        count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.subsequent_visit = 7
        group by a.dept_name,a.appointment_doctor_name
    ) t8 on t1.dept_name = t8.dept_name and t1.doctorName = t8.doctorName
    
    -- ------------
    -- 简易 
    -- ------------
    left join (
        select 
        a.dept_name,     -- 科室名称
        a.appointment_doctor_name as doctorName,     -- 医生
        count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.subsequent_visit = 5
        group by a.dept_name,a.appointment_doctor_name
    ) t9 on t1.dept_name = t9.dept_name and t1.doctorName = t9.doctorName
    
    -- ------------
    -- 转诊 
    -- ------------
    left join (
        select a.dept_name,a.appointment_doctor_name as doctorName,count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.subsequent_visit = 2
        group by a.dept_name,a.appointment_doctor_name
    ) t10 on t1.dept_name = t10.dept_name and t1.doctorName = t10.doctorName
    
    -- ------------
    -- 疫苗
    -- ------------
    left join (
        select a.dept_name,a.appointment_doctor_name as doctorName,count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.subsequent_visit = 6
        group by a.dept_name,a.appointment_doctor_name
    ) t11  on t1.dept_name = t11.dept_name and t1.doctorName = t11.doctorName
    
    -- ------------
    -- 微信
    -- ------------
    left join (
        select a.dept_name,a.appointment_doctor_name as doctorName,count(1)  as num
        from `thc_arrange`.`bpm_appointment` a
        where a.data_source = 2
        group by a.dept_name,a.appointment_doctor_name
    ) t12 on t1.dept_name = t12.dept_name and t1.doctorName = t12.doctorName
    
    
    -- ------------
    -- 挂号费 t13
    -- ------------
    
    -- ------------
    -- 急诊费 t14
    -- ------------
    left join (
        select  round(sum(t.realFee),2) as num, t.orderDept, t.orderDoctor from
    (
        select
        (
            b.preFee                     -- 原价
            - b.discountFee             -- 自费折扣金额
            - b.promotionBenefitFee     -- 活动优惠
            - b.couponFee                 -- 优惠券优惠金额
            - b.itemBenefitFee             -- 身份卡优惠金额
            - b.memberCardBenefitFee     -- 会员卡优惠金额
            - b.itemComInvBenefitFee    -- 商业保险优惠金额
        ) * b.discount AS realFee,
        d.orderDept,
        d.orderDoctor
        from `thc_rcm`.`Cs_Settlement` a
        join `thc_rcm`.`Cs_SettlementDetail` b on a.id = b.`settlementID`
        join `thc_rcm`.`Cs_AccountBill` d on b.accountBillID = d.id 
        join `thc_rcm`.`Cs_AccountBillDetail` c on b.accountBillID = c.AccountBillId and b.accountBillDetailID = c.id and         b.orderDetailId = c.orderDetailId
        where a.settlementType = 2    -- 门诊挂号
        and a.isDelete = 0
        and c.isDelete = 0
        and d.isDelete = 0
        and d.createtime >= '2018-03-14 13:30:00'
        and d.createtime <= '2018-11-30 21:00:00'
        and  c.`itemCode` = 'jiajifei'    -- 加急费:急诊费
        ) t
        group by t.orderDept,t.orderDoctor
    ) t14 on t1.dept_id = t14.orderDept and t1.appointment_doctor_id = t14.orderDoctor
    
    
    -- ------------
    -- 工本费 t15
    -- ------------
    left join (
        select  round(sum(t.realFee),2) as num, t.orderDept, t.orderDoctor from
    (
        select
        (
            b.preFee                     -- 原价
            - b.discountFee             -- 自费折扣金额
            - b.promotionBenefitFee     -- 活动优惠
            - b.couponFee                 -- 优惠券优惠金额
            - b.itemBenefitFee             -- 身份卡优惠金额
            - b.memberCardBenefitFee     -- 会员卡优惠金额
            - b.itemComInvBenefitFee    -- 商业保险优惠金额
        ) * b.discount AS realFee,
        d.orderDept,
        d.orderDoctor
        from `thc_rcm`.`Cs_Settlement` a
        join `thc_rcm`.`Cs_SettlementDetail` b on a.id = b.`settlementID`
        join `thc_rcm`.`Cs_AccountBill` d on b.accountBillID = d.id 
        join `thc_rcm`.`Cs_AccountBillDetail` c on b.accountBillID = c.AccountBillId and b.accountBillDetailID = c.id and         b.orderDetailId = c.orderDetailId
        where a.settlementType = 2    -- 门诊挂号
        and a.isDelete = 0
        and c.isDelete = 0
        and d.isDelete = 0
        and d.createtime >= '2018-03-14 13:30:00'
        and d.createtime <= '2018-11-30 21:00:00'
        and  c.`itemCode` = 'bingliben'    -- 病历本:工本费
        ) t
        group by t.orderDept,t.orderDoctor
    ) t15 on t1.dept_id = t15.orderDept and t1.appointment_doctor_id = t15.orderDoctor
    
    
    -- ------------
    -- 卡费 t16
    -- ------------
    left join (
        select  round(sum(t.realFee),2) as num, t.orderDept, t.orderDoctor from
    (
        select
        (
            b.preFee                     -- 原价
            - b.discountFee             -- 自费折扣金额
            - b.promotionBenefitFee     -- 活动优惠
            - b.couponFee                 -- 优惠券优惠金额
            - b.itemBenefitFee             -- 身份卡优惠金额
            - b.memberCardBenefitFee     -- 会员卡优惠金额
            - b.itemComInvBenefitFee    -- 商业保险优惠金额
        ) * b.discount AS realFee,
        d.orderDept,
        d.orderDoctor
        from `thc_rcm`.`Cs_Settlement` a
        join `thc_rcm`.`Cs_SettlementDetail` b on a.id = b.`settlementID`
        join `thc_rcm`.`Cs_AccountBill` d on b.accountBillID = d.id 
        join `thc_rcm`.`Cs_AccountBillDetail` c on b.accountBillID = c.AccountBillId and b.accountBillDetailID = c.id and         b.orderDetailId = c.orderDetailId
        where a.settlementType = 2    -- 门诊挂号
        and a.isDelete = 0
        and c.isDelete = 0
        and d.isDelete = 0
        and d.createtime >= '2018-03-14 13:30:00'
        and d.createtime <= '2018-11-30 21:00:00'
        and  c.`itemCode` = 'jiuzhenka'    -- 就诊卡:卡费
        ) t
        group by t.orderDept,t.orderDoctor
    ) t16 on t1.dept_id = t16.orderDept and t1.appointment_doctor_id = t16.orderDoctor
    
    
    -- ------------
    -- 现金 t17
    -- ------------
    left join (
        select  round(sum(t.realFee),2) as num, t.orderDept, t.orderDoctor from
    (
        select
        (
            b.preFee                     -- 原价
            - b.discountFee             -- 自费折扣金额
            - b.promotionBenefitFee     -- 活动优惠
            - b.couponFee                 -- 优惠券优惠金额
            - b.itemBenefitFee             -- 身份卡优惠金额
            - b.memberCardBenefitFee     -- 会员卡优惠金额
            - b.itemComInvBenefitFee    -- 商业保险优惠金额
        ) * b.discount AS realFee,
        d.orderDept,
        d.orderDoctor
        from `thc_rcm`.`Cs_Settlement` a
        join `thc_rcm`.`Cs_SettlementDetail` b on a.id = b.`settlementID`
        join `thc_rcm`.`Cs_AccountBill` d on b.accountBillID = d.id 
        join `thc_rcm`.`Cs_AccountBillDetail` c on b.accountBillID = c.AccountBillId and b.accountBillDetailID = c.id and         b.orderDetailId = c.orderDetailId
        join `thc_rcm`.`pay_trade_log` e on e.`settlement_id` = a.id
        where a.settlementType = 2    -- 门诊挂号
        and a.isDelete = 0
        and c.isDelete = 0
        and d.isDelete = 0
        and d.createtime >= '2018-03-14 13:30:00'
        and d.createtime <= '2018-11-30 21:00:00'
        and e.type = 1         -- 门诊
         and e.pay_method = 1      -- 现金
        ) t
        group by t.orderDept,t.orderDoctor
    ) t17 on t1.dept_id = t17.orderDept and t1.appointment_doctor_id = t17.orderDoctor
    
    -- ------------
    -- 银行卡 t17
    -- ------------
    left join (
        select  round(sum(t.realFee),2) as num, t.orderDept, t.orderDoctor from
    (
        select
        (
            b.preFee                     -- 原价
            - b.discountFee             -- 自费折扣金额
            - b.promotionBenefitFee     -- 活动优惠
            - b.couponFee                 -- 优惠券优惠金额
            - b.itemBenefitFee             -- 身份卡优惠金额
            - b.memberCardBenefitFee     -- 会员卡优惠金额
            - b.itemComInvBenefitFee    -- 商业保险优惠金额
        ) * b.discount AS realFee,
        d.orderDept,
        d.orderDoctor
        from `thc_rcm`.`Cs_Settlement` a
        join `thc_rcm`.`Cs_SettlementDetail` b on a.id = b.`settlementID`
        join `thc_rcm`.`Cs_AccountBill` d on b.accountBillID = d.id 
        join `thc_rcm`.`Cs_AccountBillDetail` c on b.accountBillID = c.AccountBillId and b.accountBillDetailID = c.id and         b.orderDetailId = c.orderDetailId
        join `thc_rcm`.`pay_trade_log` e on e.`settlement_id` = a.id
        where a.settlementType = 2    -- 门诊挂号
        and a.isDelete = 0
        and c.isDelete = 0
        and d.isDelete = 0
        and d.createtime >= '2018-03-14 13:30:00'
        and d.createtime <= '2018-11-30 21:00:00'
        and e.type = 1         -- 门诊
         and e.pay_method = 2      -- 现金
        ) t
        group by t.orderDept,t.orderDoctor
    ) t18 on t1.dept_id = t18.orderDept and t1.appointment_doctor_id = t18.orderDoctor
    
    
    -- ------------
    -- 预存款 t19
    -- ------------
    left join (
        select  round(sum(t.realFee),2) as num, t.orderDept, t.orderDoctor from
    (
        select
        (
            b.preFee                     -- 原价
            - b.discountFee             -- 自费折扣金额
            - b.promotionBenefitFee     -- 活动优惠
            - b.couponFee                 -- 优惠券优惠金额
            - b.itemBenefitFee             -- 身份卡优惠金额
            - b.memberCardBenefitFee     -- 会员卡优惠金额
            - b.itemComInvBenefitFee    -- 商业保险优惠金额
        ) * b.discount AS realFee,
        d.orderDept,
        d.orderDoctor
        from `thc_rcm`.`Cs_Settlement` a
        join `thc_rcm`.`Cs_SettlementDetail` b on a.id = b.`settlementID`
        join `thc_rcm`.`Cs_AccountBill` d on b.accountBillID = d.id 
        join `thc_rcm`.`Cs_AccountBillDetail` c on b.accountBillID = c.AccountBillId and b.accountBillDetailID = c.id and         b.orderDetailId = c.orderDetailId
        where a.settlementType = 2    -- 门诊挂号
        and a.isDelete = 0
        and c.isDelete = 0
        and d.isDelete = 0
        and d.createtime >= '2018-03-14 13:30:00'
        and d.createtime <= '2018-11-30 21:00:00'
        and  c.`itemCode` = 'yujian'    -- 预检:预存款
        ) t
        group by t.orderDept,t.orderDoctor
    ) t19 on t1.dept_id = t19.orderDept and t1.appointment_doctor_id = t19.orderDoctor
    
    where t1.dept_name = '中医科' -- and t1.doctorName = '王艳'
    and t1.startTime >= '2018-03-14 13:30:00'
    and t1.endTime <= '2018-11-30 21:00:00'
    order by t1.startTime asc, t1.startTime asc;

     病历本金额查询v1

    select round(t.yuanFee,2), round(t.yuanFee * t.discount,2) as zheKouFee, t.orderDept, t.orderDoctor from
    (
    select 
        (
            b.preFee                     -- 原价
            - b.discountFee             -- 自费折扣金额
            - b.promotionBenefitFee     -- 活动优惠
            - b.couponFee                 -- 优惠券优惠金额
            - b.itemBenefitFee             -- 身份卡优惠金额
            - b.memberCardBenefitFee     -- 会员卡优惠金额
            - b.itemComInvBenefitFee    -- 商业保险优惠金额
        ) AS yuanFee,
        b.discount,
        d.orderDept,
        d.orderDoctor
    from `thc_rcm`.`Cs_Settlement` a
    join `thc_rcm`.`Cs_SettlementDetail` b on a.id = b.`settlementID`
    join `thc_rcm`.`Cs_AccountBill` d on b.accountBillID = d.id 
    join `thc_rcm`.`Cs_AccountBillDetail` c on b.accountBillID = c.AccountBillId and b.accountBillDetailID = c.id and b.orderDetailId = c.orderDetailId
    where a.settlementType = 2    -- 门诊挂号
    and a.isDelete = 0
    and c.isDelete = 0
    and d.isDelete = 0
    -- and  c.`itemCode` = 'bingliben'    -- 病历本:工本费
    order by b.discount
    ) t

    按部门查挂号信息:

    select * from bpm_appointment where dept_type = 1;

    WANTED-1277 - 门诊查询统计报表-挂号来源途径统计 PRD已完成

    select count(1),DATE_FORMAT(appointment_date,'%Y-%m-%d'),     -- 按日期还是月份展示
    case data_source WHEN 1 THEN 'THC系统' WHEN 2 THEN 'App' END
    from bpm_appointment
    where DATE_FORMAT(appointment_date,'%Y-%m-%d') >= DATE_FORMAT('2018-02-09','%Y-%m-%d') 
    and DATE_FORMAT(appointment_date,'%Y-%m-%d') <= DATE_FORMAT('2018-03-01','%Y-%m-%d')
    and subsequent_visit = 1    -- 0 复诊 1 初诊
    group by  date_format(appointment_date, '%Y-%m-%d'), data_source     -- 按日期还是月份分组查询
    order by appointment_date asc,data_source asc;

    联查挂号和账单结算单

    select  a.patient_id,         -- 患者ID
        a.patient_name,     -- 患者姓名
        a.patient_phone,    -- 患者电话号
        a.dept_id,        -- 部门ID
        a.dept_name,    -- 部门名称
        a.orderId,    -- 订单ID
        a.order_item_id, -- 订单明细id
        a.medical_card_number,    -- 社保卡号,即身份证号
        a.appointment_date, -- 预约日期
        a.visit_number,    -- 看诊序号
        a.create_time,
        a.description    -- 备注
    from `thc_arrange`.`bpm_appointment` a 
    join `thc_rcm`.`Cs_AccountBill` b on a.`orderId` = b.`orderID`
    join (
        select distinct c.*,d.`accountBillID` from   `thc_rcm`.`Cs_Settlement` c  
        join `thc_rcm`.`Cs_SettlementDetail` d on c.id = d.`settlementID`
        where c.settlementType=2
    ) t on b.`id` = t.accountBillID
    where b.orderType = 3

    来自微信的单子? 

    `thc_rcm`.`pay_trade_log` 交易流水表

    `thc_rcm`.`pay_payment`  支付方式表

    -- WANTED-1283 门诊查询统计报表-挂号微信收入明细
    select  
        p.name as patientName,                              -- 患者姓名
        p.birthday,                                         -- 出生日期
        d.outpatient_number as blNumber,                    -- 病历号
        case p.sex     WHEN 1 THEN '' WHEN 2 THEN '' END,    -- 性别
        b.flow_fee,                                            -- 支付金额
        (b.flow_fee - b.charge) as realMoney,
        b.charge,                                            -- 手续费
        b.pay_time,                                            -- 缴费时间
        a.create_time,                                        -- 挂号时间
        a.dept_name,                                         -- 挂号科室名称
        a.appointment_doctor_name as doctorName,             -- 挂号医生
                                                            -- 挂号人
        
        (select t.docname from (
            SELECT u.clinic_id AS clinicid, u.id AS docid,u1.property_value AS docname
            FROM thc_warehouse.staff_record u
            LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = 'SXX000083' AND u.id = u1.staff_record_id
        ) t where t.docid = a.creator and a.dept_id = t.clinicid) AS creater,
        e.name as guaHaoRen,
        CASE a.subsequent_visit 
            WHEN 0 THEN '初诊' 
            WHEN 1 THEN '复诊' 
            WHEN 2 THEN '转诊' 
            WHEN 3 THEN '急诊' 
            WHEN 4 THEN '体检'
            WHEN 5 THEN '简易'
            WHEN 6 THEN '疫苗'  
        END AS isReVisit                            -- 初复诊
    from `thc_arrange`.`bpm_appointment` a
    join `thc_rcm`.`pay_trade_log` b on a.`patient_id` = b.`patient_id`
    join `thc_rcm`.`pay_payment` e on  e.value = b.`pay_method`
    left join `thc_passport`.`patient` p on a.patient_id = p.id
    left join `thc_passport`.`contact` c on a.patient_id = c.patient_id
    left join `thc_passport`.`patient_org` d on a.patient_id = d.patient_id
    
    
    -- WHERE b.type = 1         -- 门诊
    -- and b.`pay_method` = 4 -- 微信支付
    
    limit 100;

    帆软:行转列/列转行

    http://help.finereport.com/doc-view-1759

    -- ------------------------
    -- 门诊查询统计报表-体检信息查询V1.0
    -- ------------------------
    SELECT 
        e.outpatient_number as blNumber,    -- 病历号
        a.patient_name,                        -- 患者姓名
        a.birthday,                            -- 出生日期
        b.advice_name,                        -- 项目名称
        b.item_num,                            -- 数量
        '' as unit,                        -- 单位
        b.total_price as singlePrice,        -- 单价
                                             -- 开单医生
        (select t.docname from (
            SELECT u.clinic_id AS clinicid, u.id AS docid,u1.property_value AS docname
            FROM thc_warehouse.staff_record u
            LEFT JOIN thc_warehouse.staff_record_property u1 ON u1.property_code = 'SXX000083' AND u.id = u1.staff_record_id
        ) t where t.docid = c.creator ) AS creater,    -- and a.dept_id = t.clinicid
        c.create_time,                        -- 开单时间
        a.set_meal_name                        -- 套餐名称
    from `thc_phr`.`physical_exam` a
    join `thc_phr`.`physical_exam_item` b on a.id = b.physical_exam_id
     join `thc_market`.`setmeal_order_info` c on c.id= b.`order_id`
     join `thc_market`.`setmeal_order_detail` d  on b.order_id = d.order_id and b.order_sn = d.sn and c.id = d.`order_id` and b.order_item_id =  d.id
    left join `thc_passport`.`patient_org` e on a.patient_id = e.patient_id
    order by blNumber asc, patient_name asc
    -- ------------------------
    -- 门诊查询统计报表-体检信息查询 V2.0
    -- ------------------------
    SELECT 
        e.outpatient_number as blNumber,    -- 病历号
        a.patient_name,                        -- 患者姓名
        a.birthday,                            -- 出生日期
        b.advice_name,                        -- 项目名称
        b.item_num,                            -- 数量
        '' as unit,                        -- 单位
        round(b.price,2) as singlePrice,    -- 单价
        round(b.price_dis,2) as  shouldPay,    -- 应收金额
        '核算科室' settleDept,                -- 核算科室
        a.prov_name,                        -- 科室名称 【无值?】
        a.prov_id,                            -- 科室ID  【无值?】
        c.sale_dept_name,                    -- 开单科室(销售部门)【?】
        c.sale_man_name,                    -- 开单医生(销售人员)    【?】                     
        c.creator_name,                        -- 开单医生(单子的创建人)【?】
        c.create_time,                        -- 开单时间
        a.set_meal_name                        -- 体检标题(套餐名称)
    from `thc_phr`.`physical_exam` a        -- 体检单
    join `thc_phr`.`physical_exam_item` b on a.id = b.physical_exam_id        -- 体检明细单
    join `thc_market`.`setmeal_order_info` c on c.id= b.`order_id`            -- market 的 订单
    join `thc_market`.`setmeal_order_detail` d
    on b.order_id = d.order_id and b.order_sn = d.sn and c.id = d.`order_id` and b.order_item_id = d.id -- market 的 订单明细表
    left join `thc_passport`.`patient_org` e on a.patient_id = e.patient_id
    order by blNumber asc, patient_name asc
    
    -- where  c.sale_dept_name = '${deptName}'            -- 科室    【?】
    -- and c.creator_name = '${doctorName}'            -- 医生    【?】
    -- and '核算科室' = '${核算科室}'                        -- 核算科室    【?】
    -- and c.create_time > '${startTime}'                -- 开始时间    【?】
    -- and c.create_time < '${endTime}'                -- 结束时间    【?】
    -- and a.patient_name like '%${patientName}%'      -- 姓名
    -- and e.outpatient_number like '%${blNumber}%'    -- 病历号
    -- and a.set_meal_name like '%${title}%'            -- 体检标题    【?】
  • 相关阅读:
    day-7
    Redis数据库 : 基础
    MongoDB与python交互
    MongoDB数据库 : 管道,用户管理,副本集等
    MongoDB数据库 : 基础
    MySQL数据库 : 自关联,视图,事物,索引
    MySQL数据库 : 查询语句,连接查询及外键约束
    MySQL数据库 : 基本语句
    数据结构与算法 : 树与遍历
    python__标准库 : 测试代码运行时间(timeit)
  • 原文地址:https://www.cnblogs.com/guchunchao/p/10124244.html
Copyright © 2011-2022 走看看