Forráskód Böngészése

Merge branch 'dev' of http://192.168.1.220:10080/Amoy/patient-co-management into dev

Sand 8 éve
szülő
commit
4a0b6aa082
19 módosított fájl, 1286 hozzáadás és 391 törlés
  1. 5 0
      patient-co-statistics/pom.xml
  2. 43 6
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/controller/JobController.java
  3. 117 0
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/dataFilter/SignDataFilter.java
  4. 22 0
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/role/Level1Role.java
  5. 30 0
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/storage/DBStorage.java
  6. 3 3
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/WaitSignJob.java
  7. 27 192
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/check/CheckSignJob.java
  8. 32 6
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/message/HealthMessageJob.java
  9. 41 0
      patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/service/JobService.java
  10. 16 1
      patient-co-statistics/src/main/resources/application.yml
  11. 2 2
      patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/message/MessageDao.java
  12. 1 0
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java
  13. 775 97
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/EhrService.java
  14. 31 22
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/HealthDataService.java
  15. 39 30
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/InspectionService.java
  16. 59 10
      patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsAllService.java
  17. 9 9
      patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java
  18. 1 1
      patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java
  19. 33 12
      patient-co-wlyy/src/main/resources/system.properties

+ 5 - 0
patient-co-statistics/pom.xml

@ -362,6 +362,11 @@
                <artifactId>spring-boot-starter-test</artifactId>
                <version>${version.spring-boot}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-mail</artifactId>
                <version>${version.spring-boot}</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>

+ 43 - 6
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/controller/JobController.java

@ -224,8 +224,8 @@ public class JobController extends BaseController {
     *
     * @return
     */
    @ApiOperation(value = "启动檢查的任务")
    @RequestMapping(value = "startCheckSignJob", method = RequestMethod.GET)
   // @ApiOperation(value = "启动檢查的任务")
  //  @RequestMapping(value = "startCheckSignJob", method = RequestMethod.GET)
    public String startCheckSignJob() {
        try {
            jobService.startCheckSignJob();
@ -240,8 +240,8 @@ public class JobController extends BaseController {
     *
     * @return
     */
    @ApiOperation(value = "停止檢查的任务")
    @RequestMapping(value = "stopCheckSignJob", method = RequestMethod.GET)
   // @ApiOperation(value = "停止檢查的任务")
   // @RequestMapping(value = "stopCheckSignJob", method = RequestMethod.GET)
    public String stopCheckSignJob() {
        try {
            jobService.stopCheckSignJob();
@ -354,7 +354,7 @@ public class JobController extends BaseController {
        }
    }
  @RequestMapping(value = "startaaaa", method = RequestMethod.GET)
  //@RequestMapping(value = "startaaaa", method = RequestMethod.GET)
    public String startaaaa() {
        try {
            jobService.startaaaa();
@ -364,5 +364,42 @@ public class JobController extends BaseController {
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 生成过去某一天的健康消息
     *
     * @param day
     * @return
     */
    @ApiOperation(value = "生成过去某一天的健康消息")
    @RequestMapping(value = "productHealthDataByOneDay", method = RequestMethod.GET)
    public String productHealthDataByOneDay( @ApiParam(name = "day", value = "yyyy-MM-dd")
                                           @RequestParam(value = "day", required = true)String day) {
        try {
            jobService.productHealthDataByOneDay(day);
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
    /**
     * 生成过去某一天到某一天的某个指标的数据
     *
     * @param start
     * @param end
     * @return
     */
    @ApiOperation(value = "生成过去某一天到某一天的健康消息(包含头尾)")
    @RequestMapping(value = "productHealthDataByDayToDay", method = RequestMethod.GET)
    public String productHealthDataByDayToDay( @ApiParam(name = "start", value = "yyyy-MM-dd")@RequestParam(value = "start", required = true)String start,
                                              @ApiParam(name = "end", value = "yyyy-MM-dd")@RequestParam(value = "end", required = true)String end
                                             ) {
        try {
            jobService.productHealthDataByDayToDay(start,end);
            return success("启动成功!");
        } catch (Exception e) {
            error(e);
            return invalidUserException(e, -1, "启动失败:" + e.getMessage());
        }
    }
}

+ 117 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/dataFilter/SignDataFilter.java

@ -460,7 +460,122 @@ public class SignDataFilter {
            return Constant.level_age_6;
        }
    }
    public FilterModel filterNoTeam(List<SignFamily> signFamilies ,String level2Key,String level3Key, String sql, String filterDate) {
        //查找出系统全部的机构
        List<Hospital> hospitals = hospitalDao.findHospital2();
        Map<String, Hospital> hospitalsMap = new HashMap<String, Hospital>();
        for (Hospital hospital : hospitals) {
            hospitalsMap.put(hospital.getCode(), hospital);
        }
        //查找出厦门市全部的区
        List<Town> towns = townDao.findByCityCode(Constant.city);
        Map<String, Town> townsMap = new HashMap<String, Town>();
        for (Town town : towns) {
            townsMap.put(town.getCode(), town);
        }
        List<ETLModel> etlModelList=new ArrayList<>();//返回的ETL數據
        Long cityCount = new Long(0L); //统计到市的数目
        Long townCount = new Long(0L); //统计到所有区的数目
        Long orgCount =new Long(0L);//统计到所有机构的数目
        Long adminCount = new Long(0L);//统计到所有团队的数目
        Long errorCount=new Long(0L);//脏数据
        Boolean isAll=true;//是否统计失败
        LogModel logModel=new LogModel();
        errorModels=new ArrayList<ErrorModel>();
        for (int i=0;i<signFamilies.size();i++){
            SignFamily signFamily=signFamilies.get(i);
            String orgCode = signFamily.getHospital();
            if(StringUtils.isEmpty(orgCode)) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_hospital_null));
                isAll=false;
                errorCount++;
                continue;
            }
            if(orgCode.length()!=10) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_hospital_isTest));
                isAll=false;
                errorCount++;
                continue;
            }
            String orgCodeTemp="";
            if(!"00".equals(orgCode.substring(orgCode.length()-2,orgCode.length()))){
                //站
                orgCodeTemp=orgCode.substring(0,orgCode.length()-2)+"00";
            }else{
                //社区
                orgCodeTemp=orgCode;
            }
            //判断社区有没有值
            Hospital hospital=hospitalsMap.get(orgCodeTemp);
            if(hospital == null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_hospital_noExist));
                isAll=false;
                errorCount++;
                continue;
            }
            String town =hospital.getTown();
            if(StringUtils.isEmpty(town)) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_town_null));
                isAll=false;
                errorCount++;
                continue;
            }
            Town townObj =townsMap.get(town);
            if(townObj==null) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_town_noExist));
                isAll=false;
                errorCount++;
                continue;
            }
            String idCard=signFamily.getIdcard();
            if(idCard == null||((idCard.length()!=18&&idCard.length()!=15))) {
                errorModels.add(ErrorModel.newEM(signFamily.getCode(),ErrorModel.sign_idcard_error));
                isAll=false;
                errorCount++;
                continue;
            }
            //设置二级维度的Key
            String returnLevel2Key=getLevel2Key(level2Key,signFamily);
            String returnLevel3Key=getLevel3Key(level3Key,signFamily);
            if(StringUtils.isEmpty(returnLevel2Key)){
                //没有二级维度
                ETLModel etlModel=new ETLModel();
                etlModel.setHospital(orgCodeTemp);
                etlModel.setTown(hospital.getTown());
                etlModel.setCity(Constant.city);
                etlModelList.add(etlModel);
            }else{
                String[] level2Keys=returnLevel2Key.split(",");
                for(int j=0;j<level2Keys.length;j++){
                    ETLModel etlModel=new ETLModel();
                    etlModel.setLevel2Key(level2Keys[j]);
                    etlModel.setLevel3Key(returnLevel3Key);
                    etlModel.setHospital(orgCodeTemp);
                    etlModel.setTown(hospital.getTown());
                    etlModel.setCity(Constant.city);
                    etlModelList.add(etlModel);
                }
            }
            //统计数目+1
            cityCount++;
            townCount++;
            orgCount++;
            adminCount++;
        }
        logModel.setDate(filterDate);
        logModel.setEndTime(new Date());
        logModel.setExcuteSql(sql);
        logModel.setSuccess(isAll);
        logModel.setAllNum(signFamilies.size());
        logModel.setSuccessNum(adminCount.intValue());
        logModel.setModelList(errorModels);
        logModel.setErrorNum(errorCount.intValue());
        //String message=saveContent(signFamilies.size(),adminCount,orgCount,townCount,cityCount,isAll,errorContent,errorCount,sql,filterDate);
        return FilterModel.getFiltrerMode(logModel,etlModelList,isAll);
    }
    /**
     * 根据年龄得到对应的code
     *
@ -474,4 +589,6 @@ public class SignDataFilter {
            return Constant.level_age2_2;
        }
    }
}

+ 22 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/role/Level1Role.java

@ -66,4 +66,26 @@ public class Level1Role {
            eltMap.put(key,etlModels);
        }
    }
    public List<Map<String,List<ETLModel>>> eltNoTeam(List<ETLModel> models) {
        List<Map<String, List<ETLModel>>> returnMapsList=new ArrayList<Map<String, List<ETLModel>>>();
        Map<String, List<ETLModel>> tjCityMap = new HashMap<String, List<ETLModel>>();//市级的统计map key 是区行政区划350200
        Map<String, List<ETLModel>> tjTownMap = new HashMap<String, List<ETLModel>>();//区级的统计map key 是区行政区划350206
        Map<String, List<ETLModel>> tjOrgMap = new HashMap<String, List<ETLModel>>();//机构的统计map key 是机构的code
        for(ETLModel etlModel:models){
            //统计市市
            compute(tjCityMap, etlModel.getCity(),etlModel);
            //统计市区
            compute(tjTownMap, etlModel.getTown(),etlModel);
            //统计市机构
            compute(tjOrgMap, etlModel.getHospital(),etlModel);
        }
        returnMapsList.add(1,tjOrgMap);
        returnMapsList.add(2,tjTownMap);
        returnMapsList.add(3,tjCityMap);
        return returnMapsList;
    }
}

+ 30 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/etl/storage/DBStorage.java

@ -846,4 +846,34 @@ public class DBStorage   {
            return statementCreator;
        });
    }
    public void saveByLevel1NoTeam(List<Map<String, List<ETLModel>>> data, String date, WlyyQuotaVO wlyyQuota) throws Exception{
        this.wlyyQuota=wlyyQuota;
        List<AdminTeam> adminTeams=doctorAdminTeamDao.findAllTeam();
        for (AdminTeam adminTeam : adminTeams) {
            adminTeamMap.put(adminTeam.getId()+"", adminTeam);
        }
        //查找出系统全部的机构
        List<Hospital> hospitals = hospitalDao.findHospitalzxFWZ();
        for (Hospital hospital : hospitals) {
            hospitalsMap.put(hospital.getCode(), hospital);
        }
        //查找出厦门市全部的区
        List<Town> towns = townDao.findByCityCode(Constant.city);
        for (Town town : towns) {
            townsMap.put(town.getCode(), town);
        }
        //全部的市
        Map<String, City> cityMap = new HashMap<String, City>();
        City city=new City();
        city.setCode(Constant.city);
        city.setName(Constant.cityName);
        cityMap.put(Constant.city,city);
        //保存机构
        saveAll(saveHospitalTeamDataLevel1(data.get(1),date,hospitalsMap));
        //保存区
        saveAll(saveTownTeamDataLevel1(data.get(2),date,townsMap));
        //保存市
        saveAll(saveCityTeamDataLevel1(data.get(3),date,cityMap));
    }
}

+ 3 - 3
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/business/WaitSignJob.java

@ -92,11 +92,11 @@ public class WaitSignJob implements Job {
            //抽取數據
            List<SignFamily> signFamilies= dbExtract.extract(SignFamily.class,sql);
            //清洗數據
            FilterModel etlModels= signDataFilter.filter(signFamilies,sql,yesterday);
            FilterModel etlModels= signDataFilter.filterNoTeam(signFamilies,null,null,sql,yesterday);
            //统计数据
            List<Map<String, List<ETLModel>>>  returnDatas= levelRole.elt(etlModels.getEtlModelList());
            List<Map<String, List<ETLModel>>>  returnDatas= levelRole.eltNoTeam(etlModels.getEtlModelList());
            //保存数据
            dbStorage.saveByLevel1(returnDatas,yesterday,wlyyQuota);
            dbStorage.saveByLevel1NoTeam(returnDatas,yesterday,wlyyQuota);
            //保存日志
            quartzJobLog.setJobEndTime(new Date());
            quartzJobLog.setJobContent(JsonUtil.objToStr(etlModels.getLogModel()));

+ 27 - 192
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/check/CheckSignJob.java

@ -1,27 +1,20 @@
package com.yihu.wlyy.statistics.job.check;
import com.yihu.wlyy.statistics.dao.*;
import com.yihu.wlyy.statistics.job.business.QuartzHelper;
import com.yihu.wlyy.statistics.job.business.SignAgeGroupDiseaseJob;
import com.yihu.wlyy.statistics.job.business.SignJob;
import com.yihu.wlyy.statistics.model.job.QuartzJobConfig;
import com.yihu.wlyy.statistics.model.job.WlyyQuota;
import com.yihu.wlyy.statistics.model.job.WlyyQuotaResult;
import com.yihu.wlyy.statistics.model.signfamily.SignFamily;
import com.yihu.wlyy.statistics.util.DateUtil;
import com.yihu.wlyy.statistics.vo.WlyyJobConfigVO;
import com.yihu.wlyy.statistics.vo.WlyyQuotaVO;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.util.*;
import java.util.Date;
/**
 * Created by Administrator on 2016.10.11.
@ -30,201 +23,43 @@ import java.util.*;
@Component
@Scope("prototype")
public class CheckSignJob implements Job{
    public static String jobKey="CHECK_SIGN_JOB";
    public static String cron="0 0 12 * * ?";
    public static String cron="0 */5 * * * ?";
    @Autowired
    private WlyyQuotaResultDao wlyyQuotaResultDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private QuartzHelper quartzHelper;
    private StringRedisTemplate redisTemplate;
    @Autowired
    private QuartzJobConfigDao wlyyJobConfigDao;
    @Autowired
    private QuotaDao quotaDao;
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.from}")
    private String from;;
    @Value("${spring.mail.to}")
    private String to;;
    @Transactional
    public void execute(JobExecutionContext context) throws JobExecutionException {
        try{
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
            //得到需要检验的统计
            List<WlyyQuotaResult> wlyyQuotaResults=getNeedCheckData();
            //检验统计数据和签约数据是否一致  key:yes 是需要 no:是不需要
            Map<String,List<WlyyQuotaResult>> wlyyQuotaResultsMap=checkWlyyQuotaResult(wlyyQuotaResults);
            //更新不需要下一次统计的任务
            upDataNoNeedCheckQuato(wlyyQuotaResultsMap.get("no"));
            //添加需要重新统计的指标
            addNeedCheckQuato(wlyyQuotaResultsMap.get("yes"));
        }catch (Exception e){
            //如果出錯立即重新執行
            JobExecutionException e2 =new JobExecutionException(e);
            e2.setRefireImmediately(true);
        }
    }
    private void addNeedCheckQuato(List<WlyyQuotaResult> yes)throws Exception {
        if(yes.size()>0){
            for(WlyyQuotaResult wlyyQuotaResult:yes){
                QuartzJobConfig quartzJobConfig = wlyyJobConfigDao.findById(wlyyQuotaResult.getId());
                if (quartzJobConfig == null) {
                    throw new Exception("id不存在");
                }
                WlyyQuota wlyyQuota = quotaDao.findOne(quartzJobConfig.getQuotaId());
                WlyyQuotaVO wlyyQuotaVO = new WlyyQuotaVO();
                WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
                BeanUtils.copyProperties(wlyyQuota, wlyyQuotaVO);
                BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
                Map<String, Object> params = new HashMap<String, Object>();
                params.put("quota", wlyyQuotaVO);
                params.put("jobConfig", wlyyJobConfigVO);
                String daybefore=getNextDate(wlyyQuotaResult.getQuotaDate());
                String yesterday=wlyyQuotaResult.getQuotaDate();
                //往quartz框架添加任务
                params.put("daybefore", daybefore);
                params.put("yesterday", yesterday);
                String jobKey="checkSignQuartz:"+wlyyQuotaResult.getQuotaDate()+":"+wlyyQuotaResult.getQuatoCode();
                if(!quartzHelper.isExistJob(jobKey)){
                    quartzHelper.startAt(weeHours(new Date(),1),SignJob.class,jobKey,params);
                    //重新生成性别 疾病 扣费 和 年龄的统计
                    startJob("6",yesterday,daybefore);
                    startJob("7",yesterday,daybefore);
                    startJob("8",yesterday,daybefore);
                    startJob("12",yesterday,daybefore);
                }
            }
        }
    }
    private void startJob(String id, String yesterday, String daybefore) throws Exception{
        QuartzJobConfig quartzJobConfig = wlyyJobConfigDao.findById(id);
        if (quartzJobConfig == null) {
            throw new Exception("id不存在");
        }
        WlyyQuota wlyyQuota = quotaDao.findOne(quartzJobConfig.getQuotaId());
        WlyyQuotaVO wlyyQuotaVO = new WlyyQuotaVO();
        WlyyJobConfigVO wlyyJobConfigVO = new WlyyJobConfigVO();
        BeanUtils.copyProperties(wlyyQuota, wlyyQuotaVO);
        BeanUtils.copyProperties(quartzJobConfig, wlyyJobConfigVO);
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("quota", wlyyQuotaVO);
        params.put("jobConfig", wlyyJobConfigVO);
        //往quartz框架添加任务
        params.put("daybefore", daybefore);
        params.put("yesterday", yesterday);
        String jobKey="checkSignQuartz:"+yesterday+":"+wlyyQuota.getId();
        if(!quartzHelper.isExistJob(jobKey)){
            quartzHelper.startAt(weeHours(new Date(),1),getClassById(id),jobKey,params);
        }
    }
    private Class getClassById(String id) {
        switch (id){
            case "6":{
                return SignJob.class;
            }
            case "7":{
                return SignJob.class;
            }
            case "8":{
                return SignJob.class;
            }
            case "12":{
                return SignAgeGroupDiseaseJob.class;
            }
        }
        return null;
    }
    /**
     * 更新不需要下一次统计的任务   更新qkdoctorJobName字段为1
     * @param noNeedCheckQuatos
     */
    private void upDataNoNeedCheckQuato(List<WlyyQuotaResult> noNeedCheckQuatos) {
        if(noNeedCheckQuatos.size()>0){
            for(WlyyQuotaResult wlyyQuotaResult:noNeedCheckQuatos){
                wlyyQuotaResult.setQkdoctorJobName("1");
            }
            wlyyQuotaResultDao.save(noNeedCheckQuatos);
        }
    }
    /**
     * 检验统计数据和签约数据是否一致  key:yes 是需要 no:是不需要
     * @param wlyyQuotaResults
     * @return
     */
    private Map<String,List<WlyyQuotaResult>> checkWlyyQuotaResult(List<WlyyQuotaResult> wlyyQuotaResults) {
        Map<String,List<WlyyQuotaResult>> returnMap=new HashMap<String,List<WlyyQuotaResult>>();
        List<WlyyQuotaResult> yes=new ArrayList<WlyyQuotaResult>();//需要重新统计的
        List<WlyyQuotaResult> no=new ArrayList<WlyyQuotaResult>();//不需要重新统计
        for(WlyyQuotaResult wlyyQuotaResult:wlyyQuotaResults){
            String date=  wlyyQuotaResult.getQuotaDate();//格式  2016-10-20
            String nextDate=getNextDate(date);
            List<SignFamily> signFamilys = signFamilyDao.findByJiatingSignYesterdayExpensesStatus(date, nextDate);
            if(signFamilys.size()!=Integer.valueOf(wlyyQuotaResult.getResult())){
                //如果数目不相等 说明需要重新统计
                yes.add(wlyyQuotaResult);
            }else{
                //如果数目相等 说明需要不需要重新统计
                no.add(wlyyQuotaResult);
            String timeKey=redisTemplate.opsForValue().get("quota:timeKey");
            if(!redisTemplate.hasKey("quota:16:4:350200:"+timeKey)){
                //发送邮件给管理员
               // sendEmail();
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        returnMap.put("yes",yes);
        returnMap.put("no",no);
        return returnMap;
    }
    private String getNextDate(String date) {
        Date dateTime=  DateUtil.strToDateShort(date);
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(dateTime);
        calendar.add(calendar.DATE,-1);//把日期往后增加一天.整数往后推,负数往前移动
        Date nextDateTime=calendar.getTime();
        return DateUtil.dateToStrShort(nextDateTime);
    }
    private void sendEmail() throws Exception {
    /**
     * 得到需要检验的统计
     * @return
     */
    private List<WlyyQuotaResult> getNeedCheckData() {
        List<WlyyQuotaResult> wlyyQuotaResults=wlyyQuotaResultDao.findByLevel1TypeAndQkdoctorJobName("4","1");
        return wlyyQuotaResults;
        SimpleMailMessage message=new SimpleMailMessage();
        message.setFrom(from);//发送者.
        message.setSubject("实时统计失败");//邮件主题.
        message.setText("实时统计失败,redis数据生成失败 時間:"+ DateUtil.dateToStrLong(new Date()));//邮件内容.
        String[] tos=to.split(",");
        message.setTo(tos);
        javaMailSender.send(message);
    }
    /**
     * 获取当前时间所在的凌晨时间
     *  凌晨
     * @param date
     * @flag 0 返回yyyy-MM-dd 00:00:00日期<br>
     *       1 返回yyyy-MM-dd 23:59:59日期
     * @return
     */
    private  Date weeHours(Date date, int flag) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        //时分秒(毫秒数)
        long millisecond = hour*60*60*1000 + minute*60*1000 + second*1000;
        //凌晨00:00:00
        cal.setTimeInMillis(cal.getTimeInMillis()-millisecond);
        if (flag == 0) {
            return cal.getTime();
        } else if (flag == 1) {
            //凌晨23:59:59
            cal.setTimeInMillis(cal.getTimeInMillis()+23*60*60*1000 + 59*60*1000 + 59*1000);
        }
        return cal.getTime();
    }
}

+ 32 - 6
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/job/message/HealthMessageJob.java

@ -2,8 +2,11 @@ package com.yihu.wlyy.statistics.job.message;
import com.yihu.wlyy.statistics.dao.MessageDao;
import com.yihu.wlyy.statistics.etl.extract.DBExtract;
import com.yihu.wlyy.statistics.etl.storage.DBStorage;
import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
import com.yihu.wlyy.statistics.model.signfamily.Message;
import com.yihu.wlyy.statistics.model.signfamily.SignFamily;
import com.yihu.wlyy.statistics.util.JsonUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
@ -12,6 +15,7 @@ import org.springframework.context.annotation.Scope;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import java.text.SimpleDateFormat;
@ -33,17 +37,35 @@ public class HealthMessageJob implements Job {
    private MessageDao messageDao;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Autowired
    private DBStorage dbStorage;
    @Transactional
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
            try{
        try{
            SpringBeanAutowiringSupport.processInjectionBasedOnCurrentContext(this);
            QuartzJobLog quartzJobLog = new QuartzJobLog();
            quartzJobLog.setJobStartTime(new Date());
            quartzJobLog.setJobId(jobKey);
            quartzJobLog.setJobName(jobKey);
            String yesterday=jobExecutionContext.getMergedJobDataMap().getString("yesterday");
            String now=jobExecutionContext.getMergedJobDataMap().getString("now");
            if(StringUtils.isEmpty(yesterday)){
                yesterday=getYesterday(-1,new Date());
            }
            if(StringUtils.isEmpty(now)){
                now=getYesterday(0,new Date());
            }
            //删除原来的数据
            String deleteSql="delete from wlyy_message where type=3 and czrq >= '"+yesterday+" 17:00:00'and czrq <= '"+now+" 17:00:00'";
            jdbcTemplate.execute(deleteSql);
            //生成新的数据
            String sql="select doctor,doctor_name from wlyy_sign_family " +
                    " where  status >0 and type='2' and expenses_status='1'  " +
                    " and expenses_time >='"+getYesterday(-1,new Date())+" 17:00:00' and expenses_time<'"+getYesterday(0,new Date())+" 17:00:00' and  (doctor_health is null or doctor_health = '')" ;
                    " and expenses_time >='"+yesterday+" 17:00:00' and expenses_time<'"+now+" 17:00:00' and  (doctor_health is null or doctor_health = '')" ;
            String countSql="select count(id) from wlyy_sign_family " +
                    " where  status >0 and type='2' and expenses_status='1'  " +
                    " and expenses_time >='"+getYesterday(-1,new Date())+" 17:00:00' and expenses_time<'"+getYesterday(0,new Date())+" 17:00:00' and  (doctor_health is null or doctor_health = '')" ;
                    " and expenses_time >='"+yesterday+" 17:00:00' and expenses_time<'"+now+" 17:00:00' and  (doctor_health is null or doctor_health = '')" ;
            List<SignFamily> signFamilyList=dbExtract.extractByPage(SignFamily.class,sql,countSql,true);
            Map<String,List<SignFamily>> signFamilyMap=new HashMap<String,List<SignFamily>>();
            for(int i=0;i<signFamilyList.size();i++){
@ -59,7 +81,7 @@ public class HealthMessageJob implements Job {
            for(Map.Entry<String,List<SignFamily>> entry:signFamilyMap.entrySet()){
                 countSql="select count(id) from wlyy_sign_family " +
                        " where  status >0 and type='2' and expenses_status='1'  " +
                        "  and expenses_time<'"+getYesterday(0,new Date())+" 17:00:00' and  (doctor_health is null or doctor_health = '') and doctor='"+entry.getKey()+"'" ;
                        "  and expenses_time<'"+now+" 17:00:00' and  (doctor_health is null or doctor_health = '') and doctor='"+entry.getKey()+"'" ;
                Integer allCount=jdbcTemplate.queryForObject(countSql,Integer.class);
                Message message=new Message();
@ -68,16 +90,20 @@ public class HealthMessageJob implements Job {
                message.setOver("0");
                message.setDel("1");
                message.setSender("system");
                message.setCzrq(new Date());
                message.setCzrq(new SimpleDateFormat("yyyy-MM-dd").parse(now));
                message.setState(1);
                message.setTitle("新增系统消息");
                SimpleDateFormat dateFormat=new SimpleDateFormat("MM月dd日");
                String date=  dateFormat.format(new Date());
                message.setContent(date+",新增"+entry.getValue().size()+"个签约居民待分配健管师,目前共"+allCount+"人待处理");
                message.setContent(date+"新增"+entry.getValue().size()+"个签约居民待分配健管师,目前共"+allCount+"人待处理");
                message.setCode(UUID.randomUUID().toString());
                message.setReceiver(entry.getKey());
                messageDao.save(message);
            }
            quartzJobLog.setJobEndTime(new Date());
            quartzJobLog.setJobContent("生成"+now+"的健康管理师消息成功");
            quartzJobLog.setJobType("1");
            dbStorage.saveLog(quartzJobLog);
        }catch (Exception e){
            e.printStackTrace();
        }

+ 41 - 0
patient-co-statistics/src/main/java/com/yihu/wlyy/statistics/service/JobService.java

@ -351,12 +351,16 @@ public class JobService {
    public void startCleanCacheJob() throws  Exception {
        if(!quartzHelper.isExistJob(CacheCleanJob.jobKey)){
            quartzHelper.addJob(CacheCleanJob.class,CacheCleanJob.cron,CacheCleanJob.jobKey,new HashMap<>());
        }else{
            throw new Exception("已经启动");
        }
    }
    public void stopCleanCacheJob()throws  Exception  {
        if(quartzHelper.isExistJob(CacheCleanJob.jobKey)){
            quartzHelper.removeJob(CacheCleanJob.jobKey);
        }else{
            throw new Exception("已经停止");
        }
    }
@ -382,12 +386,49 @@ public class JobService {
    public void startHealthMessageJob() throws Exception {
        if(!quartzHelper.isExistJob(HealthMessageJob.jobKey)){
            quartzHelper.addJob(HealthMessageJob.class,HealthMessageJob.cron,HealthMessageJob.jobKey,new HashMap<>());
        }else{
            throw new Exception("已经启动");
        }
    }
    public void stopHealthMessageJob()throws Exception  {
        if(quartzHelper.isExistJob(HealthMessageJob.jobKey)){
            quartzHelper.removeJob(HealthMessageJob.jobKey);
        }else{
            throw new Exception("已经停止");
        }
    }
    public void productHealthDataByOneDay(String day)throws Exception {
        SimpleDateFormat dataSimple = new SimpleDateFormat("yyyy-MM-dd");
        Date date = dataSimple.parse(day);
        if (date == null) {
            throw new Exception("时间格式错误");
        }
        Calendar calendar = new GregorianCalendar();
        calendar.setTime(date);
        calendar.add(calendar.DATE, -1);//把日期往后增加一天.整数往后推,负数往前移动
        Date nowDate = calendar.getTime();   //这个时间就是日期往后推一天的结果
        String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(nowDate.getTime());
        Map<String, Object> params = new HashMap<String, Object>();
        //往quartz框架添加任务
        params.put("now", day);
        params.put("yesterday", yesterday);
        quartzHelper.startNow(HealthMessageJob.class, HealthMessageJob.jobKey + UUID.randomUUID().toString().replace("-",""), params);
        Thread.sleep(20000L);
    }
    public void productHealthDataByDayToDay(String start, String end) throws Exception{
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
        Date startDate=sdf.parse(start);
        Date endDate=sdf.parse(end);
        if(startDate.after(endDate)){
            throw new Exception("日期参数错误");
        }
        int day=daysBetween(startDate,endDate);
        for(int i=0;i<day;i++){
            productHealthDataByOneDay(getYesterday(i,startDate));
        }
    }
}

+ 16 - 1
patient-co-statistics/src/main/resources/application.yml

@ -53,7 +53,22 @@ spring:
      max-wait: -1 # Maximum amount of time (in milliseconds) a connection allocation should block before throwing an exception when the pool is exhausted. Use a negative value to block indefinitely.
      min-idle: 1 # Target for the minimum number of idle connections to maintain in the pool. This setting only has an effect if it is positive.
  mail:
    default-encoding: utf8
    protocol: smtp
    host: smtp.qq.com
    port: 465
    username: 1501877145
    from: 1501877145@qq.com
    to: 494679975@qq.com,463166875@qq.com #接受者,多个接受逗号分隔,接受者邮箱要开启IMAP/SMTP服务(不开可能会在垃圾箱)
    password: pnubhfagxeophfej
    properties:
      mail:
        transport:
        smtp:
          auth: true #是否开始权限验证
          ssl:
            enable: true #使用sslmail.transport.protocol
multipart:
  max-file-size: 100MB

+ 2 - 2
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/message/MessageDao.java

@ -22,10 +22,10 @@ public interface MessageDao extends PagingAndSortingRepository<Message, Long>, J
    @Query("select a from Message a where a.type =1 and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    Page<Message> amountUnreadLastByReceiver(String doctor, Pageable pageRequest);
    @Query("select count(a) from Message a where (a.type =2 or a.type =3) and a.read= 1 and a.receiver=?1 ")
    @Query("select count(a) from Message a where a.type =2 and a.read= 1 and a.receiver=?1 ")
    int amountUnreadHealthByReceiver(String doctor);
    @Query("select a from Message a where (a.type =2 or a.type =3) and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    @Query("select a from Message a where (a.type =2 ) and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    Page<Message> amountUnreadHealthLastByReceiver(String doctor,Pageable pageRequest);
    @Modifying

+ 1 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/health/PatientHealthGuidanceService.java

@ -72,6 +72,7 @@ public class PatientHealthGuidanceService extends BaseService {
			JSONObject json = new JSONObject();
			json.put("first", "健康指导提醒");
			json.put("toUser", patient.getCode());
			json.put("id", guidance.getId());
			json.put("date", DateUtil.getStringDate());
			json.put("orgName", doctor.getHosptialName());
			json.put("doctorName", doctor.getName());

+ 775 - 97
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/EhrService.java

@ -1,25 +1,18 @@
package com.yihu.wlyy.service.app.record;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.dict.SystemDict;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.system.SystemDictService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.SystemConf;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.apache.xpath.operations.Bool;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -36,47 +29,63 @@ public class EhrService extends BaseService {
    @Autowired
    ObjectMapper  objectMapper;
    private String ehrUrl = SystemConf.getInstance().getEhrServices();
    private String ehrUrl = SystemConf.getInstance().getEhrServices();   //EHR档案服务地址
    private String ehrBaseUrl = SystemConf.getInstance().getEhrServicesBase(); //EHR底层服务地址
    /**
     * 是否包含该类档案数据
     * 获取档案包含相关细表
     * @param profileId
     * @return
     */
    private Boolean contain(String profileId,String catalogCode)
    private List<String> containTables(String profileId)
    {
        Boolean re = false;
        try {
            String url = "";
            if (catalogCode.equals("0102"))     //门诊费用明细
            {
                re = false; //没数据
            }
            else if (catalogCode.equals("0131"))    //门诊检查报告单
            {
                url = ehrUrl + "/null/examination?profile_id=" + profileId;
            }
            else if (catalogCode.equals("0121"))    //门诊检验报告单
            {
                url = ehrUrl + "/null/laboratory?profile_id=" + profileId;
            }
            else if (catalogCode.equals("0141"))    //门诊用药记录
            {
                re = false; //业务不合
            }
            else if (catalogCode.equals("0116"))    //门诊手术记录
        List<String>  re = new ArrayList<>();
        String params = "{\"q\":\"profile_id:"+profileId+"\"}";
        String response = HttpClientUtil.get(ehrBaseUrl + "resources/query/sub_data?queryParams="+URLEncoder.encode(params), "UTF-8");
        JSONObject obj = new JSONObject(response);
        if(obj.has("detailModelList") && obj.getInt("totalCount")>0)
        {
            JSONArray array = obj.getJSONArray("detailModelList");
            if(array!=null && array.length()>0)
            {
                re = false;
               for(int i=0;i<array.length();i++)
               {
                   JSONObject item = array.getJSONObject(i);
                   String rowkey = item.getString("rowkey");
                   String table = rowkey.substring(rowkey.indexOf("$")+1);
                   table =  table.substring(0,table.indexOf("$"));
                   if(!re.contains(table))
                   {
                       re.add(table);
                   }
               }
            }
        }
        return re;
    }
            if(StringUtils.isEmpty(url))
    /**
     * 事件基本信息 (主表)
     */
    private JSONObject getEventBaseInfo(String profileId){
        JSONObject re = null;
        try {
            String params = "{\"q\":\"rowkey:"+profileId+"\"}";
            String url = ehrBaseUrl + "resources/query/master_data?queryParams="+URLEncoder.encode(params);
            String response = HttpClientUtil.get(url, "UTF-8");
            JSONObject obj = new JSONObject(response);
            if(obj.has("detailModelList") && obj.getInt("totalCount")>0)    //obj.getBoolean("successFlg") &&
            {
                String response = HttpClientUtil.get(url, "UTF-8");
                JSONObject obj = new JSONObject(response);
                if(obj.getBoolean("successFlg") && obj.getInt("totalCount")>0)
                JSONArray array = obj.getJSONArray("detailModelList");
                if(array!=null && array.length()>0)
                {
                    re = true;
                    re = array.getJSONObject(0);
                }
            }
        }
        catch (Exception ex)
        {
@ -86,7 +95,7 @@ public class EhrService extends BaseService {
        return re;
    }
    /*****************************************************************************************************************/
    /**
     * 获取门诊记录
     */
@ -102,35 +111,38 @@ public class EhrService extends BaseService {
            for (int i=0; i<jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                JSONObject item = new JSONObject();
                item.put("END_TIME",jsonObject.has("EHR_000065")?jsonObject.get("EHR_000065"):jsonObject.get("event_date")); //就诊时间
                item.put("ORG_NAME",jsonObject.get("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.get("org_code")); //机构代码
                item.put("END_TIME",jsonObject.has("EHR_000065")?jsonObject.optString("EHR_000065"):jsonObject.optString("event_date")); //就诊时间
                item.put("ORG_NAME",jsonObject.optString("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.optString("org_code")); //机构代码
                item.put("UNIONSSID",strSSID); //社保卡号
                item.put("NAME",jsonObject.get("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.get("event_no")); //事件号
                item.put("NAME",jsonObject.optString("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.optString("event_no")); //事件号
                String profileId = jsonObject.getString("rowkey");
                item.put("SERIAL",profileId); //rowkey
                //包含模板
                JSONObject catalog = new JSONObject();
                catalog.put("0101","门诊基本诊疗信息");
                List<String> tables = containTables(profileId);
                //判断是否有费用
                if(contain(profileId,"0102")){
                if(tables.contains("HDSC01_07")){
                    catalog.put("0102","门诊费用明细");
                }
                //判断是否有检查报告
                if(contain(profileId,"0131")){
                if(tables.contains("HDSD01_01")){
                    catalog.put("0131","门诊检查报告单");
                }
                //判断是否有检验报告
                if(contain(profileId,"0121")){
                if(tables.contains("HDSD02_01")){
                    catalog.put("0121","门诊检验报告单");
                }
                //判断是否有检验报告
                if(contain(profileId,"0141")){
                //判断是否有门诊用药记录
                if(tables.contains("HDSC01_09")){
                    catalog.put("0141","门诊用药记录");
                }
                if(contain(profileId,"0116")){
                if(tables.contains("HDSD02_05")){
                    catalog.put("0116","门诊手术记录");
                }
@ -161,55 +173,55 @@ public class EhrService extends BaseService {
            for (int i=0; i<jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                JSONObject item = new JSONObject();
                item.put("END_TIME",jsonObject.has("EHR_000230")?jsonObject.get("EHR_000230"):jsonObject.get("event_date")); //入院时间
                item.put("ORG_NAME",jsonObject.get("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.get("org_code")); //机构代码
                item.put("END_TIME",jsonObject.has("EHR_000230")?jsonObject.optString("EHR_000230"):jsonObject.optString("event_date")); //入院时间
                item.put("ORG_NAME",jsonObject.optString("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.optString("org_code")); //机构代码
                item.put("UNIONSSID",strSSID); //社保卡号
                item.put("NAME",jsonObject.get("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.get("event_no")); //事件号
                String profileId = jsonObject.getString("rowkey");
                item.put("NAME",jsonObject.optString("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.optString("event_no")); //事件号
                String profileId = jsonObject.optString("rowkey");
                item.put("SERIAL",profileId); //rowkey
                //包含模板
                JSONObject catalog = new JSONObject();
                catalog.put("0201","住院诊疗基本信息");
                //catalog.put("0212","入院病历记录");
                if(contain(profileId,"0202")){
                    catalog.put("0202","住院费用明细");
                }
                List<String> tables = containTables(profileId);
                if(contain(profileId,"0211")){
                    catalog.put("0211","住院病案首页");
                }
                if(contain(profileId,"0212")){
                    catalog.put("0212","入院病历记录");
                if(tables.contains("HDSC02_04")){
                    catalog.put("0202","住院费用明细");
                }
                if(contain(profileId,"0213")){
                if(tables.contains("HDSC02_14")){
                    catalog.put("0213","出院小结");
                }
                if(contain(profileId,"0215")){
                if(tables.contains("HDSC02_12")){
                    catalog.put("0214","长期医嘱");
                }
                if(tables.contains("HDSC02_11")){
                    catalog.put("0215","临时医嘱");
                }
                if(contain(profileId,"0216")){
                if(tables.contains("HDSD02_05")){
                    catalog.put("0216","住院手术记录");
                }
                if(contain(profileId,"0217")){
                if(tables.contains("HDSC02_15")){
                    catalog.put("0217","死亡记录");
                }
                if(contain(profileId,"0221")){
                if(tables.contains("HDSD02_01")){
                    catalog.put("0221","住院检验报告");
                }
                if(contain(profileId,"0231")){
                if(tables.contains("HDSD01_01")){
                    catalog.put("0231","住院检查报告");
                }
                if(contain(profileId,"0241")){
                if(tables.contains("HDSC01_09")){
                    catalog.put("0241","住院用药记录");
                }
@ -225,51 +237,717 @@ public class EhrService extends BaseService {
        }
    }
    /**
     * 获取检查报告
     * 获取检查检验列表
     */
    public List<Map<String,String>> examination(String idcard) {
        List<Map<String,String>> list = null;
        try {
            String url = ehrUrl + idcard + "/examination?demographic_id=" + idcard;
    public String getInspectionAndChecking(String strSSID)
    {
        //通过ssid获取身份证
        Patient patient = patientDao.findBySsc(strSSID);
        if(patient!=null) {
            String url = ehrUrl + patient.getIdcard() +"/profile/medical_events?demographic_id=" + patient.getIdcard();
            String response = HttpClientUtil.get(url, "UTF-8");
            Map<String, Object> map = objectMapper.readValue(response, Map.class);
            JSONArray jsonArray = new JSONArray(response);
            JSONArray resultArray = new JSONArray();
            for (int i=0; i<jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
            list = (List<Map<String,String>>)map.get("detailModelList");
                JSONObject item = new JSONObject();
                item.put("END_TIME",jsonObject.has("EHR_000230")?jsonObject.optString("EHR_000230"):jsonObject.optString("event_date")); //入院时间
                item.put("ORG_NAME",jsonObject.optString("org_name")); //机构名称
                item.put("ORG_CODE",jsonObject.optString("org_code")); //机构代码
                item.put("UNIONSSID",strSSID); //社保卡号
                item.put("NAME",jsonObject.optString("EHR_000004")); //姓名
                item.put("EVENT",jsonObject.optString("event_no")); //事件号
                String profileId = jsonObject.optString("rowkey");
                item.put("SERIAL",profileId); //rowkey
                //包含模板
                JSONObject catalog = new JSONObject();
                List<String> tables = containTables(profileId);
                //0门诊 1住院
                String eventType =  jsonObject.optString("event_type");
                if(eventType.equals("0"))
                {
                    //判断是否有检查报告
                    if(tables.contains("HDSD01_01")){
                        catalog.put("0131","门诊检查报告单");
                    }
                    //判断是否有检验报告
                    if(tables.contains("HDSD02_01")){
                        catalog.put("0121","门诊检验报告单");
                    }
                }
                else if(eventType.equals("1")){
                    if(tables.contains("HDSD02_01")){
                        catalog.put("0221","住院检验报告");
                    }
                    if(tables.contains("HDSD01_01")){
                        catalog.put("0231","住院检查报告");
                    }
                }
                if(catalog.length()>0) {
                    item.put("CATALOG", catalog); //档案类别
                    resultArray.put(item);
                }
            }
            return resultArray.toString();
        }
        catch (Exception e)
        {
            e.printStackTrace();
        else{
            return "[]";
        }
    }
        return list;
    /**
     * 用药记录
     */
    public String getDrugsList(String idcard) {
        String url = ehrUrl + idcard +"/laboratory?demographic_id="+idcard;
        return HttpClientUtil.get(url, "UTF-8");
    }
    /**
     * 检验报告单
     * 获取档案数据
     * @return
     */
    public List<Map<String,String>> laboratory(String idcard) {
        List<Map<String,String>> list = null;
    public String getHealthData(String strSSID,String strEvent,String strCatalog,String strSerial)
    {
        System.out.print("ssid:"+strSSID+",rowkey:"+strSerial+",catalog:"+strCatalog+"\r\n");
        String re = "";
        try {
            String url = ehrUrl + idcard + "/laboratory?demographic_id=" + idcard;
            /******************************** 主表数据 ********************************************************/
            if (strCatalog.equals("0101")) {     //门诊基本诊疗信息
                re =  get0101(strSSID,strSerial);
            }
            else if (strCatalog.equals("0201")) {   //住院诊疗基本信息
                re = get0201(strSSID,strSerial);
            }
            /******************************** 细表数据 ********************************************************/
            else if (strCatalog.equals("0102")) {   //门诊费用明细
                re = get0102(strSSID,strSerial);
            }
            else if (strCatalog.equals("0131")) {   //门诊检查报告单
                re = getExamination(strSSID,strSerial,"0131");
            }
            else if (strCatalog.equals("0121")) {   //门诊检验报告单
                re = getLaboratory(strSSID,strSerial,"0121");
            }
            else if (strCatalog.equals("0141")) {   //门诊用药记录
            }
            else if (strCatalog.equals("0116")) {   //门诊手术记录
            }
            else if (strCatalog.equals("0202")) {   //住院费用明细
            }
            else if (strCatalog.equals("0213")) {   //出院小结
            }
            else if (strCatalog.equals("0214")) {   //长期医嘱
            }
            else if (strCatalog.equals("0215")) {   //临时医嘱
            }
            else if (strCatalog.equals("0216")) {   //住院手术记录
            }
            else if (strCatalog.equals("0217")) {   //死亡记录
            }
            else if (strCatalog.equals("0221")) {   //住院检验报告
                re = getLaboratory(strSSID,strSerial,"0221");
            }
            else if (strCatalog.equals("0231")) {   //住院检查报告
                re = getExamination(strSSID,strSerial,"0231");
            }
            else if (strCatalog.equals("0241")) {   //住院用药记录
            }
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        System.out.print(re);
        return re;
    }
    //门诊基本诊疗信息
    public String get0101(String ssid,String profileId)
    {
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        if(info!=null) {
            //门诊症状
            String symptomUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/outpatient/symptom?profile_id=" + profileId;
            String symptomResponse = HttpClientUtil.get(symptomUrl, "UTF-8");
            JSONObject symptomObj = new JSONObject(symptomResponse);
            String symptomString = "";
            if (symptomObj.getBoolean("successFlg") && symptomObj.getInt("totalCount") > 0) {
                JSONArray array = symptomObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        symptomString += "<item code=\"" + item.optString("EHR_001204") + "\" codeSystem=\"CV5101.27\">" + item.optString("EHR_001204_VALUE")+ "</item>\n";
                    }
                }
            }
            //门诊诊断
            String diagnosisUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/outpatient/diagnosis?profile_id=" + profileId;
            String diagnosisResponse = HttpClientUtil.get(diagnosisUrl, "UTF-8");
            JSONObject diagnosisObj = new JSONObject(diagnosisResponse);
            String diagnosisString = "";
            if (diagnosisObj.getBoolean("successFlg") && diagnosisObj.getInt("totalCount") > 0) {
                JSONArray array = diagnosisObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        diagnosisString += "<item>\n" +
                                "            <icd code=\""+item.optString("EHR_000109") +"\" codeSystem=\"ICD-10\">"+item.optString("EHR_000109_VALUE") +"</icd>\n" +
                                "            <result code=\"" + item.optString("EHR_000110") + "\" codeSystem=\"CV5501.11\">"+item.optString("EHR_000110_VALUE")+"</result>\n" +
                                "            <prop code=\"" + item.optString("EHR_000107") + "\" codeSystem=\"STD_DIAGNOSIS_PROP\">"+item.optString("EHR_000107") +"</prop>\n" +
                                "</item>\n";
                    }
                }
            }
            String re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<ClinicalDocument>\n" +
                    "  <version code=\"2.0.0.0\" date=\"2009-12-01\">根据卫生部标准第一次修订</version>\n" +
                    "  <ehr code=\"0101\" codeSystem=\"STD_EHR\">门诊基本诊疗信息</ehr>\n" +
                    "  <title>门诊基本诊疗信息</title>\n" +
                    "  <org code=\"" + info.optString("org_code") + "\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name")+"</org>\n" +
                    "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                    "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                    "  <recordTarget>\n" +
                    "    <patient>\n" +
                    "      <id extension=\"" + ssid + "\"></id>\n" +
                    "      <name>" + info.optString("EHR_000004") + "</name>\n" +
                    "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE")  + "</sex>\n" +
                    "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                    "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE")+ "</marriage>\n" +
                    "    </patient>\n" +
                    "  </recordTarget>\n" +
                    "  <component>\n" +
                    "    <section>\n" +
                    "      <code code=\"common\" codeSystem=\"\"  displayName=\"门诊基本诊疗信息\"/>\n" +
                    "      <entry>\n" +
                    "        <onsetTime>" + info.optString("EHR_000065") + "</onsetTime>\n" +
                    "        <treatTime>" + info.optString("EHR_000065") + "</treatTime>\n" +
                    "        <diagnosisDate>" + info.optString("EHR_000065") + "</diagnosisDate>\n" +
                    "        <reg>\n" +
                    "          <value>" + info.optString("EHR_000068") + "</value>\n" +
                    "          <type code=\"【挂号类别代码(字典STD_REG_TYPE)】\" codeSystem=\"STD_REG_TYPE\">【挂号类别名称】</type>\n" +
                    "        </reg>\n" +
                    "        <sec>\n" +
                    "          <value>保险号</value>\n" +
                    "          <type code=\"【保险类别代码(字典STD_SEC_TYPE)】\" codeSystem=\"STD_SEC_TYPE\">【保险类别名称】</type>\n" +
                    "        </sec>\n" +
                    "        <dept code=\"" + info.optString("EHR_000081") + "\" codeSystem=\"GB/T 17538-1998\">" + info.optString("EHR_000082") + "</dept>\n" +
                    "        <doctor>\n" +
                    "          <id extension=\"" + info.optString("EHR_000080") + "\"/>\n" +
                    "          <name>" + info.optString("EHR_000079") + "</name>\n" +
                    "          <title code=\"【职称代码(字典STD_TECH_TITLE)】\" codeSystem=\"GB/T 8561-1988\">【职称名称】</title>\n" +
                    "        </doctor>\n" +
                    "        <symptom>\n" +
                    symptomString +
                    "        </symptom>\n" +
                    "        <diagnosis>\n" +
                    diagnosisString +
                    "        </diagnosis>\n" +
                    "      </entry>\n" +
                    "    </section>\n" +
                    "  </component>\n" +
                    "</ClinicalDocument>";
            return re;
        }
        else{
            return "";
        }
    }
    //住院诊疗基本信息
    public String get0201(String ssid,String profileId)
    {
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        if(info!=null) {
            //住院症状
            String symptomUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/hospitalized/symptom?profile_id=" + profileId;
            String symptomResponse = HttpClientUtil.get(symptomUrl, "UTF-8");
            JSONObject symptomObj = new JSONObject(symptomResponse);
            String symptomString = "";
            if (symptomObj.getBoolean("successFlg") && symptomObj.getInt("totalCount") > 0) {
                JSONArray array = symptomObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        symptomString += "<item code=\"" + item.optString("EHR_000301") + "\" codeSystem=\"CV5101.27\">" + item.optString("EHR_000302") + "</item>\n";
                    }
                }
            }
            //住院诊断
            String diagnosisUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/hospitalized/diagnosis?profile_id=" + profileId;
            String diagnosisResponse = HttpClientUtil.get(diagnosisUrl, "UTF-8");
            JSONObject diagnosisObj = new JSONObject(diagnosisResponse);
            String diagnosisString = "";
            if (diagnosisObj.getBoolean("successFlg") && diagnosisObj.getInt("totalCount") > 0) {
                JSONArray array = diagnosisObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        diagnosisString +="<item>\n" +
                                        "      <icd code=\""+item.optString("EHR_000293")+"\" codeSystem=\"ICD-10\">"+item.optString("EHR_000295")+"</icd>\n" +
                                        "</item>\n";
                    }
                }
            }
            String re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<ClinicalDocument>\n" +
                    "  <version code=\"2.0.0.1\" date=\"2011-06-01\">根据卫生部标准第2次修订</version>\n" +
                    "  <ehr code=\"0201\" codeSystem=\"STD_EHR\">住院诊疗基本信息</ehr>\n" +
                    "  <title>住院诊疗基本信息</title>\n" +
                    "  <org code=\""+info.optString("org_code") +"\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name") +"</org>\n" +
                    "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                    "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                    "  <recordTarget>\n" +
                    "    <patient>\n" +
                    "      <id extension=\""+ssid+"\"></id>\n" +
                    "      <name>"+info.optString("EHR_000004")+"</name>\n" +
                    "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE") + "</sex>\n" +
                    "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                    "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE") + "</marriage>\n" +
                    "    </patient>\n" +
                    "  </recordTarget>\n" +
                    "  <component>\n" +
                    "    <section>\n" +
                    "      <code code=\"common\" codeSystem=\"\" displayName=\"住院诊疗基本信息\"/>\n" +
                    "      <entry>\n" +
                    "        <residence>\n" +
                    "          <serial>"+info.optString("EHR_000234") +"</serial>\n" +
                    "          <code>"+info.optString("EHR_000236")+"</code>\n" +
                    "        </residence>\n" +
                    "        <sec>\n" +
                    "          <type code=\"【保险类别(字典STD_SEC_TYPE)】\" codeSystem=\"STD_SEC_TYPE\">【保险类别名称】</type>\n" +
                    "          <value>"+info.optString("EHR_000232")+"</value>\n" +
                    "        </sec>\n" +
                    "        <in>\n" +
                    "          <time>"+info.optString("EHR_000230")+"</time>\n" +
                    "          <dept code=\""+info.optString("EHR_000228")+"\" codeSystem=\"GB/T 17538-1998\">"+info.optString("EHR_000229")+"</dept>\n" +
                    "          <bed>"+info.optString("EHR_000227")+"</bed>\n" +
                    "        </in>\n" +
                    "        <move>\n" +
                    //EHR转诊业务有问题
                    /*"          <item>\n" +
                    "            <time>转科时间</time>\n" +
                    "            <dept code=\"转科科室代码(字典STD_DEPT)\" codeSystem=\"GB/T 17538-1998\">转科后科室名称</dept>\n" +
                    "            <bed>转科后床号</bed>\n" +
                    "          </item>\n" +*/
                    "        </move>\n" +
                    "        <out>\n" +
                    "          <time>"+info.optString("EHR_000224")+"</time>\n" +
                    "          <dept code=\""+info.optString("EHR_000222")+"\" codeSystem=\"GB/T 17538-1998\">"+info.optString("EHR_000223")+"</dept>\n" +
                    "          <bed>"+info.optString("EHR_000221")+"</bed>\n" +
                    "        </out>\n" +
                    "        <onsetTime>"+info.optString("EHR_000230")+"</onsetTime>\n" +
                    "        <diagnosisDate>"+info.optString("EHR_000230")+"</diagnosisDate>\n" +
                    "        <cause code=\""+info.optString("EHR_000237")+"\" codeSystem=\"CV5401.04\">"+info.optString("EHR_000237_VALUE")+"</cause>\n" +
                    "       <symptom>\n" +
                    symptomString +
                    "        </symptom>\n" +
                    "        <illStatus code=\""+info.optString("EHR_000239")+"\" codeSystem=\"CV5502.18\">"+info.optString("EHR_000239_VALUE")+"</illStatus>\n" +
                    "        <infectiousStatus code=\""+info.optString("EHR_000238")+"\" codeSystem=\"STD_JUDGE\">"+info.optString("EHR_000238_VALUE")+"</infectiousStatus>\n" +
                    "        <inDiagnosis>\n" +
                    diagnosisString+
                    "        </inDiagnosis>\n" +
                    "        <outDiagnosis>\n" +
                    "          <item>\n" +
                    "            <icd code=\""+info.optString("EHR_000158")+"\" codeSystem=\"ICD-10\">"+info.optString("EHR_000159")+"</icd>\n" +
                    "            <result code=\""+info.optString("EHR_000166")+"\" codeSystem=\"CV5501.11\">"+info.optString("EHR_000166_VALUE")+"</result>\n" +
                    "            <prop code=\"【诊断性质代码(字典STD_DIAGNOSIS_PROP)】\" codeSystem=\"STD_DIAGNOSIS_PROP\">【诊断性质名称】</prop>\n" +
                    "          </item>\n" +
                    "        </outDiagnosis>\n" +
                    "        <deathTime>"+info.optString("EHR_000255")+"</deathTime>\n" +
                    "        <causeOfDeath code=\""+info.optString("EHR_000258")+"\" codeSystem=\"ICD-10\">"+info.optString("EHR_000258_VALUE")+"</causeOfDeath>\n" +
                    "      </entry>\n" +
                    "    </section>\n" +
                    "  </component>\n" +
                    "</ClinicalDocument>";
            return re;
        }
        else{
            return "";
        }
    }
    //检查报告单(取第一条)
    public String getExamination(String ssid,String profileId,String catalog)
    {
        String re = "";
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        String catalogName = "";
        if(catalog.equals("0131"))
        {
            catalogName = "门诊检查报告单";
        }
        else if(catalog.equals("0231"))
        {
            catalogName = "住院检查报告";
        }
        if(info!=null) {
            //获取检查报告
            String url = ehrUrl + URLEncoder.encode("{demographic_id}")+"/examination?profile_id=" + profileId;
            String response = HttpClientUtil.get(url, "UTF-8");
            Map<String, Object> map = objectMapper.readValue(response, Map.class);
            JSONObject json = new JSONObject(response);
            if (json.getBoolean("successFlg") && json.getInt("totalCount") > 0) {
                JSONArray array = json.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    JSONObject obj = array.getJSONObject(0);
                    re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                            "<ClinicalDocument>\n" +
                            "  <version code=\"2.0.0.0\" date=\"2009-12-01\">根据卫生部标准第一次修订</version>\n" +
                            "  <ehr code=\""+catalog+"\" codeSystem=\"STD_EHR\">"+catalogName+"</ehr>\n" +
                            "  <title>"+catalogName+"</title>\n" +
                            "  <org code=\""+info.optString("org_code") +"\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name") +"</org>\n" +
                            "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                            "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                            "  <recordTarget>\n" +
                            "    <patient>\n" +
                            "      <id extension=\""+ssid+"\"></id>\n" +
                            "      <name>"+info.optString("EHR_000004")+"</name>\n" +
                            "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE") + "</sex>\n" +
                            "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                            "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE") + "</marriage>\n" +
                            "    </patient>\n" +
                            "  </recordTarget>\n" +
                            "  <author>\n" +
                            "    <time>"+obj.optString("EHR_000318")+"</time>\n" +
                            "    <id extension=\""+obj.optString("EHR_000345")+"\"/>\n" +
                            "    <name>【报告者:姓名】</name>\n" +
                            "  </author>\n" +
                            "  <authenticator>\n" +
                            "    <time>"+obj.optString("EHR_000341")+"</time>\n" +
                            "    <id extension=\""+obj.optString("EHR_000340")+"\"/>\n" +
                            "    <name>"+obj.optString("EHR_000342")+"</name>\n" +
                            "  </authenticator>\n" +
                            "  <participant>\n" +
                            "    <time>"+obj.optString("EHR_000338")+"</time>\n" +
                            "    <id extension=\""+obj.optString("EHR_000337")+"\"/>\n" +
                            "    <name>"+obj.optString("EHR_000339")+"</name>\n" +
                            "    <dept>"+obj.optString("EHR_000336")+"</dept>\n" +
                            "  </participant>\n" +
                            "  <inFulfillmentOf>\n" +
                            "    <order>\n" +
                            "      <id>"+obj.optString("EHR_000323")+"</id>\n" +
                            "      <priority code=\""+obj.optString("EHR_000324")+"\" codeSystem=\"HL7 27\">"+obj.optString("EHR_000324_VALUE")+"</priority>\n" +
                            "    </order>\n" +
                            "  </inFulfillmentOf>\n" +
                            "  <component>\n" +
                            "    <section>\n" +
                            "      <code code=\""+obj.optString("EHR_000330")+"\" displayName=\""+obj.optString("EHR_000330_VALUE")+"\" bodyPartCode=\""+obj.optString("EHR_000326")+"\" bodyPartName=\""+obj.optString("EHR_000326_VALUE")+"\" examCode=\""+obj.optString("EHR_000333")+"\" examName=\""+obj.optString("EHR_000333_VALUE")+"\"/>\n" +
                            "      <recognition code=\""+obj.optString("EHR_000334")+"\" codesystem=\"STD_LAB_EXAM_RECOGNITION\"/>\n" +
                            "      <entry>\n" +
                            "        <performer>\n" +
                            "          <assignedEntity>"+obj.optString("EHR_000327")+"</assignedEntity>\n" +
                            "          <name>"+obj.optString("EHR_000329")+"</name>\n" +
                            "          <time>"+obj.optString("EHR_000328")+"</time>\n" +
                            "        </performer>\n" +
                            "        <playingDevice>\n" +
                            "          <name>【检查设备名称】</name>\n" +
                            "        </playingDevice>\n" +
                            "        <clinicDiagnosis>"+obj.optString("EHR_000335")+"</clinicDiagnosis>\n" +
                            "        <patientCondition>"+obj.optString("EHR_000319")+"</patientCondition>\n" +
                            "        <examCause>"+obj.optString("EHR_000331")+"</examCause>\n" +
                            "        <description>"+obj.optString("EHR_000348")+"</description>\n" +
                            "        <isAbnormal code=\""+obj.optString("EHR_000344")+"\" codeSystem=\"\">"+(obj.optString("EHR_000344").equals("Y")?"Y":"N")+"</isAbnormal>\n" +
                            "      </entry>\n" +
                            "    </section>\n" +
                            "  </component>\n" +
                            "</ClinicalDocument>";
                }
            }
        }
        return re;
    }
            list = (List<Map<String,String>>)map.get("detailModelList");
    //检验报告单(取第一条)
    public String getLaboratory(String ssid,String profileId,String catalog)
    {
        String re = "";
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        String catalogName = "";
        if(catalog.equals("0121"))
        {
            catalogName = "门诊检验报告单";
        }
        catch (Exception e)
        else if(catalog.equals("0221"))
        {
            e.printStackTrace();
            catalogName = "住院检验报告";
        }
        if(info!=null) {
            //获取检查报告
            String url = ehrUrl + URLEncoder.encode("{demographic_id}")+"/laboratory?profile_id=" + profileId;
            String response = HttpClientUtil.get(url, "UTF-8");
            JSONObject json = new JSONObject(response);
            if (json.getBoolean("successFlg") && json.getInt("totalCount") > 0) {
                JSONArray array = json.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    JSONObject obj = array.getJSONObject(0);
                    //检验报告项目
                    String observationUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/laboratory/project?profile_id=" + profileId;
                    String observationResponse = HttpClientUtil.get(observationUrl, "UTF-8");
                    JSONObject observationJson = new JSONObject(observationResponse);
                    String observationString  = "";
                    if (observationJson.getBoolean("successFlg") && observationJson.getInt("totalCount") > 0) {
                        JSONArray observationArray = observationJson.getJSONArray("detailModelList");
                        if (observationArray != null && observationArray.length() > 0) {
                            for (int i = 0; i < observationArray.length(); i++) {
                                JSONObject item = observationArray.getJSONObject(i);
                                observationString +="<observation>\n" +
                                        "          <code code=\""+item.optString("EHR_000392")+"\" codeSystem=\"2.16.840.1.113883.6.1\" codeSystemName=\"LOINC\" displayName=\""+item.optString("EHR_000392_VALUE")+"\"/>\n" +
                                        "          <recognition code=\""+item.optString("EHR_000389")+"\" codesystem=\"STD_LAB_EXAM_RECOGNITION\"/>\n" +
                                        "          <type code=\""+item.optString("EHR_000386")+"\" codeSystem=\"STD_OBSERVATION_TYPE\">"+item.optString("EHR_000386_VALUE")+"</type>\n" +
                                        "          <value>"+item.optString("EHR_000387")+"</value>\n" +
                                        "          <unit>"+item.optString("EHR_000383")+"</unit>\n" +
                                        "          <referenceRange>\n" +
                                        "            <observationRange>\n" +
                                        "              <notes>"+item.optString("EHR_000382")+"</notes>\n" +
                                        "              <low>\n" +
                                        "                <value>"+item.optString("EHR_000391")+"</value>\n" +
                                        "                <unit>"+item.optString("EHR_000383")+"</unit>\n" +
                                        "              </low>\n" +
                                        "              <high>\n" +
                                        "                <value>"+item.optString("EHR_000390")+"</value>\n" +
                                        "                <unit>"+item.optString("EHR_000383")+"</unit>\n" +
                                        "              </high>\n" +
                                        "            </observationRange>\n" +
                                        "          </referenceRange>\n" +
                                        "          <effectiveTime>"+item.optString("EHR_000384")+"</effectiveTime>\n" +
                                        "          <interpretationCode code=\""+item.optString("EHR_000388")+"\" codeSystem=\"2.16.840.1.113883.5.83\">"+item.optString("EHR_000388_VALUE")+"</interpretationCode>\n" +
                                        "        </observation>\n" ;
                            }
                        }
                    }
                    re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                            "<ClinicalDocument>\n" +
                            "  <version code=\"2.0.0.0\" date=\"2009-12-01\">根据卫生部标准第一次修订</version>\n" +
                            "  <ehr code=\""+catalog+"\" codeSystem=\"STD_EHR\">"+catalogName+"</ehr>\n" +
                            "  <title>"+catalogName+"</title>\n" +
                            "  <org code=\""+info.optString("org_code") +"\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name") +"</org>\n" +
                            "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                            "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                            "  <recordTarget>\n" +
                            "    <patient>\n" +
                            "      <id extension=\""+ssid+"\"></id>\n" +
                            "      <name>"+info.optString("EHR_000004")+"</name>\n" +
                            "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE") + "</sex>\n" +
                            "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                            "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE") + "</marriage>\n" +
                            "    </patient>\n" +
                            "  </recordTarget>\n" +
                            "  <author>\n" +
                            "    <time>" + obj.optString("EHR_000379") + "</time>\n" +
                            "    <id extension=\""+ obj.optString("EHR_000377") + "\"/>\n" +
                            "    <name>"+ obj.optString("EHR_000378") +"</name>\n" +
                            "  </author>\n" +
                            "  <authenticator>\n" +
                            "    <time>"+ obj.optString("EHR_000375") +"</time>\n" +
                            "    <id extension=\""+ obj.optString("EHR_000374") +"\"/>\n" +
                            "    <name>"+ obj.optString("EHR_000376") +"</name>\n" +
                            "  </authenticator>\n" +
                            "  <participant>\n" +
                            "    <time>"+ obj.optString("EHR_000372") +"</time>\n" +
                            "    <id extension=\""+ obj.optString("EHR_000370") +"\"/>\n" +
                            "    <name>"+ obj.optString("EHR_000373") +"</name>\n" +
                            "    <dept>"+ obj.optString("EHR_000371") +"</dept>\n" +
                            "  </participant>\n" +
                            "  <inFulfillmentOf>\n" +
                            "    <order>\n" +
                            "      <id>"+ obj.optString("EHR_000360") +"</id>\n" +
                            "      <priority code=\""+ obj.optString("EHR_000361") +"\" codeSystem=\"HL7 27\">"+ obj.optString("EHR_000361_VALUE") +"</priority>\n" +
                            "    </order>\n" +
                            "  </inFulfillmentOf> \n" +
                            "  <component>\n" +
                            "    <section>\n" +
                            "      <code code=\"【检验的专业类型编码(字典STD_LAB_EXAM_TYPE)】\" codeSystem=\"2.16.840.1.113883.6.1\"  displayName=\"【检验的专业类型名称】\"/>\n" +
                            "      <entry>\n" +
                            "        <id>"+ obj.optString("EHR_000354") +"</id>\n" +
                            "        <performer>\n" +
                            "          <assignedEntity>"+ obj.optString("EHR_000365") +"</assignedEntity>\n" +
                            "          <name>"+ obj.optString("EHR_000367") +"</name>\n" +
                            "          <time>"+ obj.optString("EHR_000366") +"</time>\n" +
                            "        </performer>\n" +
                            "        <classCode>"+ obj.optString("EHR_000357") +"</classCode>\n" +
                            "        <specimenDeterminer code=\""+ obj.optString("EHR_000355") +"\" codeSystem=\"HL7 0163\">"+ obj.optString("EHR_000355_VALUE") +"</specimenDeterminer>\n" +
                            "        <risk code=\""+ obj.optString("EHR_000358") +"\" codeSystem=\"HL7 0489\">"+ obj.optString("EHR_000358_VALUE") +"</risk>\n" +
                            "        <quantity code=\""+ obj.optString("EHR_000359") +"\" codeSystem=\"HL7 0491\">"+ obj.optString("EHR_000359_VALUE") +"</quantity>\n" +
                            "        <rejectReason code=\""+ obj.optString("EHR_000356") +"\" codeSystem=\"HL7 0490\">"+ obj.optString("EHR_000356_VALUE") +"</rejectReason>\n" +
                            "        <playingDevice>\n" +
                            "          <name>【检验设备名称】</name>\n" +
                            "        </playingDevice>\n" +
                            observationString +
                            "      </entry>\n" +
                            "    </section>\n" +
                            "  </component>\n" +
                            "</ClinicalDocument>";
                }
            }
        }
        return list;
        return re;
    }
    /**
     * 用药记录
     */
    public String getInspectionAndChecking(String idcard) {
        String url = ehrUrl + idcard +"/laboratory?demographic_id="+idcard;
        return HttpClientUtil.get(url, "UTF-8");
    //门诊费用明细
    public String get0102(String ssid,String profileId)
    {
        //事件主要信息
        JSONObject info = getEventBaseInfo(profileId);
        if(info!=null) {
            //住院症状
            String symptomUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/hospitalized/symptom?profile_id=" + profileId;
            String symptomResponse = HttpClientUtil.get(symptomUrl, "UTF-8");
            JSONObject symptomObj = new JSONObject(symptomResponse);
            String symptomString = "";
            if (symptomObj.getBoolean("successFlg") && symptomObj.getInt("totalCount") > 0) {
                JSONArray array = symptomObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        symptomString += "<item code=\"" + item.optString("EHR_000301") + "\" codeSystem=\"CV5101.27\">" + item.optString("EHR_000302") + "</item>\n";
                    }
                }
            }
            //住院诊断
            String diagnosisUrl = ehrUrl + URLEncoder.encode("{demographic_id}")+"/hospitalized/diagnosis?profile_id=" + profileId;
            String diagnosisResponse = HttpClientUtil.get(diagnosisUrl, "UTF-8");
            JSONObject diagnosisObj = new JSONObject(diagnosisResponse);
            String diagnosisString = "";
            if (diagnosisObj.getBoolean("successFlg") && diagnosisObj.getInt("totalCount") > 0) {
                JSONArray array = diagnosisObj.getJSONArray("detailModelList");
                if (array != null && array.length() > 0) {
                    for (int i = 0; i < array.length(); i++) {
                        JSONObject item = array.getJSONObject(i);
                        diagnosisString +="<item>\n" +
                                "      <icd code=\""+item.optString("EHR_000293")+"\" codeSystem=\"ICD-10\">"+item.optString("EHR_000295")+"</icd>\n" +
                                "</item>\n";
                    }
                }
            }
            String re = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<ClinicalDocument>\n" +
                    "  <version code=\"2.0.0.1\" date=\"2011-06-01\">根据卫生部标准第2次修订</version>\n" +
                    "  <ehr code=\"0201\" codeSystem=\"STD_EHR\">住院诊疗基本信息</ehr>\n" +
                    "  <title>住院诊疗基本信息</title>\n" +
                    "  <org code=\""+info.optString("org_code") +"\" codeSystem=\"STD_HEALTH_ORG\">"+info.optString("org_name") +"</org>\n" +
                    "  <id extension=\"" + profileId + "\" eventno=\"" + info.optString("event_no") + "\"></id>\n" +
                    "  <effectiveTime value=\"" + info.optString("create_date") + "\"/>\n" +
                    "  <recordTarget>\n" +
                    "    <patient>\n" +
                    "      <id extension=\""+ssid+"\"></id>\n" +
                    "      <name>"+info.optString("EHR_000004")+"</name>\n" +
                    "      <sex code=\"" + info.optString("EHR_000019") + "\" codeSystem=\"GB/T2261.1-2003\">" + info.optString("EHR_000019_VALUE") + "</sex>\n" +
                    "      <birthDate>" + info.optString("EHR_000007") + "</birthDate>\n" +
                    "      <marriage code=\"" + info.optString("EHR_000014") + "\" codeSystem=\"GB/T 2261.2-2003\">" + info.optString("EHR_000014_VALUE") + "</marriage>\n" +
                    "    </patient>\n" +
                    "  </recordTarget>\n" +
                    "  <component>\n" +
                    "    <section>\n" +
                    "      <code code=\"common\" codeSystem=\"\" displayName=\"住院诊疗基本信息\"/>\n" +
                    "      <entry>\n" +
                    "        <residence>\n" +
                    "          <serial>"+info.optString("EHR_000234") +"</serial>\n" +
                    "          <code>"+info.optString("EHR_000236")+"</code>\n" +
                    "        </residence>\n" +
                    "        <sec>\n" +
                    "          <type code=\"【保险类别(字典STD_SEC_TYPE)】\" codeSystem=\"STD_SEC_TYPE\">【保险类别名称】</type>\n" +
                    "          <value>"+info.optString("EHR_000232")+"</value>\n" +
                    "        </sec>\n" +
                    "        <in>\n" +
                    "          <time>"+info.optString("EHR_000230")+"</time>\n" +
                    "          <dept code=\""+info.optString("EHR_000228")+"\" codeSystem=\"GB/T 17538-1998\">"+info.optString("EHR_000229")+"</dept>\n" +
                    "          <bed>"+info.optString("EHR_000227")+"</bed>\n" +
                    "        </in>\n" +
                    "        <move>\n" +
                    //EHR转诊业务有问题
                    /*"          <item>\n" +
                    "            <time>转科时间</time>\n" +
                    "            <dept code=\"转科科室代码(字典STD_DEPT)\" codeSystem=\"GB/T 17538-1998\">转科后科室名称</dept>\n" +
                    "            <bed>转科后床号</bed>\n" +
                    "          </item>\n" +*/
                    "        </move>\n" +
                    "        <out>\n" +
                    "          <time>"+info.optString("EHR_000224")+"</time>\n" +
                    "          <dept code=\""+info.optString("EHR_000222")+"\" codeSystem=\"GB/T 17538-1998\">"+info.optString("EHR_000223")+"</dept>\n" +
                    "          <bed>"+info.optString("EHR_000221")+"</bed>\n" +
                    "        </out>\n" +
                    "        <onsetTime>"+info.optString("EHR_000230")+"</onsetTime>\n" +
                    "        <diagnosisDate>"+info.optString("EHR_000230")+"</diagnosisDate>\n" +
                    "        <cause code=\""+info.optString("EHR_000237")+"\" codeSystem=\"CV5401.04\">"+info.optString("EHR_000237_VALUE")+"</cause>\n" +
                    "       <symptom>\n" +
                    symptomString +
                    "        </symptom>\n" +
                    "        <illStatus code=\""+info.optString("EHR_000239")+"\" codeSystem=\"CV5502.18\">"+info.optString("EHR_000239_VALUE")+"</illStatus>\n" +
                    "        <infectiousStatus code=\""+info.optString("EHR_000238")+"\" codeSystem=\"STD_JUDGE\">"+info.optString("EHR_000238_VALUE")+"</infectiousStatus>\n" +
                    "        <inDiagnosis>\n" +
                    diagnosisString+
                    "        </inDiagnosis>\n" +
                    "        <outDiagnosis>\n" +
                    "          <item>\n" +
                    "            <icd code=\""+info.optString("EHR_000158")+"\" codeSystem=\"ICD-10\">"+info.optString("EHR_000159")+"</icd>\n" +
                    "            <result code=\""+info.optString("EHR_000166")+"\" codeSystem=\"CV5501.11\">"+info.optString("EHR_000166_VALUE")+"</result>\n" +
                    "            <prop code=\"【诊断性质代码(字典STD_DIAGNOSIS_PROP)】\" codeSystem=\"STD_DIAGNOSIS_PROP\">【诊断性质名称】</prop>\n" +
                    "          </item>\n" +
                    "        </outDiagnosis>\n" +
                    "        <deathTime>"+info.optString("EHR_000255")+"</deathTime>\n" +
                    "        <causeOfDeath code=\""+info.optString("EHR_000258")+"\" codeSystem=\"ICD-10\">"+info.optString("EHR_000258_VALUE")+"</causeOfDeath>\n" +
                    "      </entry>\n" +
                    "    </section>\n" +
                    "  </component>\n" +
                    "</ClinicalDocument>";
            return re;
        }
        else{
            return "";
        }
    }
}

+ 31 - 22
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/HealthDataService.java

@ -23,37 +23,46 @@ public class HealthDataService extends BaseService {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    EhrService ehrService;
    /**
     * 获取健康档案信息
     */
    public String getHealthData(String strSSID, String strEvent, String strCatalog, String strSerial) throws Exception {
        String url = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
        url = url + "/third/smjk/HealthData";
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("strSSID", strSSID));
        params.add(new BasicNameValuePair("strEvent", strEvent));
        params.add(new BasicNameValuePair("strCatalog", strCatalog));
        params.add(new BasicNameValuePair("strSerial", strSerial));
        String response = HttpClientUtil.post(url, params, "UTF-8");
        String result = "";
        if (!StringUtils.isEmpty(response)){
            JSONObject jsonObject = new JSONObject(response);
            int status = jsonObject.getInt("status");
            if (status == 200){
                result = jsonObject.getString("data");
                result = result.replaceAll("<\\?xml version=\"1.0\" encoding=\"utf-8\"\\?>","");
                if (result.startsWith("error")) {
                    return result;
                }
        if(SystemConf.getInstance().getEhrUsed())     //演示环境
        {
            return ehrService.getHealthData(strSSID,strEvent,strCatalog,strSerial);
        }
        else {
            String url = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
            url = url + "/third/smjk/HealthData";
            List<NameValuePair> params = new ArrayList<>();
            params.add(new BasicNameValuePair("strSSID", strSSID));
            params.add(new BasicNameValuePair("strEvent", strEvent));
            params.add(new BasicNameValuePair("strCatalog", strCatalog));
            params.add(new BasicNameValuePair("strSerial", strSerial));
            String response = HttpClientUtil.post(url, params, "UTF-8");
            String result = "";
            if (!StringUtils.isEmpty(response)) {
                JSONObject jsonObject = new JSONObject(response);
                int status = jsonObject.getInt("status");
                if (status == 200) {
                    result = jsonObject.getString("data");
                    result = result.replaceAll("<\\?xml version=\"1.0\" encoding=\"utf-8\"\\?>", "");
                    if (result.startsWith("error")) {
                        return result;
                    }
//                if (!StringUtils.isEmpty(xmlData)){
//                    String xmlJson = XMLUtil.xml2json(xmlData);
//                    result = objectMapper.readValue(xmlJson, Map.class);
//                }
                }
            }
        }
        return result;
            return result;
        }
    }
}

+ 39 - 30
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/record/InspectionService.java

@ -31,6 +31,9 @@ public class InspectionService extends BaseService {
    @Autowired
    SystemDictService systemDictService;
    @Autowired
    EhrService ehrService;
    /**
     * 获取检查报告信息
     */
@ -56,41 +59,47 @@ public class InspectionService extends BaseService {
     * @throws Exception
     */
    public String getInspectionAndChecking(String strSSID, String startNum, String endNum) throws Exception {
        JSONArray total = new JSONArray();
        JSONArray check = getChecking(strSSID, startNum, endNum);
        if (!check.isNull(0)) {
            JSONObject jsonObject = check.getJSONObject(0);
            if (jsonObject.has("error")) {
                return jsonObject.get("error").toString();
            }
        if(SystemConf.getInstance().getEhrUsed())     //演示环境
        {
            return ehrService.getInspectionAndChecking(strSSID);
        }
        JSONArray inspect = getInspection(strSSID, startNum, endNum);
        if (!inspect.isNull(0)) {
            JSONObject jsonObject = inspect.getJSONObject(0);
            if (jsonObject.has("error")) {
                return jsonObject.get("error").toString();
        else {
            JSONArray total = new JSONArray();
            JSONArray check = getChecking(strSSID, startNum, endNum);
            if (!check.isNull(0)) {
                JSONObject jsonObject = check.getJSONObject(0);
                if (jsonObject.has("error")) {
                    return jsonObject.get("error").toString();
                }
            }
        }
        //TODO 检查检验数据合并
        for (int i = 0; i < check.length(); i++) {
            total.put(check.getJSONObject(i));
        }
        for (int i = 0; i < inspect.length(); i++) {
            total.put(inspect.getJSONObject(i));
        }
        JSONObject temp;
        for (int i = 0; i < total.length(); i++) {
            for (int j = i+1; j < total.length(); j++) {
                String endTimeNew = total.getJSONObject(j).get("END_TIME").toString();
                String endTimeOld = total.getJSONObject(i).get("END_TIME").toString();
                if (endTimeNew.compareTo(endTimeOld) > 0) {
                    temp = total.getJSONObject(i);
                    total.put(i, total.getJSONObject(j));
                    total.put(j, temp);  // 两个数交换位置
            JSONArray inspect = getInspection(strSSID, startNum, endNum);
            if (!inspect.isNull(0)) {
                JSONObject jsonObject = inspect.getJSONObject(0);
                if (jsonObject.has("error")) {
                    return jsonObject.get("error").toString();
                }
            }
            //TODO 检查检验数据合并
            for (int i = 0; i < check.length(); i++) {
                total.put(check.getJSONObject(i));
            }
            for (int i = 0; i < inspect.length(); i++) {
                total.put(inspect.getJSONObject(i));
            }
            JSONObject temp;
            for (int i = 0; i < total.length(); i++) {
                for (int j = i + 1; j < total.length(); j++) {
                    String endTimeNew = total.getJSONObject(j).get("END_TIME").toString();
                    String endTimeOld = total.getJSONObject(i).get("END_TIME").toString();
                    if (endTimeNew.compareTo(endTimeOld) > 0) {
                        temp = total.getJSONObject(i);
                        total.put(i, total.getJSONObject(j));
                        total.put(j, temp);  // 两个数交换位置
                    }
                }
            }
            return total.toString();
        }
        return total.toString();
    }

+ 59 - 10
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/StatisticsAllService.java

@ -68,6 +68,8 @@ public class StatisticsAllService extends BaseService {
    public long getIndexTotal(String endDate, String area, int level, String index) {
        long total = 0;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        boolean preFlag = false;
        String preDate = endDate;
        if (endDate.compareTo(dateFormat.format(new Date())) >= 0) {
            String val = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + getQuotaTimeStamp());
@ -76,8 +78,16 @@ public class StatisticsAllService extends BaseService {
                if (valJson.has("num")) {
                    total = valJson.getInt("num");
                }
            } else {
                preFlag = true;
                Calendar today = Calendar.getInstance();
                today.add(Calendar.DATE, -1);
                preDate = dateFormat.format(today.getTime());
            }
        } else {
            preFlag = true;
        }
        if (preFlag) {
            // 查询语句
            String sql = " select " +
                    "     ifnull(result,'0') amount" +
@ -101,7 +111,7 @@ public class StatisticsAllService extends BaseService {
                sql += " and qkdoctor_code = ?";
            }
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{index, level, endDate, area});
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{index, level, preDate, area});
            if (result != null && result.size() > 0) {
                total = (result.get(0).get("amount") != null ? Long.valueOf(result.get(0).get("amount").toString()) : 0L);
@ -122,16 +132,26 @@ public class StatisticsAllService extends BaseService {
    public long getWeiJiaoFei(String endDate, String area, int level) {
        long total = 0;
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        boolean preFlag = false;
        String preDate = endDate;
        if (endDate.compareTo(dateFormat.format(new Date())) >= 0) {
            String val = redisTemplate.opsForValue().get("quota:16:" + level + ":"+ area + ":0:" + getQuotaTimeStamp());
            String val = redisTemplate.opsForValue().get("quota:16:" + level + ":" + area + ":0:" + getQuotaTimeStamp());
            if (!StringUtils.isEmpty(val)) {
                JSONObject valJson = new JSONObject(val);
                if (valJson.has("num")) {
                    total = valJson.getInt("num");
                }
            } else {
                preFlag = true;
                Calendar today = Calendar.getInstance();
                today.add(Calendar.DATE, -1);
                preDate = dateFormat.format(today.getTime());
            }
        } else {
            preFlag = true;
        }
        if (preFlag) {
            // 查询语句
            String sql = " select " +
                    "     ifnull(result,'0') amount" +
@ -156,7 +176,7 @@ public class StatisticsAllService extends BaseService {
                sql += " and qkdoctor_code = ?";
            }
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
            List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{level, preDate, area});
            if (result != null && result.size() > 0) {
                total = (result.get(0).get("amount") != null ? Long.valueOf(result.get(0).get("amount").toString()) : 0L);
@ -239,13 +259,11 @@ public class StatisticsAllService extends BaseService {
        List<Map<String, Object>> resultList = new ArrayList<>();
        if (date.compareTo(dateFormat.format(new Date())) >= 0) {
            resultList = getTodayLowLevelTotal(date, area, level, index, lowLevel);
            resultList = getTodayLowLevelTotal(area, level, index, sort, lowLevel);
        } else {
            resultList = getTodayBeforeLowLevelTotal(date, area, level, index, sort, lowLevel);
        }
        // 结果为空时,自建结果集
        if (resultList == null || resultList.size() < 1) {
            resultList = getLowLevelMapKey(level, low_level, area);
@ -373,14 +391,13 @@ public class StatisticsAllService extends BaseService {
    /**
     * 获取今天某个区域一级指标的下级统计
     *
     * @param date
     * @param area
     * @param level
     * @param index
     * @param lowLevel
     * @return
     */
    public List<Map<String, Object>> getTodayLowLevelTotal(String date, String area, int level, String index, String lowLevel) {
    public List<Map<String, Object>> getTodayLowLevelTotal(String area, int level, String index, int sort, String lowLevel) throws Exception {
        List<Map<String, Object>> resultList = new ArrayList<>();
        String low_level = String.valueOf(StringUtils.isEmpty(lowLevel) ? (level - 1) : lowLevel);
        String redisData = redisTemplate.opsForValue().get("quota:" + index + ":" + level + ":" + area + ":" + low_level + ":" + getQuotaTimeStamp());
@ -398,6 +415,11 @@ public class StatisticsAllService extends BaseService {
                resultList.add(data);
            }
        } else {
            Calendar today = Calendar.getInstance();
            today.add(Calendar.DATE, -1);
            String preDate = new SimpleDateFormat("yyyy-MM-dd").format(today.getTime());
            resultList = getTodayBeforeLowLevelTotal(preDate, area, level, index, sort, lowLevel);
        }
        if (resultList.size() < 1) {
@ -649,6 +671,11 @@ public class StatisticsAllService extends BaseService {
                resultList.add(data);
            }
        } else {
            Calendar today = Calendar.getInstance();
            today.add(Calendar.DATE, -1);
            String preDate = new SimpleDateFormat("yyyy-MM-dd").format(today.getTime());
            resultList = getTodyBeforeLevelTwototal(preDate, area, level, index);
        }
        if (resultList.size() < 1) {
@ -834,6 +861,8 @@ public class StatisticsAllService extends BaseService {
        String areaField = "";
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        List<Map<String, Object>> resultList = new ArrayList<>();
        boolean preFlag = false;
        String preDate = endDate;
        if (endDate.compareTo(datef.format(new Date())) >= 0) {
            String redisData = redisTemplate.opsForValue().get("quota:12:" + level + ":" + area + ":6:" + getQuotaTimeStamp());
@ -851,8 +880,17 @@ public class StatisticsAllService extends BaseService {
                    resultList.add(data);
                }
            } else {
                preFlag = true;
                Calendar today = Calendar.getInstance();
                today.add(Calendar.DATE, -1);
                preDate = datef.format(today.getTime());
            }
        } else {
            preFlag = true;
        }
        if (preFlag) {
            if (level == 4) {
                // 市级别
                areaField = "city";
@ -884,7 +922,7 @@ public class StatisticsAllService extends BaseService {
                    "   and " + areaField + " = ? " +
                    " group by level3_type,level3_type_name";
            resultList = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
            resultList = jdbcTemplate.queryForList(sql, new Object[]{level, preDate, area});
        }
        if (resultList == null || resultList.size() < 1) {
@ -947,6 +985,8 @@ public class StatisticsAllService extends BaseService {
        String areaField = "";
        long total = 0;
        SimpleDateFormat datef = new SimpleDateFormat("yyyy-MM-dd");
        boolean preFlag = false;
        String preDate = endDate;
        if (endDate.compareTo(datef.format(new Date())) >= 0) {
            String code = "6";
@ -956,8 +996,17 @@ public class StatisticsAllService extends BaseService {
                if (valJson.has("num")) {
                    total = valJson.getInt("num");
                }
            } else {
                preFlag = true;
                Calendar today = Calendar.getInstance();
                today.add(Calendar.DATE, -1);
                preDate = datef.format(today.getTime());
            }
        } else {
            preFlag = true;
        }
        if (preFlag) {
            if (level == 4) {
                // 市级别
                areaField = "city";
@ -988,7 +1037,7 @@ public class StatisticsAllService extends BaseService {
            List<Map<String, Object>> result = null;
            result = jdbcTemplate.queryForList(sql, new Object[]{level, endDate, area});
            result = jdbcTemplate.queryForList(sql, new Object[]{level, preDate, area});
            if (result != null && result.size() > 0) {
                total = (result.get(0).get("amount") == null ? 0 : Math.round(Double.valueOf(result.get(0).get("amount").toString())));

+ 9 - 9
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -277,7 +277,7 @@ public class PushMsgTask {
                keyword4.setValue(json.getString("content"));
                m.put("keyword4", keyword4);
            } else if (type == 4) {
                temp.setUrl(url + "yszd/html/doctor-guidance.html?openid=" + openid + "&toUser=" + json.getString("toUser"));
                temp.setUrl(url + "yszd/html/guidance-detail.html?openid=" + openid + "&toUser=" + json.getString("toUser") + "&id=" + String.valueOf(json.get("id")));
                temp_id = SystemConf.getInstance().getSystemProperties().getProperty("template_health_notice");
                temp.setTemplate_id(temp_id);
                WechatTemplateData keyword1 = new WechatTemplateData();
@ -366,20 +366,20 @@ public class PushMsgTask {
                temp.setTemplate_id(temp_id);
                WechatTemplateData keyword1 = new WechatTemplateData();
                keyword1.setColor("#000000");
                keyword1.setValue(json.getString("name"));
                m.put("keynote1", keyword1);
                keyword1.setValue("提醒医生:" + json.getString("doctorName"));
                m.put("first", keyword1);
                WechatTemplateData keyword2 = new WechatTemplateData();
                keyword2.setColor("#000000");
                keyword2.setValue(json.getString("date"));
                m.put("keynote2", keyword2);
                keyword2.setValue("以协议为准");
                m.put("keyword1", keyword2);
                WechatTemplateData keyword3 = new WechatTemplateData();
                keyword3.setColor("#000000");
                keyword3.setValue(json.getString("doctorName"));
                m.put("keynote3", keyword3);
                keyword3.setValue("家庭医生签约");
                m.put("keyword2", keyword3);
                WechatTemplateData keyword4 = new WechatTemplateData();
                keyword4.setColor("#000000");
                keyword4.setValue("");
                m.put("keynote4", keyword4);
                keyword4.setValue(json.getString("content"));
                m.put("remark", keyword4);
            }
            temp.setData(m);
            ObjectMapper mapper = new ObjectMapper();

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/account/PatientController.java

@ -794,7 +794,7 @@ public class PatientController extends WeixinBaseController {
            if (status == -1) {
                return error(-1, "成员信息查询失败");
            } else if (status == -2) {
                return error(-1, "家庭成员不存在该人");
                return error(-2, "家庭成员不存在该人");
            } else {
                return write(200, "切换账号成功", "data", result.getJSONObject("data"));
            }

+ 33 - 12
patient-co-wlyy/src/main/resources/system.properties

@ -117,25 +117,46 @@ yihu_guahao_appid=sanshi
yihu_guahao_secret=sanshi
#微信模板消息ID
#----------------正式环境-----------------#
#----------------开发环境-----------------#
#签约邀请
doctor_invitel_template=MQn79bx1ofb6hekhmRIuqLU7KjySJQzaBzrimgqVrzA
doctor_invitel_template=TLWrBtNE2kBJaFCdVzDOOnQC8N2TtRY9ZxEzwZXQcR0
#咨询回复
template_consult_notice=0mF_vHj-ILx8EH8DwzmAi7LqzjqYiU9IrSRRmziTZyc
template_consult_notice=qSOW0DBxO3qEBm4ucG0Ial0jxsOyD7_f2TFK5e-mQEc
#签约成功
template_sign_success=0D2vYZVRzFz15p9Y_pkZ1DKutDq8UOsks79FXUKS0tA
template_sign_success=hDWV_sknKlhxhOwR5h68OCXbAhRpcgnx9INrT8BybE8
#签约失败
template_sign_failed=My2VNERjJt4NXR4Ibh42pdrP6B6ka8rQxZeWinQh99s
template_sign_failed=ezgttXE7rG4rAboQK2ituG1dKq4PeyCj3LxGJWO_vOA
#健康指导提醒
template_health_notice=uv31ES_VCmq3tBYtyGmEQvIwU_zh9LDhF3bFpbIUt5g
template_health_notice=128RCfyCHi22jW8PZzo7vabKMsA3SBv5VeHaDPr2Bhw
#解约提醒
template_termination=C0tdXtA_8k-Cy4a1EkzQuI877vqaqAtRkc-e_Gsd7sk
template_termination=LrrzHjnIF67ww5uQUvSiv3_pVKJiIK4ZE3fKrvsT0AE
#预约成功
template_appoint_success=FY3Pqa66tHIE1Fv-irbFBPOh5cYP71fkOzfZKH4S-Fo
template_appoint_success=Bo2yqNczSU9zkg4wXoouv9tSeefZ6TziggWL3dTXPYE
#预约取消
template_appoint_failed=tldWEb9AN7p_RoHoD8ml0GxWW3V1V_mpEEhp2v6p56s
template_appoint_failed=pErTBTdweIdrNRf_1Oo62YtQC0aHwPvtLaCzw44JzCQ
#缴费提醒
template_expenses_remind=BkTGJ8S18qZ3DfaptAXnZznAk8RJjx9v93og5vyO0bs
#----------------正式环境-----------------#
##签约邀请
#doctor_invitel_template=MQn79bx1ofb6hekhmRIuqLU7KjySJQzaBzrimgqVrzA
##咨询回复
#template_consult_notice=0mF_vHj-ILx8EH8DwzmAi7LqzjqYiU9IrSRRmziTZyc
##签约成功
#template_sign_success=0D2vYZVRzFz15p9Y_pkZ1DKutDq8UOsks79FXUKS0tA
##签约失败
#template_sign_failed=My2VNERjJt4NXR4Ibh42pdrP6B6ka8rQxZeWinQh99s
##健康指导提醒
#template_health_notice=uv31ES_VCmq3tBYtyGmEQvIwU_zh9LDhF3bFpbIUt5g
##解约提醒
#template_termination=C0tdXtA_8k-Cy4a1EkzQuI877vqaqAtRkc-e_Gsd7sk
##预约成功
#template_appoint_success=FY3Pqa66tHIE1Fv-irbFBPOh5cYP71fkOzfZKH4S-Fo
##预约取消
#template_appoint_failed=tldWEb9AN7p_RoHoD8ml0GxWW3V1V_mpEEhp2v6p56s
##缴费提醒
template_expenses_remind=tldWEb9AN7p_RoHoD8ml0GxWW3V1V_mpEEhp2v6p56s
#template_expenses_remind=tldWEb9AN7p_RoHoD8ml0GxWW3V1V_mpEEhp2v6p56s
#----------------测试环境(健康之路i厦门)----------------#
##签约邀请
@ -182,7 +203,7 @@ guahao_url = http://www.xmsmjk.com/UrpNetService/ReservationNet.asmx
guahao_namespace = http://www.zysoft.com.cn/
#EHR档案服务地址
ehr_used = false
ehr_used = true
ehr_services = http://localhost:9009/api/v1.0/
ehr_services_base = http://localhost:9009/api/v1.0/
ehr_services_base = http://localhost:10220/api/v1.0/