Explorar o código

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

zd_123 %!s(int64=7) %!d(string=hai) anos
pai
achega
792967673e
Modificáronse 20 ficheiros con 554 adicións e 82 borrados
  1. 104 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/TrackPatient.java
  2. 17 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/repository/TrackPatientDao.java
  3. 4 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/device/DeviceHealthIndexService.java
  4. 4 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/device/WlyyPatientDeviceService.java
  5. 66 0
      patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/sign/SignFamilyService.java
  6. 5 0
      patient-co-service/wlyy_service/pom.xml
  7. 3 4
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/common/SystemConfig.java
  8. 14 1
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/ZysoftApi.java
  9. 68 7
      patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/guahao/GuahaoService.java
  10. BIN=BIN
      patient-co-service/wlyy_service/src/main/resources/ImmPublicTest.key
  11. 18 16
      patient-co-service/wlyy_service/src/main/resources/system.properties
  12. 120 0
      patient-co/patient-co-statistics-es/readme.MD
  13. 2 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/template/DoctorTeamGuidanceTemplateDao.java
  14. 53 40
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java
  15. 66 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java
  16. 3 3
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/statistics/ServiceStatisticsService.java
  17. 1 5
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/imm/ChildFamilyImmuneService.java
  18. 3 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorTeamGuidanceService.java
  19. 1 0
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java
  20. 2 2
      patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/family/FamilyMemberController.java

+ 104 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/entity/TrackPatient.java

@ -0,0 +1,104 @@
package com.yihu.wlyy.entity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Trick on 2018/1/4.
 */
@Entity
@Table(name = "wlyy_track_patient")
public class TrackPatient extends IdEntity {
    private String patientCode;//关联居民code,医生的重点关注对象
    private String patientName;//患者姓名
    private String doctorCode;//所属医生
    private String doctorName;//所属医生名
    private Integer teamCode;//居民签约团队
    private String idcard;//身份证号
    private String ssc;//社保卡号
    private String del;//删除
    private Date createTime;//创建时间
    private Date updateTime;//更新时间
    public String getPatientCode() {
        return patientCode;
    }
    public void setPatientCode(String patientCode) {
        this.patientCode = patientCode;
    }
    public String getPatientName() {
        return patientName;
    }
    public void setPatientName(String patientName) {
        this.patientName = patientName;
    }
    public String getDoctorCode() {
        return doctorCode;
    }
    public void setDoctorCode(String doctorCode) {
        this.doctorCode = doctorCode;
    }
    public String getDoctorName() {
        return doctorName;
    }
    public void setDoctorName(String doctorName) {
        this.doctorName = doctorName;
    }
    public Integer getTeamCode() {
        return teamCode;
    }
    public void setTeamCode(Integer teamCode) {
        this.teamCode = teamCode;
    }
    public String getIdcard() {
        return idcard;
    }
    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }
    public String getSsc() {
        return ssc;
    }
    public void setSsc(String ssc) {
        this.ssc = ssc;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getDel() {
        return del;
    }
    public void setDel(String del) {
        this.del = del;
    }
}

+ 17 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/repository/TrackPatientDao.java

@ -0,0 +1,17 @@
package com.yihu.wlyy.repository;
import com.yihu.wlyy.entity.TrackPatient;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by Trick on 2018/1/4.
 */
public interface TrackPatientDao extends PagingAndSortingRepository<TrackPatient, String>, JpaSpecificationExecutor<TrackPatient> {
    public TrackPatient findByDoctorCodeAndPatientCode(String doctorCode, String patientCode);
    public List<TrackPatient> findByDoctorCodeAndTeamCodeAndDel(String doctorCode, Integer teamCode, String del);
}

+ 4 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/device/DeviceHealthIndexService.java

@ -72,11 +72,15 @@ public class DeviceHealthIndexService extends BaseDeviceJpaService<DeviceHealthI
        }
        List<DeviceHealthIndex> list = (List<DeviceHealthIndex>)search("", filter.toString(), "-czrq", page, pageSize);
        long count = 0;
        String regex = "(\\w{3})(\\w+)(\\w{3})";
        if(list !=null && list.size()>0){
            count = getCount(filter.toString());
            for (DeviceHealthIndex info : list){
                Patient patient = findPatient(info.getUser());
                info.setUserName(patient== null?"":patient.getName());
                if(StringUtils.isNotBlank(info.getIdcard())){
                    info.setIdcard(info.getIdcard().replaceAll(regex, "$1****$3"));
                }
            }
        }
        return new PageImpl<DeviceHealthIndex>(list,pageRequest,count);

+ 4 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/device/WlyyPatientDeviceService.java

@ -61,10 +61,14 @@ public class WlyyPatientDeviceService extends BaseJpaService<WlyyPatientDevice,W
        }
        List<WlyyPatientDevice> list = (List<WlyyPatientDevice>)search("", filters.toString(), "-czrq", page, pageSize);
        long count = 0;
        String regex = "(\\w{3})(\\w+)(\\w{3})";
        if(list !=null && list.size()>0){
            count = getCount(filters.toString());
            for (WlyyPatientDevice info : list){
                Patient patient = findPatient(info.getUser());
                if(StringUtils.isNotBlank(info.getUserIdcard())){
                    info.setUserIdcard(info.getUserIdcard().replaceAll(regex, "$1****$3"));
                }
                info.setUserName(patient== null?"":patient.getName());
            }
        }

+ 66 - 0
patient-co-manage/wlyy-manage/src/main/java/com/yihu/wlyy/service/manager/sign/SignFamilyService.java

@ -66,6 +66,9 @@ public class SignFamilyService extends BaseJpaService<SignFamily,Long> {
    @Autowired
    JdbcTemplate jdbcTemplate;
    @Autowired
    private TrackPatientDao trackPatientDao;
    //签约居民管理**********************
    @Transactional
@ -272,10 +275,18 @@ public class SignFamilyService extends BaseJpaService<SignFamily,Long> {
            }
            if(!StringUtils.isEmpty(doctor)){
                //1.4.2更新重点关注列表,取消关注
                updateTrackPatient(signFamily.getPatient(),signFamily.getDoctor(),signFamily.getDoctorHealth(),doctor,doctorHealth);
                signFamily.setDoctor(doctor);
                signFamily.setDoctorName(doctorName);
            }
            if(!StringUtils.isEmpty(doctorHealth)){
                //1.4.2更新重点关注列表,取消关注
                updateTrackPatient(signFamily.getPatient(),signFamily.getDoctorHealth(),signFamily.getDoctor(),doctor,doctorHealth);
                signFamily.setDoctorHealth(doctorHealth);
                signFamily.setDoctorHealthName(doctorHealthName);
            }
@ -435,4 +446,59 @@ public class SignFamilyService extends BaseJpaService<SignFamily,Long> {
        list =  jdbcTemplate.query(sql,new BeanPropertyRowMapper(SignPayVO.class));
        return list ;
    }
    /**
     * 设置取消关注
     * @param patient
     * @param oldDoctor 患者签约旧的要取消关注的医生
     * @param oldDoctor2 患者旧的签约的另一个医生
     * @param newDoctor 患者新签约的全科医生
     * @param newHDoctor 患者新签约的健康管理师
     */
    public void updateTrackPatient(String patient,String oldDoctor,String oldDoctor2,String newDoctor,String newHDoctor){
        //是否需要修改
        boolean flag = false;
        if(StringUtils.isBlank(oldDoctor)){
            return ;
        }
        //1.两个都修改
        if(StringUtils.isNotBlank(newDoctor)&&StringUtils.isNotBlank(newHDoctor)){
            if((!oldDoctor.equals(newDoctor))&&(!oldDoctor.equals(newHDoctor))){
                flag = true;
            }
            //只改全科
        }else if(StringUtils.isNotBlank(newDoctor)&&StringUtils.isBlank(newHDoctor)){
            if(!oldDoctor.equals(newDoctor)){
                if(StringUtils.isBlank(oldDoctor2)){
                    flag = true;
                }else{
                    if(!oldDoctor.equals(oldDoctor2)){
                        flag = true;
                    }
                }
            }
            //只改健管
        }else if(StringUtils.isBlank(newDoctor)&&StringUtils.isNotBlank(newHDoctor)){
            if(!oldDoctor.equals(newHDoctor)){
                if(StringUtils.isBlank(oldDoctor2)){
                    flag = true;
                }else{
                    if(!oldDoctor.equals(oldDoctor2)){
                        flag = true;
                    }
                }
            }
        }else{
            return ;
        }
        if(flag){
            TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(oldDoctor,patient);
            if(trackPatient!=null){
                trackPatient.setDel("0");
                trackPatientDao.save(trackPatient);
            }
        }
    }
}

+ 5 - 0
patient-co-service/wlyy_service/pom.xml

@ -189,6 +189,11 @@
            <artifactId>commons-discovery</artifactId>
            <version>0.5</version>
        </dependency>
        <dependency>
            <groupId>org.assertj</groupId>
            <artifactId>assertj-core</artifactId>
            <version>2.5.0</version>
        </dependency>
        <!-- 智业接口引用 END -->
    </dependencies>

+ 3 - 4
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/common/SystemConfig.java

@ -69,10 +69,9 @@ public class SystemConfig {
        return  getSystemProperties().getProperty("gateway_licence");
    }
    public String getPublicKey()
    {
        return  getSystemProperties().getProperty("gateway_public_key");
    }
    public String getPublicKey() { return  getSystemProperties().getProperty("gateway_public_key"); }
    
    public String getImmPublicKey() { return  getSystemProperties().getProperty("imm_public_key"); }
    public String getJwHospital()
    {

+ 14 - 1
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/ZysoftApi.java

@ -23,7 +23,20 @@ public class ZysoftApi extends AbstractApiExecuter {
    private static byte[]  publicKey;
    private static byte[]  zkzlPublicKey;
    private static byte[]  zkzlPrivateKey;
    private static String  immPublicKey;
    
    /**
     * 获取计免预约加密公钥
     */
    public static String getImmPublicKey() throws Exception {
        if(immPublicKey == null)
        {
            immPublicKey =  ZysoftApi.class.getClassLoader().getResource(SystemConfig.getInstance().getImmPublicKey()).toURI().getPath();
        }
        return immPublicKey;
    }
    
    /**
     * 智业公钥
     */
@ -165,7 +178,7 @@ public class ZysoftApi extends AbstractApiExecuter {
        return  apiCryptoParameter;
    }
    
    public String getCryptoCredential() throws Exception
    {
        return buildApiCryptoParameter().getTarget();

+ 68 - 7
patient-co-service/wlyy_service/src/main/java/com/yihu/wlyy/service/service/guahao/GuahaoService.java

@ -18,14 +18,19 @@ import org.apache.commons.lang3.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.hibernate.validator.internal.util.privilegedactions.GetResource;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.crypto.Cipher;
import java.io.*;
import java.security.PublicKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.security.KeyFactory;
import java.text.SimpleDateFormat;
import java.util.*;
@ -47,6 +52,16 @@ public class GuahaoService {
    private String ORDER_INFO = "GetReservationRecord";//预约信息
    private String REG_LIST = "GetRegList";//获取市民预约挂号信息
    /** *//**
     * RSA最大加密明文大小
     */
    private static final int MAX_ENCRYPT_BLOCK = 117;
    /** *//**
     * RSA最大解密密文大小
     */
    private static final int MAX_DECRYPT_BLOCK = 128;
    @Autowired
    private PatientDao patientDao;
@ -1179,7 +1194,7 @@ public class GuahaoService {
        
        int times = 0;
        try {
            re = ZysoftApi.getSingleton().post("imm/"+apistr, params, null,false);
            re = api.post("imm/"+apistr, params, null,false);
    
            //---结果验证,并保存日志 ---START
            if (StringUtils.isEmpty(re)) {
@ -1281,19 +1296,65 @@ public class GuahaoService {
        
        return result;
    }
    
    /**
     * 获取免疫接种机构列表
     * @param condition
     * @return
     */
    public String GetOrgImmuneList()throws Exception  {
        String result = "";
        Map<String,String> params = new HashMap<>();
        String condition = "<root><zone>350203</zone><zone>350206</zone><zone>350205</zone><zone>350211</zone><zone>350212</zone><zone>350213</zone></root>";
        ZysoftApi api = ZysoftApi.getSingleton();
        PublicKey publicKey=immPublicKeyget(api.getImmPublicKey());
        byte[] encryptedBytes = this.encrypt(condition.getBytes(),publicKey);
        condition = new String(encryptedBytes,"utf-8");
        System.out.println(condition);
        params.put("Condition", condition);
        return immPostSecond("GetOrgImmuneList","计免预约-获取免疫接种机构列表",params);
    }
    public static byte[] encrypt(byte[] data, PublicKey publicKey) throws Exception{
        Cipher cipher=Cipher.getInstance("RSA");//java默认"RSA"="RSA/ECB/PKCS1Padding"
        cipher.init(Cipher.ENCRYPT_MODE, publicKey);
        int inputLen = data.length;
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        int offSet = 0;
        byte[] cache;
        int i = 0;
        // 对数据分段加密
        while (inputLen - offSet > 0) {
            if (inputLen - offSet > MAX_ENCRYPT_BLOCK) {
                cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK);
            } else {
                cache = cipher.doFinal(data, offSet, inputLen - offSet);
            }
            out.write(cache, 0, cache.length);
            i++;
            offSet = i * MAX_ENCRYPT_BLOCK;
        }
        byte[] encryptedData = out.toByteArray();
        out.close();
        return encryptedData;
    }
    public PublicKey immPublicKeyget(String filename) throws Exception {
        File f = new File(filename);
        FileInputStream fis = new FileInputStream(f);
        DataInputStream dis = new DataInputStream(fis);
        byte[] keyBytes = new byte[(int)f.length()];
        dis.readFully(keyBytes);
        dis.close();
        X509EncodedKeySpec spec = new X509EncodedKeySpec(keyBytes);
        KeyFactory kf = KeyFactory.getInstance("RSA");
        return kf.generatePublic(spec);
    }
    
    
    
    /**
     * 获取免疫接种号源
@ -1377,7 +1438,7 @@ public class GuahaoService {
        params.put("BarCode", barCode);
        params.put("OrgCode", orgCode);
        params.put("SectionType", sectionType);
        params.put("strStart", strStart);
        params.put("StartTime", strStart);
        params.put("SSID", ssid);
        params.put("PatientName", patientName);
        params.put("PatientID", patientID);
@ -1419,7 +1480,7 @@ public class GuahaoService {
        params.put("BarCode", barCode);
        params.put("OrgCode", orgCode);
        params.put("SectionType", sectionType);
        params.put("strStart", strStart);
        params.put("StartTime", strStart);
        params.put("SSID", ssid);
        params.put("PatientName", patientName);
        params.put("PatientID", patientID);

BIN=BIN
patient-co-service/wlyy_service/src/main/resources/ImmPublicTest.key


+ 18 - 16
patient-co-service/wlyy_service/src/main/resources/system.properties

@ -1,20 +1,22 @@
###基卫测试环境服务
#gateway_url = http://117.25.173.18:18280/
#gateway_licence = 5YGl5bq45LmL7Lev
#gateway_public_key = PublicKeyTest.key
#jw_hospital = 350211B1013
#jw_licence = 5YGl5bq45LmL7Lev
#ca_url = http://117.29.183.114:8081/XMCAService?wsdl
#ca_namespace = http://platfomservice.xmca.com/
gateway_url = http://117.25.173.18:18280/
gateway_licence = 5YGl5bq45LmL7Lev
gateway_public_key = PublicKeyTest.key
imm_public_key=ImmPublicTest.key
jw_hospital = 350211B1013
jw_licence = 5YGl5bq45LmL7Lev
ca_url = http://117.29.183.114:8081/XMCAService?wsdl
ca_namespace = http://platfomservice.xmca.com/
##基卫服务
guahao_url =  http://10.95.18.10/urp.service/urp.open.service/ReservationPulic.asmx
guahao_namespace = http://www.zysoft.com.cn/
gateway_url = http://10.95.21.21:18280/
gateway_licence = 5YGl5bq45LmL7Lev
gateway_public_key = PublicGov.key
jw_hospital = 350211B1004
jw_licence = 5YGl5bq35LmL6LevMzUwMjExQjEwMDQ=
ca_url = http://10.95.21.21:18280/base/XMCA6_UnifiedCallInterface
ca_namespace = http://platfomservice.xmca.com/
#guahao_url =  http://10.95.18.10/urp.service/urp.open.service/ReservationPulic.asmx
#guahao_namespace = http://www.zysoft.com.cn/
#gateway_url = http://10.95.21.21:18280/
#gateway_licence = 5YGl5bq45LmL7Lev
#gateway_public_key = PublicGov.key
#imm_public_key=ImmPublic.key
#jw_hospital = 350211B1004
#jw_licence = 5YGl5bq35LmL6LevMzUwMjExQjEwMDQ=
#ca_url = http://10.95.21.21:18280/base/XMCA6_UnifiedCallInterface
#ca_namespace = http://platfomservice.xmca.com/

+ 120 - 0
patient-co/patient-co-statistics-es/readme.MD

@ -0,0 +1,120 @@
[es-sql](http://172.19.103.68:9200/_plugin/sql/) 例子
[elasticsearch-sql文档](https://github.com/NLPchina/elasticsearch-sql/wiki/Functions-support)
**重命名配置支持**
{elasticsearch_home}/config/elasticsearch.yml
```
script.inline: on
script.indexed: on
script.engine.groovy.inline.aggs: on
```
**目前2.4.2 es-sql不支持update delete**
6.x 系列的es支持delete
**查询表**
```SELECT * FROM wlyy_quota_test```
**条件查询表**
```SELECT * FROM wlyy_quota_test where townName='湖里区'```
**模糊查询**
SELECT * FROM wlyy_quota_test where townName like '%湖里%'
**查询返回单个字段**
```SELECT city FROM wlyy_quota_test```
**查询返回单个字段并且重命名**
```SELECT city as slavename FROM wlyy_quota_test```
**查询根据某个字段聚合**
```SELECT city  FROM wlyy_quota_test group by city```
**查询根据某个字段聚合并且重命名**
```SELECT city as slavename  FROM wlyy_quota_test group by slavename```
**条件查询并且排序表**
```SELECT * FROM wlyy_quota_test where townName='湖里区' order by createTime desc ```
**分页查询(分页查询不能与group by 同时使用)**
```SELECT city as slavename  FROM wlyy_quota_test limit 0,10```
**分页查询带条件(分页查询不能与group by 同时使用)**
```SELECT townName as slavename  FROM wlyy_quota_test where townName='湖里区' limit 0,10```
**count使用**
```SELECT count(*) num FROM wlyy_quota_test where townName='湖里区'```
**count distinct使用**
```select count( distinct town) from wlyy_quota_test```
**max使用**
```SELECT max(result1) FROM wlyy_quota_test where townName='湖里区'```
**min使用**
```SELECT min(result1) FROM wlyy_quota_test where townName='湖里区'```
**sum使用**
```select sum(result1) from wlyy_quota_test```
**按照年龄分组使用**
```SELECT count(age) FROM account GROUP BY range(age, 20,25,30,35,40)```
**时间聚合使用**
```select town,townName,sum(result1) result1 from wlyy_quota_test group by town,townName,date_histogram(field='quotaDate','interval'='month')```
interval例子
```
1天    date_histogram(field='quotaDate','interval'='1d')
每周   date_histogram(field='quotaDate','interval'='week')
每月   date_histogram(field='quotaDate','interval'='month')
每季度 date_histogram(field='quotaDate','interval'='quarter')
每年   date_histogram(field='quotaDate','interval'='year')
```
**子字段(nested)查询**
```SELECT townName.name FROM wlyy_quota_test where townName.name like '%湖里%'```
**join(只支持2个表,简单的查询 不支持分组)**
```select  table1.town town1 ,table2.townName townName2 from wlyy_quota_test table1 join wlyy_quota_test table2 on table1.town=table2.town```

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/template/DoctorTeamGuidanceTemplateDao.java

@ -67,8 +67,8 @@ public interface DoctorTeamGuidanceTemplateDao extends PagingAndSortingRepositor
    List<DoctorTeamGuidanceTemplate> countTeamListByTile(String doctor, String title);
    // 根据模板文章标题模糊搜索团队指导模板
    @Query("SELECT b FROM DoctorTeamGuidanceDetail a, DoctorTeamGuidanceTemplate b WHERE a.code = b.teamTemplateCode  " +
            " AND b.del = 1 AND b.creater = ?1 AND b.title LIKE ?2 order by b.useTimes desc ,b.createTime desc ")
    @Query("SELECT b FROM DoctorTeamGuidanceTemplate b ,DoctorTeamGuidanceDetail a WHERE a.code = b.teamTemplateCode  " +
            " AND b.del = 1 AND b.creater = ?1 AND b.title LIKE ?2 ")
    List<DoctorTeamGuidanceTemplate> getListByTile(String doctor, String title, Pageable pageRequest);
}

+ 53 - 40
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/account/DoctorInfoService.java

@ -29,6 +29,7 @@ import com.yihu.wlyy.repository.patient.SignFamilyDao;
import com.yihu.wlyy.repository.prescription.PrescriptionDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.app.sign.FamilyContractService;
import com.yihu.wlyy.service.app.talk.TalkGroupService;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.service.third.httplog.LogService;
@ -41,6 +42,8 @@ import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
@ -70,6 +73,7 @@ import java.util.*;
@Component
public class DoctorInfoService extends BaseService {
    private static Logger logger = LoggerFactory.getLogger(DoctorInfoService.class);
    @Autowired
    private DoctorDao doctorDao;
    @Autowired
@ -131,6 +135,9 @@ public class DoctorInfoService extends BaseService {
    @Autowired
    private LogService logService;
    @Autowired
    private FamilyContractService familyContractService;
    /**
     * 获取医生的签约病人
     *
@ -851,6 +858,9 @@ public class DoctorInfoService extends BaseService {
        Doctor newD = doctorDao.findByCode(newDoctorCode);
        String oldDoctorHealthName = signFamily.getDoctorHealthName();
        //1.4.2更新重点关注列表,取消关注
        familyContractService.updateTrackPatient(patient,signFamily.getDoctorHealth(),signFamily.getDoctor(),null,newDoctorCode);
        //修改签约中的健康管理师
        signFamily.setDoctorHealth(newD.getCode());
        signFamily.setDoctorHealthName(newD.getName());
@ -1004,6 +1014,10 @@ public class DoctorInfoService extends BaseService {
        }
        Doctor newD = doctorDao.findByCode(newDoctorCode);
        //1.4.2更新重点关注列表,取消关注
        familyContractService.updateTrackPatient(patient,signFamily.getDoctorHealth(),signFamily.getDoctor(),null,newDoctorCode);
        //修改签约中的健康管理师
        signFamily.setDoctorHealth(newD.getCode());
        signFamily.setDoctorHealthName(newD.getName());
@ -1226,6 +1240,10 @@ public class DoctorInfoService extends BaseService {
        Doctor newD = doctorDao.findByCode(newDoctorCode);
        String oldDoctorName = signFamily.getDoctorName();
        //1.4.2更新重点关注列表,取消关注
        familyContractService.updateTrackPatient(patient,signFamily.getDoctor(),signFamily.getDoctorHealth(),newDoctorCode,null);
        //修改签约中的全科医生
        signFamily.setDoctor(newD.getCode());
        signFamily.setDoctorName(newD.getName());
@ -1242,50 +1260,45 @@ public class DoctorInfoService extends BaseService {
        newDoctorTeamMember.setCode(UUID.randomUUID().toString().replace("-", ""));
        doctorTeamDoctor.save(newDoctorTeamMember);
        Patient p = patientDao.findByCode(patient);
        JSONObject data = new JSONObject();
        data.put("toUser", patient);
        data.put("represented",patient);//被代理人
        data.put("doctor", newD.getCode());
        data.put("doctorName", newD.getName());
        data.put("keyword3", "家庭医生-全科医生");
        data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
        data.put("keyword1", newD.getName());
        if (StringUtils.isEmpty(signFamily.getDoctorHealth()) || signFamily.getDoctor().equals(signFamily.getDoctorHealth())) {
            data.put("remark", newD.getName() + "医生将继续为您提供优质健康服务");
        } else {
            data.put("remark", newD.getName() + "医生将继续为您提供优质健康服务");
        }
        try{
            Patient p = patientDao.findByCode(patient);
            JSONObject data = new JSONObject();
            data.put("toUser", patient);
            data.put("represented",patient);//被代理人
            data.put("doctor", newD.getCode());
            data.put("doctorName", newD.getName());
            data.put("keyword3", "家庭医生-全科医生");
            data.put("keyword2", DateUtil.dateToStrNoSecond(new Date()));
            data.put("keyword1", newD.getName());
            if (StringUtils.isEmpty(signFamily.getDoctorHealth()) || signFamily.getDoctor().equals(signFamily.getDoctorHealth())) {
                data.put("remark", newD.getName() + "医生将继续为您提供优质健康服务");
            } else {
                data.put("remark", newD.getName() + "医生将继续为您提供优质健康服务");
            }
        if (StringUtils.isNotBlank(p.getOpenid())) {
            data.put("first", p.getName() + ",您签约团队的全科医生已变更,您的新全科医生信息如下:");
            pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), data);
        }
//        else {
//            //如果自己没有绑定,则发给家人
//            JSONObject json = weiXinOpenIdUtils.getFamilyOpenId(p.getCode());
//            Patient member = (Patient) json.get("member");
//            if (StringUtils.isNotBlank(member.getOpenid())) {
//                data.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) json.get("relation"), member.getName()) + p.getName() + ",您好!因签约团队内分工调整,您的责任医生有变动," + oldDoctorName +
//                        "医生无法继续为您服务,具体变动如下:");
//                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), member.getName(), data);
//            }
//        }
            if (StringUtils.isNotBlank(p.getOpenid())) {
                data.put("first", p.getName() + ",您签约团队的全科医生已变更,您的新全科医生信息如下:");
                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, p.getOpenid(), p.getName(), data);
            }
        //发送代理人
        JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
        if(jsonArray!=null&&jsonArray.length()>0){
            for (int i = 0;i<jsonArray.length();i++){
                JSONObject j  = jsonArray.getJSONObject(i);
                Patient member = (Patient) j.get("member");
                JSONObject json = data;
                json.remove("toUser");
                json.put("toUser",member.getCode());
                json.remove("first");
                json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) json.get("relation"), p.getName()) + p.getName() + ",您好!您签约团队的全科医生已变更,您的新全科医生信息如下:");
                pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), json);
            //发送代理人
            JSONArray jsonArray = weiXinOpenIdUtils.getAgentOpenId(p.getCode(),p.getOpenid());
            if(jsonArray!=null&&jsonArray.length()>0){
                for (int i = 0;i<jsonArray.length();i++){
                    JSONObject j  = jsonArray.getJSONObject(i);
                    Patient member = (Patient) j.get("member");
                    JSONObject json = data;
                    json.remove("toUser");
                    json.put("toUser",member.getCode());
                    json.remove("first");
                    json.put("first", weiXinOpenIdUtils.getTitleMes(p, (int) json.get("relation"), p.getName()) + p.getName() + ",您好!您签约团队的全科医生已变更,您的新全科医生信息如下:");
                    pushMsgTask.putWxMsg(accessTokenUtils.getAccessToken(), 10, member.getOpenid(), p.getName(), json);
                }
            }
        }catch (Exception e){
            logger.info(e.getMessage());
        }
    }
//    /**

+ 66 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -161,6 +161,8 @@ public class FamilyContractService extends BaseService {
    private String targetUrl;
    @Autowired
    private HttpClientUtil httpClientUtil;
    @Autowired
    private TrackPatientDao trackPatientDao;
    public SignFamily findSignFamilyByCode(String code) {
@ -2277,6 +2279,9 @@ public class FamilyContractService extends BaseService {
        SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
        String oldDoctor = signFamily.getDoctor();
        String oldHdoctor = signFamily.getDoctorHealth();
        if (signFamily == null) {
            result.put("status", -1);
            result.put("msg", "居民不存在家庭签约");
@ -2374,6 +2379,9 @@ public class FamilyContractService extends BaseService {
                doctorTeamDoctor.save(newTeamMember);
            }
            //1.4.2更新重点关注列表,取消关注
            updateTrackPatient(patient,oldHdoctor,oldDoctor,doctor,healthDoctor);
            signFamily.setDoctorHealth(docHealth.getCode());
            signFamily.setDoctorHealthName(docHealth.getName());
            signFamily.setCzrq(new Date());
@ -2425,6 +2433,9 @@ public class FamilyContractService extends BaseService {
                doctorTeamDoctor.save(newTeamMember);
            }
            //1.4.2更新重点关注列表,取消关注
            updateTrackPatient(patient,oldDoctor,oldHdoctor,doctor,healthDoctor);
            signFamily.setDoctor(docQk.getCode());
            signFamily.setDoctorName(docQk.getName());
            signFamily.setCzrq(new Date());
@ -4316,4 +4327,59 @@ public class FamilyContractService extends BaseService {
        return rs;
    }
    /**
     * 设置取消关注
     * @param patient
     * @param oldDoctor 患者签约旧的要取消关注的医生
     * @param oldDoctor2 患者旧的签约的另一个医生
     * @param newDoctor 患者新签约的全科医生
     * @param newHDoctor 患者新签约的健康管理师
     */
    public void updateTrackPatient(String patient,String oldDoctor,String oldDoctor2,String newDoctor,String newHDoctor){
        //是否需要修改
        boolean flag = false;
        if(StringUtils.isBlank(oldDoctor)){
            return ;
        }
        //1.两个都修改
        if(StringUtils.isNotBlank(newDoctor)&&StringUtils.isNotBlank(newHDoctor)){
            if((!oldDoctor.equals(newDoctor))&&(!oldDoctor.equals(newHDoctor))){
                flag = true;
            }
        //只改全科
        }else if(StringUtils.isNotBlank(newDoctor)&&StringUtils.isBlank(newHDoctor)){
            if(!oldDoctor.equals(newDoctor)){
                if(StringUtils.isBlank(oldDoctor2)){
                    flag = true;
                }else{
                    if(!oldDoctor.equals(oldDoctor2)){
                        flag = true;
                    }
                }
            }
        //只改健管
        }else if(StringUtils.isBlank(newDoctor)&&StringUtils.isNotBlank(newHDoctor)){
            if(!oldDoctor.equals(newHDoctor)){
                if(StringUtils.isBlank(oldDoctor2)){
                    flag = true;
                }else{
                    if(!oldDoctor.equals(oldDoctor2)){
                        flag = true;
                    }
                }
            }
        }else{
            return ;
        }
       if(flag){
            TrackPatient trackPatient = trackPatientDao.findByDoctorCodeAndPatientCode(oldDoctor,patient);
            if(trackPatient!=null){
                trackPatient.setDel("0");
                trackPatientDao.save(trackPatient);
            }
        }
    }
}

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

@ -175,9 +175,9 @@ public class ServiceStatisticsService extends BaseService {
        }*/
        //数据转移至Es
        String sqlHistory="select count(*) AS h from " + esType + " where patients.code='" + patient + "' and adminTeamCode = '"+teamCode+"'";
        String sqlYear = "select count(*) AS y from "+esType+" where patients.code='" + patient + "' and adminTeamCode = '"+teamCode+"' and czrq >= "+changeDate(yearBegin)+" and czrq <= "+changeDate(yearEnd);
        String sqlMonth = "select count(*) AS m from "+esType+" where patients.code='" + patient + "' and adminTeamCode = '"+teamCode+"' and czrq >= "+changeDate(monthBegin);
        String sqlHistory="select count(*) AS h from " + esType + " where patientCode='" + patient + "' and adminTeamCode = '"+teamCode+"'";
        String sqlYear = "select count(*) AS y from "+esType+" where patientCode='" + patient + "' and adminTeamCode = '"+teamCode+"' and czrq >= "+changeDate(yearBegin)+" and czrq <= "+changeDate(yearEnd);
        String sqlMonth = "select count(*) AS m from "+esType+" where patientCode='" + patient + "' and adminTeamCode = '"+teamCode+"' and czrq >= "+changeDate(monthBegin);
        result.put("history", elasticsearchUtil.excuteForLong(sqlHistory,esType,esIndex));
        result.put("year", elasticsearchUtil.excuteForLong(sqlYear,esType,esIndex));

+ 1 - 5
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/imm/ChildFamilyImmuneService.java

@ -45,11 +45,7 @@ public class ChildFamilyImmuneService extends BaseService {
	public void addFamilyMembers(ChildInfo childInfo, String uid, String idcard, String ssc,Integer relation) throws Exception {
		
		ChildFamilyImmune childFamilyImmune = new ChildFamilyImmune();
		if(childInfo.getId() == null
				|| StringUtils.isBlank(childInfo.getIdcard())
					|| StringUtils.isBlank(childInfo.getSsc())){
			childInfo.setIdcard(idcard);
			childInfo.setSsc(ssc);
		if(childInfo.getId() == null){
			childInfoDao.save(childInfo);
		}else{
			childFamilyImmune = childFamilyImmuneDao.findByfaAndChildCodeAndFamilyCode(childInfo.getCode(),uid);

+ 3 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/template/DoctorTeamGuidanceService.java

@ -268,8 +268,8 @@ public class DoctorTeamGuidanceService extends BaseService {
     * @return
     * @throws Exception
     */
    public List getTeamGuidanceList(String doctor, String filter, int teamId, int pageNo, int pageSize) throws Exception {
        Sort sort = new Sort(Sort.Direction.DESC, "createTime");
    public List getTeamGuidanceList(String doctor, String filter, Integer teamId, int pageNo, int pageSize) throws Exception {
        Sort sort = new Sort(Sort.Direction.DESC, "useTimes","createTime");
        PageRequest request = new PageRequest(pageNo, pageSize, sort);
        List list = new ArrayList();
        List<DoctorTeamGuidanceTemplate> listGuidances = null;
@ -288,6 +288,7 @@ public class DoctorTeamGuidanceService extends BaseService {
            map.put("teamTemplateCode", teamTemplateCode);
            map.put("title", title);
            map.put("useTimes", useTimes);
            map.put("createTime", guidance.getCreateTime());
            list.add(map);
        }

+ 1 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java

@ -1163,6 +1163,7 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            }
            return write(200, "更新成功");
        } catch (Exception e) {
            error(e);
            return error(-1, "更新失败");
        }
    }

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/family/FamilyMemberController.java

@ -494,11 +494,11 @@ public class FamilyMemberController extends WeixinBaseController {
    
            ChildInfo childInfo  = childInfoService.getByBarCode(barCode);
            
            if(!idcard.equals(childInfo.getIdcard()) && StringUtils.isNotBlank(childInfo.getIdcard())){
            if(StringUtils.isNotBlank(idcard) && !idcard.equals(childInfo.getIdcard()) && StringUtils.isNotBlank(childInfo.getIdcard())){
                return error(-1, "输入的新生儿身份证信息不一致,无法绑定");
            }
    
            if(!ssc.equals(childInfo.getSsc()) && StringUtils.isNotBlank(childInfo.getSsc())){
            if(StringUtils.isNotBlank(ssc)&& !ssc.equals(childInfo.getSsc()) && StringUtils.isNotBlank(childInfo.getSsc())){
                return error(-1, "输入的新生儿社保卡不一致,无法绑定");
            }