Explorar o código

居民服务统计

lyr %!s(int64=8) %!d(string=hai) anos
pai
achega
89b5d13ffe

+ 3 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -332,4 +332,7 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
	@Query("select count(f) from SignFamily f where f.adminTeamId = ?1 and f.status >= ?2 ")
	int findByAdminTeamIdAndStatus(long teamCode,int status);
	@Query("select f from SignFamily f where f.patient = ?1 and f.adminTeamId = ?2 and f.status > 0")
	SignFamily findByPatientAndAdminTeamId(String patient,Long teamCode);
}

+ 241 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/ServiceStatisticsService.java

@ -0,0 +1,241 @@
package com.yihu.wlyy.service.app.statistics;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
/**
 * Created by lyr-pc on 2017/1/10.
 */
@Service
public class ServiceStatisticsService extends BaseService {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    SignFamilyDao signFamilyDao;
    public JSONObject getServiceStatistics(String patient, long teamCode) {
        JSONObject result = new JSONObject();
        SignFamily signFamily = signFamilyDao.findByPatientAndAdminTeamId(patient, teamCode);
        Calendar today = Calendar.getInstance();
        today.set(Calendar.DATE, 1);
        String monthBegin = DateUtil.dateToStrShort(today.getTime()) + " 00:00:00";
        String yearBegin = DateUtil.dateToStrShort(signFamily.getBegin()) + " 00:00:00";
        String yearEnd = DateUtil.dateToStrShort(signFamily.getEnd()) + " 23:59:59";
        JSONObject consult = getConsultStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
        result.put("consult", consult);
        JSONObject followup = getFollowupStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
        result.put("followup", followup);
        JSONObject reservation = getReservationStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
        result.put("reservation", reservation);
        JSONObject guidance = getGuidanceStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
        result.put("guidance", guidance);
        JSONObject article = getArticleStatistics(patient, teamCode, yearBegin, yearEnd, monthBegin);
        result.put("article", article);
        return result;
    }
    /**
     * 咨询统计
     *
     * @param patient
     * @param teamCode
     * @param yearBegin
     * @param yearEnd
     * @param monthBegin
     * @return
     */
    public JSONObject getConsultStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
        JSONObject result = new JSONObject();
        result.put("history", 0);
        result.put("history", 0);
        result.put("history", 0);
        String sqlHistory = "select count(1) h from wlyy_consult_team where patient = ? and admin_team_code = ?";
        String sqlYear = "select count(1) y from wlyy_consult_team where patient = ? and admin_team_code = ? and czrq >= ? and czrq <= ?";
        String sqlMonth = "select count(1) m from wlyy_consult_team where patient = ? and admin_team_code = ? and czrq >= ?";
        String sql = "select * from " +
                "(" + sqlHistory + ") a" +
                ",(" + sqlYear + ") b" +
                ",(" + sqlMonth + ") c";
        List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
                patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
        });
        if (counts != null && counts.size() > 0) {
            result.put("history", counts.get(0).get("h").toString());
            result.put("year", counts.get(0).get("y").toString());
            result.put("month", counts.get(0).get("m").toString());
        }
        return result;
    }
    /**
     * 健康教育统计
     *
     * @param patient
     * @param teamCode
     * @param yearBegin
     * @param yearEnd
     * @param monthBegin
     * @return
     */
    public JSONObject getArticleStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
        JSONObject result = new JSONObject();
        result.put("history", 0);
        result.put("year", 0);
        result.put("month", 0);
        String sqlHistory = "select count(1) h from wlyy_health_edu_article_patient where patient = ? and admin_team_code = ?";
        String sqlYear = "select count(1) y from wlyy_health_edu_article_patient where patient = ? and admin_team_code = ? and czrq >= ? and czrq <= ?";
        String sqlMonth = "select count(1) m from wlyy_health_edu_article_patient where patient = ? and admin_team_code = ? and czrq >= ?";
        String sql = "select * from " +
                "(" + sqlHistory + ") a" +
                ",(" + sqlYear + ") b" +
                ",(" + sqlMonth + ") c";
        List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
                patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
        });
        if (counts != null && counts.size() > 0) {
            result.put("history", counts.get(0).get("h").toString());
            result.put("year", counts.get(0).get("y").toString());
            result.put("month", counts.get(0).get("m").toString());
        }
        return result;
    }
    /**
     * 健康指导统计
     *
     * @param patient
     * @param teamCode
     * @param yearBegin
     * @param yearEnd
     * @param monthBegin
     * @return
     */
    public JSONObject getGuidanceStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
        JSONObject result = new JSONObject();
        result.put("history", 0);
        result.put("year", 0);
        result.put("month", 0);
        String sqlHistory = "select count(1) h from wlyy_patient_health_guidance where patient = ? and admin_team_code = ?";
        String sqlYear = "select count(1) y from wlyy_patient_health_guidance where patient = ? and admin_team_code = ? and czrq >= ? and czrq <= ?";
        String sqlMonth = "select count(1) m from wlyy_patient_health_guidance where patient = ? and admin_team_code = ? and czrq >= ?";
        String sql = "select * from " +
                "(" + sqlHistory + ") a" +
                ",(" + sqlYear + ") b" +
                ",(" + sqlMonth + ") c";
        List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
                patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
        });
        if (counts != null && counts.size() > 0) {
            result.put("history", counts.get(0).get("h").toString());
            result.put("year", counts.get(0).get("y").toString());
            result.put("month", counts.get(0).get("m").toString());
        }
        return result;
    }
    /**
     * 随访计划统计
     *
     * @param patient
     * @param teamCode
     * @param yearBegin
     * @param yearEnd
     * @param monthBegin
     * @return
     */
    public JSONObject getFollowupStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
        JSONObject result = new JSONObject();
        result.put("history", 0);
        result.put("year", 0);
        result.put("month", 0);
        String sqlHistory = "select count(1) h from wlyy_followup where patient_code = ? and admin_team_code = ?";
        String sqlYear = "select count(1) y from wlyy_followup where patient_code = ? and admin_team_code = ? and create_time >= ? and create_time <= ?";
        String sqlMonth = "select count(1) m from wlyy_followup where patient_code = ? and admin_team_code = ? and create_time >= ?";
        String sql = "select * from " +
                "(" + sqlHistory + " and status > 0" + ") a" +
                ",(" + sqlYear + " and status > 0" + ") b" +
                ",(" + sqlMonth + " and status > 0" + ") c" +
                ",(" + sqlHistory.replace(" h ", " hh ") + " and status = 1" + ") d" +
                ",(" + sqlYear.replace(" y ", " yy ") + " and status = 1" + ") e" +
                ",(" + sqlMonth.replace(" m ", " mm ") + " and status = 1" + ") f";
        List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
                patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin,patient, teamCode,
                patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
        });
        if (counts != null && counts.size() > 0) {
            result.put("history", counts.get(0).get("hh").toString() + "/" + counts.get(0).get("h").toString());
            result.put("year", counts.get(0).get("yy").toString() + "/" + counts.get(0).get("y").toString());
            result.put("month", counts.get(0).get("mm").toString() + "/" + counts.get(0).get("m").toString());
        }
        return result;
    }
    /**
     * 随访计划统计
     *
     * @param patient
     * @param teamCode
     * @param yearBegin
     * @param yearEnd
     * @param monthBegin
     * @return
     */
    public JSONObject getReservationStatistics(String patient, long teamCode, String yearBegin, String yearEnd, String monthBegin) {
        JSONObject result = new JSONObject();
        result.put("history", 0);
        result.put("year", 0);
        result.put("month", 0);
        String sqlHistory = "select count(1) h from wlyy_patient_reservation where patient = ? and admin_team_code = ?";
        String sqlYear = "select count(1) y from wlyy_patient_reservation where patient = ? and admin_team_code = ? and czrq >= ? and czrq <= ?";
        String sqlMonth = "select count(1) m from wlyy_patient_reservation where patient = ? and admin_team_code = ? and czrq >= ?";
        String sql = "select * from " +
                "(" + sqlHistory + ") a" +
                ",(" + sqlYear + ") b" +
                ",(" + sqlMonth + ") c";
        List<Map<String, Object>> counts = jdbcTemplate.queryForList(sql, new Object[]{patient, teamCode,
                patient, teamCode, yearBegin, yearEnd, patient, teamCode, monthBegin
        });
        if (counts != null && counts.size() > 0) {
            result.put("history", counts.get(0).get("h").toString());
            result.put("year", counts.get(0).get("y").toString());
            result.put("month", counts.get(0).get("m").toString());
        }
        return result;
    }
}

+ 43 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/patient/ServiceStatisticsController.java

@ -0,0 +1,43 @@
package com.yihu.wlyy.web.doctor.patient;
import com.yihu.wlyy.service.app.statistics.ServiceStatisticsService;
import com.yihu.wlyy.web.BaseController;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by lyr-pc on 2017/1/10.
 */
@RestController
@RequestMapping(value = "/patient/service")
public class ServiceStatisticsController extends BaseController {
    @Autowired
    ServiceStatisticsService serviceStatistics;
    /**
     * 居民服务统计查询
     *
     * @param patient 居民
     * @return
     */
    @RequestMapping(value = "/statistics", method = {RequestMethod.GET, RequestMethod.POST})
    @ApiOperation(value = "居民服务统计查询")
    public String statistics(@RequestParam @ApiParam(value = "居民code") String patient,
                             @RequestParam @ApiParam(value = "团队Code") Long teamCode) {
        try {
            JSONObject result = serviceStatistics.getServiceStatistics(patient, teamCode);
            return write(200, "查询成功", "data", result);
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1, "查询失败");
        }
    }
}