Sfoglia il codice sorgente

修改咨询导出的模糊查询,订单导出数据的查询,眼科财务报表的模糊查询

hxm 3 anni fa
parent
commit
e2164b4e72

+ 186 - 125
business/base-service/src/main/java/com/yihu/jw/hospital/prescription/service/PrescriptionService.java

@ -3231,8 +3231,8 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
     * @param size
     * @return
     */
    public MixEnvelop findExpressageList2(String status, String oneselfPickupFlg, String nameKey, String startTime, String endTime, Integer page, Integer size, String wxId,String patientName) {
        String totalSql = "SELECT " +
    public MixEnvelop  findExpressageList2(String status, String oneselfPickupFlg, String nameKey, String startTime, String endTime, Integer page, Integer size, String wxId,String patientName) {
        /*String totalSql = "SELECT " +
                " COUNT(1) AS \"total\" " +
                " FROM " +
                " wlyy_outpatient o " +
@ -3282,6 +3282,9 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        if (rstotal != null && rstotal.size() > 0) {
            count = Long.parseLong(rstotal.get(0).get("total").toString());
        }
        String sql = "SELECT  ";
        if ("xm_ykyy_wx".equals(wxId)) {
            if (flag){
@ -3317,108 +3320,192 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            sql = sql +
                    "p.id AS \"prescriptionId\",\n" +
                    "p.create_time AS \"time\",\n" +
                    "\te. NAME AS \"name\",\n" +
                    "\te.name AS \"name\",\n" +
                    "\tp.pay_time AS \"pay_time\",\n" +
                    "\tp.real_order AS \"realOrder\",\n" +
                    " o.icd10_name AS \"icd10Name\", " +
                    " e.id AS \"expressageId\" ,"+
                    "\to.patient_name AS \"patientName\",\n" +
                    "\tp.create_time AS \"create_time\",\n" +
                    "\te.oneself_pickup_flg AS \"oneself_pickup_flg\",\n" +
                    "\tp. STATUS AS \"status\"\n" +
                    "\tp.status AS \"status\"\n" +
                    "FROM\n" +
                    "\twlyy_outpatient o\n" +
                    "JOIN wlyy_prescription p ON p.outpatient_id = o.id\n" +
                    "JOIN wlyy_prescription_expressage e ON e.outpatient_id = o.id\n" +
                    "WHERE\n" +
                    "\t1 = 1\n";//oracle
            if (StringUtils.isNotBlank(status)) {
                totalSql += " AND p.status in(" + status + ") ";
            }
            if (StringUtils.isNotBlank(oneselfPickupFlg)) {
                totalSql += " AND e.oneself_pickup_flg = " + oneselfPickupFlg+" ";
            }
            if (StringUtils.isNotBlank(nameKey)) {
                totalSql += " AND e.name like '%" + nameKey + "%' ";
            }
            if (StringUtils.isNotBlank(patientName)) {
                totalSql += " AND o.patient_name like '%" + patientName + "%' ";
            }
            if (StringUtils.isNotBlank(startTime)) {
                if ("xm_ykyy_wx".equals(wxId)) {
                    if (flag){
                        totalSql += " and p.create_time >= str_to_date('" + startTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                    }else {
                        totalSql += " and p.create_time >= to_date('" + startTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                    }
                } else {
                    totalSql += " AND p.create_time >='" + startTime + " 00:00:00'";
                }
            }
            if (StringUtils.isNotBlank(endTime)) {
                if ("xm_ykyy_wx".equals(wxId)) {
                    if (flag){
                        totalSql += " and p.create_time <= str_to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                    }else {
                        totalSql += " and p.create_time <= to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                    }
                } else {
                    sql += " AND p.create_time <='" + endTime + " 23:59:59'";
                }
            }
        } else {
            sql = sql +
                    "p.id AS \"prescriptionId\",\n" +
                    "\tp.create_time AS \"time\",\n" +
                    "\te. NAME AS \"name\",\n" +
                    "\te.name AS \"name\",\n" +
                    "\tp.pay_time AS \"pay_time\",\n" +
                    "\tp.real_order AS \"realOrder\",\n" +
                    " o.icd10_name AS \"icd10Name\", " +
                    " e.id AS \"expressageId\" ,"+
                    "\to.patient_name AS \"patientName\",\n" +
                    "\tp.create_time AS \"create_time\",\n" +
                    "\te.oneself_pickup_flg AS \"oneself_pickup_flg\",\n" +
                    "\tp. STATUS AS \"status\"\n" +
                    "\tp.status AS \"status\"\n" +
                    "FROM\n" +
                    "\twlyy_outpatient o\n" +
                    "JOIN wlyy_prescription p ON p.outpatient_id = o.id\n" +
                    "JOIN wlyy_prescription_expressage e ON e.outpatient_id = o.id\n" +
                    "WHERE\n" +
                    "\t1 = 1\n";//MySQL
            if (StringUtils.isNotBlank(status)) {
                totalSql += " AND p.status in(" + status + ") ";
                    "\t1 = 1\n";
        }
        if (StringUtils.isNotBlank(status)) {
            sql += " AND p.status in(" + status + ") ";
        }
        if (StringUtils.isNotBlank(oneselfPickupFlg)) {
            sql += " AND e.oneself_pickup_flg =" + oneselfPickupFlg+" ";
        }
        if (StringUtils.isNotBlank(nameKey)) {
            sql += " AND e.name like '%" + nameKey + "%' ";
        }
        if (StringUtils.isNotBlank(patientName)) {
            sql += " AND o.patient_name like '%" + patientName + "%' ";
        }
        if (StringUtils.isNotBlank(startTime)) {
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    sql += " and p.create_time >= str_to_date('" + startTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                }else {
                    sql += " and p.create_time >= to_date('" + startTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                }
            } else {
                sql += " AND p.create_time >='" + startTime + " 00:00:00'";
            }
            if (StringUtils.isNotBlank(oneselfPickupFlg)) {
                totalSql += " AND e.oneself_pickup_flg = " + oneselfPickupFlg+" ";
        }
        if (StringUtils.isNotBlank(endTime)) {
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    sql += " and p.create_time <= str_to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                }else {
                    sql += " and p.create_time <= to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                }
            } else {
                sql += " AND p.create_time <='" + endTime + " 23:59:59'";
            }
            if (StringUtils.isNotBlank(nameKey)) {
                totalSql += " AND e.name like '%" + nameKey + "%' ";
        }
        sql +=" order by p.create_time desc ";
        *//*       sql += " LIMIT " + (page - 1) * size + "," + size + "";*//*
        List<Map<String, Object>> mapList = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> map : mapList) {
            if (map.get("prescriptionId") != null) {
                List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = prescriptionInfoDao.findByPrescriptionId(map.get("prescriptionId").toString(), 1);
                map.put("info", wlyyPrescriptionInfoDOS);
                String infoName = "";
                for (WlyyPrescriptionInfoDO info:wlyyPrescriptionInfoDOS) {
                    infoName += info.getDrugName() + "*" + info.getQuantity() + ",";
                }
                map.put("infooName",infoName);
            }
            if (StringUtils.isNotBlank(patientName)) {
                totalSql += " AND o.patient_name like '%" + patientName + "%' ";
        }*/
        String totalSql = "SELECT " +
                " COUNT(1) AS \"total\" " +
                " FROM " +
                " wlyy_outpatient o " +
                " JOIN wlyy_prescription p ON p.outpatient_id = o.id " +
                " JOIN wlyy_prescription_expressage e ON e.outpatient_id = o.id" +
                " WHERE" +
                " 1=1 ";
        if (StringUtils.isNotBlank(status)) {
            totalSql += " AND p.status in(" + status + ") ";
        }
        if (StringUtils.isNotBlank(oneselfPickupFlg)) {
            totalSql += " AND e.oneself_pickup_flg = " + oneselfPickupFlg+" ";
        }
        if (StringUtils.isNotBlank(nameKey)) {
            totalSql += " AND e.name like '%" + nameKey + "%' ";
        }
        if (StringUtils.isNotBlank(patientName)) {
            totalSql += " AND o.patient_name like '%" + patientName + "%' ";
        }
        if (StringUtils.isNotBlank(startTime)) {
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    totalSql += " and p.create_time >= str_to_date('" + startTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                }else {
                    totalSql += " and p.create_time >= to_date('" + startTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                }
            } else {
                totalSql += " AND p.create_time >='" + startTime + " 00:00:00'";
            }
            if (StringUtils.isNotBlank(startTime)) {
                if ("xm_ykyy_wx".equals(wxId)) {
                    if (flag){
                        totalSql += " and p.create_time >= str_to_date('" + startTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                    }else {
                        totalSql += " and p.create_time >= to_date('" + startTime + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                    }
                } else {
                    totalSql += " AND p.create_time >='" + startTime + " 00:00:00'";
        }
        if (StringUtils.isNotBlank(endTime)) {
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    totalSql += " and p.create_time <= str_to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                }else {
                    totalSql += " and p.create_time <= to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                }
            } else {
                totalSql += " AND p.create_time <='" + endTime + " 23:59:59'";
            }
        }
        List<Map<String, Object>> rstotal = hibenateUtils.createSQLQuery(totalSql);
        Long count = 0L;
        if (rstotal != null && rstotal.size() > 0) {
            count = Long.parseLong(rstotal.get(0).get("total").toString());
        }
        String sql = "SELECT  ";
        if ("xm_ykyy_wx".equals(wxId)) {
            if (flag){
                sql = sql + "date_format(e.create_time,'YYYY-MM-DD hh24:mi:ss')  AS \"expressCreateTime\",";
            }else {
                sql = sql + "to_char(e.create_time,'YYYY-MM-DD hh24:mi:ss')  AS \"expressCreateTime\",";
            }
            if (StringUtils.isNotBlank(endTime)) {
                if ("xm_ykyy_wx".equals(wxId)) {
                    if (flag){
                        totalSql += " and p.create_time <= str_to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                    }else {
                        totalSql += " and p.create_time <= to_date('" + endTime + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                    }
                } else {
                    sql += " AND p.create_time <='" + endTime + " 23:59:59'";
                }
        } else {
            sql = sql + "date_format(e.create_time,'%Y-%m-%d %H:%i:%S' )  AS \"expressCreateTime\",";
        }
        if ("xm_ykyy_wx".equals(wxId)) {
            if (flag){
                sql = sql + "date_format(p.create_time,'YYYY-MM-DD hh24:mi:ss')  AS \"createTime\",";
            }else {
                sql = sql + "to_char(p.create_time,'YYYY-MM-DD hh24:mi:ss')  AS \"createTime\",";
            }
        } else {
            sql = sql + "date_format(p.create_time,'%Y-%m-%d %H:%i:%S' )  AS \"createTime\",";
        }
        if ("xm_ykyy_wx".equals(wxId)) {
            if (flag){
                sql = sql + "date_format(p.pay_time,'YYYY-MM-DD hh24:mi:ss')  AS \"payTime\",";
            }else {
                sql = sql + "to_char(p.pay_time,'YYYY-MM-DD hh24:mi:ss')  AS \"payTime\",";
            }
        } else {
            sql = sql + "date_format(p.pay_time,'%Y-%m-%d %H:%i:%S' )  AS \"payTime\",";
        }
        sql = sql + " e.name as \"name\", " +
                " e.oneself_pickup_flg AS \"oneselfPickupFlg\", " +
                " o.id AS \"outpatientId\", " +
                " o.icd10_name AS \"icd10Name\", " +
                " p.status as \"status\", " +
                " p.id AS \"prescriptionId\" ," +
                " e.id AS \"expressageId\" ,"+
                " p.real_order AS \"realOrder\" ,"+
                " p.origin_real_order AS \"originRealOrder\"," +
                " o.patient_name as \"patientName\" "+
                " FROM " +
                " wlyy_outpatient o " +
                " JOIN wlyy_prescription p ON p.outpatient_id = o.id " +
                " JOIN wlyy_prescription_expressage e ON e.outpatient_id = o.id " +
                " WHERE" +
                " 1=1";
        if (StringUtils.isNotBlank(status)) {
            sql += " AND p.status in(" + status + ") ";
        }
@ -3431,6 +3518,7 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        if (StringUtils.isNotBlank(patientName)) {
            sql += " AND o.patient_name like '%" + patientName + "%' ";
            /*sql += " and (a.patient_name like '" + title + "' OR a.doctor_name like '" + title + "' OR a.dept_name like '" + title + "' )"*/
        }
        if (StringUtils.isNotBlank(startTime)) {
            if ("xm_ykyy_wx".equals(wxId)) {
@ -3459,16 +3547,11 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
        }
        sql +=" order by p.create_time desc ";
        /*       sql += " LIMIT " + (page - 1) * size + "," + size + "";*/
        List<Map<String, Object>> mapList = hibenateUtils.createSQLQuery(sql);
        List<Map<String, Object>> mapList = hibenateUtils.createSQLQuery(sql, page, size);
        for (Map<String, Object> map : mapList) {
            if (map.get("prescriptionId") != null) {
                List<WlyyPrescriptionInfoDO> wlyyPrescriptionInfoDOS = prescriptionInfoDao.findByPrescriptionId(map.get("prescriptionId").toString(), 1);
                map.put("info", wlyyPrescriptionInfoDOS);
                String infoName = "";
                for (WlyyPrescriptionInfoDO info:wlyyPrescriptionInfoDOS) {
                    infoName += info.getDrugName() + "*" + info.getQuantity() + ",";
                }
                map.put("infooName",infoName);
            }
        }
        return MixEnvelop.getSuccessListWithPage2(BaseHospitalRequestMapping.Prescription.api_success, mapList);
@ -3837,31 +3920,6 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
            for (Map<String, Object> m : list) {
                /*Object status = m.get("status");
                String statuss = "";
                if (status == null) {
                    statuss += " ";
                }else if (status.equals("0")) {
                    statuss += "未支付";
                }else if (status.equals("1")) {
                    statuss += "已支付";
                }else if (status.equals("2")) {
                    statuss += "交易关闭";
                }else if (status.equals("3")) {
                    statuss += "支付超时";
                }else if (status.equals("4")) {
                    statuss += "交易完成";
                }else if (status.equals("5")) {
                    statuss += "交易进行中";
                }else if (status.equals("6")) {
                    statuss += "退款申请";
                }else if (status.equals("9")) {
                    statuss += "退款完成";
                }else {
                    statuss += " ";
                }*/
                String odry = "";
                String orderCategory = "";
                String odte = "";
@ -3871,34 +3929,37 @@ public class PrescriptionService extends BaseJpaService<WlyyPrescriptionDO, Pres
                if (m.get("orderCategory")==null){
                    odry = null;
                }else {
                    orderCategory = m.get("orderCategory").toString();
                    if (orderCategory.equals("1")) {
                        odry += "专家咨询";
                    }else if (orderCategory.equals("2")) {
                        odry += "复诊";
                    }else if (orderCategory.equals("3")) {
                        odry += "视频诊室";
                    }else if (orderCategory.equals("4")) {
                        odry += "处方";
                        odte += "处方";
                    }else if (orderCategory.equals("5")) {
                        odry += "就诊卡充值";
                        odte += "就诊卡充值";
                    }else {
                        odry += " ";
                    if(m.get("orderType") == null) {
                        odte = null;
                    }else{
                        String orderType =  m.get("orderType").toString();
                        orderCategory = m.get("orderCategory").toString();
                        if (orderCategory.equals("1")) {
                            odry += "专家咨询";
                            if (orderType.equalsIgnoreCase("1")) {
                                odte += "图文";
                            }else if (orderType.equalsIgnoreCase("3")) {
                                odte += "视频";
                            }
                        }else if (orderCategory.equals("2")) {
                            odry += "在线复诊";
                            if (orderType.equalsIgnoreCase("1")) {
                                odte += "图文";
                            }else if (orderType.equalsIgnoreCase("3")) {
                                odte += "视频";
                            }
                        }else if (orderCategory.equals("4")) {
                            odry += "处方";
                            odte += "处方";
                        }else if (orderCategory.equals("5")) {
                            odry += "就诊卡充值";
                            odte += "就诊卡充值";
                        }else {
                            odry += " ";
                        }
                    }
                }
                if(m.get("orderType") == null) {
                    odte = null;
                }else{
                    String orderType =  m.get("orderType").toString();
                    if (orderType.equalsIgnoreCase("1")) {
                        odte += "图文";
                    }else if (orderType.equalsIgnoreCase("3")) {
                        odte += "视频";
                    }
                }
                if (m.get("status") == null) {
                    status = null;

+ 5 - 3
business/base-service/src/main/java/com/yihu/jw/order/BusinessOrderService.java

@ -2114,15 +2114,17 @@ public class BusinessOrderService extends BaseJpaService<BusinessOrderDO,Busines
        if (StringUtils.isNoneBlank(idCard)){
            sql+=" and b.idcard like '%"+idCard+"%'";
        }
        if (StringUtils.isNoneBlank(medicard)){
            sql+=" and t.relation_code like '%"+medicard+"%'";
        }
        if (status!=null){
            sql+=" and t.status ="+status+"";
        }
        if (StringUtils.isNoneBlank(orderType)){
            sql+=" and t.order_type like %"+orderType+"%";
            sql+=" and t.order_type ="+orderType+"";
        }
        if (StringUtils.isNoneBlank(orderCategory)){
            if (orderCategory.equalsIgnoreCase("2")){
                sql+=" and t.order_category IN ('2','3') ";

+ 134 - 31
business/im-service/src/main/java/com/yihu/jw/im/service/ImService.java

@ -4315,9 +4315,8 @@ public class ImService {
    public MixEnvelop recordByDoctor(String doctor, String id,String type, Integer status,String title, String start_time, String end_time, String patient) { //
        String pushSql = "";
        pushSql =
                "SELECT\n" +
        String sql = "";
        sql ="SELECT\n" +
                        "\ta.patient_name AS \"pname\",\n" +
                        "\ta.doctor_name AS \"dname\",\n" +
                        "\ta.dept_name AS \"dept\",\n" +
@ -4331,56 +4330,160 @@ public class ImService {
                        "FROM\n" +
                        "\twlyy_outpatient a\n" +
                        "LEFT JOIN wlyy_prescription b ON a.id = b.outpatient_id\n" +
                        "LEFT JOIN wlyy_consult c ON c.relation_code = a.id\n" +
                        "LEFT JOIN wlyy_consult_team d ON c.id = d.consult\n" +
                        "LEFT JOIN base_patient e ON a.patient = e.id\n" +
                        "WHERE\n" +
                        "\t1 = 1";
                        "\t1 = 1 ";
        if (status != null) {
            pushSql += " AND a. STATUS in(" + status + ") ";
        }
        if (org.apache.commons.lang3.StringUtils.isNotBlank(type)) {
            if (type.equals("0")) {
            }else {
                pushSql += " AND a.type = " + type +" ";
            }
        if (status == null){
        }else if (status == 1) {
            sql += " and a.status = 0 and a.pay_status =1 ";
        } else if (status == 0) {
        } else if (status == 2) {
            sql += " and a.status = 1";
        } else {
            sql += " and a.status = " + status;
        }
        if (org.apache.commons.lang3.StringUtils.isNotBlank(doctor)) {
            pushSql += " AND a.doctor = '" + doctor + "' ";
        if (org.apache.commons.lang.StringUtils.isNotBlank(doctor)) {
            sql += " AND a.doctor='" + doctor + "' ";
        }
        if (org.apache.commons.lang3.StringUtils.isNotBlank(patient)) {
            pushSql += " AND a.patient = '" + patient + "' ";
        if (org.apache.commons.lang.StringUtils.isNotBlank(patient)) {
            sql += " AND (a.consumer='" + patient + "' or a.patient ='" + patient + "')";
        }
        if (!StringUtils.isEmpty(title)) {
            title = "%" + title + "%";
            pushSql += " and (a.patient_name like '" + title + "' OR a.doctor_name like '" + title + "' OR a.dept_name like '" + title + "' )";
            sql += " and (a.patient_name like '" + title + "' OR a.doctor_name like '" + title + "' OR a.dept_name like '" + title + "' )";
        }
        if (org.apache.commons.lang3.StringUtils.isNotBlank(start_time)) {
        if (!StringUtils.isEmpty(start_time)) {
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    pushSql += " and a.create_time >= str_to_date('" + start_time + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                }else {
                    pushSql += " and a.create_time >= to_date('" + start_time + " 00:00:00','YYYY-MM-DD HH24:MI:SS')";
                if (flag) {
                    sql += " and a.create_time >= str_to_date('" + start_time + "','YYYY-MM-DD HH24:MI:SS')";
                } else {
                    sql += " and a.create_time >= to_date('" + start_time + "','YYYY-MM-DD HH24:MI:SS')";
                }
            } else {
                pushSql += " AND a.create_time >='" + start_time + " 00:00:00'";
                sql += " and a.create_time >= '" + start_time + "'";
            }
        }
        if (org.apache.commons.lang3.StringUtils.isNotBlank(end_time)) {
        if (!StringUtils.isEmpty(end_time)) {
            if ("xm_ykyy_wx".equals(wxId)) {
                if (flag){
                    pushSql += " and a.create_time <= str_to_date('" + end_time + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                }else {
                    pushSql += " and a.create_time <= to_date('" + end_time + " 23:59:59','YYYY-MM-DD HH24:MI:SS')";
                if (flag) {
                    sql += " and a.create_time <= str_to_date('" + end_time + "','YYYY-MM-DD HH24:MI:SS')";
                } else {
                    sql += " and a.create_time <= to_date('" + end_time + "','YYYY-MM-DD HH24:MI:SS')";
                }
            } else {
                pushSql += " AND a.create_time <='" + end_time + " 23:59:59'";
                sql += " and a.create_time <= '" + end_time + "'";
            }
        }
        pushSql = pushSql + "\tORDER BY a.create_time desc ";
        //咨询类型
        if (!StringUtils.isEmpty(type)) {
            if (type.equalsIgnoreCase("9")) {
                sql += " AND a.type =1 and a.outpatient_type = 1";
            } else if (type.equalsIgnoreCase("16")) {
                sql += " AND a.type =2 and a.outpatient_type = 1";
            } else if (type.equalsIgnoreCase("1")) {
                sql += " AND a.type =1 and a.outpatient_type = 3";
            } else if (type.equalsIgnoreCase("15")) {
                sql += " AND a.type =3 and a.outpatient_type = 3";
            } else if (type.equalsIgnoreCase("17")) {
                sql += " AND a.type =2 and a.outpatient_type = 3";
            } else if (type.equalsIgnoreCase("12")) {
                sql += " AND a.outpatient_type = 2";
            } else {
                sql += " AND a.type in (1,2,3) ";
            }
        }
        if (!StringUtils.isEmpty(id)) {
            sql += " and a.id = '" + id + "'";
        }
        sql = sql + "\tORDER BY a.create_time desc ";
        List<Map<String, Object>> mapList = hibenateUtils.createSQLQuery(pushSql);
        List<Map<String, Object>> mapList = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> map : mapList) {
            if (map.get("patientIdcard") != null) {
                String idcard = map.get("patientIdcard").toString();
                Integer age = IdCardUtil.getAgeForIdcard(idcard);
                map.put("patientAge", age);
            } else {
                map.put("patientAge", null);
            }
            if (map.get("doctor") != null) {
                String doctorId = map.get("doctor").toString();
                BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctorId);
                List<BaseDoctorHospitalDO> doctorHospitalDOS = doctorHospitalDao.findByDoctorCode(doctorId);
                if (doctorHospitalDOS != null && doctorHospitalDOS.size() != 0) {
                    map.put("deptName", doctorHospitalDOS.get(0).getDeptName());
                }
                if (baseDoctorDO != null) {
                    map.put("doctorName", baseDoctorDO.getName());
                }
            }
            if (map.get("outpatientId") != null) {
                WlyyOutpatientDO wlyyOutpatientDO = outpatientDao.findById(map.get("outpatientId").toString());
                map.put("deptName", wlyyOutpatientDO.getDeptName());
            }
            if (map.get("outpatientType") != null) {
                if ("3".equalsIgnoreCase(map.get("outpatientType").toString()) && "1".equalsIgnoreCase(map.get("type").toString())) {
                    map.put("type", 1);
                }
                if ("3".equalsIgnoreCase(map.get("outpatientType").toString()) && "2".equalsIgnoreCase(map.get("type").toString())) {
                    map.put("type", 17);
                }
                if ("3".equalsIgnoreCase(map.get("outpatientType").toString()) && "3".equalsIgnoreCase(map.get("type").toString())) {
                    map.put("type", 15);
                }
                if ("1".equalsIgnoreCase(map.get("outpatientType").toString()) && "1".equalsIgnoreCase(map.get("type").toString())) {
                    map.put("type", 9);
                }
                if ("1".equalsIgnoreCase(map.get("outpatientType").toString()) && "2".equalsIgnoreCase(map.get("type").toString())) {
                    map.put("type", 16);
                }
                if ("2".equalsIgnoreCase(map.get("outpatientType").toString())) {
                    map.put("type", 12);
                }
            }
            if (map.get("id") != null) {
                if ("1".equals(type) || "15".equals(type) || type.contains(",") || "17".equals(type)) {
                    String consultCode = map.get("id").toString();
                    List<WlyyConsultAdvice> consultAdvices = wlyyConsultAdviceDao.getByConsult(consultCode);
                    StringBuffer content = new StringBuffer();
                    for (WlyyConsultAdvice consultAdvice : consultAdvices) {
                        content.append(consultAdvice.getAdviceValue() + ",");
                    }
                    if (content != null && content.length() > 0) {
                        System.out.println("content+=====" + content);
                        content.deleteCharAt(content.length() - 1);
                    }
                    map.put("icd10Name", content);
                } else if ("0".equals(type) && null != map.get("outpatientType") && "3".equalsIgnoreCase(map.get("outpatientType").toString())) {
                    String consultCode = map.get("id").toString();
                    List<WlyyConsultAdvice> consultAdvices = wlyyConsultAdviceDao.getByConsult(consultCode);
                    StringBuffer content = new StringBuffer();
                    for (WlyyConsultAdvice consultAdvice : consultAdvices) {
                        content.append(consultAdvice.getAdviceValue() + ",");
                    }
                    if (content != null && content.length() > 0) {
                        System.out.println("content+=====" + content);
                        content.deleteCharAt(content.length() - 1);
                    }
                    map.put("icd10Name", content);
                }
            }
        }
        return MixEnvelop.getSuccessListWithPage2(BaseHospitalRequestMapping.Prescription.api_success, mapList);
    }