You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
356 lines
13 KiB
356 lines
13 KiB
2 years ago
|
package com.ynxbd.common.dao;
|
||
|
|
||
|
import com.ynxbd.common.bean.Patient;
|
||
|
import com.ynxbd.common.bean.PatientLink;
|
||
|
import com.ynxbd.common.bean.enums.HCardTypeEnum;
|
||
|
import com.ynxbd.common.config.db.DataBase;
|
||
|
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
|
||
|
/**
|
||
|
* 患者表操作
|
||
|
*
|
||
|
* @Author wsq
|
||
|
* @Date 2020/9/25 11:08
|
||
|
* @Copyright @ 2020 云南新八达科技有限公司 All rights reserved.
|
||
|
*/
|
||
|
public class PatientDao {
|
||
|
|
||
|
/**
|
||
|
* 根据openid查询绑定健康卡的用户
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @return 患者集合
|
||
|
*/
|
||
|
public List<Patient> selectHealthCardListByOpenid(String openid) {
|
||
|
String sql = "select * from patientBase where openid= ? and deletedState = 0 and healthCardId is not null";
|
||
|
return DataBase.select(sql, Patient.class, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据openid查询患者
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @return 患者列表
|
||
|
*/
|
||
|
public List<Patient> selectListByToken(String openid, String unionId) {
|
||
|
if (unionId == null || "".equals(unionId)) {
|
||
|
return selectListByOpenid(openid);
|
||
|
}
|
||
|
String sql = "select * from patientBase where openid = ? and deletedState = 0 order by isDefault desc";
|
||
|
return DataBase.select(sql, Patient.class, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据openid查询患者
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @return 患者列表
|
||
|
*/
|
||
|
public List<Patient> selectListByOpenid(String openid) {
|
||
|
String sql = "select * from patientBase where openid = ? and deletedState = 0 order by isDefault desc";
|
||
|
return DataBase.select(sql, Patient.class, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据openid查询患者 部分信息 用作外部对接
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @return 患者列表
|
||
|
*/
|
||
|
public List<PatientLink> selectPatientsByOpenid(String openid) {
|
||
|
String sql = "select OpenID,PatientID,Name,Sex,IDCardNo,Age,Birthday,Address,Nation from patientBase where openid = ? and deletedState = 0 order by isDefault desc";
|
||
|
return DataBase.select(sql, PatientLink.class, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
});
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据身份证查询患者
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @param idCardNo 身份证号
|
||
|
* @return 患者信息
|
||
|
*/
|
||
|
public Patient selectByIdCardNo(String openid, String idCardNo) {
|
||
|
String sql = "select * from patientBase where openid= ? and idCardNo= ?";
|
||
|
List<Patient> resultList = DataBase.select(sql, Patient.class, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
ps.setString(2, idCardNo);
|
||
|
});
|
||
|
return resultList.size() > 0 ? resultList.get(0) : null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 根据身份证查询患者
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @param patientId 患者ID
|
||
|
* @return 患者信息
|
||
|
*/
|
||
|
public boolean hasPatient(String openid, String patientId) {
|
||
|
return selectByOpenidAndPatientId(openid, patientId) != null;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 根据身份证查询患者
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @return 患者信息
|
||
|
*/
|
||
|
public Patient selectMyself(String openid) {
|
||
|
String sql = "select * from patientBase where openid= ? and isMyself = 1";
|
||
|
List<Patient> resultList = DataBase.select(sql, Patient.class, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
});
|
||
|
return resultList.size() > 0 ? resultList.get(0) : null;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 根据身份证查询患者
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @param patientId 患者ID
|
||
|
* @return 患者信息
|
||
|
*/
|
||
|
public Patient selectByOpenidAndPatientId(String openid, String patientId) {
|
||
|
String sql = "select * from patientBase where openid= ? and patientId= ? and deletedState = 0";
|
||
|
List<Patient> resultList = DataBase.select(sql, Patient.class, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
ps.setString(2, patientId);
|
||
|
});
|
||
|
return resultList.size() > 0 ? resultList.get(0) : null;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 健康卡解绑
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @param patientId 身份证号
|
||
|
* @return 是否成功
|
||
|
*/
|
||
|
public boolean removePatient(String openid, String patientId) {
|
||
|
String sql = "update patientBase set updateTime=now(), deletedState=1 where openid=? and patientId=?";
|
||
|
return DataBase.update(sql, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
ps.setString(2, patientId);
|
||
|
}) > 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 更新用户信息
|
||
|
*
|
||
|
* @param openid openid
|
||
|
* @param idCardNo idCardNo
|
||
|
* @param healthCardId 健康卡id
|
||
|
* @param name 姓名
|
||
|
* @param nation 民族
|
||
|
* @param tel 电话
|
||
|
* @param address 地址
|
||
|
* @return 是否成功
|
||
|
*/
|
||
|
public boolean updateInfo(String openid, String idCardNo, String patientId, String healthCardId, String name, String nation, String tel, String address, String uuid, String county) {
|
||
|
String sql = "update patientBase set deletedState=0, healthCardId=?, name=?, nation=?, tel=?, address=?, uuid=?, county=?, patientId=? where openid=? and idCardNo=?";
|
||
|
|
||
|
return DataBase.update(sql, ps -> {
|
||
|
ps.setString(1, healthCardId);
|
||
|
ps.setString(2, name);
|
||
|
ps.setString(3, nation);
|
||
|
ps.setString(4, tel);
|
||
|
ps.setString(5, address);
|
||
|
ps.setString(6, uuid);
|
||
|
ps.setString(7, county);
|
||
|
ps.setString(8, patientId);
|
||
|
// 条件
|
||
|
ps.setString(9, openid);
|
||
|
ps.setString(10, idCardNo);
|
||
|
}) > 0;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* [患者]绑定身份证(成人)
|
||
|
*
|
||
|
* @param healthCardId 健康卡ID
|
||
|
* @param openid openid
|
||
|
* @param patientId 患者ID
|
||
|
* @param hisTransNo hisTransNo
|
||
|
* @param name 姓名
|
||
|
* @param sex 性别
|
||
|
* @param idCardNo 身份证
|
||
|
* @param tel 电话
|
||
|
* @param address 地址
|
||
|
* @param birthday 生日
|
||
|
* @param nation 民族
|
||
|
*/
|
||
|
public boolean insertCard(boolean isMyself, String healthCardId, String openid, String patientId, String hisTransNo,
|
||
|
String name, String sex, String idCardNo, HCardTypeEnum cardTypeEnum, String birthday, String age,
|
||
|
String address, String nation, String tel, String uuid, String county) {
|
||
|
return insert(isMyself, healthCardId, openid, patientId, hisTransNo, name, sex, idCardNo, cardTypeEnum, birthday, age, address, nation, tel, uuid, county, null, null, null, null, null, null);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* [患者]绑定身份证
|
||
|
*
|
||
|
* @param healthCardId 健康卡ID
|
||
|
* @param openid openid
|
||
|
* @param patientId 患者ID
|
||
|
* @param hisTransNo hisTransNo
|
||
|
* @param name 姓名
|
||
|
* @param sex 性别
|
||
|
* @param idCardNo 身份证
|
||
|
* @param tel 电话
|
||
|
* @param address 地址
|
||
|
* @param birthday 生日
|
||
|
* @param nation 民族
|
||
|
* @param fName 父亲姓名
|
||
|
* @param fTel 父亲电话
|
||
|
* @param fIDCardNo 父亲身份证
|
||
|
* @param mName 母亲姓名
|
||
|
* @param mTel 母亲电话
|
||
|
* @param mIDCardNo 母亲身份证号
|
||
|
*/
|
||
|
public boolean insert(boolean isMyself, String healthCardId, String openid, String patientId, String hisTransNo,
|
||
|
String name, String sex, String idCardNo, HCardTypeEnum cardTypeEnum, String birthday, String age,
|
||
|
String address, String nation, String tel, String uuid, String county,
|
||
|
String fName, String fTel, String fIDCardNo,
|
||
|
String mName, String mTel, String mIDCardNo) {
|
||
|
|
||
|
String sql = "insert into patientBase(bindDate, openid, patientId, hisTransNo, name, sex, idCardNo, tel, address, birthday, nation, healthCardId, age, uuid, fatherName, fatherTel, fatherIDCardNo, motherName, motherTel, motherIDCardNo, county, isMyself, cardType) " +
|
||
|
" values(now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?)";
|
||
|
return DataBase.insert(sql, ps -> {
|
||
|
ps.setString(1, openid);
|
||
|
ps.setString(2, patientId);
|
||
|
ps.setString(3, hisTransNo);
|
||
|
ps.setString(4, name);
|
||
|
ps.setString(5, sex);
|
||
|
ps.setString(6, idCardNo);
|
||
|
ps.setString(7, tel);
|
||
|
ps.setString(8, address);
|
||
|
ps.setString(9, birthday);
|
||
|
ps.setString(10, nation);
|
||
|
ps.setString(11, healthCardId);
|
||
|
ps.setString(12, age);
|
||
|
ps.setString(13, uuid);
|
||
|
//
|
||
|
ps.setString(14, fName);
|
||
|
ps.setString(15, fTel);
|
||
|
ps.setString(16, fIDCardNo);
|
||
|
ps.setString(17, mName);
|
||
|
ps.setString(18, mTel);
|
||
|
ps.setString(19, mIDCardNo);
|
||
|
ps.setString(20, county);
|
||
|
ps.setBoolean(21, isMyself);
|
||
|
ps.setString(22, cardTypeEnum.WX_CODE);
|
||
|
}) > 0;
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 查询所有未领取健康卡的用户信息,民族、电话不能为空,一次读取15条信息
|
||
|
*/
|
||
|
public List<Patient> selectPatient4BatchUpdateHealthCard() {
|
||
|
String sql = "select * from patientBase where HealthCardID is null and ifnull(idcardno,'') <> '' " +
|
||
|
"and ifnull(nation,'') <> '' and ifnull(tel, '') <> '' and callFlag=0 LIMIT 15";
|
||
|
return DataBase.select(sql, Patient.class);
|
||
|
}
|
||
|
|
||
|
|
||
|
/**
|
||
|
* 批量领卡后,更新健康卡ID
|
||
|
*
|
||
|
* @param healthCardId 健康卡id
|
||
|
* @param idCardNo 身份证
|
||
|
*/
|
||
|
public boolean updateHealthCard(String healthCardId, String idCardNo) {
|
||
|
String sql = "update patientBase set healthCardId = ? where idCardNo = ?";
|
||
|
return DataBase.update(sql, ps -> {
|
||
|
ps.setString(1, healthCardId);
|
||
|
ps.setString(2, idCardNo);
|
||
|
}) > 0;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 批量领卡调用标记(领取成功与否都更新为1)
|
||
|
*
|
||
|
* @param idCardNo 身份证
|
||
|
* @return
|
||
|
*/
|
||
|
public boolean updateCallFlag(String idCardNo) {
|
||
|
String sql = "update patientBase set callFlag = 1 where idCardNo = ?";
|
||
|
return DataBase.update(sql, ps -> {
|
||
|
ps.setString(1, idCardNo);
|
||
|
}) > 0;
|
||
|
}
|
||
|
|
||
|
public List<Patient> selectOpenIdsByPatientId(String patientId) {
|
||
|
List<Patient> dataList = DataBase.select("select bindDate, openid from patientBase where patientId= ? and deletedState = 0 and openid is not null and length(openid) > 20 order by bindDate desc", Patient.class, ps -> {
|
||
|
ps.setString(1, patientId);
|
||
|
});
|
||
|
|
||
|
if (dataList.size() == 0) {
|
||
|
return new ArrayList<>();
|
||
|
}
|
||
|
return dataList;
|
||
|
}
|
||
|
|
||
|
public List<Patient> selectOpenIdsByCardNo(String cardNo) {
|
||
|
List<Patient> dataList = DataBase.select("select bindDate, openid from patientBase where idCardNo= ? and deletedState = 0 and openid is not null and length(openid) > 20 order by bindDate desc", Patient.class, ps -> {
|
||
|
ps.setString(1, cardNo);
|
||
|
});
|
||
|
|
||
|
if (dataList.size() == 0) {
|
||
|
return new ArrayList<>();
|
||
|
}
|
||
|
return dataList;
|
||
|
}
|
||
|
|
||
|
public List<Patient> selectListByPatientId(String patientId) {
|
||
|
List<Patient> dataList = DataBase.select("select * from patientBase where patientId= ? and deletedState = 0 order by bindDate desc", Patient.class, ps -> {
|
||
|
ps.setString(1, patientId);
|
||
|
});
|
||
|
|
||
|
if (dataList.size() == 0) {
|
||
|
return new ArrayList<>();
|
||
|
}
|
||
|
return dataList;
|
||
|
|
||
|
}
|
||
|
|
||
|
public boolean updateMyself(String openid, String idCardNo, String patientId, String name, String address, String county, String nation, String tel) {
|
||
|
if (idCardNo == null) {
|
||
|
return false;
|
||
|
}
|
||
|
idCardNo = "'" + idCardNo + "'";
|
||
|
String sql = "update patientBase set isMyself = (CASE idCardNo WHEN " + idCardNo + " THEN 1 else 0 end)," +
|
||
|
" deletedState = (CASE idCardNo WHEN " + idCardNo + " THEN 0 else deletedState end)," +
|
||
|
" county = (CASE idCardNo WHEN " + idCardNo + " THEN ? else county end)," +
|
||
|
" address = (CASE idCardNo WHEN " + idCardNo + " THEN ? else address end)," +
|
||
|
" patientId = (CASE idCardNo WHEN " + idCardNo + " THEN ? else patientId end)," +
|
||
|
" name = (CASE idCardNo WHEN " + idCardNo + " THEN ? else name end)," +
|
||
|
" tel = (CASE idCardNo WHEN " + idCardNo + " THEN ? else tel end)," +
|
||
|
" nation = (CASE idCardNo WHEN " + idCardNo + " THEN ? else nation end)" +
|
||
|
" where openid = ?";
|
||
|
return DataBase.update(sql, ps -> {
|
||
|
ps.setString(1, county);
|
||
|
ps.setString(2, address);
|
||
|
ps.setString(3, patientId);
|
||
|
ps.setString(4, name);
|
||
|
ps.setString(5, tel);
|
||
|
ps.setString(6, nation);
|
||
|
//---------------------------------------
|
||
|
ps.setString(7, openid);
|
||
|
}) > 0;
|
||
|
}
|
||
|
}
|