123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605 |
- package com.yihu.wlyy.service.app.sign;
- import java.util.*;
- import com.yihu.wlyy.entity.organization.Hospital;
- import com.yihu.wlyy.entity.dict.SystemDict;
- import com.yihu.wlyy.entity.doctor.profile.Doctor;
- import com.yihu.wlyy.entity.doctor.team.sign.DoctorPatientGroupInfo;
- import com.yihu.wlyy.entity.doctor.profile.DoctorService;
- import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeam;
- import com.yihu.wlyy.entity.doctor.team.sign.DoctorTeamMember;
- import com.yihu.wlyy.entity.message.Message;
- import com.yihu.wlyy.entity.patient.Patient;
- import com.yihu.wlyy.entity.patient.PatientDisease;
- import com.yihu.wlyy.entity.patient.SignFamily;
- import com.yihu.wlyy.entity.patient.SignFamilyCode;
- import com.yihu.wlyy.repository.consult.ConsultTeamDao;
- import com.yihu.wlyy.repository.dict.SystemDictDao;
- import com.yihu.wlyy.repository.doctor.*;
- import com.yihu.wlyy.repository.message.MessageDao;
- import com.yihu.wlyy.repository.organization.HospitalDao;
- import com.yihu.wlyy.repository.patient.PatientDao;
- import com.yihu.wlyy.repository.patient.PatientDiseaseDao;
- import com.yihu.wlyy.repository.patient.SignFamilyDao;
- import com.yihu.wlyy.repository.patient.SocialSecurityInfoDao;
- import com.yihu.wlyy.repository.statistics.WlyySignFamilyCodeDao;
- import com.yihu.wlyy.service.app.disease.PatientDiseaseService;
- import com.yihu.wlyy.service.app.label.SignPatientLabelInfoService;
- import com.yihu.wlyy.task.SignUploadTask;
- import org.apache.commons.lang3.StringUtils;
- import org.json.JSONArray;
- import org.json.JSONObject;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.data.domain.Sort;
- import org.springframework.data.domain.Sort.Direction;
- import org.springframework.data.jpa.domain.Specification;
- import org.springframework.data.redis.core.StringRedisTemplate;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.stereotype.Component;
- import org.springframework.transaction.annotation.Transactional;
- import org.springside.modules.persistence.DynamicSpecifications;
- import org.springside.modules.persistence.SearchFilter;
- import org.springside.modules.persistence.SearchFilter.Operator;
- import com.yihu.wlyy.service.BaseService;
- import com.yihu.wlyy.task.PushMsgTask;
- import com.yihu.wlyy.util.DateUtil;
- import com.yihu.wlyy.util.IdcardInfoExtractor;
- import com.yihu.wlyy.util.MessageType;
- /**
- * 家庭签约业务处理类
- *
- * @author George
- */
- @Component
- @Transactional
- public class FamilyContractService extends BaseService {
- @Autowired
- private DoctorPatientDao doctorPatientDao;
- @Autowired
- private SignFamilyDao signFamilyDao;
- @Autowired
- private DoctorServiceDao doctorServiceDao;
- @Autowired
- private HospitalDao hospitalDao;
- @Autowired
- private DoctorDao doctorDao;
- @Autowired
- private PatientDao patientDao;
- @Autowired
- private MessageDao messageDao;
- @Autowired
- private DoctorTeamDao doctorTeamDao;
- @Autowired
- private DoctorTeamMemberDao doctorTeamDoctor;
- @Autowired
- private DoctorPatientGroupInfoDao doctorPatientGroupInfoDao;
- @Autowired
- private ConsultTeamDao consultTeamDao;
- @Autowired
- private JdbcTemplate jdbcTemplate;
- @Autowired
- private WlyySignFamilyCodeDao wlyySignFamilyCodeDao;
- @Autowired
- private SystemDictDao systemDictDao;
- @Autowired
- private PatientDiseaseService patientDiseaseService;
- @Autowired
- private PatientDiseaseDao patientDiseaseDao;
- @Autowired
- private SocialSecurityInfoDao socialSecurityInfoDao;
- @Autowired
- private SignPatientLabelInfoService labelInfoService;
- @Autowired
- private DoctorAdminTeamDao doctorAdminTeamDao;
- public SignFamily findSignFamilyByCode(String code) {
- return signFamilyDao.findByCodeAndType(code, 2);
- }
- public SignFamily findByPatientByType(String patient, int type) {
- return signFamilyDao.findByPatientAndType(patient, type);
- }
- public SignFamily findByPatient(String patient) {
- return signFamilyDao.findByjiatingPatient(patient);
- }
- public SignFamily findSignByPatient(String patient) {
- return signFamilyDao.findSignByPatient(patient);
- }
- /**
- * 获取患者待签约数据
- *
- * @param patient
- * @return
- */
- public SignFamily findSigningByPatient(String patient) {
- return signFamilyDao.findSigningByPatient(patient);
- }
- /**
- * 查询医院列表
- *
- * @param type 医院类型:0全部,1大医院,2社区医院
- * @param province 省代码
- * @param city 城市代码
- * @param key 搜索关键字
- * @param id
- * @param pagesize 分页大小
- * @return
- */
- public Page<Hospital> findHospitals(int type, String province, String city, String town, String key, long id, int pagesize) {
- if (pagesize <= 0) {
- pagesize = 10;
- }
- // 排序
- Sort sort = new Sort(Direction.ASC, "id");
- // 分页信息
- PageRequest pageRequest = new PageRequest(0, pagesize, sort);
- // 设置查询条件
- Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
- if (type == 1) {
- // 查询大医院
- filters.put("level", new SearchFilter("level", Operator.EQ, 1));
- } else if (type == 2) {
- // 查询社区医院
- filters.put("level", new SearchFilter("level", Operator.EQ, 2));
- }
- if (StringUtils.isNotEmpty(province)) {
- filters.put("province", new SearchFilter("province", Operator.EQ, province));
- }
- if (StringUtils.isNotEmpty(city)) {
- filters.put("city", new SearchFilter("city", Operator.EQ, city));
- }
- if (StringUtils.isNotEmpty(town)) {
- filters.put("town", new SearchFilter("town", Operator.EQ, town));
- }
- if (StringUtils.isNotEmpty(key)) {
- filters.put("name", new SearchFilter("name", Operator.LIKE, key));
- }
- if (id > 0) {
- filters.put("id", new SearchFilter("id", Operator.GT, id));
- }
- // 未作废
- filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
- Specification<Hospital> spec = DynamicSpecifications.bySearchFilter(filters.values(), Hospital.class);
- return hospitalDao.findAll(spec, pageRequest);
- }
- /**
- * 查询医院下的医生
- *
- * @param hospital
- * @param level 医生类型:1专科医生,2全科医生,3健康管理师
- * @return
- */
- public Page<Doctor> findDoctors(String hospital, int level, long id, int pagesize) {
- if (pagesize <= 0) {
- pagesize = 10;
- }
- // 排序
- Sort sort = new Sort(Direction.ASC, "id");
- // 分页信息
- PageRequest pageRequest = new PageRequest(0, pagesize, sort);
- // 设置查询条件
- Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
- if (StringUtils.isNoneEmpty(hospital)) {
- filters.put("hospital", new SearchFilter("hospital", Operator.EQ, hospital));
- }
- if (id > 0) {
- filters.put("id", new SearchFilter("id", Operator.GT, id));
- }
- // 医生类型过滤
- if (level > 0) {
- filters.put("level", new SearchFilter("level", Operator.EQ, level));
- }
- // 未作废
- filters.put("status", new SearchFilter("status", Operator.EQ, 1));
- Specification<Doctor> spec = DynamicSpecifications.bySearchFilter(filters.values(), Doctor.class);
- return doctorDao.findAll(spec, pageRequest);
- }
- /**
- * 查询医生主页信息
- *
- * @param doctor 医生标识
- * @param patient 患者标识
- * @return
- */
- public JSONObject findDoctorMainPage(String patient, String doctor) {
- JSONObject json = new JSONObject();
- // 查询医生基本信息
- Doctor d = doctorDao.findByCode(doctor);
- json.put("doctor", d.getCode());
- json.put("name", d.getName());
- json.put("photo", d.getPhoto());
- json.put("sex", d.getSex());
- json.put("job", d.getJob());
- json.put("jobName", d.getJobName());
- json.put("hospital", d.getHosptialName());
- json.put("dept", d.getDeptName());
- json.put("intro", d.getIntroduce());
- json.put("expertise", d.getExpertise());
- // 查询与当前医生的签约状态
- SignFamily sf = signFamilyDao.findByDoctorPatient(doctor, patient);
- if (sf == null) {
- // 没有签约信息
- json.put("sign", -1);
- } else {
- // 有签约信息
- json.put("sign", sf.getStatus());
- }
- //设置查看病人所在分组
- List<DoctorPatientGroupInfo> dctorPatientGroupInfo = doctorPatientGroupInfoDao.findByMorenPatient(patient);
- if (dctorPatientGroupInfo != null && dctorPatientGroupInfo.size() > 0) {
- json.put("group", dctorPatientGroupInfo.get(0).getGroup());
- } else {
- json.put("group", "0");
- }
- // 查询医生服务
- List<DoctorService> list = doctorServiceDao.findByDoctor(doctor);
- JSONArray services = new JSONArray();
- for (DoctorService ds : list) {
- if (ds == null) {
- continue;
- }
- JSONObject service = new JSONObject();
- service.put("logo", ds.getLogo());
- service.put("title", ds.getTitle());
- service.put("content", ds.getContent());
- service.put("url", ds.getUrl());
- services.put(service);
- }
- json.put("services", services);
- return json;
- }
- /**
- * 查询患者与医生的签约信息
- *
- * @param patient
- * @param doctor
- * @return
- */
- public int findSignStatus(String patient, String doctor) {
- // 查询与当前医生的签约状态
- SignFamily sf = signFamilyDao.findByDoctorPatient(doctor, patient);
- if (sf == null) {
- // 没有签约信息
- return -1;
- } else {
- // 有签约信息
- return sf.getStatus();
- }
- }
- /**
- * 校验签约状态
- *
- * @return
- * @throws Exception
- */
- public JSONObject checkSign(Patient patient) throws Exception {
- JSONObject json = new JSONObject();
- // 查询是否已存在家庭签约
- SignFamily sf = signFamilyDao.findByIdcard(patient.getIdcard());
- if (sf != null) {
- // 已签约
- json.put("sign", 1);
- } else {
- // 未签约
- json.put("sign", 0);
- }
- return json;
- }
- /**
- * 校验当前openid是否签约家庭医生
- *
- * @return
- */
- public String checkPatient(String patient) {
- SignFamily sf = signFamilyDao.findByjiatingPatientStatus0(patient);
- if (sf != null) {
- return sf.getDoctor();
- }
- return null;
- }
- /**
- * 查询是否存在签约状态
- *
- * @param idcard
- * @return
- */
- public int hasSingStatus(String idcard) {
- return signFamilyDao.hasSingStatus(idcard);
- }
- /**
- * 发起签约申请
- *
- * @param province 省代码
- * @param provinceName 省名称
- * @param city 城市代码
- * @param cityName 城市名称
- * @param town 区县代码
- * @param townName 区县名称
- * @param address 详细地址
- * @param name 患者姓名
- * @param doctor 医生标识
- * @param openid 微信openid
- * @param patient 患者标识
- * @param idcard 患者身份证号
- * @param ssc 患者社保卡号
- * @param mobile 患者手机号
- * @param emerMobile 患者紧急联系人
- * @return
- */
- public JSONObject sign(String province,
- String provinceName,
- String city,
- String cityName,
- String town,
- String townName,
- String address,
- String name,
- String doctor,
- String openid,
- String patient,
- String idcard,
- String ssc,
- String mobile,
- String emerMobile) {
- // 查询三师签约
- JSONObject json = new JSONObject();
- SignFamily sc = signFamilyDao.findByIdcard(idcard);
- //判断身份证号是否已经注册
- if (sc != null) {
- json.put("res", "-3");
- return json;
- }
- Doctor d = doctorDao.findByCode(doctor);
- SignFamily sf = new SignFamily();
- sf.setCode(getCode());
- // 设置两网编码
- sf.setLwCode(sc != null ? sc.getCode() : null);
- sf.setCzrq(new Date());
- sf.setPatientApplyDate(new Date());
- sf.setDoctor(doctor);
- //设置全科医生的行政团队
- sf.setAdminTeamId(doctorAdminTeamDao.findIdByLeaderCode(doctor));
- sf.setMobile(mobile);
- sf.setDoctorName(d.getName());
- sf.setEmerMobile(emerMobile);
- sf.setName(name);
- sf.setIdcard(idcard);
- sf.setOpenid(openid);
- sf.setPatient(patient);
- sf.setHospital(d.getHospital());
- sf.setHospitalName(d.getHosptialName());
- sf.setSsc(ssc);
- sf.setStatus(0);//0为初始状态
- sf.setType(2);// 设置为家庭签约
- sf.setSignType("1");//用户申请
- sf.setSignSource("2");//签约来源【1 社区签约 2 移动签约】
- //******************扣费接口**********************/
- sf.setExpensesStatus("0"); //扣费状态 【0未扣费 1已扣费 2已退费】
- // 判断用户表是否存在该身份证号
- Patient p = patientDao.findByIdcard(idcard);
- if (p == null) {
- // 插入患者基本信息
- IdcardInfoExtractor ie = new IdcardInfoExtractor(idcard);
- p = new Patient();
- p.setCode(getCode());
- p.setName(name);
- p.setProvince(province);
- p.setProvinceName(provinceName);
- p.setCity(city);
- p.setCityName(cityName);
- p.setTown(town);
- p.setTownName(townName);
- p.setAddress(address);
- p.setOpenid(openid);
- p.setIdcard(idcard);
- p.setMobile(mobile);
- p.setSsc(ssc);
- // 从身份证号中提取生日
- p.setBirthday(ie.getBirthday());
- // 从身份证号中提取性别
- p.setSex(ie.getGender());
- p.setCzrq(new Date());
- p.setStatus(1);
- // 保存新的用户信息
- p = patientDao.save(p);
- } else {
- if (StringUtils.isNotEmpty(patient) && !StringUtils.equals(p.getCode(), patient)) {
- // 身份证信息与登录信息不匹配
- json.put("res", -1);
- return json;
- }
- if (StringUtils.isNotEmpty(openid) && !StringUtils.equals(p.getOpenid(), openid)) {
- // 身份证信息与登录信息不匹配
- json.put("res", -1);
- return json;
- }
- if (StringUtils.isNotEmpty(idcard) && !StringUtils.equals(p.getIdcard(), idcard)) {
- // 身份证信息与登录信息不匹配
- json.put("res", -1);
- return json;
- }
- }
- // 更新签约用户信息
- patient = p.getCode();
- sf.setPatient(patient);
- SignFamily temp = signFamilyDao.save(sf);
- if (temp != null) {
- // 添加签约消息
- Message message = new Message();
- message.setCzrq(new Date());
- message.setContent("您有一条新的家庭签约申请!");
- message.setRead(1);//设置未读
- message.setReceiver(doctor);//设置接受医生的code
- message.setSender(patient);//设置发送的用户
- message.setSenderName(p.getName());
- message.setCode(getCode());
- message.setSenderPhoto(p.getPhoto());
- message.setTitle("家庭签约申请");
- message.setType(1);//家庭签约信息
- message.setReadonly(1);//是否只读消息
- message.setSignStatus("1");//新的签约
- message.setSex(p.getSex());
- message.setOver("1");//未处理
- message.setData(temp.getCode());
- messageDao.save(message);
- // 发送消息给医生
- PushMsgTask.getInstance().put(doctor, MessageType.MESSAGE_TYPE_DOCTOR_NEW_SIGN_WEB.D_SW_01.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_SIGN_WEB.家庭签约.name(), "您有一条新的家庭签约申请!", patient);
- }
- json.put("id", p.getId());
- json.put("uid", p.getCode());
- json.put("res", 1);
- return json;
- }
- /**
- * 取消签约申请
- *
- * @param patient 患者标识
- * @param doctor 医生标识
- * @return
- */
- public int unsign(String patient, String doctor) {
- //修改签约标识为无效
- SignFamily sf = signFamilyDao.findByDoctorPatient(doctor, patient);
- Message message = messageDao.findByPatient(patient, doctor);
- if (sf.getStatus() != 0 && sf.getStatus() != 2) {
- return -2;
- }
- if (sf != null) {
- sf.setStatus(-1);
- } else {
- return -2;
- }
- //修改信息为无效
- if (message != null) {
- message.setRead(0);
- message.setOver("0");
- }
- return 200;
- }
- /**
- * 申请解约
- *
- * @param patient 患者标识
- * @param doctor 医生标识
- * @param openid 微信openid
- * @param reason 解约理由
- * @return
- */
- public int surrender(String patient, String patientName, String userPhoto, String doctor, String doctorName, String openid, String reason, int sex) {
- // 更新为待解约
- int res = signFamilyDao.surrender(patient, doctor);
- SignFamily signFamily = signFamilyDao.findByjiatingPatient(patient);
- signFamily.setPatientApplyUnsignDate(new Date());
- if (res == 0) {
- return 0;
- }
- // 添加签约消息
- Message message = new Message();
- // 消息时间
- message.setCzrq(new Date());
- // 消息内容
- message.setContent("申请解除与您的签约关系");
- // 未读
- message.setRead(1);
- message.setReceiverName(doctorName);
- // 接收人
- message.setReceiver(doctor);
- message.setCode(getCode());
- // 发送人
- message.setSender(patient);
- message.setSenderName(patientName);
- message.setSenderPhoto(userPhoto);
- // 标题
- message.setTitle("解除家庭签约申请");
- message.setType(1);
- message.setSignStatus("4");
- message.setReadonly(1);
- message.setSex(sex);
- message.setOver("1");
- // 设置解约理由
- message.setReason(reason);
- message.setData(signFamily.getCode());
- messageDao.save(message);
- // 发送消息给医生
- PushMsgTask.getInstance().put(doctor, MessageType.MESSAGE_TYPE_DOCTOR_SIGN_WEB_RELIEVE.D_SW_02.name(), MessageType.MESSAGE_TYPE_DOCTOR_SIGN_WEB_RELIEVE.家庭签约.name(), patientName + " 申请解除与您的家庭签约!", patient);
- return 1;
- }
- /**
- * 查询患者的签约消息
- *
- * @param id
- * @param pagesize
- * @return
- */
- public Page<Message> findMessageByPatient(String patient, long id, int pagesize) {
- if (pagesize <= 0) {
- pagesize = 10;
- }
- // 排序
- Sort sort = new Sort(Direction.DESC, "id");
- // 分页信息
- PageRequest pageRequest = new PageRequest(0, pagesize, sort);
- // 设置查询条件
- Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
- filters.put("receiver", new SearchFilter("receiver", Operator.EQ, patient));
- if (id > 0) {
- filters.put("id", new SearchFilter("id", Operator.LT, id));
- }
- Specification<Message> spec = DynamicSpecifications.bySearchFilter(filters.values(), Message.class);
- return messageDao.findAll(spec, pageRequest);
- }
- /**
- * 查询跟医生相关的家庭签约信息
- *
- * @param type 0全部,1待签约,2已签约,3待解约,4已解约
- * @param id
- * @param pagesize 分页大小
- * @return
- */
- public Page<SignFamily> findSignByDoctor(int type, long id, int pagesize) {
- if (pagesize <= 0) {
- pagesize = 10;
- }
- // 排序
- Sort sort = new Sort(Direction.DESC, "id");
- // 分页信息
- PageRequest pageRequest = new PageRequest(0, pagesize, sort);
- // 设置查询条件
- Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
- // 只查家庭签约(网络签约)
- filters.put("type", new SearchFilter("type", Operator.EQ, 2));
- switch (type) {
- case 1:
- // 待签约
- filters.put("status", new SearchFilter("status", Operator.EQ, 0));
- break;
- case 2:
- // 已签约
- filters.put("status", new SearchFilter("status", Operator.EQ, 1));
- break;
- case 3:
- // 待解约
- filters.put("status", new SearchFilter("status", Operator.EQ, 2));
- break;
- case 4:
- // 已解约
- filters.put("status", new SearchFilter("status", Operator.EQ, -3));
- break;
- }
- if (id > 0) {
- filters.put("id", new SearchFilter("id", Operator.LT, id));
- }
- Specification<SignFamily> spec = DynamicSpecifications.bySearchFilter(filters.values(), SignFamily.class);
- return signFamilyDao.findAll(spec, pageRequest);
- }
- /**
- * 代理签约
- *
- * @param name 患者姓名
- * @param doctor 医生标识
- * @param doctorName 医生姓名
- * @param doctorHealth 健康管理师标识
- * @param doctorHealthName 健康管理师姓名
- * @param hospital 签约医院标识
- * @param hospitalName 签约医院名称
- * @param idcard 患者身份证号
- * @param ssc 患者社保卡号
- * @param mobile 患者手机号
- * @param emerMobile 患者紧急联系人
- * @param expenses
- * @return
- * @throws Exception
- */
- synchronized public SignFamily agent(String access_token, String name,
- String doctor, String doctorName,
- String doctorHealth, String doctorHealthName,
- String majorDoctor,
- String majorDoctorName,
- String hospital, String hospitalName,
- String idcard, String ssc, String mobile,
- String emerMobile, String images,
- String healthLabel, String customLabel, String disease,
- String expenses, String signDoctorCode,
- String signDoctorName, String signDoctorLevel, String customGroup) throws Exception {
- // 查询是否有家庭签约
- SignFamily sc = signFamilyDao.findByIdcard(idcard);
- if (sc != null) {
- throw new Exception("已签约了家庭医生!");
- }
- //判断是否有三师签约 并且判断全科医生一致
- SignFamily sssignFamily = signFamilyDao.findSSByIdcard(idcard);
- if (sssignFamily != null && !doctor.equals(sssignFamily.getDoctor())) {
- throw new Exception("全科医生不一致!");
- }
- List<SystemDict> systemDicts = systemDictDao.findByDictName("SIGN_YEAR");
- String signYear = systemDicts.get(0).getCode();
- SignFamily sf = new SignFamily();
- sf.setSignYear(signYear);//设置签约年度
- sf.setBegin(DateUtil.getNowDateShort());
- sf.setCode(getCode());
- sf.setCzrq(new Date());
- //设置全科医生的行政团队
- sf.setAdminTeamId(doctorAdminTeamDao.findIdByLeaderCode(doctor));
- sf.setDoctor(doctor);
- sf.setDoctorName(doctorName);
- sf.setDoctorHealth(doctorHealth);
- sf.setExpensesType(StringUtils.isEmpty(expenses) ? "01" : expenses);
- sf.setFamilyCode(createSignCode(doctor, hospital));
- sf.setDoctorHealthName(doctorHealthName);
- sf.setEmerMobile(emerMobile);
- sf.setEnd(DateUtil.strToDateShort(DateUtil.getNextYear(DateUtil.getNowDateShort(), 1)));
- sf.setName(name);
- sf.setIdcard(idcard);
- sf.setMobile(mobile);
- sf.setHospital(hospital);
- sf.setHospitalName(hospitalName);
- String sscD = "";
- if (StringUtils.isNumeric(ssc.trim())) {
- //如果是纯数字的医保号换成D开头的
- sscD = socialSecurityInfoDao.findBySfzh18Max(idcard).getCardno();
- } else {
- sscD = ssc;
- }
- sf.setSsc(sscD);
- sf.setStatus(1);// 代理签约,直接生效
- sf.setImages(images);
- sf.setApplyDate(new Date());
- sf.setType(2);// 设置为家庭签约
- sf.setSignType("2");//手工带签
- sf.setSignDoctorCode(doctor);
- sf.setSignDoctorLevel("2");
- sf.setSignDoctorName(doctorName);
- sf.setAgentDoctorCode(signDoctorCode);
- sf.setAgentDoctorLevel(signDoctorLevel);
- sf.setAgentDoctorName(signDoctorName);
- sf.setSignSource("2");//签约来源【1 社区签约 2 移动签约】
- //******************扣费接口**********************/
- sf.setExpensesStatus("0"); //扣费状态 【0未扣费 1已扣费 2已退费】
- // 查询该患者是否已注册
- Patient patient = patientDao.findByIdcard(idcard);
- if (patient == null) {
- // 插入患者基本信息
- IdcardInfoExtractor ie = new IdcardInfoExtractor(idcard);
- patient = new Patient();
- patient.setCode(getCode());
- patient.setName(name);
- patient.setIdcard(idcard);
- patient.setSsc(sscD);
- patient.setBirthday(ie.getBirthday());
- patient.setSex(ie.getGender());
- patient.setMobile(mobile);
- patient.setStatus(1);
- patient.setDisease(0);
- }
- //病人疾病更新
- // if (!StringUtils.isEmpty(disease)) {
- // patient.setDisease(Integer.valueOf(disease));
- // }
- // 保存用户信息
- patientDao.save(patient);
- sf.setOpenid(patient.getOpenid());
- sf.setPatient(patient.getCode());
- // 改为签约生效
- sf.setStatus(1);
- // 更新签约日期
- sf.setBegin(DateUtil.getNowDateShort());
- sf.setEnd(DateUtil.strToDateShort(DateUtil.getNextYear(DateUtil.getNowDateShort(), 1)));
- //建立团队
- DoctorTeam doctorTeam = new DoctorTeam();
- String doctorTeamCode = getCode();
- doctorTeam.setCode(doctorTeamCode);
- doctorTeam.setCzrq(new Date());
- doctorTeam.setName("团队名称:" + name);
- doctorTeam.setSignType("2");//家庭签约
- doctorTeam.setDel("1");
- doctorTeamDao.save(doctorTeam);
- sf.setTeamCode(doctorTeamCode);
- signFamilyDao.save(sf);
- //添加团队成员
- //添加健康管理师
- DoctorTeamMember wlyyDoctorTeamDoctor = new DoctorTeamMember();
- wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
- wlyyDoctorTeamDoctor.setMemberCode(doctorHealth);
- wlyyDoctorTeamDoctor.setName(doctorHealthName);
- wlyyDoctorTeamDoctor.setDel("1");
- wlyyDoctorTeamDoctor.setType(3);
- wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
- wlyyDoctorTeamDoctor.setCode(getCode());
- wlyyDoctorTeamDoctor.setCzrq(new Date());
- doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
- //添加全科医生
- wlyyDoctorTeamDoctor = new DoctorTeamMember();
- wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
- wlyyDoctorTeamDoctor.setMemberCode(doctor);
- wlyyDoctorTeamDoctor.setName(doctorName);
- wlyyDoctorTeamDoctor.setDel("1");
- wlyyDoctorTeamDoctor.setType(2);
- wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
- wlyyDoctorTeamDoctor.setCode(getCode());
- wlyyDoctorTeamDoctor.setCzrq(new Date());
- doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
- // if (StringUtils.isNotEmpty(disease) && !disease.equals("0")) {
- // //如果有选择病种
- // //添加专科医生
- // wlyyDoctorTeamDoctor = new DoctorTeamMember();
- // wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
- // wlyyDoctorTeamDoctor.setMemberCode(majorDoctor);
- // wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
- // wlyyDoctorTeamDoctor.setName(majorDoctorName);
- // wlyyDoctorTeamDoctor.setDel("1");
- // wlyyDoctorTeamDoctor.setType(1);
- // wlyyDoctorTeamDoctor.setCode(getCode());
- // wlyyDoctorTeamDoctor.setCzrq(new Date());
- //
- // doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
- // }
- //添加患者和团队的关系
- DoctorTeamMember wlyyDoctorTeamPatient = new DoctorTeamMember();
- wlyyDoctorTeamPatient.setTeam(doctorTeamCode);
- wlyyDoctorTeamPatient.setMemberCode(patient.getCode());
- wlyyDoctorTeamPatient.setName(patient.getName());
- wlyyDoctorTeamPatient.setDel("1");
- wlyyDoctorTeamPatient.setSignType("2");//家庭签约
- wlyyDoctorTeamPatient.setType(5);
- wlyyDoctorTeamPatient.setCode(getCode());
- wlyyDoctorTeamPatient.setCzrq(new Date());
- doctorTeamDoctor.save(wlyyDoctorTeamPatient);
- // 患者标签设置
- if(!(labelInfoService.setPatientLabels(patient.getCode(),patient.getIdcard(),
- patient.getName(),healthLabel,disease,customLabel) == 1)){
- throw new Exception("patient sign label settting error:" + patient.getIdcard());
- }
- SignFamily temp = signFamilyDao.save(sf);
- if (temp != null && patient != null) {
- Doctor doc = doctorDao.findByCode(sf.getDoctor());
- Hospital hos = hospitalDao.findByCode(doc.getHospital());
- String content = "祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
- "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
- (hos != null ? hos.getAddress() : "") + ")缴费。";
- JSONObject json = new JSONObject();
- json.put("first", "签约成功通知");
- json.put("doctor", sf.getDoctor());
- json.put("doctorName", sf.getDoctorName());
- json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
- json.put("content", content);
- json.put("remark", ""); //您好,您成功签约家庭医生
- // 添加到发送队列
- PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
- new Thread(new SignUploadTask(sf.getCode())).start();
- }
- return temp;
- }
- /**
- * 处理签约申请
- *
- * @param healthDoctor 健康管理师标识
- * @param healthDoctorName 健康管理师姓名
- * @param msgid 消息id
- * @param patientCard 患者身份证
- * @param type 处理类型:1同意,2拒绝
- * @return
- */
- public int handleSign(String signType,
- String access_token,
- String healthDoctor,
- String healthDoctorName,
- long msgid,
- String patientCard, int type,
- String healthLabel, String customLabel, String disease,
- String majorDoctor, String majorhDoctorName, String customGroup, String expenses) throws Exception {
- if (type != 1 && type != 2) {
- return -1;
- }
- // 查询患者信息
- Patient p = patientDao.findByIdcard(patientCard);
- // 更新消息状态为已处理
- if (msgid > 0) {
- Message message = messageDao.findOne(msgid);
- message.setRead(0);//设置已读
- message.setOver("0");//设置消息操作结束
- message.setCzrq(new Date());
- }
- // 判断患者有没有家庭签约
- SignFamily sf = signFamilyDao.findByPatientStatus(patientCard, 0);
- if (sf == null) {
- return 0;
- }
- if (type == 1) {
- List<SystemDict> systemDicts = systemDictDao.findByDictName("SIGN_YEAR");
- String year = systemDicts.get(0).getCode();
- //病人疾病更新
- // if (!StringUtils.isEmpty(disease)) {
- // p.setDisease(Integer.valueOf(disease));
- // }
- //签约类型:1三师签约,2家庭签约
- // 改为签约生效
- sf.setStatus(1);
- // 更新签约日期
- sf.setBegin(DateUtil.getNowDateShort());
- sf.setSignType("1");//患者发起签约
- sf.setExpensesType(StringUtils.isEmpty(expenses) ? "01" : expenses);//收费类别
- sf.setEnd(DateUtil.strToDateShort(DateUtil.getNextYear(DateUtil.getNowDateShort(), 1)));
- //设置签约人 患者发起的签约 默认签约人是全科医生
- sf.setSignDoctorCode(sf.getDoctor());
- sf.setSignDoctorName(sf.getDoctorName());
- sf.setSignDoctorLevel("2");
- // 更新健康管理师
- sf.setDoctorHealth(healthDoctor);
- sf.setDoctorHealthName(healthDoctorName);
- sf.setCzrq(new Date());
- sf.setSignYear(year);//设置签约年度
- sf.setApplyDate(new Date());
- Doctor doctor = doctorDao.findByCode(sf.getDoctor());
- sf.setFamilyCode(createSignCode(sf.getDoctor(), doctor.getHospital()));
- //建立团队
- DoctorTeam doctorTeam = new DoctorTeam();
- String doctorTeamCode = getCode();
- doctorTeam.setName("三师签约团队患者:" + p.getName());
- doctorTeam.setCode(doctorTeamCode);
- doctorTeam.setCzrq(new Date());
- doctorTeam.setSignType("2");
- doctorTeam.setDel("1");
- doctorTeamDao.save(doctorTeam);
- sf.setTeamCode(doctorTeamCode);
- //添加团队成员
- //添加健康管理师
- DoctorTeamMember wlyyDoctorTeamDoctor = new DoctorTeamMember();
- wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
- wlyyDoctorTeamDoctor.setMemberCode(healthDoctor);
- wlyyDoctorTeamDoctor.setName(healthDoctorName);
- wlyyDoctorTeamDoctor.setDel("1");
- wlyyDoctorTeamDoctor.setSignType("2");
- wlyyDoctorTeamDoctor.setType(3);
- wlyyDoctorTeamDoctor.setCode(getCode());
- wlyyDoctorTeamDoctor.setCzrq(new Date());
- doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
- //添加全科医生
- wlyyDoctorTeamDoctor = new DoctorTeamMember();
- wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
- wlyyDoctorTeamDoctor.setMemberCode(sf.getDoctor());
- wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
- wlyyDoctorTeamDoctor.setName(sf.getDoctorName());
- wlyyDoctorTeamDoctor.setDel("1");
- wlyyDoctorTeamDoctor.setType(2);
- wlyyDoctorTeamDoctor.setCode(getCode());
- wlyyDoctorTeamDoctor.setCzrq(new Date());
- doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
- //添加患者和团队的关系
- DoctorTeamMember wlyyDoctorTeamPatient = new DoctorTeamMember();
- wlyyDoctorTeamPatient.setTeam(doctorTeamCode);
- wlyyDoctorTeamPatient.setMemberCode(sf.getPatient());
- wlyyDoctorTeamPatient.setName(p.getName());
- wlyyDoctorTeamPatient.setDel("1");
- wlyyDoctorTeamPatient.setSignType("2");//家庭签约
- wlyyDoctorTeamPatient.setType(5);//患者
- wlyyDoctorTeamPatient.setCode(getCode());
- wlyyDoctorTeamPatient.setCzrq(new Date());
- doctorTeamDoctor.save(wlyyDoctorTeamPatient);
- // if (StringUtils.isNotEmpty(disease) && !disease.equals("0")) {
- // //如果有选择病种
- // //添加专科医生
- // wlyyDoctorTeamDoctor = new DoctorTeamMember();
- // wlyyDoctorTeamDoctor.setTeam(doctorTeamCode);
- // wlyyDoctorTeamDoctor.setMemberCode(majorDoctor);
- // wlyyDoctorTeamDoctor.setSignType("2");//家庭签约
- // wlyyDoctorTeamDoctor.setName(majorhDoctorName);
- // wlyyDoctorTeamDoctor.setDel("1");
- // wlyyDoctorTeamDoctor.setType(1);
- // wlyyDoctorTeamDoctor.setCode(getCode());
- // wlyyDoctorTeamDoctor.setCzrq(new Date());
- // doctorTeamDoctor.save(wlyyDoctorTeamDoctor);
- // }
- } else {
- // 医生拒绝
- sf.setStatus(-2);
- sf.setCzrq(new Date());
- // 拒绝签约
- JSONObject json = new JSONObject();
- json.put("first", "签约失败通知");
- json.put("doctor", sf.getDoctor());
- json.put("doctorName", sf.getDoctorName());
- json.put("date", DateUtil.dateToStrShort(new Date()));
- json.put("content", "您与 " + sf.getDoctorName() + " 医生建立家庭医生签约关系失败,请查看!");
- json.put("remark", "您好,签约家庭医生失败通知");
- // 添加到发送队列
- PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
- return 2;
- }
- // 患者标签设置
- if(!(labelInfoService.setPatientLabels(p.getCode(),p.getIdcard(),
- p.getName(),healthLabel,disease,customLabel) == 1)){
- throw new Exception("patient sign label settting error:" + p.getIdcard());
- }
- // 推送消息消息给微信端
- if (type == 1) {
- Doctor doc = doctorDao.findByCode(sf.getDoctor());
- Hospital hos = hospitalDao.findByCode(doc.getHospital());
- String content = "祝贺您,成功签约" + sf.getDoctorName() + "医生团队,您已可以享受家庭医生所带来的无微不至的健康保健服务。" +
- "为了给您提供更好的服务,请尽快到" + (hos != null ? hos.getName() : "") + "社区(地址:" +
- (hos != null ? hos.getAddress() : "") + ")缴费。";
- // 同意签约
- JSONObject json = new JSONObject();
- json.put("first", "签约成功通知");
- json.put("doctor", sf.getDoctor());
- json.put("doctorName", sf.getDoctorName());
- json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
- json.put("content", content);
- json.put("remark", ""); //您好,您成功签约家庭医生
- // 添加到发送队列
- PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
- new Thread(new SignUploadTask(sf.getCode())).start();
- } else if (type == 2) {
- System.out.println(" ---------- fail send weixin-------------");
- // 拒绝签约
- JSONObject json = new JSONObject();
- json.put("first", "签约失败通知");
- json.put("doctor", sf.getDoctor());
- json.put("doctorName", sf.getDoctorName());
- json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
- json.put("content", "您与 " + sf.getDoctorName() + " 医生建立家庭医生签约关系失败,请查看!");
- json.put("remark", "您好,签约家庭医生失败通知");
- // 添加到发送队列
- PushMsgTask.getInstance().putWxMsg(access_token, 2, sf.getOpenid(), sf.getName(), json);
- }
- return 1;
- }
- /**
- * 处理解约申请
- *
- * @param patient 患者标识
- * @param type 处理类型:1同意,2拒绝
- * @param reason 解约原因
- * @return
- */
- public int handleSurrender(String access_token, long msgid, String patient, int type, String reason) throws Exception {
- if (type != 1 && type != 2) {
- return -1;
- }
- SignFamily sf = signFamilyDao.findByPatientCodeStatus(patient, 2);
- if (sf == null) {
- return 0;
- }
- // 更新消息状态为已处理
- if (msgid > 0) {
- Message message = messageDao.findOne(msgid);
- message.setRead(0);
- message.setOver("0");
- }
- if (type == 1) {
- // 设置家庭签约疾病无效
- if (!patientDiseaseService.updatePatientDisease(patient, "")) {
- throw new Exception("patient's disease update failed");
- }
- // 将签约状态改为已解约
- sf.setReason(reason);
- sf.setStatus(-3);
- sf.setApplyUnsignDate(new Date());
- //signFamilyDao.handleSurrender(reason, patient);
- //设置患者所在团队失效
- doctorTeamDao.deleteTeam(sf.getTeamCode());
- //设置团队成员失效
- doctorTeamDoctor.deleteMember(sf.getTeamCode());
- //把患者移除健康管理师和全科医生的晃患者管理
- doctorPatientGroupInfoDao.deleteByPatient(patient);
- //结束患者家庭签约咨询
- consultTeamDao.updateStatusByPatient(patient);
- // 推送消息消息给微信端
- JSONObject json = new JSONObject();
- json.put("first", "解约申请通知");
- json.put("date", DateUtil.getStringDateShort());
- json.put("doctor", sf.getDoctor());
- json.put("doctorName", sf.getDoctorName());
- json.put("orgName", sf.getHospitalName());
- json.put("remark", "您好,您的签约医生已同意您的解约申请,解约已生效。");
- // 添加到发送队列
- PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
- } else {
- // 更新状态为正常
- signFamilyDao.refuseSurrender(patient);
- // 拒绝解约,推送消息消息给微信端
- JSONObject json = new JSONObject();
- json.put("first", "解约申请通知");
- json.put("date", DateUtil.getStringDateShort());
- json.put("doctor", sf.getDoctor());
- json.put("doctorName", sf.getDoctorName());
- json.put("orgName", sf.getHospitalName());
- json.put("remark", "您好,您的签约医生拒绝您的解约申请,解约失败。");
- // 添加到发送队列
- PushMsgTask.getInstance().putWxMsg(access_token, 5, sf.getOpenid(), sf.getName(), json);
- }
- return 1;
- }
- /**
- * 查询医生的签约消息
- *
- * @param doctor 医生标识
- * @param id
- * @param pagesize 分页大小
- * @return
- */
- public Page<Message> findMessageByDoctor(String doctor, long id, int pagesize) {
- if (pagesize <= 0) {
- pagesize = 10;
- }
- // 排序
- Sort sort = new Sort(Direction.DESC, "czrq");
- // sort.and(new Sort(Direction.DESC,"read"));
- // sort.and(new Sort(Direction.DESC,"czrq"));
- // 分页信息
- PageRequest pageRequest = new PageRequest(0, pagesize, sort);
- // 设置查询条件
- Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
- filters.put("receiver", new SearchFilter("receiver", Operator.EQ, doctor));
- if (id > 0) {
- filters.put("id", new SearchFilter("id", Operator.LT, id));
- }
- // 只查询未处理的消息
- filters.put("type", new SearchFilter("type", Operator.EQ, 1));
- // filters.put("over", new SearchFilter("over", Operator.EQ, 1));
- // filters.put("read", new SearchFilter("read", Operator.EQ, 1));
- Specification<Message> spec = DynamicSpecifications.bySearchFilter(filters.values(), Message.class);
- return messageDao.findAll(spec, pageRequest);
- }
- /**
- * 查询已签约总数
- *
- * @param doctor
- * @return
- */
- public int countAmountSigned(String doctor) {
- return signFamilyDao.countAmountSignedByDoctor(doctor);
- }
- /**
- * 查询待签约总数
- *
- * @param doctor
- * @return
- */
- public int countAmountUnsign(String doctor) {
- return signFamilyDao.countAmountUnsignByDoctor(doctor);
- }
- public List<?> amountPatients(String uid) {
- return null;
- }
- public SignFamily getFamilyContractByIdcard(String idCard) {
- return signFamilyDao.findByIdcard(idCard);
- }
- public SignFamily getFamilyContractByMobile(String mobile) {
- return signFamilyDao.findByMobile(mobile);
- }
- /**
- * 生成签约标识
- *
- * @param doctor 医生标识
- * @return
- */
- private String createSignCode(String doctor, String hospital) {
- // 获取当前年份
- String year = DateUtil.getStringDate(DateUtil.YY);
- Hospital hospital1 = hospitalDao.findByCode(hospital);
- Integer amount = 0;
- SignFamilyCode wlyySignFamilyCode = wlyySignFamilyCodeDao.findByOrgCodeAndYear(hospital, year);
- if (wlyySignFamilyCode != null) {
- amount = wlyySignFamilyCode.getSequence() + 1;
- wlyySignFamilyCode.setSequence(amount);
- wlyySignFamilyCode.setModifyTime(new Date());
- } else {
- //创建序列
- amount = 1;
- SignFamilyCode wlyySignFamilyCodeTemp = new SignFamilyCode();
- wlyySignFamilyCodeTemp.setModifyTime(new Date());
- wlyySignFamilyCodeTemp.setOrgCode(hospital1.getCode());
- wlyySignFamilyCodeTemp.setOrgName(hospital1.getName());
- wlyySignFamilyCodeTemp.setYear(year);
- wlyySignFamilyCodeTemp.setSequence(1);
- wlyySignFamilyCodeDao.save(wlyySignFamilyCodeTemp);
- }
- return year + hospital1.getRoadCode() + hospital1.getCenterSite() + "Y" + StringUtils.leftPad(String.valueOf(amount + 1), 5, "0");
- }
- public int countAmountSigned2(String uid) {
- return signFamilyDao.countAmountSignedByHeather(uid);
- }
- public SignFamily findBySanshiPatient(String code) {
- return signFamilyDao.findSanshiSignByPatient(code);
- }
- public SignFamily findByFamilySignPatient(String code) {
- return signFamilyDao.findFamilySignByPatient(code);
- }
- public SignFamily findByJiatingPatient(String code) {
- return signFamilyDao.findByjiatingPatientYes(code);
- }
- /**
- * 查询患者已签约信息
- *
- * @param code
- * @return
- */
- public SignFamily findBySsPatient(String code) {
- return signFamilyDao.findBySsPatient(code);
- }
- public List<Map<String, Object>> getDoctorsByhospitalNoPage(String hospital, String name, Integer type) {
- String sql = "select * from wlyy_doctor where 1=1 and del=1 and iscertified=1 and status=1 ";
- List<Object> params = new ArrayList<Object>();
- if (StringUtils.isNoneEmpty(hospital)) {
- sql += " and hospital =? ";
- params.add(hospital);
- }
- if (StringUtils.isNoneEmpty(name)) {
- sql += " and name like ? ";
- params.add("%" + name + "%");
- }
- if (type != null && type > 0) {
- sql += " and level =? ";
- params.add(type);
- }
- return jdbcTemplate.queryForList(sql, params.toArray());
- }
- public Map<String, Object> getSanshiSignByPatientCode(String patientCode) {
- Map<String, Object> map = new HashMap<>();
- SignFamily signFamily = signFamilyDao.findBySanshiPatient(patientCode);
- //判斷之前有没有三师签约
- if (signFamily != null) {
- map.put("hasSanshi", "true");
- //得到团队的专科医生
- DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 1);
- map.put("zkCode", doctorTeamMember.getMemberCode());
- map.put("zkName", doctorTeamMember.getName());
- //得到团队的全科医生
- doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 2);
- map.put("qkCode", doctorTeamMember.getMemberCode());
- map.put("qkName", doctorTeamMember.getName());
- //得到团队的健康管理医生
- doctorTeamMember = doctorTeamDoctor.findSanshiByTeamAndType(signFamily.getTeamCode(), 3);
- map.put("glsCode", doctorTeamMember.getMemberCode());
- map.put("glsName", doctorTeamMember.getName());
- //得到之前病人得的病
- Patient pa = patientDao.findByCode(patientCode);
- map.put("disease", pa.getDisease());
- } else {
- map.put("hasSanshi", "false");
- }
- return map;
- }
- public SignFamily findByPatientYes(String id) {
- return signFamilyDao.findByjiatingPatient(id);
- }
- public SignFamily findBySanshiPatientYes(String id) {
- return signFamilyDao.findBySanshiPatientYes(id);
- }
- /**
- * 根据身份证号查找病人的三师签约信息
- *
- * @param idCard
- * @return
- */
- public JSONObject getSanshiSingInfoByPatientIdCard(String idCard) throws Exception {
- JSONObject result = new JSONObject();
- SignFamily sign = signFamilyDao.findByPatientSanshiSignInfo(idCard);
- SignFamily signFamily = signFamilyDao.findByPatientFamilySignInfo(idCard);
- Patient p = patientDao.findByIdcard(idCard);
- if (p == null) {
- result.put("signStatus", "0");
- result.put("msg", "病人未注册");
- return result;
- }
- if (signFamily != null) {
- result.put("signStatus", "2");
- result.put("msg", "病人已申请过家庭签约!");
- return result;
- }
- if (sign != null) {
- List<DoctorTeamMember> members = doctorTeamDoctor.findByTeamAndDel(sign.getTeamCode(), "1");
- if (members == null) {
- throw new Exception("签约团队信息有误!");
- }
- //三师签约医生信息
- for (DoctorTeamMember member : members) {
- if (member.getType() == 1) {
- result.put("majorDoctor", member.getMemberCode());
- result.put("majorDoctorName", member.getName());
- } else if (member.getType() == 2) {
- Doctor doctor = doctorDao.findByCode(member.getMemberCode());
- result.put("hospital", doctor.getHospital());
- result.put("doctor", member.getMemberCode());
- result.put("doctorName", member.getName());
- } else if (member.getType() == 3) {
- result.put("healthDoctor", member.getMemberCode());
- result.put("healthDoctorName", member.getName());
- }
- }
- // 查询患者疾病
- List<PatientDisease> diseases = patientDiseaseDao.findByPatientSsDisease(p.getCode());
- if (diseases != null && diseases.size() > 0) {
- JSONArray disArray = new JSONArray();
- for (PatientDisease dis : diseases) {
- disArray.put(new JSONObject(dis));
- }
- result.put("diseases", disArray);
- } else {
- result.put("diseases", "");
- }
- result.put("signStatus", "1");
- } else {
- result.put("signStatus", "3");
- }
- if (p != null) {
- JSONObject pJson = new JSONObject(p);
- result.put("patient", pJson);
- }
- return result;
- }
- public JSONArray getSignDoctorMessage(String patientCode) {
- JSONArray jsonArray = new JSONArray();
- //找出患者的三师签约信息
- SignFamily signFamily = signFamilyDao.findSanshiSignByPatient(patientCode);
- Patient patient = patientDao.findByCode(patientCode);
- if (signFamily != null) {
- //得到三师签约的服务团队
- List<Doctor> doctors = doctorDao.findSanshiDoctorByTeam(signFamily.getTeamCode());
- for (Doctor doctor : doctors) {
- JSONObject jo = new JSONObject();
- jo.put("code", doctor.getCode());//医生code
- jo.put("sex", doctor.getSex());//医生性别 1男,2女)
- jo.put("name", doctor.getName());//医生名称
- jo.put("photo", doctor.getPhoto());//医生头像
- jo.put("hosptialName", doctor.getHosptialName());//所属机构名称
- jo.put("level", doctor.getLevel());//医生等级1专科医生,2全科医生,3健康管理师
- jo.put("signType", "1");//签约类别 1是三师 2是家庭
- jo.put("signStatus", signFamily.getStatus());//签约状态 0待签约,1已签约 2待解约
- jo.put("jobName", doctor.getJobName());//职称
- jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
- if (signFamily.getStatus() == 0) {
- jo.put("sqDate", DateUtil.dateToStrShort(signFamily.getPatientApplyDate()));//申请时间
- } else if (signFamily.getStatus() == 1) {
- jo.put("qyDate", DateUtil.dateToStrShort(signFamily.getApplyDate()));//签约时间
- jo.put("endDate", DateUtil.dateToStrShort(signFamily.getEnd()));//结束时间
- } else if (signFamily.getStatus() == 2) {
- jo.put("qyDate", DateUtil.dateToStrShort(signFamily.getPatientApplyUnsignDate()));//申请解约时间
- jo.put("endDate", DateUtil.dateToStrShort(signFamily.getEnd()));//结束时间
- }
- jsonArray.put(jo);
- }
- }
- //得到家庭签约
- SignFamily jtSignFamily = signFamilyDao.findFamilySignByPatient(patientCode);
- if (jtSignFamily != null) {
- //家庭签约只找全科医生
- Doctor doctor = doctorDao.findByCode(jtSignFamily.getDoctor());
- if (doctor != null) {
- JSONObject jo = new JSONObject();
- jo.put("code", doctor.getCode());
- jo.put("sex", doctor.getSex());
- jo.put("name", doctor.getName());
- jo.put("photo", doctor.getPhoto());
- jo.put("hosptialName", doctor.getHosptialName());
- jo.put("level", doctor.getLevel());
- jo.put("signType", "2");//三师签约
- jo.put("signStatus", jtSignFamily.getStatus());
- jo.put("jobName", doctor.getJobName());
- jo.put("disease", patient.getDisease());//0健康,1高血压,2糖尿病,3高血压+糖尿病
- if (jtSignFamily.getStatus() == 0) {
- jo.put("sqDate", DateUtil.dateToStrShort(jtSignFamily.getPatientApplyDate()));//申请时间
- } else {
- jo.put("qyDate", DateUtil.dateToStrShort(jtSignFamily.getApplyDate()));//签约时间
- jo.put("endDate", DateUtil.dateToStrShort(jtSignFamily.getEnd()));//结束时间
- }
- jsonArray.put(jo);
- }
- }
- return jsonArray;
- }
- public SignFamily getPatientSign(String patient) {
- return signFamilyDao.findByPatient(patient);
- }
- public SignFamily getssPatientSign(String invitePatientCode) {
- return signFamilyDao.findBySsPatient(invitePatientCode);
- }
- /**
- * 患者家庭签约收费类型更新
- *
- * @param expensesType
- * @param patient
- * @return
- */
- public boolean updateExpensesType(String expensesType, String patient) {
- if (signFamilyDao.updateExpensesType(expensesType, patient) > 0) {
- return true;
- } else {
- return false;
- }
- }
- public boolean updateSignStatus(String patientCard) {
- // 判断患者有没有家庭签约
- SignFamily sf = signFamilyDao.findByPatientStatus(patientCard, 0);
- if (sf != null) {
- sf.setStatus(-5);
- }
- return true;
- }
- public String produceSignAdminTeamCode() {
- StringBuffer sf = new StringBuffer();
- StringBuffer sf1 = new StringBuffer();
- Long size = 0L;
- //找出家庭签约中团队code是空的
- List<SignFamily> signFamilys = signFamilyDao.findBySignTypeAndTeamCode();
- sf.append("家庭签约中团队code是空的数据数:" + signFamilys.size());
- for (SignFamily signFamily : signFamilys) {
- //得到签约中的全科医生的团队
- String doctorCode = signFamily.getDoctor();
- Long id = doctorAdminTeamDao.findIdByLeaderCode(doctorCode);
- if (id != null && id > 0) {
- size++;
- signFamily.setAdminTeamId(id);
- } else {
- sf1.append(",找不到医生所属的团队,医生code:" + doctorCode);
- }
- }
- sf.append(",填充团队的签约数据数:" + size);
- sf.append(sf1);
- return sf.toString();
- }
- /**
- * 分配健管师
- *
- * @param patient 患者code
- * @param healthDoctor 健康管理师code
- * @return
- */
- public JSONObject updateSignInfo(String patient, String healthDoctor, String expensesType) {
- JSONObject result = new JSONObject();
- SignFamily signFamily = signFamilyDao.findByjiatingPatientYes(patient);
- if (signFamily == null) {
- result.put("status", -1);
- result.put("msg", "居民不存在家庭签约");
- }
- if (StringUtils.isNotEmpty(healthDoctor)) {
- Doctor doctor = doctorDao.findByCode(healthDoctor);
- if (doctor == null) {
- result.put("status", -2);
- result.put("msg", "医生不存在");
- }
- if (StringUtils.isNotEmpty(signFamily.getDoctorHealth())) {
- // 取消原有健康管理师的家庭签约分组,并新增分组
- List<DoctorPatientGroupInfo> groups = doctorPatientGroupInfoDao.findGroupInfoByPatientAndDoctor(signFamily.getDoctorHealth(), patient);
- if (groups != null) {
- List<DoctorPatientGroupInfo> newGroups = new ArrayList<>();
- for (DoctorPatientGroupInfo group : groups) {
- if (group.getGroup().equals("1") || group.getGroup().equals("2") || group.getGroup().equals("3")) {
- DoctorPatientGroupInfo newGroup = new DoctorPatientGroupInfo();
- newGroup.setDoctor(doctor.getCode());
- newGroup.setCzrq(new Date());
- newGroup.setGroup(group.getGroup());
- newGroup.setPatient(patient);
- newGroup.setSignType("2");
- newGroup.setStatus(1);
- newGroup.setPname(group.getPname());
- newGroups.add(newGroup);
- }
- group.setStatus(0);
- group.setCzrq(new Date());
- }
- if (newGroups.size() > 0) {
- doctorPatientGroupInfoDao.save(newGroups);
- }
- // 更新团队信息
- if (StringUtils.isNotEmpty(signFamily.getTeamCode())) {
- DoctorTeamMember teamMember = doctorTeamDoctor.findMemberByTeamAndCode(signFamily.getTeamCode(), signFamily.getDoctorHealth());
- if (teamMember != null) {
- teamMember.setDel("0");
- teamMember.setCzrq(new Date());
- }
- DoctorTeamMember newTeamMember = new DoctorTeamMember();
- newTeamMember.setCode(getCode());
- newTeamMember.setMemberCode(doctor.getCode());
- newTeamMember.setName(doctor.getName());
- newTeamMember.setTeam(signFamily.getTeamCode());
- newTeamMember.setDel("1");
- newTeamMember.setSignType("2");
- newTeamMember.setType(3);
- newTeamMember.setCzrq(new Date());
- doctorTeamDoctor.save(newTeamMember);
- }
- }
- } else {
- // 新增分组
- List<DoctorPatientGroupInfo> groups = doctorPatientGroupInfoDao.findGroupInfoByPatientAndDoctor(signFamily.getDoctor(), patient);
- if (groups != null) {
- List<DoctorPatientGroupInfo> newGroups = new ArrayList<>();
- for (DoctorPatientGroupInfo group : groups) {
- if (group.getGroup().equals("1") || group.getGroup().equals("2") || group.getGroup().equals("3")) {
- DoctorPatientGroupInfo newGroup = new DoctorPatientGroupInfo();
- newGroup.setDoctor(doctor.getCode());
- newGroup.setCzrq(new Date());
- newGroup.setGroup(group.getGroup());
- newGroup.setPatient(patient);
- newGroup.setSignType("2");
- newGroup.setStatus(1);
- newGroup.setPname(group.getPname());
- newGroups.add(newGroup);
- }
- }
- if (newGroups.size() > 0) {
- doctorPatientGroupInfoDao.save(newGroups);
- }
- // 新增团队信息
- if (StringUtils.isNotEmpty(signFamily.getTeamCode())) {
- DoctorTeamMember newTeamMember = new DoctorTeamMember();
- newTeamMember.setCode(getCode());
- newTeamMember.setMemberCode(doctor.getCode());
- newTeamMember.setName(doctor.getName());
- newTeamMember.setTeam(signFamily.getTeamCode());
- newTeamMember.setDel("1");
- newTeamMember.setSignType("2");
- newTeamMember.setType(3);
- newTeamMember.setCzrq(new Date());
- doctorTeamDoctor.save(newTeamMember);
- }
- }
- }
- signFamily.setDoctorHealth(doctor.getCode());
- signFamily.setDoctorHealthName(doctor.getName());
- signFamily.setCzrq(new Date());
- }
- if (StringUtils.isNotEmpty(expensesType)) {
- if (StringUtils.isNotEmpty(signFamily.getMedicalInsuranceNum())) {
- result.put("status", -3);
- result.put("msg", "数据已上传社保,不能修改补贴类型");
- } else {
- signFamily.setExpensesType(expensesType);
- }
- }
- result.put("status", 1);
- result.put("msg", "更新成功");
- return result;
- }
- public List<SignFamily> findNoHealthSignFamilyNum(String doctor) {
- return signFamilyDao.findNoHealthSignFamilyNum(doctor);
- }
- public Page<SignFamily> findNoHealthSignFamilyHealth(String doctor, Integer page, Integer pagesize) {
- if (pagesize == null || pagesize <= 0) {
- pagesize = 10;
- }
- if (page == null || page < 0) {
- page = 0;
- }
- // 分页信息
- PageRequest pageRequest = new PageRequest(page, pagesize);
- return signFamilyDao.findNoHealthSignFamilyHealth(doctor, pageRequest);
- }
- }
|