diff --git a/platform-common/src/main/java/com/lyms/platform/common/dao/BaseMongoDAOImpl.java b/platform-common/src/main/java/com/lyms/platform/common/dao/BaseMongoDAOImpl.java index 16e23d0..222eb6c 100644 --- a/platform-common/src/main/java/com/lyms/platform/common/dao/BaseMongoDAOImpl.java +++ b/platform-common/src/main/java/com/lyms/platform/common/dao/BaseMongoDAOImpl.java @@ -1,197 +1,197 @@ -package com.lyms.platform.common.dao; - -import com.lyms.platform.common.dao.operator.MongoCondition; -import com.lyms.platform.common.dao.operator.MongoOper; -import com.lyms.platform.common.dao.operator.MongoQuery; -import com.lyms.platform.common.dao.operator.Page; -import com.lyms.platform.common.pojo.SyncDataModel; -import com.lyms.platform.common.pojo.UpdateMultiData; -import com.lyms.platform.common.utils.*; -import org.apache.commons.codec.binary.Base64; -import org.apache.commons.collections.CollectionUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.data.mongodb.core.query.Update; -import org.springframework.util.Assert; - -import java.io.Serializable; -import java.util.Collection; -import java.util.Date; -import java.util.List; - -public class BaseMongoDAOImpl implements BaseMongoDAO { - - /** - * spring mongodb 集成操作类 - */ - @Autowired - protected MongoTemplate mongoTemplate; - - @Override - public void batchSave(Collection list) { - if (CollectionUtils.isNotEmpty(list)) { - mongoTemplate.insertAll(list); - } - } - - @Override - public List find(Query query) { - Assert.notNull(query, "execute find method query must not null."); - return mongoTemplate.find(query, this.getEntityClass()); - } - - @Override - public T findOne(Query query) { - Assert.notNull(query, "execute findOne method query must not null."); - return mongoTemplate.findOne(query, this.getEntityClass()); - } - - /** - * 修改根据所有查询条件查出来的数据 - */ - public void update(Query query, T obj) { - Update update = MongoConvertHelper - .convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); - Assert.notNull(update, "execute update method must not null."); -// query.getQueryObject().get() - mongoTemplate.updateMulti(query, update, this.getEntityClass()); - Object id = query.getQueryObject().get("id"); - if (id != null) { - addSyncData("UPDATE", obj, id.toString()); - } - } - - @Override - public T save(T entity) { - Assert.notNull(entity, "execute insert method must not null."); - mongoTemplate.insert(entity); - addSyncData("ADD", entity, ""); - return entity; - } - - @Override - public T save(T entity, String collection) { - Assert.notNull(entity, "execute insert method must not null."); - mongoTemplate.insert(entity, collection); - return entity; - } - - @Override - public T findById(String id) { - return mongoTemplate.findById(id, this.getEntityClass()); - } - - @Override - public T findById(String id, String collectionName) { - return mongoTemplate - .findById(id, this.getEntityClass(), collectionName); - } - - public Page findPage(Query query) { - Page page = new Page(); - page.setPage(query.getSkip()); - page.setLimit(query.getLimit()); - - long count = this.count(query); - page.reBuild((int) count); - List rows = this.find(query); - page.setDataList(rows); - return page; - } - - @Override - public long count(Query query) { - return mongoTemplate.count(query, this.getEntityClass()); - } - - public long count(Query query, String collection) { - return mongoTemplate.count(query, collection); - } - - public void delete(Query query) { - Object id = query.getQueryObject().get("id"); - if (id != null) { - addSyncData("DELETE", this.getEntityClass(), id.toString()); - } - mongoTemplate.findAllAndRemove(query, this.getEntityClass()); - } - public void delete(Query query,Class clazz) { - mongoTemplate.findAllAndRemove(query,clazz); - } - /** - * 修改找到的第一条数据 - * - * @param query - * @param obj - */ - public void findAndModify(Query query,T obj){ - Assert.notNull(obj, "execute findAndModify method must not null."); - Update update = MongoConvertHelper - .convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); - Assert.notNull(update, "execute findAndModify method must not null.update:" + update); - mongoTemplate.findAndModify(query,update,this.getEntityClass()); - } - - /** - * 修改符合条件的所有数据 - * @param query - * @param obj - */ - public void updateMulti(Query query,T obj){ - Assert.notNull(obj, "execute findAndModify method must not null."); - Update update = MongoConvertHelper - .convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); - Assert.notNull(update, "execute findAndModify method must not null.update:" + update); - mongoTemplate.updateMulti(query,update,this.getEntityClass()); - // 数据上传 - UpdateMultiData data = new UpdateMultiData(); - data.setMongoQuery(query); - data.setUpdate(ReflectionUtils.getUpdateField(obj)); - // 批量修改的情况下,ID字段是要修改的CLASS - addSyncData("UPDATEMULTI", data, obj.getClass().getName()); - } - - public static String mongo_crypto_key = Config.getItem("mongo_crypto_key", "0"); - public static String mongo_sync = Config.getItem("mongo_sync", "0"); - public void addSyncData(String action, Object data, String id) { - if ("SyncDataModel".equals(data.getClass().getSimpleName()) - || "ArchiveData".equals(data.getClass().getSimpleName())) { - return; - } - if ("1".equals(mongo_sync)) { - try { - if (action.startsWith("Mysql")) { - return; - } - SyncDataModel model = new SyncDataModel(); - model.setAction(action); - if (null != data) { - model.setClassName(LymsEncodeUtil.aesEncrypt(data.getClass().getName(), mongo_crypto_key)); - model.setJsonData(Base64.encodeBase64String(SerializUtils.objToByte((Serializable)data))); - model.setType(1); - } - model.setCreated(new Date()); - model.setModified(model.getCreated()); - if (org.apache.commons.lang.StringUtils.isNotBlank(id)) { - model.setDataId(LymsEncodeUtil.aesEncrypt(id, mongo_crypto_key)); - } - model.setStatus(1); - mongoTemplate.insert(model); - } catch (Exception e) { - e.printStackTrace(); - System.out.println(data); - } - } - } - - /** - * 获取需要操作的实体类class - * - * @return - */ - private Class getEntityClass() { - return ReflectionUtils.getSuperClassGenricType(getClass()); - } +package com.lyms.platform.common.dao; + +import com.lyms.platform.common.dao.operator.MongoCondition; +import com.lyms.platform.common.dao.operator.MongoOper; +import com.lyms.platform.common.dao.operator.MongoQuery; +import com.lyms.platform.common.dao.operator.Page; +import com.lyms.platform.common.pojo.SyncDataModel; +import com.lyms.platform.common.pojo.UpdateMultiData; +import com.lyms.platform.common.utils.*; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.collections.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; +import org.springframework.util.Assert; + +import java.io.Serializable; +import java.util.Collection; +import java.util.Date; +import java.util.List; + +public class BaseMongoDAOImpl implements BaseMongoDAO { + + /** + * spring mongodb 集成操作类 + */ + @Autowired + protected MongoTemplate mongoTemplate; + + @Override + public void batchSave(Collection list) { + if (CollectionUtils.isNotEmpty(list)) { + mongoTemplate.insertAll(list); + } + } + + @Override + public List find(Query query) { + Assert.notNull(query, "execute find method query must not null."); + return mongoTemplate.find(query, this.getEntityClass()); + } + + @Override + public T findOne(Query query) { + Assert.notNull(query, "execute findOne method query must not null."); + return mongoTemplate.findOne(query, this.getEntityClass()); + } + + /** + * 修改根据所有查询条件查出来的数据 + */ + public void update(Query query, T obj) { + Update update = MongoConvertHelper + .convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); + Assert.notNull(update, "execute update method must not null."); +// query.getQueryObject().get() + mongoTemplate.updateMulti(query, update, this.getEntityClass()); + Object id = query.getQueryObject().get("id"); + if (id != null) { + addSyncData("UPDATE", obj, id.toString()); + } + } + + @Override + public T save(T entity) { + Assert.notNull(entity, "execute insert method must not null."); + mongoTemplate.insert(entity); + addSyncData("ADD", entity, ""); + return entity; + } + + @Override + public T save(T entity, String collection) { + Assert.notNull(entity, "execute insert method must not null."); + mongoTemplate.insert(entity, collection); + return entity; + } + + @Override + public T findById(String id) { + return mongoTemplate.findById(id, this.getEntityClass()); + } + + @Override + public T findById(String id, String collectionName) { + return mongoTemplate + .findById(id, this.getEntityClass(), collectionName); + } + + public Page findPage(Query query) { + Page page = new Page(); + page.setPage(query.getSkip()); + page.setLimit(query.getLimit()); + + long count = this.count(query); + page.reBuild((int) count); + List rows = this.find(query); + page.setDataList(rows); + return page; + } + + @Override + public long count(Query query) { + return mongoTemplate.count(query, this.getEntityClass()); + } + + public long count(Query query, String collection) { + return mongoTemplate.count(query, collection); + } + + public void delete(Query query) { + Object id = query.getQueryObject().get("id"); + if (id != null) { + addSyncData("DELETE", this, id.toString()); + } + mongoTemplate.findAllAndRemove(query, this.getEntityClass()); + } + public void delete(Query query,Class clazz) { + mongoTemplate.findAllAndRemove(query,clazz); + } + /** + * 修改找到的第一条数据 + * + * @param query + * @param obj + */ + public void findAndModify(Query query,T obj){ + Assert.notNull(obj, "execute findAndModify method must not null."); + Update update = MongoConvertHelper + .convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); + Assert.notNull(update, "execute findAndModify method must not null.update:" + update); + mongoTemplate.findAndModify(query,update,this.getEntityClass()); + } + + /** + * 修改符合条件的所有数据 + * @param query + * @param obj + */ + public void updateMulti(Query query,T obj){ + Assert.notNull(obj, "execute findAndModify method must not null."); + Update update = MongoConvertHelper + .convertToNativeUpdate(ReflectionUtils.getUpdateField(obj)); + Assert.notNull(update, "execute findAndModify method must not null.update:" + update); + mongoTemplate.updateMulti(query,update,this.getEntityClass()); + // 数据上传 + UpdateMultiData data = new UpdateMultiData(); + data.setMongoQuery(query); + data.setUpdate(ReflectionUtils.getUpdateField(obj)); + // 批量修改的情况下,ID字段是要修改的CLASS + addSyncData("UPDATEMULTI", data, obj.getClass().getName()); + } + + public static String mongo_crypto_key = Config.getItem("mongo_crypto_key", "0"); + public static String mongo_sync = Config.getItem("mongo_sync", "0"); + public void addSyncData(String action, Object data, String id) { + if ("SyncDataModel".equals(data.getClass().getSimpleName()) + || "ArchiveData".equals(data.getClass().getSimpleName())) { + return; + } + if ("1".equals(mongo_sync)) { + try { + if (action.startsWith("Mysql")) { + return; + } + SyncDataModel model = new SyncDataModel(); + model.setAction(action); + if (null != data) { + model.setClassName(LymsEncodeUtil.aesEncrypt(data.getClass().getName(), mongo_crypto_key)); + model.setJsonData(Base64.encodeBase64String(SerializUtils.objToByte((Serializable)data))); + model.setType(1); + } + model.setCreated(new Date()); + model.setModified(model.getCreated()); + if (org.apache.commons.lang.StringUtils.isNotBlank(id)) { + model.setDataId(LymsEncodeUtil.aesEncrypt(id, mongo_crypto_key)); + } + model.setStatus(1); + mongoTemplate.insert(model); + } catch (Exception e) { + e.printStackTrace(); + System.out.println(data); + } + } + } + + /** + * 获取需要操作的实体类class + * + * @return + */ + private Class getEntityClass() { + return ReflectionUtils.getSuperClassGenricType(getClass()); + } } \ No newline at end of file diff --git a/platform-job-index/src/main/resources/spring/applicationContext_biz_patient.xml b/platform-job-index/src/main/resources/spring/applicationContext_biz_patient.xml index 43e8f96..59c1db3 100644 --- a/platform-job-index/src/main/resources/spring/applicationContext_biz_patient.xml +++ b/platform-job-index/src/main/resources/spring/applicationContext_biz_patient.xml @@ -1,58 +1,58 @@ - - - - - - - - - - - - - - - - - - - - - dalInterceptor - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + dalInterceptor + + + + + + + + + + \ No newline at end of file diff --git a/platform-operate-api/pom.xml b/platform-operate-api/pom.xml index 5b299ee..6be4135 100644 --- a/platform-operate-api/pom.xml +++ b/platform-operate-api/pom.xml @@ -1,156 +1,156 @@ - - - - com.lyms.core - regional-platform - 1.0.1 - - 4.0.0 - war - platform-operate-api - - - - - - - - - - - - - - com.lyms.core - platform-common - ${project.version} - - - com.lyms.core - platform-dal - ${project.version} - - - com.lyms.core - platform-biz-service - ${project.version} - - - com.lyms.core - platform-biz-patient-service - ${project.version} - - - com.lyms.core - platform-reportData - ${project.version} - - - org.apache.activemq - activemq-all - ${org.activemq.version} - - - javax.jms - javax.jms-api - 2.0.1 - - - org.springframework - spring-jms - ${org.springframework.version} - - - org.apache.activemq - activemq-core - ${org.activemq.version} - - - org.apache.activemq - activemq-pool - ${org.activemq.version} - - - - - - ../platform-resource/resources - - - **/* - - - true - - - src/main/resources - - **/* - - - - - - - src/main/resources - - database.properties - - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.7 - 1.7 - ${maven.compiler.encoding} - - - - org.apache.maven.plugins - maven-resources-plugin - 2.6 - - ${project.build.sourceEncoding} - - - - - platform-operate-api - - - - dev - - - - true - - - - ../platform-resource/resources/config-dev.properties - - - - - test - - - ../platform-resource/resources/config-test.properties - - - - - prod - - - ../platform-resource/resources/config-product.properties - - - - + + + + com.lyms.core + regional-platform + 1.0.1 + + 4.0.0 + war + platform-operate-api + + + + + + + + + + + + + + com.lyms.core + platform-common + ${project.version} + + + com.lyms.core + platform-dal + ${project.version} + + + com.lyms.core + platform-biz-service + ${project.version} + + + com.lyms.core + platform-biz-patient-service + ${project.version} + + + com.lyms.core + platform-reportData + ${project.version} + + + org.apache.activemq + activemq-all + ${org.activemq.version} + + + javax.jms + javax.jms-api + 2.0.1 + + + org.springframework + spring-jms + ${org.springframework.version} + + + org.apache.activemq + activemq-core + ${org.activemq.version} + + + org.apache.activemq + activemq-pool + ${org.activemq.version} + + + + + + ../platform-resource/resources + + + **/* + + + true + + + src/main/resources + + **/* + + + + + + + src/main/resources + + database.properties + + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.7 + 1.7 + ${maven.compiler.encoding} + + + + org.apache.maven.plugins + maven-resources-plugin + 2.6 + + ${project.build.sourceEncoding} + + + + + platform-operate-api + + + + dev + + + + true + + + + ../platform-resource/resources/config-dev.properties + + + + + test + + + ../platform-resource/resources/config-test.properties + + + + + prod + + + ../platform-resource/resources/config-product.properties + + + + \ No newline at end of file diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/RegionController.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/RegionController.java index f8077e1..ce818cc 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/RegionController.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/controller/RegionController.java @@ -1,206 +1,206 @@ -package com.lyms.platform.operate.web.controller; - - -import com.lyms.platform.biz.service.BasicConfigService; -import com.lyms.platform.common.annotation.TokenRequired; -import com.lyms.platform.common.base.BaseController; -import com.lyms.platform.common.base.LoginContext; -import com.lyms.platform.common.constants.ErrorCodeConstants; -import com.lyms.platform.common.enums.UserTypeEnum; -import com.lyms.platform.common.enums.YnEnums; -import com.lyms.platform.common.result.BaseObjectResponse; -import com.lyms.platform.common.utils.ResultUtils; -import com.lyms.platform.common.utils.SystemConfig; -import com.lyms.platform.permission.model.Organization; -import com.lyms.platform.permission.model.Users; -import com.lyms.platform.permission.service.OrganizationService; -import com.lyms.platform.permission.service.UsersService; -import com.lyms.platform.pojo.BasicConfig; -import com.lyms.platform.query.BasicConfigQuery; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * Created by Administrator on 2015/9/17 0017. - */ -@Controller -public class RegionController extends BaseController{ - - @Autowired - private BasicConfigService basicConfigService; - @Autowired - private UsersService usersService; - @Autowired - private OrganizationService organizationService; - /** - * mongo 里面省市区的id - */ - public static final String CHINA_BASIC_ID = "f6c505dd-835a-43d7-b0bb-fdb9eb0b7b31"; - @TokenRequired - @RequestMapping(value = "/regions",method = RequestMethod.GET) - public void getRegions(@RequestParam(value = "parentId", required = false) String parentId, - HttpServletResponse httpServletResponse, HttpServletRequest request ){ - //获取登录用户 - LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); - Users user = usersService.getUsers(loginState.getId()); - if(null == user) { - ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SYSTEM_ERROR, "not find login user!"); - return; - } - BasicConfigQuery query = new BasicConfigQuery(); - query.setYn(YnEnums.YES.getId()); - query.setTypeId("b7ea005c-dfac-4c2a-bdae-25239b3f44fd"); - - if(UserTypeEnum.NORMAL_USER.getId().equals(user.getType())) { - if(null == user.getOrgId()) { - ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SYSTEM_ERROR, "user not defined orgId error!"); - return; - } - Organization organization = organizationService.getOrganization(user.getOrgId()); - if("0".equals(parentId)){ - parentId = SystemConfig.CHINA_BASIC_ID;; - } - /* if (null != organization.getProvinceId() && null==parentId) { - parentId = organization.getProvinceId(); - query.setId(parentId); - }else if(StringUtils.isNotEmpty(organization.getCityId())&&null!=parentId &&parentId.equals(organization.getProvinceId())) { - parentId = organization.getCityId(); - query.setId(parentId); - }else if(StringUtils.isNotEmpty(organization.getAreaId())&&null!=parentId &&parentId.equals(organization.getCityId())) { - parentId = organization.getAreaId(); - query.setId(parentId); - } - else if(StringUtils.isNotEmpty(organization.getStreetId())&&null!=parentId &&parentId.equals(organization.getAreaId())) { - parentId = organization.getStreetId(); - query.setId(parentId); - }else {*/ - query.setParentId(parentId); -// } - }else{ - query.setParentId(parentId); - } - - - if ((UserTypeEnum.SUPPER_ADMIN.getId().equals(user.getType()) || UserTypeEnum.PLATFORM_ADMIN.getId().equals(user.getType())) && ("0".equals(parentId) || StringUtils.isBlank(parentId))) { - parentId = SystemConfig.CHINA_BASIC_ID; - query.setParentId(parentId); - } - query.setEnable(1); - - List configList = basicConfigService.queryBasicConfig(query); - List> list =new ArrayList>(); - if (CollectionUtils.isNotEmpty(configList)){ - for (BasicConfig config :configList){ - Map region=new HashMap(); - region.put("id",config.getId()); - region.put("regionName",config.getName()); - region.put("parentId", config.getParentId()); - region.put("code", config.getCode() ); - list.add(region); - } - } - ResultUtils.buildSuccessResultAndWrite(httpServletResponse, list); - } - - - @RequestMapping(value = "/queryRegions",method = RequestMethod.GET) - public void queryRegions(@RequestParam(value = "parentId", required = false) String parentId, - @RequestParam(value = "id", required = false) String id, - HttpServletResponse httpServletResponse, HttpServletRequest request ){ - BasicConfigQuery query = new BasicConfigQuery(); - if(StringUtils.isBlank(parentId) && StringUtils.isBlank(id)) { - query.setParentId(SystemConfig.CHINA_BASIC_ID); - } else if(StringUtils.isNotBlank(parentId)){ - query.setParentId(parentId); - }else if(StringUtils.isNotBlank(id)) { - query.setId(id); - } - - query.setYn(YnEnums.YES.getId()); - query.setTypeId("b7ea005c-dfac-4c2a-bdae-25239b3f44fd"); - - List configList = basicConfigService.queryBasicConfig(query); - List> list =new ArrayList>(); - if (CollectionUtils.isNotEmpty(configList)){ - for (BasicConfig config :configList){ - Map region=new HashMap(); - region.put("id",config.getId()); - region.put("name",config.getName()); - region.put("code",config.getCode()); - list.add(region); - } - } - ResultUtils.buildSuccessResultAndWrite(httpServletResponse, list); - } - @RequestMapping(value = "/getAddress",method = RequestMethod.GET) - public void getAddress() { - BasicConfigQuery regionsQuery = new BasicConfigQuery(); - regionsQuery.setParentId(CHINA_BASIC_ID); - regionsQuery.setYn(YnEnums.YES.getId()); - List basicConfigList = basicConfigService.queryBasicConfig(regionsQuery); - List list = new ArrayList<>(); - for(BasicConfig bc : basicConfigList) - { - list.add(bc.getName()); - regionsQuery.setParentId(bc.getId()); - List list1 = basicConfigService.queryBasicConfig(regionsQuery); - for(BasicConfig bc1 : list1) - { - list.add(bc1.getName()); - - regionsQuery.setParentId(bc1.getId()); - List list2 = basicConfigService.queryBasicConfig(regionsQuery); - for(BasicConfig bc2 : list2) - { - list.add(bc2.getName()); - - regionsQuery.setParentId(bc2.getId()); - List list3 = basicConfigService.queryBasicConfig(regionsQuery); - for(BasicConfig bc3 : list3) - { - list.add(bc3.getName()); - } - - } - - } - - } - try { - FileUtils.writeLines(new File("F:\\ext.dic"), list); - } catch (IOException e) { - e.printStackTrace(); - } - - } - - - /** - * 解析身份证地址 - * @param address - * @return - */ - @RequestMapping(value = "/getAddressItems", method = RequestMethod.GET) - @ResponseBody - public BaseObjectResponse getAddressItems(@RequestParam(required = true)String address) throws UnsupportedEncodingException { - //address = new String(address.getBytes("ISO-8859-1"),"utf-8"); - return basicConfigService.getAddressItems(address); - } +package com.lyms.platform.operate.web.controller; + + +import com.lyms.platform.biz.service.BasicConfigService; +import com.lyms.platform.common.annotation.TokenRequired; +import com.lyms.platform.common.base.BaseController; +import com.lyms.platform.common.base.LoginContext; +import com.lyms.platform.common.constants.ErrorCodeConstants; +import com.lyms.platform.common.enums.UserTypeEnum; +import com.lyms.platform.common.enums.YnEnums; +import com.lyms.platform.common.result.BaseObjectResponse; +import com.lyms.platform.common.utils.ResultUtils; +import com.lyms.platform.common.utils.SystemConfig; +import com.lyms.platform.permission.model.Organization; +import com.lyms.platform.permission.model.Users; +import com.lyms.platform.permission.service.OrganizationService; +import com.lyms.platform.permission.service.UsersService; +import com.lyms.platform.pojo.BasicConfig; +import com.lyms.platform.query.BasicConfigQuery; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * Created by Administrator on 2015/9/17 0017. + */ +@Controller +public class RegionController extends BaseController{ + + @Autowired + private BasicConfigService basicConfigService; + @Autowired + private UsersService usersService; + @Autowired + private OrganizationService organizationService; + /** + * mongo 里面省市区的id + */ + public static final String CHINA_BASIC_ID = "f6c505dd-835a-43d7-b0bb-fdb9eb0b7b31"; + @TokenRequired + @RequestMapping(value = "/regions",method = RequestMethod.GET) + public void getRegions(@RequestParam(value = "parentId", required = false) String parentId, + HttpServletResponse httpServletResponse, HttpServletRequest request ){ + //获取登录用户 + LoginContext loginState = (LoginContext) request.getAttribute("loginContext"); + Users user = usersService.getUsers(loginState.getId()); + if(null == user) { + ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SYSTEM_ERROR, "not find login user!"); + return; + } + BasicConfigQuery query = new BasicConfigQuery(); + query.setYn(YnEnums.YES.getId()); + query.setTypeId("b7ea005c-dfac-4c2a-bdae-25239b3f44fd"); + + if(UserTypeEnum.NORMAL_USER.getId().equals(user.getType())) { + if(null == user.getOrgId()) { + ResultUtils.buildResultAndWrite(httpServletResponse, ErrorCodeConstants.SYSTEM_ERROR, "user not defined orgId error!"); + return; + } + Organization organization = organizationService.getOrganization(user.getOrgId()); + if("0".equals(parentId)){ + parentId = SystemConfig.CHINA_BASIC_ID;; + } + /* if (null != organization.getProvinceId() && null==parentId) { + parentId = organization.getProvinceId(); + query.setId(parentId); + }else if(StringUtils.isNotEmpty(organization.getCityId())&&null!=parentId &&parentId.equals(organization.getProvinceId())) { + parentId = organization.getCityId(); + query.setId(parentId); + }else if(StringUtils.isNotEmpty(organization.getAreaId())&&null!=parentId &&parentId.equals(organization.getCityId())) { + parentId = organization.getAreaId(); + query.setId(parentId); + } + else if(StringUtils.isNotEmpty(organization.getStreetId())&&null!=parentId &&parentId.equals(organization.getAreaId())) { + parentId = organization.getStreetId(); + query.setId(parentId); + }else {*/ + query.setParentId(parentId); +// } + }else{ + query.setParentId(parentId); + } + + + if ((UserTypeEnum.SUPPER_ADMIN.getId().equals(user.getType()) || UserTypeEnum.PLATFORM_ADMIN.getId().equals(user.getType())) && ("0".equals(parentId) || StringUtils.isBlank(parentId))) { + parentId = SystemConfig.CHINA_BASIC_ID; + query.setParentId(parentId); + } + query.setEnable(1); + + List configList = basicConfigService.queryBasicConfig(query); + List> list =new ArrayList>(); + if (CollectionUtils.isNotEmpty(configList)){ + for (BasicConfig config :configList){ + Map region=new HashMap(); + region.put("id",config.getId()); + region.put("regionName",config.getName()); + region.put("parentId", config.getParentId()); + region.put("code", config.getCode() ); + list.add(region); + } + } + ResultUtils.buildSuccessResultAndWrite(httpServletResponse, list); + } + + + @RequestMapping(value = "/queryRegions",method = RequestMethod.GET) + public void queryRegions(@RequestParam(value = "parentId", required = false) String parentId, + @RequestParam(value = "id", required = false) String id, + HttpServletResponse httpServletResponse, HttpServletRequest request ){ + BasicConfigQuery query = new BasicConfigQuery(); + if(StringUtils.isBlank(parentId) && StringUtils.isBlank(id)) { + query.setParentId(SystemConfig.CHINA_BASIC_ID); + } else if(StringUtils.isNotBlank(parentId)){ + query.setParentId(parentId); + }else if(StringUtils.isNotBlank(id)) { + query.setId(id); + } + + query.setYn(YnEnums.YES.getId()); + query.setTypeId("b7ea005c-dfac-4c2a-bdae-25239b3f44fd"); + + List configList = basicConfigService.queryBasicConfig(query); + List> list =new ArrayList>(); + if (CollectionUtils.isNotEmpty(configList)){ + for (BasicConfig config :configList){ + Map region=new HashMap(); + region.put("id",config.getId()); + region.put("name",config.getName()); + region.put("code",config.getCode()); + list.add(region); + } + } + ResultUtils.buildSuccessResultAndWrite(httpServletResponse, list); + } + @RequestMapping(value = "/getAddress",method = RequestMethod.GET) + public void getAddress() { + BasicConfigQuery regionsQuery = new BasicConfigQuery(); + regionsQuery.setParentId(CHINA_BASIC_ID); + regionsQuery.setYn(YnEnums.YES.getId()); + List basicConfigList = basicConfigService.queryBasicConfig(regionsQuery); + List list = new ArrayList<>(); + for(BasicConfig bc : basicConfigList) + { + list.add(bc.getName()); + regionsQuery.setParentId(bc.getId()); + List list1 = basicConfigService.queryBasicConfig(regionsQuery); + for(BasicConfig bc1 : list1) + { + list.add(bc1.getName()); + + regionsQuery.setParentId(bc1.getId()); + List list2 = basicConfigService.queryBasicConfig(regionsQuery); + for(BasicConfig bc2 : list2) + { + list.add(bc2.getName()); + + regionsQuery.setParentId(bc2.getId()); + List list3 = basicConfigService.queryBasicConfig(regionsQuery); + for(BasicConfig bc3 : list3) + { + list.add(bc3.getName()); + } + + } + + } + + } + try { + FileUtils.writeLines(new File("F:\\ext.dic"), list); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + + /** + * 解析身份证地址 + * @param address + * @return + */ + @RequestMapping(value = "/getAddressItems", method = RequestMethod.GET) + @ResponseBody + public BaseObjectResponse getAddressItems(@RequestParam(required = true)String address) throws UnsupportedEncodingException { + //address = new String(address.getBytes("ISO-8859-1"),"utf-8"); + return basicConfigService.getAddressItems(address); + } } \ No newline at end of file diff --git a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java index 7c5d67e..bcbe59c 100644 --- a/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java +++ b/platform-operate-api/src/main/java/com/lyms/platform/operate/web/facade/BookbuildingFacade.java @@ -1,1522 +1,1522 @@ -package com.lyms.platform.operate.web.facade; - -import com.lyms.hospitalapi.fnfy.FnfyHisService; -import com.lyms.hospitalapi.qhdfy.QhdfyHisService; -import com.lyms.hospitalapi.qinglongxian.QingLongXianHisService; -import com.lyms.hospitalapi.v2.HisService; -import com.lyms.platform.biz.service.*; -import com.lyms.platform.common.base.PageInfo; -import com.lyms.platform.common.constants.ErrorCodeConstants; -import com.lyms.platform.common.enums.*; -import com.lyms.platform.common.result.BaseListResponse; -import com.lyms.platform.common.result.BaseObjectResponse; -import com.lyms.platform.common.result.BaseResponse; -import com.lyms.platform.common.utils.*; -import com.lyms.platform.common.utils.StringUtils; -import com.lyms.platform.operate.web.request.*; -import com.lyms.platform.operate.web.result.*; -import com.lyms.platform.operate.web.utils.CommonsHelper; -import com.lyms.platform.operate.web.utils.JdbcUtil; -import com.lyms.platform.operate.web.utils.MessageCenterService; -import com.lyms.platform.permission.model.Organization; -import com.lyms.platform.permission.model.OrganizationQuery; -import com.lyms.platform.permission.model.Users; -import com.lyms.platform.permission.service.OrganizationService; -import com.lyms.platform.permission.service.UsersService; -import com.lyms.platform.pojo.*; -import com.lyms.platform.query.*; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Sort; -import org.springframework.stereotype.Component; - -import javax.servlet.http.HttpServletResponse; -import java.io.OutputStream; -import java.util.*; - -/** - * - */ -@Component -public class BookbuildingFacade { - - private Logger logger = LoggerFactory.getLogger(BookbuildingFacade.class); - public static final String HIS_VERSION = PropertiesUtils.getPropertyValue("his_version"); - - @Autowired - private YunBookbuildingService yunBookbuildingService; - - @Autowired - private BasicConfigFacade basicConfigFacade; - - @Autowired - private OrganizationService organizationService; - - - @Autowired - private PersonService personService; - - @Autowired - private SmsTemplateService smsTemplateService; - - - @Autowired - private AntenatalExaminationService antenatalExaminationService; - - @Autowired - private AutoMatchFacade autoMatchFacade; - - @Autowired - private UsersService usersService; - - @Autowired - private PatientsService patientsService; - - @Autowired - private BasicConfigService basicConfigService; - - @Autowired - private AntenatalExaminationFacade antenatalExaminationFacade; - - @Autowired - private SmsConfigFacade smsConfigFacade; - - @Autowired - private HisService hisServiceV2; - - @Autowired - private QingLongXianHisService qingLongXianHisService; - - @Autowired - private FnfyHisService fnfyHisService; - @Autowired - private QhdfyHisService qhdfyHisService; - - - @Autowired - private DeleteProcessHandler deleteProcessHandler; - - @Autowired - private SyncDataService syncDataService; - @Autowired - private SieveService sieveService; - @Autowired - private OrganizationGroupsFacade groupsFacade; - - @Autowired - private AutoIncermentService autoIncermentService; - - @Autowired - private PatientCheckTicketService patientCheckTicketService; - @Autowired - private AreaCodeService areaCodeService; - - /** - * 根据患者的建档ID,查询还未使用的免费产检查券 - * - * @param patientId - * @return - */ - public BaseListResponse getTicketList(String patientId) { - List list = patientCheckTicketService.queryTicket(patientId, null, null, null); - return new BaseListResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功").setData(list).setPageInfo(new PageInfo()); - } - - /** - * 添加孕妇建档 - * - * @param yunRequest - * @return - */ - public BaseObjectResponse addPregnantBookbuilding( - YunBookbuildingAddRequest yunRequest, Integer userId) { - - BaseObjectResponse br = new BaseObjectResponse(); - PatientsQuery patientsQuery = new PatientsQuery(); - patientsQuery.setYn(YnEnums.YES.getId()); - patientsQuery.setType(1); - patientsQuery.setHospitalId(yunRequest.getHospitalId()); - patientsQuery.setBuildTypeEq(0); - patientsQuery.setDueStatus(0); - - if (yunRequest.getPregnantCertificateNum() != null) { - patientsQuery.setCardNo(yunRequest.getPregnantCertificateNum()); - //判断该身份证号码是否有孕妇建档 在该医院 - List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patients)) { - br.setErrorcode(ErrorCodeConstants.DATA_EXIST); - br.setErrormsg("该身份证在医院已经建档"); - return br; - } - } - if (yunRequest.getPregnantPhone() != null) { - patientsQuery.setCardNo(null); - patientsQuery.setPhone(yunRequest.getPregnantPhone()); - //判断该手机号码在 孕期内有没有建档 - List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patients)) { - br.setErrorcode(ErrorCodeConstants.DATA_EXIST); - br.setErrormsg("该手机号码已经建档"); - return br; - } - } - - //就诊卡号判断 - if (StringUtils.isNotEmpty(yunRequest.getVcCardNo())) { - patientsQuery.setCardNo(null); - patientsQuery.setPhone(null); - patientsQuery.setVcCardNo(yunRequest.getVcCardNo()); - patientsQuery.setHospitalId(yunRequest.getHospitalId()); - List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patients)) { - br.setErrorcode(ErrorCodeConstants.DATA_EXIST); - br.setErrormsg("该就诊卡号在该医院已经建档"); - return br; - } - } - - Integer type = 1; //1孕妇 2儿童 3产妇 - //建档类型 0 未分娩建档 1儿童建档时建档 2 自动分娩类型 3 转诊自动建档 - Integer buildType = 0; - Date date = null; - if (yunRequest.getLastMenstrualPeriod() != null) { - date = DateUtil.addWeek(DateUtil.parseYMD(yunRequest.getLastMenstrualPeriod()), 42); - Date currentDate = DateUtil.formatDate(new Date()); - if (date.getTime() <= currentDate.getTime()) { - type = 3; - buildType = 2; - } - } - - PersonModel resperson = null; - if (StringUtils.isNotEmpty(yunRequest.getPregnantCertificateNum())) { - - PersonModelQuery personModelQuery = new PersonModelQuery(); - personModelQuery.setCardNo(yunRequest.getPregnantCertificateNum()); - personModelQuery.setYn(YnEnums.YES.getId()); - personModelQuery.setTypes(new Integer[]{1, 3}); //孕妇或者产妇基本信息 - List personModels = personService.queryPersons(personModelQuery); - - PersonModel pmodel = new PersonModel(); - pmodel.setName(yunRequest.getPregnantName()); - pmodel.setBirth(DateUtil.parseYMD(yunRequest.getBirthday())); - pmodel.setPhone(yunRequest.getPregnantPhone()); - pmodel.setCardNo(yunRequest.getPregnantCertificateNum()); - pmodel.setType(type); - pmodel.setModified(new Date()); - if (CollectionUtils.isNotEmpty(personModels) && personModels.get(0) != null) { - - resperson = personModels.get(0); - personService.updatePerson(pmodel, personModels.get(0).getId()); - } else { - pmodel.setYn(YnEnums.YES.getId()); - pmodel.setCreated(new Date()); - resperson = personService.addPerson(pmodel); - } - } - - Patients patient = getPatientsData(yunRequest); - patient.setDueStatus(0); - //1孕妇 3 产妇 - patient.setType(type); - if (type == 3) { - patient.setIsAutoFm(YnEnums.YES.getId()); - } - patient.setBuildType(buildType); - if (type == ServiceObjEnums.CHANOBJ.getId() && date != null) { - patient.setFmDate(date); - } - if (resperson != null) { - patient.setPid(resperson.getId()); - HighScoreResult highScoreResult = antenatalExaminationFacade.findLastRisk(resperson.getId(), true); - if (CollectionUtils.isNotEmpty(highScoreResult.getHighId())) { - patient.setRiskFactorId(highScoreResult.getHighId()); - } - patient.setRiskScore(highScoreResult.getScore()); - if (CollectionUtils.isNotEmpty(highScoreResult.getLevelId())) { - patient.setRiskLevelId(JsonUtil.array2JsonString(highScoreResult.getLevelId())); - } - } - - patient.setCreated(new Date()); - patient.setModified(new Date()); - patient.setOperator(userId); - Patients p = yunBookbuildingService.addPregnantBookbuilding(patient); - - if (p == null || p.getId() == null) { - br.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); - br.setErrormsg("建档失败,保存异常"); - return br; - - } - - //加入产筛 - patientsService.validata(p); - - if (type == ServiceObjEnums.YUNOBJ.getId()) { - //生成建档短信 - createBuildSms(p); - } - - - if (p.getType() != null && p.getType() == 1) { - - Organization organization = organizationService.getOrganization(Integer.valueOf(yunRequest.getHospitalId())); - if (null != organization) { - AreaCodeQuery areaCodeQuery = new AreaCodeQuery(); - areaCodeQuery.setAreaId(organization.getCityId()); - areaCodeQuery.setYn(YnEnums.YES.getId()); - List code = areaCodeService.queryList(areaCodeQuery); - AreaCodeModel areaCode = null; - if (CollectionUtils.isNotEmpty(code)) { - areaCode = code.get(0); - } - if (null != areaCode&&StringUtils.isNotEmpty(areaCode.getAreaCode())) { - // 建档成功后,给孕妇造五个条形码 - String ticketPid = autoIncermentService.nextPatientTicketId(areaCode.getAreaCode()); - for (Integer i = PatientCheckTicketFacade.complyCurrentDay(p.getLastMenses()); i <= 5; i++) { - PatientCheckTicket ticket = new PatientCheckTicket(); - ticket.setStatus(1); - ticket.setHospitalId(p.getHospitalId()); - ticket.setPatientId(p.getId()); - ticket.setCreated(new Date()); - ticket.setId(areaCode.getAreaCode() + ticketPid + i); - ticket.setPid(p.getPid()); - patientCheckTicketService.addTicket(ticket); - } - } - } - } - - br.setErrorcode(ErrorCodeConstants.SUCCESS); - br.setErrormsg("成功"); - br.setData(p.getId()); - return br; - - } - - /** - * 创建孕妇建档短信 - */ - private void createBuildSms(Patients patient) { - - //判断医院是否启动和对应的服务项是否启用 - SmsConfigModel configModel = new SmsConfigModel(); - BaseResponse response = smsConfigFacade.hospitalIsStart(patient.getHospitalId(), configModel, SmsServiceEnums.FWKT.getId()); - if (response != null) { - return; - } - - SmsTemplateQuery query = new SmsTemplateQuery(); - query.setYn(YnEnums.YES.getId()); - query.setStatus(1); - query.setHospitalId(patient.getHospitalId()); - query.setServiceObj(ServiceObjEnums.YUNOBJ.getId()); - query.setSpecialDateType(SpecialDateEnums.JD.getId()); - - Integer serviceType = patient.getServiceType(); - Integer serviceStatus = patient.getServiceStatus(); - - List sendList = new ArrayList<>(); - - List temps = smsTemplateService.querySmsTemplates(query); - if (CollectionUtils.isNotEmpty(temps)) { - - for (SmsTemplateModel temp : temps) { - if (temp.getServiceType() == serviceType && temp.getServiceStatus() == serviceStatus) { - sendList.add(temp); - } else if (temp.getServiceType() == serviceType && temp.getServiceStatus() == serviceStatus) { - sendList.add(temp); - } else if (temp.getServiceStatus() == ServiceStatusEnums.ADD_ALL.getId()) { - if (serviceStatus == ServiceStatusEnums.ADD_OPEN.getId() || serviceStatus == ServiceStatusEnums.UNSUBSCRIBE.getId() - || serviceStatus == ServiceStatusEnums.ADD_OVERDUE.getId() || serviceStatus == ServiceStatusEnums.SUSPEND.getId()) { - sendList.add(temp); - } - } else if (temp.getServiceStatus() == ServiceStatusEnums.ALL_OPEN.getId()) { - if (serviceStatus == ServiceStatusEnums.STANDARD_OPEN.getId() || serviceStatus == ServiceStatusEnums.ADD_OPEN.getId()) { - sendList.add(temp); - } - } else if (temp.getServiceStatus() == ServiceStatusEnums.ALL_OVERDUE.getId()) { - if (serviceStatus == ServiceStatusEnums.STANDARD_OVERDUE.getId() || serviceStatus == ServiceStatusEnums.ADD_OVERDUE.getId()) { - sendList.add(temp); - } - } else if (temp.getServiceType() == ServiceTypeEnums.ALL_SERVICE.getId() && temp.getServiceStatus() == ServiceStatusEnums.ALL.getId()) { - sendList.add(temp); - } - } - - if (CollectionUtils.isNotEmpty(sendList)) { - - //短信前缀 - String messagePrefix = smsConfigFacade.getSmsPrefix(configModel, patient.getBookbuildingDoctor()); - for (SmsTemplateModel templateModel : sendList) { - if (templateModel != null && templateModel.getStatus() == 1) { - MessageListRequest smsList = new MessageListRequest(); - List messages = new ArrayList<>(); - MessageRequest mr = new MessageRequest(); - Date dueDate = DateUtil.addDay(patient.getLastMenses(), 7); - dueDate = DateUtil.addMonth(dueDate, 9); - String content = StringUtils.replaceEL(patient.getUsername(), dueDate, templateModel.getContent()); - - mr.setContent("【" + messagePrefix + "】" + content); - mr.setObjType(ServiceObjEnums.YUNOBJ.getId()); - mr.setPhone(patient.getPhone()); - mr.setTimeType(SmsTimeTypeEnums.ONTIME.getId()); - //短信商 - mr.setServiceType(SmsProviderEnums.YM.getId()); - mr.setTypeId(ProjectTypeEnums.YNXT.getId()); - mr.setPlanTime(DateUtil.getyyyy_MM_dd_hms(new Date())); - mr.setSubTypeId(SmsServiceEnums.FWKT.getId()); - mr.setStatus(SmsStatusEnums.WFS.getId()); - mr.setExt1(patient.getHospitalId()); - mr.setExt2(templateModel.getId()); - mr.setExt3(patient.getId()); - messages.add(mr); - - if (CollectionUtils.isNotEmpty(messages)) { - smsList.setTypeId(ProjectTypeEnums.YNXT.getId()); - smsList.setMessages(messages); - //调用发送接口 - - if ("4".equals(HIS_VERSION)) - { - //秦皇岛 - //保存到同步表中 - syncDataService.savePostMsg(JsonUtil.obj2JsonString(smsList), messages.get(0).getExt1()); - } - else - { - //保存到短信中心 线上 - MessageCenterService.saveSmsCenter(smsList); - } - } - } - } - } - } - } - - - /** - * 判断对应服务是否启动 - */ - private boolean isStartService(Integer smsType, String serviceStr) { - if (StringUtils.isEmpty(serviceStr)) { - return false; - } - //消息服务启动 - List smsServices = JsonUtil.toList(serviceStr, Map.class); - - if (CollectionUtils.isNotEmpty(smsServices)) { - for (Map map : smsServices) { - String status = String.valueOf(map.get(String.valueOf(smsType))); - if ("true".equals(status)) { - return true; - } - } - } - return false; - } - - /** - * 更新孕妇信息 - * - * @param id - * @param yunRequest - */ - public BaseResponse updatePregnantById(String id, YunBookbuildingAddRequest yunRequest, Integer userId) { - - - BaseResponse br = new BaseResponse(); - PatientsQuery patientsQuery = new PatientsQuery(); - patientsQuery.setYn(YnEnums.YES.getId()); - patientsQuery.setType(1); - patientsQuery.setHospitalId(yunRequest.getHospitalId()); - patientsQuery.setBuildTypeEq(0); - patientsQuery.setDueStatus(0); - - if (yunRequest.getPregnantCertificateNum() != null) { - patientsQuery.setCardNo(yunRequest.getPregnantCertificateNum()); - //判断该身份证号码是否有孕妇建档 在该医院 - List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patients)) { - Patients pat = patients.get(0); - if (pat != null && !pat.getPhone().equals(yunRequest.getPregnantPhone())) { - if (StringUtils.isNotEmpty(yunRequest.getPregnantPhone())) { - patientsQuery.setCardNo(null); - patientsQuery.setPhone(yunRequest.getPregnantPhone()); - //判断该手机号码在 孕期内有没有建档 - patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patients)) { - br.setErrorcode(ErrorCodeConstants.DATA_EXIST); - br.setErrormsg("该手机号码已经建档"); - return br; - } - } - } - - if (pat != null && StringUtils.isNotEmpty(pat.getVcCardNo()) && !pat.getVcCardNo().equals(yunRequest.getVcCardNo())) { - - //就诊卡号判断 - if (StringUtils.isNotEmpty(yunRequest.getVcCardNo())) { - patientsQuery.setCardNo(null); - patientsQuery.setPhone(null); - patientsQuery.setVcCardNo(yunRequest.getVcCardNo()); - patientsQuery.setHospitalId(yunRequest.getHospitalId()); - patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patients)) { - br.setErrorcode(ErrorCodeConstants.DATA_EXIST); - br.setErrormsg("该就诊卡号在该医院已经建档"); - return br; - } - } - } - } - } - - - Patients patient = getPatientsData(yunRequest); - patient.setModified(new Date()); - -// Integer type = ServiceObjEnums.YUNOBJ.getId(); -// if (patient.getLastMenses() != null) -// { -// Date date = DateUtil.addWeek(DateUtil.parseYMD(yunRequest.getLastMenstrualPeriod()),42); -// Date currentDate = DateUtil.formatDate(new Date()); -// if (date.getTime() <= currentDate.getTime()) -// { -// type = ServiceObjEnums.CHANOBJ.getId(); -// } -// } -// patient.setType(type); - - - if (!StringUtils.isEmpty(yunRequest.getPid())) { - PersonModel pmodel = new PersonModel(); - pmodel.setName(yunRequest.getPregnantName()); - pmodel.setBirth(DateUtil.parseYMD(yunRequest.getBirthday())); - pmodel.setPhone(yunRequest.getPregnantPhone()); - pmodel.setCardNo(yunRequest.getPregnantCertificateNum()); - pmodel.setYn(YnEnums.YES.getId()); - pmodel.setModified(new Date()); - personService.updatePerson(pmodel, yunRequest.getPid()); - } - patient.setId(id); - //加入产筛 - patientsService.validata(patient); - - PatientsQuery pQuery = new PatientsQuery(); - pQuery.setYn(YnEnums.YES.getId()); - pQuery.setId(id); - List list = yunBookbuildingService.queryPregnantWithQuery(pQuery); - if (CollectionUtils.isNotEmpty(list)) { - Patients pat = list.get(0); - if (!(pat.getServiceStatus() == ServiceStatusEnums.STANDARD_OPEN.getId() || pat.getServiceStatus() == ServiceStatusEnums.ADD_OPEN.getId())) { - - if (pat.getServiceType() == ServiceTypeEnums.STANDARD_SERVICE.getId()) { - pat.setServiceStatus(ServiceStatusEnums.STANDARD_OPEN.getId()); - } else if (pat.getServiceType() == ServiceTypeEnums.ADD_SERVICE.getId()) { - pat.setServiceStatus(ServiceStatusEnums.ADD_OPEN.getId()); - } - - createBuildSms(pat); - } - } - - patient.setOperator(userId); - - yunBookbuildingService.updatePregnant(patient, id); - //如果当前是建档医院,那么需要修改其他非建档医院的数据 - if (autoMatchFacade.checkBStatus(userId)) { - patientsService.updateBaseData(patient); - } - return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); - } - - /** - * 查询孕妇建档记录 - * - * @param bookbuildingQueryRequest - * @return - */ - public BaseListResponse queryPregnantBuildRecord(BookbuildingQueryRequest bookbuildingQueryRequest, Integer userId) { - List patients = new ArrayList<>(); - Map typeMap = new HashMap<>(); - PatientsQuery patientsQuery = new PatientsQuery(); - patientsQuery.setYn(YnEnums.YES.getId()); - patientsQuery.setBuildType(1); - //查询主档案 - patientsQuery.setExtEnable(false); - - //如果身份证号码不为空就以身份证号码查询 - if (!StringUtils.isEmpty(bookbuildingQueryRequest.getCardNo())) { - patientsQuery.setCardNo(bookbuildingQueryRequest.getCardNo()); - patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery, "bookbuildingDate", Sort.Direction.DESC); - } - //否则用就诊卡号 查询到这个孕妇的身份证号码 再用身份证号码查询该孕妇的所有建档 包括产妇记录 - else if (!StringUtils.isEmpty(bookbuildingQueryRequest.getVcCardNo())) { - - patientsQuery.setVcCardNo(bookbuildingQueryRequest.getVcCardNo()); - patientsQuery.setHospitalId(autoMatchFacade.getHospitalId(userId)); - //优先查询本院通过就诊卡 - List localPatients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - patientsQuery.setHospitalId(null); - if (CollectionUtils.isNotEmpty(localPatients)) - { - patients = localPatients; - } - else - { - //区域模式 - patientsQuery.setHospitalList(groupsFacade.findGroupHospital(userId, false)); - - List patientsVc = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patientsVc)) { - if (patientsVc.get(0) == null || StringUtils.isEmpty(patientsVc.get(0).getCardNo())) { - patients = patientsVc; - } else { - patientsQuery.setHospitalId(null); - patientsQuery.setVcCardNo(null); - patientsQuery.setCardNo(patientsVc.get(0).getCardNo()); - patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery, "bookbuildingDate", Sort.Direction.DESC); - } - } - // 如果为空,初次建档,根据就诊卡号从HIS库取患者信息 - else { - if ("2".equals(HIS_VERSION)) { - typeMap.put("hisPatient", hisServiceV2.getPatientInfoList(bookbuildingQueryRequest.getVcCardNo())); - } else if ("3".equals(HIS_VERSION)) { - typeMap.put("hisPatient", qingLongXianHisService.getPatientInfoList(bookbuildingQueryRequest.getVcCardNo())); - } else if ("5".equals(HIS_VERSION)) { - typeMap.put("hisPatient", fnfyHisService.getPatientInfoList(bookbuildingQueryRequest.getVcCardNo())); - } else if ("4".equals(HIS_VERSION)) { - typeMap.put("hisPatient", qhdfyHisService.getPatientInfoList(bookbuildingQueryRequest.getVcCardNo())); - } - } - } - - } else if (!StringUtils.isEmpty(bookbuildingQueryRequest.getId())) { - // id,HuJiaqi添加,为了建档管理里面的查看单条使用 - patients.add(yunBookbuildingService.findOneById(bookbuildingQueryRequest.getId())); - } else if (StringUtils.isNotEmpty(bookbuildingQueryRequest.getPid())) { - patientsQuery.setPid(bookbuildingQueryRequest.getPid()); - - //区域模式 - patientsQuery.setHospitalList(groupsFacade.findGroupHospital(userId, false)); - - List patientsVc = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patientsVc)) { - if (patientsVc.get(0) == null || StringUtils.isEmpty(patientsVc.get(0).getCardNo())) { - patients = patientsVc; - } else { - patientsQuery.setHospitalId(null); - patientsQuery.setVcCardNo(null); - patientsQuery.setCardNo(patientsVc.get(0).getCardNo()); - patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery, "bookbuildingDate", Sort.Direction.DESC); - } - } - } - - String group = groupsFacade.findByCurrentUserId(autoMatchFacade.getHospitalId(userId)); - if (StringUtils.isNotEmpty(group)) { - //区域模式 - patientsQuery.setHospitalList(groupsFacade.findGroupHospital(userId, false)); - } - int count = patientsService.queryPatientCount(patientsQuery); - - //历史建档记录 - List list = new ArrayList<>(); - List results = new ArrayList<>(); - if (CollectionUtils.isNotEmpty(patients)) { - - for (Patients pat : patients) { - if (pat != null) { - BookbuildingRecordResult result = new BookbuildingRecordResult(); - if (StringUtils.isNotEmpty(pat.getHospitalId())) { - Organization org = organizationService.getOrganization(Integer.valueOf(pat.getHospitalId())); - if (org != null) { - result.setBookbuildHospital(org.getName()); - result.setHospitalId(String.valueOf(org.getId())); - } - } - result.setFmTime(DateUtil.getyyyy_MM_dd(pat.getFmDate())); - result.setBookbuildDate(DateUtil.getyyyy_MM_dd(pat.getBookbuildingDate())); - result.setId(pat.getId()); - result.setType(pat.getType()); - result.setDueStatus(pat.getDueStatus()); - results.add(result); - } - } - } - - - //证件类型 - List pcerteTypeResult = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.CERTE_TYPE_ID); - typeMap.put("certeType", pcerteTypeResult); - - //国籍 - List countiryResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.COUNTRY_TYPE_ID); - typeMap.put("country", countiryResults); - - // 民族 - List nationResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.NATION_TYPE_ID); - typeMap.put("nation", nationResults); - - // 职业类别 - List professionTypeResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.PROFESSION_TYPE_ID); - typeMap.put("professionType", professionTypeResults); - - // 户籍类别 - List censusType = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.CENSUS_TYPE_ID); - typeMap.put("censusType", censusType); - - // 户籍类别 - List liveType = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.LIVE_TYPE_ID); - typeMap.put("liveType", liveType); - - //服务类型 - List serviceType = ServiceTypeEnums.getServiceTypeList(); - typeMap.put("serviceType", serviceType); - - //服务状态 - List serviceStatus = ServiceStatusEnums.getServiceStatusList(); - typeMap.put("serviceStatus", serviceStatus); - - //孕妇体验类型 - List expYunEnums = ExpYunEnums.getExpYunEnums(); - typeMap.put("expYunEnums", expYunEnums); - - list.add(typeMap); - - - Map mapData = new HashMap<>(); - mapData.put("data", results); -// 是否在本医院所在区域建档 - mapData.put("rBType", count > 0); - mapData.put("initBuildDate", DateUtil.getyyyy_MM_dd(new Date())); - list.add(mapData); - - BaseListResponse listResponse = new BaseListResponse(); - listResponse.setData(list); - listResponse.setErrorcode(ErrorCodeConstants.SUCCESS); - listResponse.setErrormsg("成功"); - return listResponse; - } - - - /** - * 准备修改和添加的孕妇建档数据 - * - * @param yunRequest - * @return - */ - private Patients getPatientsData(YunBookbuildingAddRequest yunRequest) { - Patients patient = new Patients(); - patient.setUsername(yunRequest.getPregnantName()); - - patient.setPcerteTypeId(yunRequest.getPregnantCertificateTypeId()); - - patient.setCardNo(yunRequest.getPregnantCertificateNum()); - - patient.setPcountryId(yunRequest.getPregnantCountryId()); - patient.setPnationId(yunRequest.getPregnantNationId()); - patient.setBirth(DateUtil.parseYMD(yunRequest.getBirthday())); - - patient.setPcensusTypeId(yunRequest.getPregnantCensusTypeId()); - - patient.setPliveTypeId(yunRequest.getPregnantLiveTypeId()); - - patient.setPprofessionTypeId(yunRequest.getPregnantProfessionTypeId()); - - patient.setPhone(yunRequest.getPregnantPhone()); - - patient.setPworkUnit(yunRequest.getPregnantWorkUnit()); - patient.setPlevelTypeId(yunRequest.getPregnantLevelTypeId()); - - //孕妇居住地 - patient.setAddressRegister(yunRequest.getPregnantCensusAddr()); - patient.setProvinceRegisterId(yunRequest.getPregnantCensusProvinceId()); - patient.setCityRegisterId(yunRequest.getPregnantCensusCityId()); - patient.setAreaRegisterId(yunRequest.getPregnantCensusAreaId()); - patient.setStreetRegisterId(yunRequest.getPregnantCensusStreetId()); - - //孕妇户籍地址 - patient.setAddress(yunRequest.getPregnantLiveAddr()); - patient.setProvinceId(yunRequest.getPregnantLiveProvinceId()); - patient.setCityId(yunRequest.getPregnantLiveCityId()); - patient.setAreaId(yunRequest.getPregnantLiveAreaId()); - patient.setStreetId(yunRequest.getPregnantLiveStreetId()); - - //孕妇产后修养地 - patient.setAddressPostRest(yunRequest.getChildbirthAddr()); - patient.setProvincePostRestId(yunRequest.getChildbirthProvinceId()); - patient.setCityPostRestId(yunRequest.getChildbirthCityId()); - patient.setAreaPostRestId(yunRequest.getChildbirthAreaId()); - patient.setStreetPostRestId(yunRequest.getChildbirthStreetId()); - - //丈夫信息 - patient.setHusbandName(yunRequest.getHusbandName()); - patient.setHcertificateTypeId(yunRequest.getHusbandCertificateTypeId()); - - if (StringUtils.isNotEmpty(yunRequest.getHusbandCertificateTypeId()) && StringUtils.isNotEmpty(yunRequest.getHusbandCertificateNum())) { - BasicConfigQuery basicConfigQuery = new BasicConfigQuery(); - basicConfigQuery.setId(yunRequest.getHusbandCertificateTypeId()); - basicConfigQuery.setYn(YnEnums.YES.getId()); - List data = basicConfigService.queryBasicConfig(basicConfigQuery); - if (CollectionUtils.isNotEmpty(data)) { - //身份证类型得到丈夫的生日 必须为身份证类型 - if (StringUtils.isNotEmpty(data.get(0).getCode()) && "SFZ".endsWith(data.get(0).getCode())) { - String cardNo = yunRequest.getHusbandCertificateNum(); - Date birth = StringUtils.getBirthDay(cardNo); - patient.setHusbandBirth(birth); - } - } - } - - patient.setHcertificateNum(yunRequest.getHusbandCertificateNum()); - patient.setHusbandPhone(yunRequest.getHusbandPhone()); - patient.setHcountryId(yunRequest.getHusbandCountryId()); - patient.setHnationId(yunRequest.getHusbandNationId()); - patient.setHprofessionTypeId(yunRequest.getHusbandProfessionTypeId()); - patient.setHworkUnit(yunRequest.getHusbandWorkUnit()); - patient.setHaddressRegister(yunRequest.getHusbandAddressRegister()); - patient.setHprovinceRegisterId(yunRequest.getHusbandProvinceRegisterId()); - patient.setHcityRegisterId(yunRequest.getHusbandCityRegisterId()); - patient.setHareaRegisterId(yunRequest.getHusbandAreaRegisterId()); - patient.setHstreetRegisterId(yunRequest.getHusbandStreetRegisterId()); - patient.setHlevelTypeId(yunRequest.getHusbandLevelTypeId()); - - patient.setServiceStatus(yunRequest.getServiceStatus()); - - if (yunRequest.getExpType() != null) { - if (yunRequest.getExpType() == ExpYunEnums.SGY.getId()) { - Date vipEndTime = DateUtil.addMonth(DateUtil.parseYMD(yunRequest.getBookbuildingDate()), 3); - Date dueDate = DateUtil.parseYMD(yunRequest.getDueDate()); - if (vipEndTime.getTime() > dueDate.getTime()) { - vipEndTime = dueDate; - } - patient.setVipEndTime(vipEndTime); - } else { - Date vipEndTime = DateUtil.parseYMD(yunRequest.getDueDate()); - patient.setVipEndTime(vipEndTime); - } - patient.setExpType(yunRequest.getExpType()); - } - - - //patient.setVipEndTime(DateUtil.parseYMD(yunRequest.getVipEndTime())); - patient.setExpVip(yunRequest.getExpVip()); - patient.setMremark(yunRequest.getMremark()); - - patient.setLastMenses(DateUtil.parseYMD(yunRequest.getLastMenstrualPeriod())); - patient.setDueDate(DateUtil.parseYMD(yunRequest.getDueDate())); - patient.setFileCode(yunRequest.getFileCode()); - patient.setBookbuildingDoctor(yunRequest.getBookbuildingDoctor()); - patient.setBookbuildingDate(DateUtil.parseYMD(yunRequest.getBookbuildingDate())); - patient.setServiceType(yunRequest.getServiceType()); - patient.setVcCardNo(yunRequest.getVcCardNo()); - patient.setHospitalId(yunRequest.getHospitalId()); - patient.setYn(YnEnums.YES.getId()); - - return patient; - } - - /** - * 查询孕妇建档详细 - * - * @param id - * @return - */ - public BaseObjectResponse queryPregnantBuildById(String id) { - - PatientsQuery patientsQuery = new PatientsQuery(); - patientsQuery.setId(id); - patientsQuery.setYn(YnEnums.YES.getId()); - PregnantInfoResult result = new PregnantInfoResult(); - List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (patients != null && patients.size() > 0) { - Patients p = patients.get(0); - result = getResult(p); - } - - BaseObjectResponse objectResponse = new BaseObjectResponse(); - objectResponse.setData(result); - objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); - objectResponse.setErrormsg("成功"); - return objectResponse; - } - - - private PregnantInfoResult getResult(Patients p) { - PregnantInfoResult result = new PregnantInfoResult(); - result.setId(p.getId()); - /**********孕妇基本信息***************/ - result.setPregnantName(p.getUsername()); - result.setPregnantCertificateTypeId(p.getPcerteTypeId()); - result.setPregnantCertificateNum(p.getCardNo()); - result.setPregnantCountryId(p.getPcountryId()); - result.setPregnantNationId(p.getPnationId()); - result.setBirthday(DateUtil.getyyyy_MM_dd(p.getBirth())); - result.setPregnantCensusTypeId(p.getPcensusTypeId()); - result.setPregnantLiveTypeId(p.getPliveTypeId()); - result.setPregnantProfessionTypeId(p.getPprofessionTypeId()); - result.setPregnantLevelTypeId(p.getPlevelTypeId()); - - /**********孕妇联系方式***************/ - result.setPregnantPhone(p.getPhone()); - result.setPregnantWorkUnit(p.getPworkUnit()); - - result.setPregnantCensusProvinceId(p.getProvinceRegisterId()); - result.setPregnantCensusCityId(p.getCityRegisterId()); - result.setPregnantCensusAreaId(p.getAreaRegisterId()); - result.setPregnantCensusStreetId(p.getStreetRegisterId()); - result.setPregnantCensusAddr(p.getAddressRegister()); - - result.setPregnantLiveProvinceId(p.getProvinceId()); - result.setPregnantLiveCityId(p.getCityId()); - result.setPregnantLiveAreaId(p.getAreaId()); - result.setPregnantLiveStreetId(p.getStreetId()); - result.setPregnantLiveAddr(p.getAddress()); - - - result.setChildbirthAddr(p.getAddressPostRest()); - result.setChildbirthProvinceId(p.getProvincePostRestId()); - result.setChildbirthCityId(p.getCityPostRestId()); - result.setChildbirthAreaId(p.getAreaPostRestId()); - result.setChildbirthStreetId(p.getStreetPostRestId()); - - /****************丈夫信息**************/ - result.setHusbandName(p.getHusbandName()); - result.setHusbandPhone(p.getHusbandPhone()); - - result.setHusbandCertificateTypeId(p.getHcertificateTypeId()); - result.setHusbandCertificateNum(p.getHcertificateNum()); - result.setHusbandCountryId(p.getHcountryId()); - result.setHusbandNationId(p.getHnationId()); - result.setHusbandProfessionTypeId(p.getHprofessionTypeId()); - result.setHusbandWorkUnit(p.getHworkUnit()); - result.setHusbandLevelTypeId(p.getHlevelTypeId()); - - result.setHusbandAddressRegister(p.getHaddressRegister()); - result.setHusbandProvinceRegisterId(p.getHprovinceRegisterId()); - result.setHusbandCityRegisterId(p.getHcityRegisterId()); - result.setHusbandAreaRegisterId(p.getHareaRegisterId()); - result.setHusbandStreetRegisterId(p.getHstreetRegisterId()); - - result.setServiceStatus(p.getServiceStatus() == null ? "" : String.valueOf(p.getServiceStatus())); - result.setVipEndTime(DateUtil.getyyyy_MM_dd(p.getVipEndTime())); - result.setExpVip(p.getExpVip()); - result.setMremark(p.getMremark()); - - - //院内信息 - result.setLastMenstrualPeriod(DateUtil.getyyyy_MM_dd(p.getLastMenses())); - result.setDueDate(DateUtil.getyyyy_MM_dd(p.getDueDate())); - result.setFileCode(p.getFileCode()); - result.setVcCardNo(p.getVcCardNo()); - - if (StringUtils.isNotEmpty(p.getBookbuildingDoctor())) { - Users users = usersService.getUsers(Integer.parseInt(p.getBookbuildingDoctor())); - if (users != null) { - Map doctorObj = new HashMap<>(); - doctorObj.put("id", p.getBookbuildingDoctor()); - doctorObj.put("name", users.getName()); - result.setBookbuildingDoctor(doctorObj); - } - } - - result.setBookbuildingDate(DateUtil.getyyyy_MM_dd(p.getBookbuildingDate())); - result.setServiceType(p.getServiceType() == null ? "" : String.valueOf(p.getServiceType())); - - result.setExpType(p.getExpType()); - - result.setPid(p.getPid()); - result.setDueStatus(p.getDueStatus()); - return result; - } - - /** - * 孕妇建档页面基础数据 - * - * @return - */ - public BaseObjectResponse getYunBuildBaseConfig() { - Map typeMap = new HashMap<>(); - - //证件类型 - List pcerteTypeResult = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.CERTE_TYPE_ID); - typeMap.put("certeType", pcerteTypeResult); - - //国籍 - List countiryResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.COUNTRY_TYPE_ID); - typeMap.put("country", countiryResults); - - // 民族 - List nationResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.NATION_TYPE_ID); - typeMap.put("nation", nationResults); - - // 职业类别 - List professionTypeResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.PROFESSION_TYPE_ID); - typeMap.put("professionType", professionTypeResults); - - // 户籍类别 - List censusType = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.CENSUS_TYPE_ID); - typeMap.put("censusType", censusType); - - // 户籍类别 - List liveType = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.LIVE_TYPE_ID); - typeMap.put("liveType", liveType); - - //服务类型 - List serviceType = ServiceTypeEnums.getServiceTypeList(); - typeMap.put("serviceType", serviceType); - - //服务状态 - List serviceStatus = ServiceStatusEnums.getServiceStatusList(); - typeMap.put("serviceStatus", serviceStatus); - - //孕妇体验类型 - List expYunEnums = ExpYunEnums.getExpYunEnums(); - typeMap.put("expYunEnums", expYunEnums); - - - BaseObjectResponse objectResponse = new BaseObjectResponse(); - objectResponse.setData(typeMap); - objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); - objectResponse.setErrormsg("成功"); - return objectResponse; - } - - /** - * 删除孕妇建档 - * - * @param id - * @return - */ - public BaseResponse deletePregnantById(String id, Integer userId) { - - if(org.apache.commons.lang.StringUtils.isNotEmpty(id)){ - //获取初诊记录 - String hospital = autoMatchFacade.getHospitalId(userId); - Patients patients = yunBookbuildingService.findOneById(id); - - if (!deleteProcessHandler.deleteBookBuild(patients.getPid(), patients.getBookbuildingDate(), hospital)) { - return new BaseResponse().setErrorcode(ErrorCodeConstants.DONT_DELETE).setErrormsg("孕妇存在检查记录,不能删除建档"); - } - yunBookbuildingService.deletePregnantById(id); - //删除建档需要删除产筛数据 - SieveQuery sieveQuery = new SieveQuery(); - sieveQuery.setYn(YnEnums.YES.getId()); - sieveQuery.setParentId(id); - sieveService.deleteById(sieveQuery); - - PatientCheckTicketQuery patientCheckTicketQuery=new PatientCheckTicketQuery(); - patientCheckTicketQuery.setPatientId(id); - patientCheckTicketQuery.setStatus(1); - PatientCheckTicket patientCheckTicket=new PatientCheckTicket(); - patientCheckTicket.setStatus(3); - patientCheckTicket.setPatientId(id); - patientCheckTicketService.findAndModify(patientCheckTicketQuery,patientCheckTicket); - } - - return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); - } - - /** - * 查询孕妇基本信息 通过就诊卡号或者身份证 - * - * @param cardNo - * @param vcCardNo - * @return - */ - public BaseObjectResponse queryYunBuildInfo(String cardNo, String vcCardNo, Integer userId) { - Patients pat = null; - PatientsQuery patientsQuery = new PatientsQuery(); - patientsQuery.setYn(YnEnums.YES.getId()); - if (StringUtils.isNotEmpty(cardNo)) { - patientsQuery.setCardNo(cardNo); - List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patients)) { - pat = patients.get(0); - } - } - - String hospitalId = ""; - //得到当前登录的医院id - if (userId != null) { - Users dbuser = usersService.getUsers(userId); - if (dbuser != null) { - hospitalId = String.valueOf(dbuser.getOrgId()); - } - } - - if (StringUtils.isNotEmpty(vcCardNo) && StringUtils.isNotEmpty(hospitalId)) { - patientsQuery.setVcCardNo(vcCardNo); - patientsQuery.setHospitalId(hospitalId); - List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(patients)) { - Patients vcCardNoPat = patients.get(0); - patientsQuery.setHospitalId(null); - patientsQuery.setVcCardNo(null); - patientsQuery.setCardNo(vcCardNoPat.getCardNo()); - List cardNoPat = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (CollectionUtils.isNotEmpty(cardNoPat)) { - pat = cardNoPat.get(0); - } - } - } - BaseObjectResponse objectResponse = new BaseObjectResponse(); - if (pat == null) { - objectResponse.setData(""); - } else { - objectResponse.setData(getResult(pat)); - } - - objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); - objectResponse.setErrormsg("成功"); - return objectResponse; - } - - public BaseObjectResponse queryHospitals(String keyWord, Integer page, Integer limit) { - OrganizationQuery organizationQuery = new OrganizationQuery(); - if (null != page && limit != page) { - organizationQuery.setNeed("true"); - organizationQuery.setPage(page); - organizationQuery.setLimit(limit); - organizationQuery.setSort("modified desc"); - } - - organizationQuery.setYn(YnEnums.YES.getId()); - organizationQuery.setKeyword(keyWord); - - - List> mapList = new ArrayList<>(); - List orgs = organizationService.queryHospitals(organizationQuery); - if (CollectionUtils.isNotEmpty(orgs)) { - for (Organization org : orgs) { - Map map = new HashMap<>(); - map.put("id", org.getId() + ""); - map.put("name", org.getName()); - mapList.add(map); - } - } - - BaseObjectResponse objectResponse = new BaseObjectResponse(); - objectResponse.setData(mapList); - - objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); - objectResponse.setErrormsg("成功"); - return objectResponse; - } - - public BaseListResponse queryChanJianReport(Integer userId, String exDateStart, - String exDateEnd, - String name, - Integer weekStarts, - Integer weekEnds, - String hbsag, - String hbeag, - String hbeab, - String hbcab, - String syphilis, - String hiv, - String hcv, - String doctorNo, - Integer page, - Integer limit) { - - String hospitalId = autoMatchFacade.getHospitalId(userId); - - int start = 0; - int end = 1000; - if (page != null && limit != null) { - start = (page - 1) * limit + 1; - end = page * limit; - } - String countSql = " SELECT count(*) as allCount " + - "FROM ODS_F_AUXILIARY_EXAMI A\n" + - "INNER JOIN ODS_F_GRAVIDA_RECORD B ON A.RECORD_ID=B.RECORD_ID\n" + - "INNER JOIN ODS_D_HOSPITAL C ON A.HOSPITAL_NO=C.HOSPITAL_NO AND C.VER_NO=2\n" + - "WHERE C.YCY_STSTEM_ID= '" + hospitalId + "'"; - - - String sql = "SELECT * FROM ( SELECT A.*, ROWNUM RN FROM ( SELECT A.EXAMINE_DATE,\n" + - " A.NAME,\n" + - " A.AGE,\n" + - " A.NOW_WEEKS,\n" + - " A.NOW_WEEKS_DAY, \n" + - " B.EDD_DATE,\n" + - " A.HBSAG,\n" + - " A.HBSAB,\n" + - " A.HBEAG,\n" + - " A.HBEAB,\n" + - " A.HBCAB,\n" + - " A.SYPHILIS,\n" + - " A.HIV,\n" + - " A.HCV,\n" + - " (CASE WHEN A.HIGH_RISK_GRADE IS NULL THEN '绿色预警' ELSE A.HIGH_RISK_GRADE END) AS HIGH_RISK_GRADE,\n" + - " (CASE WHEN A.HIGH_RISK_FACTOR IS NULL THEN '健康' ELSE A.HIGH_RISK_FACTOR END) AS HIGH_RISK_FACTOR,\n" + - " A.NEXT_EXAMINE_DATE,\n" + - " A.EXAMINE_HISTORY_NUM,\n" + - " A.DOCTOR_NAME,\n" + - " A.DOCTOR_NAME AS BOOKER,\n" + - " DECODE(B.IS_VIP_ID,1,'增值服务','标准服务') AS SERVICE_STATUS,\n" + - " A.SUGGESTION,\n" + - " B.TEL_NO,\n" + - " B.HOME_ADDR,\n" + - " B.STREET_VALLAGE_ID,\n" + - " B.STREET_VALLAGE,\n" + - " B.AREA_COUNTY_ID,\n" + - " B.AREA_COUNTY,\n" + - " B.CITY_ID,\n" + - " B.CITY,\n" + - " B.PROVINCE_ID,\n" + - " B.PROVINCE\n" + - " FROM ODS_F_AUXILIARY_EXAMI A " + - " INNER JOIN ODS_F_GRAVIDA_RECORD B ON A.RECORD_ID=B.RECORD_ID \n" + - " INNER JOIN ODS_D_HOSPITAL C ON A.HOSPITAL_NO=C.HOSPITAL_NO AND C.VER_NO=2 \n" + - " WHERE C.YCY_STSTEM_ID= '" + hospitalId + "'"; - if (StringUtils.isNotEmpty(exDateStart)) { - sql += " AND A.EXAMINE_DATE>= to_date('" + exDateStart + "','yyyy-MM-dd')"; - countSql += " AND A.EXAMINE_DATE>= to_date('" + exDateStart + "','yyyy-MM-dd')"; - } - if (StringUtils.isNotEmpty(exDateEnd)) { - sql += " AND A.EXAMINE_DATE <= to_date('" + exDateEnd + "','yyyy-MM-dd')"; - countSql += " AND A.EXAMINE_DATE <= to_date('" + exDateEnd + "','yyyy-MM-dd')"; - } - - if (StringUtils.isNotEmpty(name)) { - sql += " AND A.NAME LIKE '%" + name + "%'"; - countSql += " AND A.NAME LIKE '%" + name + "%'"; - } - - if (weekStarts != null) { - sql += " AND A.NOW_WEEKS>= " + weekStarts; - countSql += " AND A.NOW_WEEKS>= " + weekStarts; - } - - if (weekEnds != null) { - sql += " AND A.NOW_WEEKS <= " + weekEnds; - countSql += " AND A.NOW_WEEKS <= " + weekEnds; - } - - if (StringUtils.isNotEmpty(hbsag)) { - sql += " AND A.HBSAG = " + hbsag; - countSql += " AND A.HBSAG = " + hbsag; - } - - if (StringUtils.isNotEmpty(hbeag)) { - sql += " AND A.HBEAG = " + hbeag; - countSql += " AND A.HBEAG = " + hbeag; - } - - if (StringUtils.isNotEmpty(hbeab)) { - sql += " AND A.HBEAB = " + hbeab; - countSql += " AND A.HBEAB = " + hbeab; - } - - if (StringUtils.isNotEmpty(hbcab)) { - sql += " AND A.HBCAB = " + hbcab; - countSql += " AND A.HBCAB = " + hbcab; - } - if (StringUtils.isNotEmpty(syphilis)) { - sql += " AND A.SYPHILIS = " + syphilis; - countSql += " AND A.SYPHILIS = " + syphilis; - } - - if (StringUtils.isNotEmpty(hiv)) { - sql += " AND A.HIV = " + hiv; - countSql += " AND A.HIV = " + hiv; - } - - if (StringUtils.isNotEmpty(hcv)) { - sql += " AND A.HCV = " + hcv; - countSql += " AND A.HCV = " + hcv; - } - if (StringUtils.isNotEmpty(doctorNo)) { - sql += " AND A.DOCTOR_NO = " + doctorNo; - countSql += " AND A.DOCTOR_NO = " + doctorNo; - } - - sql += " order by A.EXAMINE_DATE DESC,A.Name ASC,A.EXAMINE_ID DESC ) A WHERE ROWNUM <= " + end + " ) WHERE RN >= " + start; - - logger.info(sql); - List> list = JdbcUtil.getListDataBySql(sql); - - Integer count = Integer.parseInt(String.valueOf(JdbcUtil.getOralceSingleObjBySql(countSql))); - BaseListResponse listResponse = new BaseListResponse(); - listResponse.setData(list); - - PageInfo pageInfo = new PageInfo(page, 0, count, limit); - - listResponse.setPageInfo(pageInfo); - - listResponse.setErrorcode(ErrorCodeConstants.SUCCESS); - listResponse.setErrormsg("成功"); - return listResponse; - } - - - public void exportChanReport(Integer userId, HttpServletResponse httpServletResponse, - String exDateStart, - String exDateEnd, - String name, - Integer weekStarts, - Integer weekEnds, - String hbsag, - String hbeag, - String hbeab, - String hbcab, - String syphilis, - String hiv, - String hcv, - String doctorNo) { - String hospitalId = autoMatchFacade.getHospitalId(userId); - String sql = "SELECT A.EXAMINE_DATE,\n" + - " A.NAME,\n" + - " A.AGE,\n" + - " (CASE WHEN A.NOW_WEEKS_DAY<>0 THEN '孕'||A.NOW_WEEKS|| '周+'||A.NOW_WEEKS_DAY||'天' ELSE '孕'||A.NOW_WEEKS|| '周' END) as NOW_WEEKS,\n" + - " A.NOW_WEEKS_DAY, \n" + - " B.EDD_DATE,\n" + - " A.HBSAG,\n" + - " A.HBSAB,\n" + - " A.HBEAG,\n" + - " A.HBEAB,\n" + - " A.HBCAB,\n" + - " A.SYPHILIS,\n" + - " A.HIV,\n" + - " A.HCV,\n" + - " (CASE WHEN A.HIGH_RISK_GRADE IS NULL THEN '绿色预警' ELSE A.HIGH_RISK_GRADE END) AS HIGH_RISK_GRADE,\n" + - " (CASE WHEN A.HIGH_RISK_FACTOR IS NULL THEN '健康' ELSE A.HIGH_RISK_FACTOR END) AS HIGH_RISK_FACTOR,\n" + - " A.NEXT_EXAMINE_DATE,\n" + - " A.EXAMINE_HISTORY_NUM,\n" + - " A.DOCTOR_NAME,\n" + - " A.DOCTOR_NAME AS BOOKER,\n" + - " DECODE(B.IS_VIP_ID,1,'增值服务','标准服务') AS SERVICE_STATUS,\n" + - " A.SUGGESTION,\n" + - " B.TEL_NO,\n" + - " B.HOME_ADDR,\n" + - " B.STREET_VALLAGE_ID,\n" + - " B.STREET_VALLAGE,\n" + - " B.AREA_COUNTY_ID,\n" + - " B.AREA_COUNTY,\n" + - " B.CITY_ID,\n" + - " B.CITY,\n" + - " B.PROVINCE_ID,\n" + - " B.PROVINCE\n" + - " FROM ODS_F_AUXILIARY_EXAMI A " + - " INNER JOIN ODS_F_GRAVIDA_RECORD B ON A.RECORD_ID=B.RECORD_ID \n" + - " INNER JOIN ODS_D_HOSPITAL C ON A.HOSPITAL_NO=C.HOSPITAL_NO AND C.VER_NO=2 \n" + - " WHERE C.YCY_STSTEM_ID= '" + hospitalId + "'"; - if (StringUtils.isNotEmpty(exDateStart)) { - sql += " AND A.EXAMINE_DATE>= to_date('" + exDateStart + "','yyyy-MM-dd')"; - } - if (StringUtils.isNotEmpty(exDateEnd)) { - sql += " AND A.EXAMINE_DATE <= to_date('" + exDateEnd + "','yyyy-MM-dd')"; - } - - if (StringUtils.isNotEmpty(name)) { - sql += " AND A.NAME LIKE '%" + name + "%'"; - } - - if (weekStarts != null) { - sql += " AND A.NOW_WEEKS>= " + weekStarts; - } - - if (weekEnds != null) { - sql += " AND A.NOW_WEEKS <= " + weekEnds; - } - - if (StringUtils.isNotEmpty(hbsag)) { - sql += " AND A.HBSAG = " + hbsag; - } - - if (StringUtils.isNotEmpty(hbeag)) { - sql += " AND A.HBEAG = " + hbeag; - } - - if (StringUtils.isNotEmpty(hbeab)) { - sql += " AND A.HBEAB = " + hbeab; - } - - if (StringUtils.isNotEmpty(hbcab)) { - sql += " AND A.HBCAB = " + hbcab; - } - if (StringUtils.isNotEmpty(syphilis)) { - sql += " AND A.SYPHILIS = " + syphilis; - } - - if (StringUtils.isNotEmpty(hiv)) { - sql += " AND A.HIV = " + hiv; - } - - if (StringUtils.isNotEmpty(hcv)) { - sql += " AND A.HCV = " + hcv; - } - if (StringUtils.isNotEmpty(doctorNo)) { - sql += " AND A.DOCTOR_NO = " + doctorNo; - } - - sql += " order by A.EXAMINE_DATE DESC,A.Name ASC,A.EXAMINE_ID DESC "; - - try { - List> datas = JdbcUtil.getListDataBySql(sql); - OutputStream out = httpServletResponse.getOutputStream(); - Map cnames = new LinkedHashMap<>(); - - cnames.put("NAME", "姓名"); - cnames.put("AGE", "年龄"); - cnames.put("NOW_WEEKS", "孕周"); - cnames.put("TEL_NO", "联系方式"); - cnames.put("SUGGESTION", "处理意见"); - cnames.put("HBSAG", "乙肝表面抗原"); - cnames.put("HBSAB", "乙肝表面抗体"); - cnames.put("HBEAG", "乙肝e抗原"); - cnames.put("HBEAB", "乙肝e抗体"); - cnames.put("HBCAB", "乙肝核心抗体"); - cnames.put("SYPHILIS", "梅毒"); - cnames.put("HIV", "HIV"); - cnames.put("HCV", "丙肝"); - cnames.put("NEXT_EXAMINE_DATE", "预约产检日期"); - cnames.put("EXAMINE_HISTORY_NUM", "本院产检次数"); - cnames.put("DOCTOR_NAME", "产检医生"); - cnames.put("BOOKER", "登记人"); - cnames.put("SERVICE_STATUS", "服务类型"); - cnames.put("HIGH_RISK_FACTOR", "高危因素"); - cnames.put("HIGH_RISK_GRADE", "高危等级"); - cnames.put("EDD_DATE", "预产期"); - cnames.put("EXAMINE_DATE", "产检日期"); - cnames.put("HOME_ADDR", "居住地"); - httpServletResponse.setContentType("application/octet-stream"); - httpServletResponse.setCharacterEncoding("UTF-8"); - httpServletResponse.setHeader("Content-Disposition", "attachment;fileName=datas.xls"); - ExcelUtil.toChanExcel(out, datas, cnames); - } catch (Exception e) { - logger.error(e + "", e); - } - } - - /** - * 建档管理页面 - * - * @param bookBuildManagerQueryRequest - * @return - */ - public BaseListResponse queryBookBuild(BookBuildManagerQueryRequest bookBuildManagerQueryRequest, Integer userId) { - PatientsQuery patientsQuery1 = new PatientsQuery(); - patientsQuery1.setYn(YnEnums.YES.getId()); - List buildType = new ArrayList(); - buildType.add(0); - buildType.add(2); - patientsQuery1.setBuildTypeList(buildType); - String hospitalId = autoMatchFacade.getHospitalId(userId); - patientsQuery1.setHospitalId(hospitalId); - patientsQuery1.setNeed("1"); - patientsQuery1.setLimit(bookBuildManagerQueryRequest.getLimit()); - patientsQuery1.setPage(bookBuildManagerQueryRequest.getPage()); - patientsQuery1.setPhone(bookBuildManagerQueryRequest.getPhone()); - patientsQuery1.setCardNo(bookBuildManagerQueryRequest.getCardNo()); - patientsQuery1.setPhone(bookBuildManagerQueryRequest.getPhone()); - - List patientses = yunBookbuildingService.queryPregnantWithQuery(patientsQuery1); - - BookBuildManagerResult bookBuildManagerResult = new BookBuildManagerResult(); - List data = new ArrayList<>(); - for (Patients patients : patientses) { - bookBuildManagerResult.convertToResult(patients); - - } - return new BaseListResponse().setData(data).setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); - } - - public BaseResponse findPatientById(String parentId, Integer userId) { - PatientsQuery patientsQuery = new PatientsQuery(); - patientsQuery.setId(parentId); - patientsQuery.setYn(YnEnums.YES.getId()); - patientsQuery.setHospitalId(autoMatchFacade.getHospitalId(userId)); - PregnantInfoResult result = new PregnantInfoResult(); - SimplePregnantResult patientResult = new SimplePregnantResult(); - List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); - if (patients != null && patients.size() > 0) { - Patients p = patients.get(0); - result = getResult(p); - - patientResult.setId(result.getId()); - patientResult.setPid(result.getPid()); - - patientResult.setPregnantName(result.getPregnantName()); - patientResult.setPregnantPhone(result.getPregnantPhone()); - patientResult.setPregnantAge(DateUtil.getAge(p.getBirth()) + ""); - - patientResult.setPregnantLiveAddr(p.getAddressRegister()); - patientResult.setPregnantLiveProvinceId(p.getProvinceRegisterId()); - patientResult.setPregnantLiveCityId(p.getCityRegisterId()); - patientResult.setPregnantLiveAreaId(p.getAreaRegisterId()); - patientResult.setPregnantLiveStreetId(p.getStreetRegisterId()); - - - patientResult.setPregnantLiveProvince(getBasicConfig(patientResult.getPregnantLiveProvinceId())); - patientResult.setPregnantLiveCity(getBasicConfig(patientResult.getPregnantLiveCityId())); - patientResult.setPregnantLiveArea(getBasicConfig(patientResult.getPregnantLiveAreaId())); - patientResult.setPregnantLiveStreet(getBasicConfig(patientResult.getPregnantLiveStreetId())); - patientResult.setHusbandName(result.getHusbandName()); - //丈夫证件号 - if (StringUtils.isNotEmpty(result.getHusbandCertificateNum()) && result.getHusbandCertificateNum().length() == 18) { - - int years, months, days; - try { - String year = result.getHusbandCertificateNum().substring(6, 10); - String month = result.getHusbandCertificateNum().substring(10, 12); - String day = result.getHusbandCertificateNum().substring(12, 14); - years = Integer.valueOf(year); - months = Integer.valueOf(month); - days = Integer.valueOf(day); - Calendar calendar = Calendar.getInstance(); - calendar.set(years, months - 1, days); - patientResult.setHusbandAge(DateUtil.getAge(calendar.getTime()) + ""); - } catch (Exception e) { - } - } - - patientResult.setHusbandCertificateNum(result.getHusbandCertificateNum()); - patientResult.setHusbandCertificateTypeId(result.getHusbandCertificateTypeId()); - patientResult.setHusbandPhone(result.getHusbandPhone()); - } - // 增加初诊信息,桓台医院打印使用 - AntExChuQuery antExChuQuery = new AntExChuQuery(); - antExChuQuery.setParentId(patientResult.getId()); - antExChuQuery.setYn(YnEnums.YES.getId()); - List antExChuModels = antenatalExaminationService.queryAntExChu(antExChuQuery); - if (CollectionUtils.isNotEmpty(antExChuModels)) { - AntExChuModel antExChuModel = antExChuModels.get(0); - patientResult.setPregnancyTimes(antExChuModel.getPregnancyTimes()); - patientResult.setProdTime(antExChuModel.getProdTime()); - patientResult.setDelivery(antExChuModel.getDelivery()); - patientResult.setPlanedProd(antExChuModel.getPlanedProd()); - } - - BaseObjectResponse objectResponse = new BaseObjectResponse(); - objectResponse.setData(patientResult); - objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); - objectResponse.setErrormsg("成功"); - return objectResponse; - } - - private String getBasicConfig(String id) { - if (StringUtils.isEmpty(id)) { - return ""; - } - BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(id); - if (null != basicConfig) { - return basicConfig.getName(); - } - return ""; - } - - - - +package com.lyms.platform.operate.web.facade; + +import com.lyms.hospitalapi.fnfy.FnfyHisService; +import com.lyms.hospitalapi.qhdfy.QhdfyHisService; +import com.lyms.hospitalapi.qinglongxian.QingLongXianHisService; +import com.lyms.hospitalapi.v2.HisService; +import com.lyms.platform.biz.service.*; +import com.lyms.platform.common.base.PageInfo; +import com.lyms.platform.common.constants.ErrorCodeConstants; +import com.lyms.platform.common.enums.*; +import com.lyms.platform.common.result.BaseListResponse; +import com.lyms.platform.common.result.BaseObjectResponse; +import com.lyms.platform.common.result.BaseResponse; +import com.lyms.platform.common.utils.*; +import com.lyms.platform.common.utils.StringUtils; +import com.lyms.platform.operate.web.request.*; +import com.lyms.platform.operate.web.result.*; +import com.lyms.platform.operate.web.utils.CommonsHelper; +import com.lyms.platform.operate.web.utils.JdbcUtil; +import com.lyms.platform.operate.web.utils.MessageCenterService; +import com.lyms.platform.permission.model.Organization; +import com.lyms.platform.permission.model.OrganizationQuery; +import com.lyms.platform.permission.model.Users; +import com.lyms.platform.permission.service.OrganizationService; +import com.lyms.platform.permission.service.UsersService; +import com.lyms.platform.pojo.*; +import com.lyms.platform.query.*; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Sort; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletResponse; +import java.io.OutputStream; +import java.util.*; + +/** + * + */ +@Component +public class BookbuildingFacade { + + private Logger logger = LoggerFactory.getLogger(BookbuildingFacade.class); + public static final String HIS_VERSION = PropertiesUtils.getPropertyValue("his_version"); + + @Autowired + private YunBookbuildingService yunBookbuildingService; + + @Autowired + private BasicConfigFacade basicConfigFacade; + + @Autowired + private OrganizationService organizationService; + + + @Autowired + private PersonService personService; + + @Autowired + private SmsTemplateService smsTemplateService; + + + @Autowired + private AntenatalExaminationService antenatalExaminationService; + + @Autowired + private AutoMatchFacade autoMatchFacade; + + @Autowired + private UsersService usersService; + + @Autowired + private PatientsService patientsService; + + @Autowired + private BasicConfigService basicConfigService; + + @Autowired + private AntenatalExaminationFacade antenatalExaminationFacade; + + @Autowired + private SmsConfigFacade smsConfigFacade; + + @Autowired + private HisService hisServiceV2; + + @Autowired + private QingLongXianHisService qingLongXianHisService; + + @Autowired + private FnfyHisService fnfyHisService; + @Autowired + private QhdfyHisService qhdfyHisService; + + + @Autowired + private DeleteProcessHandler deleteProcessHandler; + + @Autowired + private SyncDataService syncDataService; + @Autowired + private SieveService sieveService; + @Autowired + private OrganizationGroupsFacade groupsFacade; + + @Autowired + private AutoIncermentService autoIncermentService; + + @Autowired + private PatientCheckTicketService patientCheckTicketService; + @Autowired + private AreaCodeService areaCodeService; + + /** + * 根据患者的建档ID,查询还未使用的免费产检查券 + * + * @param patientId + * @return + */ + public BaseListResponse getTicketList(String patientId) { + List list = patientCheckTicketService.queryTicket(patientId, null, null, null); + return new BaseListResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功").setData(list).setPageInfo(new PageInfo()); + } + + /** + * 添加孕妇建档 + * + * @param yunRequest + * @return + */ + public BaseObjectResponse addPregnantBookbuilding( + YunBookbuildingAddRequest yunRequest, Integer userId) { + + BaseObjectResponse br = new BaseObjectResponse(); + PatientsQuery patientsQuery = new PatientsQuery(); + patientsQuery.setYn(YnEnums.YES.getId()); + patientsQuery.setType(1); + patientsQuery.setHospitalId(yunRequest.getHospitalId()); + patientsQuery.setBuildTypeEq(0); + patientsQuery.setDueStatus(0); + + if (yunRequest.getPregnantCertificateNum() != null) { + patientsQuery.setCardNo(yunRequest.getPregnantCertificateNum()); + //判断该身份证号码是否有孕妇建档 在该医院 + List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patients)) { + br.setErrorcode(ErrorCodeConstants.DATA_EXIST); + br.setErrormsg("该身份证在医院已经建档"); + return br; + } + } + if (yunRequest.getPregnantPhone() != null) { + patientsQuery.setCardNo(null); + patientsQuery.setPhone(yunRequest.getPregnantPhone()); + //判断该手机号码在 孕期内有没有建档 + List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patients)) { + br.setErrorcode(ErrorCodeConstants.DATA_EXIST); + br.setErrormsg("该手机号码已经建档"); + return br; + } + } + + //就诊卡号判断 + if (StringUtils.isNotEmpty(yunRequest.getVcCardNo())) { + patientsQuery.setCardNo(null); + patientsQuery.setPhone(null); + patientsQuery.setVcCardNo(yunRequest.getVcCardNo()); + patientsQuery.setHospitalId(yunRequest.getHospitalId()); + List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patients)) { + br.setErrorcode(ErrorCodeConstants.DATA_EXIST); + br.setErrormsg("该就诊卡号在该医院已经建档"); + return br; + } + } + + Integer type = 1; //1孕妇 2儿童 3产妇 + //建档类型 0 未分娩建档 1儿童建档时建档 2 自动分娩类型 3 转诊自动建档 + Integer buildType = 0; + Date date = null; + if (yunRequest.getLastMenstrualPeriod() != null) { + date = DateUtil.addWeek(DateUtil.parseYMD(yunRequest.getLastMenstrualPeriod()), 42); + Date currentDate = DateUtil.formatDate(new Date()); + if (date.getTime() <= currentDate.getTime()) { + type = 3; + buildType = 2; + } + } + + PersonModel resperson = null; + if (StringUtils.isNotEmpty(yunRequest.getPregnantCertificateNum())) { + + PersonModelQuery personModelQuery = new PersonModelQuery(); + personModelQuery.setCardNo(yunRequest.getPregnantCertificateNum()); + personModelQuery.setYn(YnEnums.YES.getId()); + personModelQuery.setTypes(new Integer[]{1, 3}); //孕妇或者产妇基本信息 + List personModels = personService.queryPersons(personModelQuery); + + PersonModel pmodel = new PersonModel(); + pmodel.setName(yunRequest.getPregnantName()); + pmodel.setBirth(DateUtil.parseYMD(yunRequest.getBirthday())); + pmodel.setPhone(yunRequest.getPregnantPhone()); + pmodel.setCardNo(yunRequest.getPregnantCertificateNum()); + pmodel.setType(type); + pmodel.setModified(new Date()); + if (CollectionUtils.isNotEmpty(personModels) && personModels.get(0) != null) { + + resperson = personModels.get(0); + personService.updatePerson(pmodel, personModels.get(0).getId()); + } else { + pmodel.setYn(YnEnums.YES.getId()); + pmodel.setCreated(new Date()); + resperson = personService.addPerson(pmodel); + } + } + + Patients patient = getPatientsData(yunRequest); + patient.setDueStatus(0); + //1孕妇 3 产妇 + patient.setType(type); + if (type == 3) { + patient.setIsAutoFm(YnEnums.YES.getId()); + } + patient.setBuildType(buildType); + if (type == ServiceObjEnums.CHANOBJ.getId() && date != null) { + patient.setFmDate(date); + } + if (resperson != null) { + patient.setPid(resperson.getId()); + HighScoreResult highScoreResult = antenatalExaminationFacade.findLastRisk(resperson.getId(), true); + if (CollectionUtils.isNotEmpty(highScoreResult.getHighId())) { + patient.setRiskFactorId(highScoreResult.getHighId()); + } + patient.setRiskScore(highScoreResult.getScore()); + if (CollectionUtils.isNotEmpty(highScoreResult.getLevelId())) { + patient.setRiskLevelId(JsonUtil.array2JsonString(highScoreResult.getLevelId())); + } + } + + patient.setCreated(new Date()); + patient.setModified(new Date()); + patient.setOperator(userId); + Patients p = yunBookbuildingService.addPregnantBookbuilding(patient); + + if (p == null || p.getId() == null) { + br.setErrorcode(ErrorCodeConstants.SYSTEM_ERROR); + br.setErrormsg("建档失败,保存异常"); + return br; + + } + + //加入产筛 + patientsService.validata(p); + + if (type == ServiceObjEnums.YUNOBJ.getId()) { + //生成建档短信 + createBuildSms(p); + } + + + if (p.getType() != null && p.getType() == 1) { + + Organization organization = organizationService.getOrganization(Integer.valueOf(yunRequest.getHospitalId())); + if (null != organization) { + AreaCodeQuery areaCodeQuery = new AreaCodeQuery(); + areaCodeQuery.setAreaId(organization.getCityId()); + areaCodeQuery.setYn(YnEnums.YES.getId()); + List code = areaCodeService.queryList(areaCodeQuery); + AreaCodeModel areaCode = null; + if (CollectionUtils.isNotEmpty(code)) { + areaCode = code.get(0); + } + if (null != areaCode&&StringUtils.isNotEmpty(areaCode.getAreaCode())) { + // 建档成功后,给孕妇造五个条形码 + String ticketPid = autoIncermentService.nextPatientTicketId(areaCode.getAreaCode()); + for (Integer i = PatientCheckTicketFacade.complyCurrentDay(p.getLastMenses()); i <= 5; i++) { + PatientCheckTicket ticket = new PatientCheckTicket(); + ticket.setStatus(1); + ticket.setHospitalId(p.getHospitalId()); + ticket.setPatientId(p.getId()); + ticket.setCreated(new Date()); + ticket.setId(areaCode.getAreaCode() + ticketPid + i); + ticket.setPid(p.getPid()); + patientCheckTicketService.addTicket(ticket); + } + } + } + } + + br.setErrorcode(ErrorCodeConstants.SUCCESS); + br.setErrormsg("成功"); + br.setData(p.getId()); + return br; + + } + + /** + * 创建孕妇建档短信 + */ + private void createBuildSms(Patients patient) { + + //判断医院是否启动和对应的服务项是否启用 + SmsConfigModel configModel = new SmsConfigModel(); + BaseResponse response = smsConfigFacade.hospitalIsStart(patient.getHospitalId(), configModel, SmsServiceEnums.FWKT.getId()); + if (response != null) { + return; + } + + SmsTemplateQuery query = new SmsTemplateQuery(); + query.setYn(YnEnums.YES.getId()); + query.setStatus(1); + query.setHospitalId(patient.getHospitalId()); + query.setServiceObj(ServiceObjEnums.YUNOBJ.getId()); + query.setSpecialDateType(SpecialDateEnums.JD.getId()); + + Integer serviceType = patient.getServiceType(); + Integer serviceStatus = patient.getServiceStatus(); + + List sendList = new ArrayList<>(); + + List temps = smsTemplateService.querySmsTemplates(query); + if (CollectionUtils.isNotEmpty(temps)) { + + for (SmsTemplateModel temp : temps) { + if (temp.getServiceType() == serviceType && temp.getServiceStatus() == serviceStatus) { + sendList.add(temp); + } else if (temp.getServiceType() == serviceType && temp.getServiceStatus() == serviceStatus) { + sendList.add(temp); + } else if (temp.getServiceStatus() == ServiceStatusEnums.ADD_ALL.getId()) { + if (serviceStatus == ServiceStatusEnums.ADD_OPEN.getId() || serviceStatus == ServiceStatusEnums.UNSUBSCRIBE.getId() + || serviceStatus == ServiceStatusEnums.ADD_OVERDUE.getId() || serviceStatus == ServiceStatusEnums.SUSPEND.getId()) { + sendList.add(temp); + } + } else if (temp.getServiceStatus() == ServiceStatusEnums.ALL_OPEN.getId()) { + if (serviceStatus == ServiceStatusEnums.STANDARD_OPEN.getId() || serviceStatus == ServiceStatusEnums.ADD_OPEN.getId()) { + sendList.add(temp); + } + } else if (temp.getServiceStatus() == ServiceStatusEnums.ALL_OVERDUE.getId()) { + if (serviceStatus == ServiceStatusEnums.STANDARD_OVERDUE.getId() || serviceStatus == ServiceStatusEnums.ADD_OVERDUE.getId()) { + sendList.add(temp); + } + } else if (temp.getServiceType() == ServiceTypeEnums.ALL_SERVICE.getId() && temp.getServiceStatus() == ServiceStatusEnums.ALL.getId()) { + sendList.add(temp); + } + } + + if (CollectionUtils.isNotEmpty(sendList)) { + + //短信前缀 + String messagePrefix = smsConfigFacade.getSmsPrefix(configModel, patient.getBookbuildingDoctor()); + for (SmsTemplateModel templateModel : sendList) { + if (templateModel != null && templateModel.getStatus() == 1) { + MessageListRequest smsList = new MessageListRequest(); + List messages = new ArrayList<>(); + MessageRequest mr = new MessageRequest(); + Date dueDate = DateUtil.addDay(patient.getLastMenses(), 7); + dueDate = DateUtil.addMonth(dueDate, 9); + String content = StringUtils.replaceEL(patient.getUsername(), dueDate, templateModel.getContent()); + + mr.setContent("【" + messagePrefix + "】" + content); + mr.setObjType(ServiceObjEnums.YUNOBJ.getId()); + mr.setPhone(patient.getPhone()); + mr.setTimeType(SmsTimeTypeEnums.ONTIME.getId()); + //短信商 + mr.setServiceType(SmsProviderEnums.YM.getId()); + mr.setTypeId(ProjectTypeEnums.YNXT.getId()); + mr.setPlanTime(DateUtil.getyyyy_MM_dd_hms(new Date())); + mr.setSubTypeId(SmsServiceEnums.FWKT.getId()); + mr.setStatus(SmsStatusEnums.WFS.getId()); + mr.setExt1(patient.getHospitalId()); + mr.setExt2(templateModel.getId()); + mr.setExt3(patient.getId()); + messages.add(mr); + + if (CollectionUtils.isNotEmpty(messages)) { + smsList.setTypeId(ProjectTypeEnums.YNXT.getId()); + smsList.setMessages(messages); + //调用发送接口 + + if ("4".equals(HIS_VERSION)) + { + //秦皇岛 + //保存到同步表中 + syncDataService.savePostMsg(JsonUtil.obj2JsonString(smsList), messages.get(0).getExt1()); + } + else + { + //保存到短信中心 线上 + MessageCenterService.saveSmsCenter(smsList); + } + } + } + } + } + } + } + + + /** + * 判断对应服务是否启动 + */ + private boolean isStartService(Integer smsType, String serviceStr) { + if (StringUtils.isEmpty(serviceStr)) { + return false; + } + //消息服务启动 + List smsServices = JsonUtil.toList(serviceStr, Map.class); + + if (CollectionUtils.isNotEmpty(smsServices)) { + for (Map map : smsServices) { + String status = String.valueOf(map.get(String.valueOf(smsType))); + if ("true".equals(status)) { + return true; + } + } + } + return false; + } + + /** + * 更新孕妇信息 + * + * @param id + * @param yunRequest + */ + public BaseResponse updatePregnantById(String id, YunBookbuildingAddRequest yunRequest, Integer userId) { + + + BaseResponse br = new BaseResponse(); + PatientsQuery patientsQuery = new PatientsQuery(); + patientsQuery.setYn(YnEnums.YES.getId()); + patientsQuery.setType(1); + patientsQuery.setHospitalId(yunRequest.getHospitalId()); + patientsQuery.setBuildTypeEq(0); + patientsQuery.setDueStatus(0); + + if (yunRequest.getPregnantCertificateNum() != null) { + patientsQuery.setCardNo(yunRequest.getPregnantCertificateNum()); + //判断该身份证号码是否有孕妇建档 在该医院 + List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patients)) { + Patients pat = patients.get(0); + if (pat != null && !pat.getPhone().equals(yunRequest.getPregnantPhone())) { + if (StringUtils.isNotEmpty(yunRequest.getPregnantPhone())) { + patientsQuery.setCardNo(null); + patientsQuery.setPhone(yunRequest.getPregnantPhone()); + //判断该手机号码在 孕期内有没有建档 + patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patients)) { + br.setErrorcode(ErrorCodeConstants.DATA_EXIST); + br.setErrormsg("该手机号码已经建档"); + return br; + } + } + } + + if (pat != null && StringUtils.isNotEmpty(pat.getVcCardNo()) && !pat.getVcCardNo().equals(yunRequest.getVcCardNo())) { + + //就诊卡号判断 + if (StringUtils.isNotEmpty(yunRequest.getVcCardNo())) { + patientsQuery.setCardNo(null); + patientsQuery.setPhone(null); + patientsQuery.setVcCardNo(yunRequest.getVcCardNo()); + patientsQuery.setHospitalId(yunRequest.getHospitalId()); + patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patients)) { + br.setErrorcode(ErrorCodeConstants.DATA_EXIST); + br.setErrormsg("该就诊卡号在该医院已经建档"); + return br; + } + } + } + } + } + + + Patients patient = getPatientsData(yunRequest); + patient.setModified(new Date()); + +// Integer type = ServiceObjEnums.YUNOBJ.getId(); +// if (patient.getLastMenses() != null) +// { +// Date date = DateUtil.addWeek(DateUtil.parseYMD(yunRequest.getLastMenstrualPeriod()),42); +// Date currentDate = DateUtil.formatDate(new Date()); +// if (date.getTime() <= currentDate.getTime()) +// { +// type = ServiceObjEnums.CHANOBJ.getId(); +// } +// } +// patient.setType(type); + + + if (!StringUtils.isEmpty(yunRequest.getPid())) { + PersonModel pmodel = new PersonModel(); + pmodel.setName(yunRequest.getPregnantName()); + pmodel.setBirth(DateUtil.parseYMD(yunRequest.getBirthday())); + pmodel.setPhone(yunRequest.getPregnantPhone()); + pmodel.setCardNo(yunRequest.getPregnantCertificateNum()); + pmodel.setYn(YnEnums.YES.getId()); + pmodel.setModified(new Date()); + personService.updatePerson(pmodel, yunRequest.getPid()); + } + patient.setId(id); + //加入产筛 + patientsService.validata(patient); + + PatientsQuery pQuery = new PatientsQuery(); + pQuery.setYn(YnEnums.YES.getId()); + pQuery.setId(id); + List list = yunBookbuildingService.queryPregnantWithQuery(pQuery); + if (CollectionUtils.isNotEmpty(list)) { + Patients pat = list.get(0); + if (!(pat.getServiceStatus() == ServiceStatusEnums.STANDARD_OPEN.getId() || pat.getServiceStatus() == ServiceStatusEnums.ADD_OPEN.getId())) { + + if (pat.getServiceType() == ServiceTypeEnums.STANDARD_SERVICE.getId()) { + pat.setServiceStatus(ServiceStatusEnums.STANDARD_OPEN.getId()); + } else if (pat.getServiceType() == ServiceTypeEnums.ADD_SERVICE.getId()) { + pat.setServiceStatus(ServiceStatusEnums.ADD_OPEN.getId()); + } + + createBuildSms(pat); + } + } + + patient.setOperator(userId); + + yunBookbuildingService.updatePregnant(patient, id); + //如果当前是建档医院,那么需要修改其他非建档医院的数据 + if (autoMatchFacade.checkBStatus(userId)) { + patientsService.updateBaseData(patient); + } + return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); + } + + /** + * 查询孕妇建档记录 + * + * @param bookbuildingQueryRequest + * @return + */ + public BaseListResponse queryPregnantBuildRecord(BookbuildingQueryRequest bookbuildingQueryRequest, Integer userId) { + List patients = new ArrayList<>(); + Map typeMap = new HashMap<>(); + PatientsQuery patientsQuery = new PatientsQuery(); + patientsQuery.setYn(YnEnums.YES.getId()); + patientsQuery.setBuildType(1); + //查询主档案 + patientsQuery.setExtEnable(false); + + //如果身份证号码不为空就以身份证号码查询 + if (!StringUtils.isEmpty(bookbuildingQueryRequest.getCardNo())) { + patientsQuery.setCardNo(bookbuildingQueryRequest.getCardNo()); + patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery, "bookbuildingDate", Sort.Direction.DESC); + } + //否则用就诊卡号 查询到这个孕妇的身份证号码 再用身份证号码查询该孕妇的所有建档 包括产妇记录 + else if (!StringUtils.isEmpty(bookbuildingQueryRequest.getVcCardNo())) { + + patientsQuery.setVcCardNo(bookbuildingQueryRequest.getVcCardNo()); + patientsQuery.setHospitalId(autoMatchFacade.getHospitalId(userId)); + //优先查询本院通过就诊卡 + List localPatients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + patientsQuery.setHospitalId(null); + if (CollectionUtils.isNotEmpty(localPatients)) + { + patients = localPatients; + } + else + { + //区域模式 + patientsQuery.setHospitalList(groupsFacade.findGroupHospital(userId, false)); + + List patientsVc = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patientsVc)) { + if (patientsVc.get(0) == null || StringUtils.isEmpty(patientsVc.get(0).getCardNo())) { + patients = patientsVc; + } else { + patientsQuery.setHospitalId(null); + patientsQuery.setVcCardNo(null); + patientsQuery.setCardNo(patientsVc.get(0).getCardNo()); + patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery, "bookbuildingDate", Sort.Direction.DESC); + } + } + // 如果为空,初次建档,根据就诊卡号从HIS库取患者信息 + else { + if ("2".equals(HIS_VERSION)) { + typeMap.put("hisPatient", hisServiceV2.getPatientInfoList(bookbuildingQueryRequest.getVcCardNo())); + } else if ("3".equals(HIS_VERSION)) { + typeMap.put("hisPatient", qingLongXianHisService.getPatientInfoList(bookbuildingQueryRequest.getVcCardNo())); + } else if ("5".equals(HIS_VERSION)) { + typeMap.put("hisPatient", fnfyHisService.getPatientInfoList(bookbuildingQueryRequest.getVcCardNo())); + } else if ("4".equals(HIS_VERSION)) { + typeMap.put("hisPatient", qhdfyHisService.getPatientInfoList(bookbuildingQueryRequest.getVcCardNo())); + } + } + } + + } else if (!StringUtils.isEmpty(bookbuildingQueryRequest.getId())) { + // id,HuJiaqi添加,为了建档管理里面的查看单条使用 + patients.add(yunBookbuildingService.findOneById(bookbuildingQueryRequest.getId())); + } else if (StringUtils.isNotEmpty(bookbuildingQueryRequest.getPid())) { + patientsQuery.setPid(bookbuildingQueryRequest.getPid()); + + //区域模式 + patientsQuery.setHospitalList(groupsFacade.findGroupHospital(userId, false)); + + List patientsVc = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patientsVc)) { + if (patientsVc.get(0) == null || StringUtils.isEmpty(patientsVc.get(0).getCardNo())) { + patients = patientsVc; + } else { + patientsQuery.setHospitalId(null); + patientsQuery.setVcCardNo(null); + patientsQuery.setCardNo(patientsVc.get(0).getCardNo()); + patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery, "bookbuildingDate", Sort.Direction.DESC); + } + } + } + + String group = groupsFacade.findByCurrentUserId(autoMatchFacade.getHospitalId(userId)); + if (StringUtils.isNotEmpty(group)) { + //区域模式 + patientsQuery.setHospitalList(groupsFacade.findGroupHospital(userId, false)); + } + int count = patientsService.queryPatientCount(patientsQuery); + + //历史建档记录 + List list = new ArrayList<>(); + List results = new ArrayList<>(); + if (CollectionUtils.isNotEmpty(patients)) { + + for (Patients pat : patients) { + if (pat != null) { + BookbuildingRecordResult result = new BookbuildingRecordResult(); + if (StringUtils.isNotEmpty(pat.getHospitalId())) { + Organization org = organizationService.getOrganization(Integer.valueOf(pat.getHospitalId())); + if (org != null) { + result.setBookbuildHospital(org.getName()); + result.setHospitalId(String.valueOf(org.getId())); + } + } + result.setFmTime(DateUtil.getyyyy_MM_dd(pat.getFmDate())); + result.setBookbuildDate(DateUtil.getyyyy_MM_dd(pat.getBookbuildingDate())); + result.setId(pat.getId()); + result.setType(pat.getType()); + result.setDueStatus(pat.getDueStatus()); + results.add(result); + } + } + } + + + //证件类型 + List pcerteTypeResult = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.CERTE_TYPE_ID); + typeMap.put("certeType", pcerteTypeResult); + + //国籍 + List countiryResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.COUNTRY_TYPE_ID); + typeMap.put("country", countiryResults); + + // 民族 + List nationResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.NATION_TYPE_ID); + typeMap.put("nation", nationResults); + + // 职业类别 + List professionTypeResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.PROFESSION_TYPE_ID); + typeMap.put("professionType", professionTypeResults); + + // 户籍类别 + List censusType = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.CENSUS_TYPE_ID); + typeMap.put("censusType", censusType); + + // 户籍类别 + List liveType = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.LIVE_TYPE_ID); + typeMap.put("liveType", liveType); + + //服务类型 + List serviceType = ServiceTypeEnums.getServiceTypeList(); + typeMap.put("serviceType", serviceType); + + //服务状态 + List serviceStatus = ServiceStatusEnums.getServiceStatusList(); + typeMap.put("serviceStatus", serviceStatus); + + //孕妇体验类型 + List expYunEnums = ExpYunEnums.getExpYunEnums(); + typeMap.put("expYunEnums", expYunEnums); + + list.add(typeMap); + + + Map mapData = new HashMap<>(); + mapData.put("data", results); +// 是否在本医院所在区域建档 + mapData.put("rBType", count > 0); + mapData.put("initBuildDate", DateUtil.getyyyy_MM_dd(new Date())); + list.add(mapData); + + BaseListResponse listResponse = new BaseListResponse(); + listResponse.setData(list); + listResponse.setErrorcode(ErrorCodeConstants.SUCCESS); + listResponse.setErrormsg("成功"); + return listResponse; + } + + + /** + * 准备修改和添加的孕妇建档数据 + * + * @param yunRequest + * @return + */ + private Patients getPatientsData(YunBookbuildingAddRequest yunRequest) { + Patients patient = new Patients(); + patient.setUsername(yunRequest.getPregnantName()); + + patient.setPcerteTypeId(yunRequest.getPregnantCertificateTypeId()); + + patient.setCardNo(yunRequest.getPregnantCertificateNum()); + + patient.setPcountryId(yunRequest.getPregnantCountryId()); + patient.setPnationId(yunRequest.getPregnantNationId()); + patient.setBirth(DateUtil.parseYMD(yunRequest.getBirthday())); + + patient.setPcensusTypeId(yunRequest.getPregnantCensusTypeId()); + + patient.setPliveTypeId(yunRequest.getPregnantLiveTypeId()); + + patient.setPprofessionTypeId(yunRequest.getPregnantProfessionTypeId()); + + patient.setPhone(yunRequest.getPregnantPhone()); + + patient.setPworkUnit(yunRequest.getPregnantWorkUnit()); + patient.setPlevelTypeId(yunRequest.getPregnantLevelTypeId()); + + //孕妇居住地 + patient.setAddressRegister(yunRequest.getPregnantCensusAddr()); + patient.setProvinceRegisterId(yunRequest.getPregnantCensusProvinceId()); + patient.setCityRegisterId(yunRequest.getPregnantCensusCityId()); + patient.setAreaRegisterId(yunRequest.getPregnantCensusAreaId()); + patient.setStreetRegisterId(yunRequest.getPregnantCensusStreetId()); + + //孕妇户籍地址 + patient.setAddress(yunRequest.getPregnantLiveAddr()); + patient.setProvinceId(yunRequest.getPregnantLiveProvinceId()); + patient.setCityId(yunRequest.getPregnantLiveCityId()); + patient.setAreaId(yunRequest.getPregnantLiveAreaId()); + patient.setStreetId(yunRequest.getPregnantLiveStreetId()); + + //孕妇产后修养地 + patient.setAddressPostRest(yunRequest.getChildbirthAddr()); + patient.setProvincePostRestId(yunRequest.getChildbirthProvinceId()); + patient.setCityPostRestId(yunRequest.getChildbirthCityId()); + patient.setAreaPostRestId(yunRequest.getChildbirthAreaId()); + patient.setStreetPostRestId(yunRequest.getChildbirthStreetId()); + + //丈夫信息 + patient.setHusbandName(yunRequest.getHusbandName()); + patient.setHcertificateTypeId(yunRequest.getHusbandCertificateTypeId()); + + if (StringUtils.isNotEmpty(yunRequest.getHusbandCertificateTypeId()) && StringUtils.isNotEmpty(yunRequest.getHusbandCertificateNum())) { + BasicConfigQuery basicConfigQuery = new BasicConfigQuery(); + basicConfigQuery.setId(yunRequest.getHusbandCertificateTypeId()); + basicConfigQuery.setYn(YnEnums.YES.getId()); + List data = basicConfigService.queryBasicConfig(basicConfigQuery); + if (CollectionUtils.isNotEmpty(data)) { + //身份证类型得到丈夫的生日 必须为身份证类型 + if (StringUtils.isNotEmpty(data.get(0).getCode()) && "SFZ".endsWith(data.get(0).getCode())) { + String cardNo = yunRequest.getHusbandCertificateNum(); + Date birth = StringUtils.getBirthDay(cardNo); + patient.setHusbandBirth(birth); + } + } + } + + patient.setHcertificateNum(yunRequest.getHusbandCertificateNum()); + patient.setHusbandPhone(yunRequest.getHusbandPhone()); + patient.setHcountryId(yunRequest.getHusbandCountryId()); + patient.setHnationId(yunRequest.getHusbandNationId()); + patient.setHprofessionTypeId(yunRequest.getHusbandProfessionTypeId()); + patient.setHworkUnit(yunRequest.getHusbandWorkUnit()); + patient.setHaddressRegister(yunRequest.getHusbandAddressRegister()); + patient.setHprovinceRegisterId(yunRequest.getHusbandProvinceRegisterId()); + patient.setHcityRegisterId(yunRequest.getHusbandCityRegisterId()); + patient.setHareaRegisterId(yunRequest.getHusbandAreaRegisterId()); + patient.setHstreetRegisterId(yunRequest.getHusbandStreetRegisterId()); + patient.setHlevelTypeId(yunRequest.getHusbandLevelTypeId()); + + patient.setServiceStatus(yunRequest.getServiceStatus()); + + if (yunRequest.getExpType() != null) { + if (yunRequest.getExpType() == ExpYunEnums.SGY.getId()) { + Date vipEndTime = DateUtil.addMonth(DateUtil.parseYMD(yunRequest.getBookbuildingDate()), 3); + Date dueDate = DateUtil.parseYMD(yunRequest.getDueDate()); + if (vipEndTime.getTime() > dueDate.getTime()) { + vipEndTime = dueDate; + } + patient.setVipEndTime(vipEndTime); + } else { + Date vipEndTime = DateUtil.parseYMD(yunRequest.getDueDate()); + patient.setVipEndTime(vipEndTime); + } + patient.setExpType(yunRequest.getExpType()); + } + + + //patient.setVipEndTime(DateUtil.parseYMD(yunRequest.getVipEndTime())); + patient.setExpVip(yunRequest.getExpVip()); + patient.setMremark(yunRequest.getMremark()); + + patient.setLastMenses(DateUtil.parseYMD(yunRequest.getLastMenstrualPeriod())); + patient.setDueDate(DateUtil.parseYMD(yunRequest.getDueDate())); + patient.setFileCode(yunRequest.getFileCode()); + patient.setBookbuildingDoctor(yunRequest.getBookbuildingDoctor()); + patient.setBookbuildingDate(DateUtil.parseYMD(yunRequest.getBookbuildingDate())); + patient.setServiceType(yunRequest.getServiceType()); + patient.setVcCardNo(yunRequest.getVcCardNo()); + patient.setHospitalId(yunRequest.getHospitalId()); + patient.setYn(YnEnums.YES.getId()); + + return patient; + } + + /** + * 查询孕妇建档详细 + * + * @param id + * @return + */ + public BaseObjectResponse queryPregnantBuildById(String id) { + + PatientsQuery patientsQuery = new PatientsQuery(); + patientsQuery.setId(id); + patientsQuery.setYn(YnEnums.YES.getId()); + PregnantInfoResult result = new PregnantInfoResult(); + List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (patients != null && patients.size() > 0) { + Patients p = patients.get(0); + result = getResult(p); + } + + BaseObjectResponse objectResponse = new BaseObjectResponse(); + objectResponse.setData(result); + objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); + objectResponse.setErrormsg("成功"); + return objectResponse; + } + + + private PregnantInfoResult getResult(Patients p) { + PregnantInfoResult result = new PregnantInfoResult(); + result.setId(p.getId()); + /**********孕妇基本信息***************/ + result.setPregnantName(p.getUsername()); + result.setPregnantCertificateTypeId(p.getPcerteTypeId()); + result.setPregnantCertificateNum(p.getCardNo()); + result.setPregnantCountryId(p.getPcountryId()); + result.setPregnantNationId(p.getPnationId()); + result.setBirthday(DateUtil.getyyyy_MM_dd(p.getBirth())); + result.setPregnantCensusTypeId(p.getPcensusTypeId()); + result.setPregnantLiveTypeId(p.getPliveTypeId()); + result.setPregnantProfessionTypeId(p.getPprofessionTypeId()); + result.setPregnantLevelTypeId(p.getPlevelTypeId()); + + /**********孕妇联系方式***************/ + result.setPregnantPhone(p.getPhone()); + result.setPregnantWorkUnit(p.getPworkUnit()); + + result.setPregnantCensusProvinceId(p.getProvinceRegisterId()); + result.setPregnantCensusCityId(p.getCityRegisterId()); + result.setPregnantCensusAreaId(p.getAreaRegisterId()); + result.setPregnantCensusStreetId(p.getStreetRegisterId()); + result.setPregnantCensusAddr(p.getAddressRegister()); + + result.setPregnantLiveProvinceId(p.getProvinceId()); + result.setPregnantLiveCityId(p.getCityId()); + result.setPregnantLiveAreaId(p.getAreaId()); + result.setPregnantLiveStreetId(p.getStreetId()); + result.setPregnantLiveAddr(p.getAddress()); + + + result.setChildbirthAddr(p.getAddressPostRest()); + result.setChildbirthProvinceId(p.getProvincePostRestId()); + result.setChildbirthCityId(p.getCityPostRestId()); + result.setChildbirthAreaId(p.getAreaPostRestId()); + result.setChildbirthStreetId(p.getStreetPostRestId()); + + /****************丈夫信息**************/ + result.setHusbandName(p.getHusbandName()); + result.setHusbandPhone(p.getHusbandPhone()); + + result.setHusbandCertificateTypeId(p.getHcertificateTypeId()); + result.setHusbandCertificateNum(p.getHcertificateNum()); + result.setHusbandCountryId(p.getHcountryId()); + result.setHusbandNationId(p.getHnationId()); + result.setHusbandProfessionTypeId(p.getHprofessionTypeId()); + result.setHusbandWorkUnit(p.getHworkUnit()); + result.setHusbandLevelTypeId(p.getHlevelTypeId()); + + result.setHusbandAddressRegister(p.getHaddressRegister()); + result.setHusbandProvinceRegisterId(p.getHprovinceRegisterId()); + result.setHusbandCityRegisterId(p.getHcityRegisterId()); + result.setHusbandAreaRegisterId(p.getHareaRegisterId()); + result.setHusbandStreetRegisterId(p.getHstreetRegisterId()); + + result.setServiceStatus(p.getServiceStatus() == null ? "" : String.valueOf(p.getServiceStatus())); + result.setVipEndTime(DateUtil.getyyyy_MM_dd(p.getVipEndTime())); + result.setExpVip(p.getExpVip()); + result.setMremark(p.getMremark()); + + + //院内信息 + result.setLastMenstrualPeriod(DateUtil.getyyyy_MM_dd(p.getLastMenses())); + result.setDueDate(DateUtil.getyyyy_MM_dd(p.getDueDate())); + result.setFileCode(p.getFileCode()); + result.setVcCardNo(p.getVcCardNo()); + + if (StringUtils.isNotEmpty(p.getBookbuildingDoctor())) { + Users users = usersService.getUsers(Integer.parseInt(p.getBookbuildingDoctor())); + if (users != null) { + Map doctorObj = new HashMap<>(); + doctorObj.put("id", p.getBookbuildingDoctor()); + doctorObj.put("name", users.getName()); + result.setBookbuildingDoctor(doctorObj); + } + } + + result.setBookbuildingDate(DateUtil.getyyyy_MM_dd(p.getBookbuildingDate())); + result.setServiceType(p.getServiceType() == null ? "" : String.valueOf(p.getServiceType())); + + result.setExpType(p.getExpType()); + + result.setPid(p.getPid()); + result.setDueStatus(p.getDueStatus()); + return result; + } + + /** + * 孕妇建档页面基础数据 + * + * @return + */ + public BaseObjectResponse getYunBuildBaseConfig() { + Map typeMap = new HashMap<>(); + + //证件类型 + List pcerteTypeResult = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.CERTE_TYPE_ID); + typeMap.put("certeType", pcerteTypeResult); + + //国籍 + List countiryResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.COUNTRY_TYPE_ID); + typeMap.put("country", countiryResults); + + // 民族 + List nationResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.NATION_TYPE_ID); + typeMap.put("nation", nationResults); + + // 职业类别 + List professionTypeResults = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.PROFESSION_TYPE_ID); + typeMap.put("professionType", professionTypeResults); + + // 户籍类别 + List censusType = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.CENSUS_TYPE_ID); + typeMap.put("censusType", censusType); + + // 户籍类别 + List liveType = basicConfigFacade.getBaseicConfigByParentId(SystemConfig.LIVE_TYPE_ID); + typeMap.put("liveType", liveType); + + //服务类型 + List serviceType = ServiceTypeEnums.getServiceTypeList(); + typeMap.put("serviceType", serviceType); + + //服务状态 + List serviceStatus = ServiceStatusEnums.getServiceStatusList(); + typeMap.put("serviceStatus", serviceStatus); + + //孕妇体验类型 + List expYunEnums = ExpYunEnums.getExpYunEnums(); + typeMap.put("expYunEnums", expYunEnums); + + + BaseObjectResponse objectResponse = new BaseObjectResponse(); + objectResponse.setData(typeMap); + objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); + objectResponse.setErrormsg("成功"); + return objectResponse; + } + + /** + * 删除孕妇建档 + * + * @param id + * @return + */ + public BaseResponse deletePregnantById(String id, Integer userId) { + + if(org.apache.commons.lang.StringUtils.isNotEmpty(id)){ + //获取初诊记录 + String hospital = autoMatchFacade.getHospitalId(userId); + Patients patients = yunBookbuildingService.findOneById(id); + + if (!deleteProcessHandler.deleteBookBuild(patients.getPid(), patients.getBookbuildingDate(), hospital)) { + return new BaseResponse().setErrorcode(ErrorCodeConstants.DONT_DELETE).setErrormsg("孕妇存在检查记录,不能删除建档"); + } + yunBookbuildingService.deletePregnantById(id); + //删除建档需要删除产筛数据 + SieveQuery sieveQuery = new SieveQuery(); + sieveQuery.setYn(YnEnums.YES.getId()); + sieveQuery.setParentId(id); + sieveService.deleteById(sieveQuery); + + PatientCheckTicketQuery patientCheckTicketQuery=new PatientCheckTicketQuery(); + patientCheckTicketQuery.setPatientId(id); + patientCheckTicketQuery.setStatus(1); + PatientCheckTicket patientCheckTicket=new PatientCheckTicket(); + patientCheckTicket.setStatus(3); + patientCheckTicket.setPatientId(id); + patientCheckTicketService.findAndModify(patientCheckTicketQuery,patientCheckTicket); + } + + return new BaseResponse().setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); + } + + /** + * 查询孕妇基本信息 通过就诊卡号或者身份证 + * + * @param cardNo + * @param vcCardNo + * @return + */ + public BaseObjectResponse queryYunBuildInfo(String cardNo, String vcCardNo, Integer userId) { + Patients pat = null; + PatientsQuery patientsQuery = new PatientsQuery(); + patientsQuery.setYn(YnEnums.YES.getId()); + if (StringUtils.isNotEmpty(cardNo)) { + patientsQuery.setCardNo(cardNo); + List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patients)) { + pat = patients.get(0); + } + } + + String hospitalId = ""; + //得到当前登录的医院id + if (userId != null) { + Users dbuser = usersService.getUsers(userId); + if (dbuser != null) { + hospitalId = String.valueOf(dbuser.getOrgId()); + } + } + + if (StringUtils.isNotEmpty(vcCardNo) && StringUtils.isNotEmpty(hospitalId)) { + patientsQuery.setVcCardNo(vcCardNo); + patientsQuery.setHospitalId(hospitalId); + List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(patients)) { + Patients vcCardNoPat = patients.get(0); + patientsQuery.setHospitalId(null); + patientsQuery.setVcCardNo(null); + patientsQuery.setCardNo(vcCardNoPat.getCardNo()); + List cardNoPat = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (CollectionUtils.isNotEmpty(cardNoPat)) { + pat = cardNoPat.get(0); + } + } + } + BaseObjectResponse objectResponse = new BaseObjectResponse(); + if (pat == null) { + objectResponse.setData(""); + } else { + objectResponse.setData(getResult(pat)); + } + + objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); + objectResponse.setErrormsg("成功"); + return objectResponse; + } + + public BaseObjectResponse queryHospitals(String keyWord, Integer page, Integer limit) { + OrganizationQuery organizationQuery = new OrganizationQuery(); + if (null != page && limit != page) { + organizationQuery.setNeed("true"); + organizationQuery.setPage(page); + organizationQuery.setLimit(limit); + organizationQuery.setSort("modified desc"); + } + + organizationQuery.setYn(YnEnums.YES.getId()); + organizationQuery.setKeyword(keyWord); + + + List> mapList = new ArrayList<>(); + List orgs = organizationService.queryHospitals(organizationQuery); + if (CollectionUtils.isNotEmpty(orgs)) { + for (Organization org : orgs) { + Map map = new HashMap<>(); + map.put("id", org.getId() + ""); + map.put("name", org.getName()); + mapList.add(map); + } + } + + BaseObjectResponse objectResponse = new BaseObjectResponse(); + objectResponse.setData(mapList); + + objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); + objectResponse.setErrormsg("成功"); + return objectResponse; + } + + public BaseListResponse queryChanJianReport(Integer userId, String exDateStart, + String exDateEnd, + String name, + Integer weekStarts, + Integer weekEnds, + String hbsag, + String hbeag, + String hbeab, + String hbcab, + String syphilis, + String hiv, + String hcv, + String doctorNo, + Integer page, + Integer limit) { + + String hospitalId = autoMatchFacade.getHospitalId(userId); + + int start = 0; + int end = 1000; + if (page != null && limit != null) { + start = (page - 1) * limit + 1; + end = page * limit; + } + String countSql = " SELECT count(*) as allCount " + + "FROM ODS_F_AUXILIARY_EXAMI A\n" + + "INNER JOIN ODS_F_GRAVIDA_RECORD B ON A.RECORD_ID=B.RECORD_ID\n" + + "INNER JOIN ODS_D_HOSPITAL C ON A.HOSPITAL_NO=C.HOSPITAL_NO AND C.VER_NO=2\n" + + "WHERE C.YCY_STSTEM_ID= '" + hospitalId + "'"; + + + String sql = "SELECT * FROM ( SELECT A.*, ROWNUM RN FROM ( SELECT A.EXAMINE_DATE,\n" + + " A.NAME,\n" + + " A.AGE,\n" + + " A.NOW_WEEKS,\n" + + " A.NOW_WEEKS_DAY, \n" + + " B.EDD_DATE,\n" + + " A.HBSAG,\n" + + " A.HBSAB,\n" + + " A.HBEAG,\n" + + " A.HBEAB,\n" + + " A.HBCAB,\n" + + " A.SYPHILIS,\n" + + " A.HIV,\n" + + " A.HCV,\n" + + " (CASE WHEN A.HIGH_RISK_GRADE IS NULL THEN '绿色预警' ELSE A.HIGH_RISK_GRADE END) AS HIGH_RISK_GRADE,\n" + + " (CASE WHEN A.HIGH_RISK_FACTOR IS NULL THEN '健康' ELSE A.HIGH_RISK_FACTOR END) AS HIGH_RISK_FACTOR,\n" + + " A.NEXT_EXAMINE_DATE,\n" + + " A.EXAMINE_HISTORY_NUM,\n" + + " A.DOCTOR_NAME,\n" + + " A.DOCTOR_NAME AS BOOKER,\n" + + " DECODE(B.IS_VIP_ID,1,'增值服务','标准服务') AS SERVICE_STATUS,\n" + + " A.SUGGESTION,\n" + + " B.TEL_NO,\n" + + " B.HOME_ADDR,\n" + + " B.STREET_VALLAGE_ID,\n" + + " B.STREET_VALLAGE,\n" + + " B.AREA_COUNTY_ID,\n" + + " B.AREA_COUNTY,\n" + + " B.CITY_ID,\n" + + " B.CITY,\n" + + " B.PROVINCE_ID,\n" + + " B.PROVINCE\n" + + " FROM ODS_F_AUXILIARY_EXAMI A " + + " INNER JOIN ODS_F_GRAVIDA_RECORD B ON A.RECORD_ID=B.RECORD_ID \n" + + " INNER JOIN ODS_D_HOSPITAL C ON A.HOSPITAL_NO=C.HOSPITAL_NO AND C.VER_NO=2 \n" + + " WHERE C.YCY_STSTEM_ID= '" + hospitalId + "'"; + if (StringUtils.isNotEmpty(exDateStart)) { + sql += " AND A.EXAMINE_DATE>= to_date('" + exDateStart + "','yyyy-MM-dd')"; + countSql += " AND A.EXAMINE_DATE>= to_date('" + exDateStart + "','yyyy-MM-dd')"; + } + if (StringUtils.isNotEmpty(exDateEnd)) { + sql += " AND A.EXAMINE_DATE <= to_date('" + exDateEnd + "','yyyy-MM-dd')"; + countSql += " AND A.EXAMINE_DATE <= to_date('" + exDateEnd + "','yyyy-MM-dd')"; + } + + if (StringUtils.isNotEmpty(name)) { + sql += " AND A.NAME LIKE '%" + name + "%'"; + countSql += " AND A.NAME LIKE '%" + name + "%'"; + } + + if (weekStarts != null) { + sql += " AND A.NOW_WEEKS>= " + weekStarts; + countSql += " AND A.NOW_WEEKS>= " + weekStarts; + } + + if (weekEnds != null) { + sql += " AND A.NOW_WEEKS <= " + weekEnds; + countSql += " AND A.NOW_WEEKS <= " + weekEnds; + } + + if (StringUtils.isNotEmpty(hbsag)) { + sql += " AND A.HBSAG = " + hbsag; + countSql += " AND A.HBSAG = " + hbsag; + } + + if (StringUtils.isNotEmpty(hbeag)) { + sql += " AND A.HBEAG = " + hbeag; + countSql += " AND A.HBEAG = " + hbeag; + } + + if (StringUtils.isNotEmpty(hbeab)) { + sql += " AND A.HBEAB = " + hbeab; + countSql += " AND A.HBEAB = " + hbeab; + } + + if (StringUtils.isNotEmpty(hbcab)) { + sql += " AND A.HBCAB = " + hbcab; + countSql += " AND A.HBCAB = " + hbcab; + } + if (StringUtils.isNotEmpty(syphilis)) { + sql += " AND A.SYPHILIS = " + syphilis; + countSql += " AND A.SYPHILIS = " + syphilis; + } + + if (StringUtils.isNotEmpty(hiv)) { + sql += " AND A.HIV = " + hiv; + countSql += " AND A.HIV = " + hiv; + } + + if (StringUtils.isNotEmpty(hcv)) { + sql += " AND A.HCV = " + hcv; + countSql += " AND A.HCV = " + hcv; + } + if (StringUtils.isNotEmpty(doctorNo)) { + sql += " AND A.DOCTOR_NO = " + doctorNo; + countSql += " AND A.DOCTOR_NO = " + doctorNo; + } + + sql += " order by A.EXAMINE_DATE DESC,A.Name ASC,A.EXAMINE_ID DESC ) A WHERE ROWNUM <= " + end + " ) WHERE RN >= " + start; + + logger.info(sql); + List> list = JdbcUtil.getListDataBySql(sql); + + Integer count = Integer.parseInt(String.valueOf(JdbcUtil.getOralceSingleObjBySql(countSql))); + BaseListResponse listResponse = new BaseListResponse(); + listResponse.setData(list); + + PageInfo pageInfo = new PageInfo(page, 0, count, limit); + + listResponse.setPageInfo(pageInfo); + + listResponse.setErrorcode(ErrorCodeConstants.SUCCESS); + listResponse.setErrormsg("成功"); + return listResponse; + } + + + public void exportChanReport(Integer userId, HttpServletResponse httpServletResponse, + String exDateStart, + String exDateEnd, + String name, + Integer weekStarts, + Integer weekEnds, + String hbsag, + String hbeag, + String hbeab, + String hbcab, + String syphilis, + String hiv, + String hcv, + String doctorNo) { + String hospitalId = autoMatchFacade.getHospitalId(userId); + String sql = "SELECT A.EXAMINE_DATE,\n" + + " A.NAME,\n" + + " A.AGE,\n" + + " (CASE WHEN A.NOW_WEEKS_DAY<>0 THEN '孕'||A.NOW_WEEKS|| '周+'||A.NOW_WEEKS_DAY||'天' ELSE '孕'||A.NOW_WEEKS|| '周' END) as NOW_WEEKS,\n" + + " A.NOW_WEEKS_DAY, \n" + + " B.EDD_DATE,\n" + + " A.HBSAG,\n" + + " A.HBSAB,\n" + + " A.HBEAG,\n" + + " A.HBEAB,\n" + + " A.HBCAB,\n" + + " A.SYPHILIS,\n" + + " A.HIV,\n" + + " A.HCV,\n" + + " (CASE WHEN A.HIGH_RISK_GRADE IS NULL THEN '绿色预警' ELSE A.HIGH_RISK_GRADE END) AS HIGH_RISK_GRADE,\n" + + " (CASE WHEN A.HIGH_RISK_FACTOR IS NULL THEN '健康' ELSE A.HIGH_RISK_FACTOR END) AS HIGH_RISK_FACTOR,\n" + + " A.NEXT_EXAMINE_DATE,\n" + + " A.EXAMINE_HISTORY_NUM,\n" + + " A.DOCTOR_NAME,\n" + + " A.DOCTOR_NAME AS BOOKER,\n" + + " DECODE(B.IS_VIP_ID,1,'增值服务','标准服务') AS SERVICE_STATUS,\n" + + " A.SUGGESTION,\n" + + " B.TEL_NO,\n" + + " B.HOME_ADDR,\n" + + " B.STREET_VALLAGE_ID,\n" + + " B.STREET_VALLAGE,\n" + + " B.AREA_COUNTY_ID,\n" + + " B.AREA_COUNTY,\n" + + " B.CITY_ID,\n" + + " B.CITY,\n" + + " B.PROVINCE_ID,\n" + + " B.PROVINCE\n" + + " FROM ODS_F_AUXILIARY_EXAMI A " + + " INNER JOIN ODS_F_GRAVIDA_RECORD B ON A.RECORD_ID=B.RECORD_ID \n" + + " INNER JOIN ODS_D_HOSPITAL C ON A.HOSPITAL_NO=C.HOSPITAL_NO AND C.VER_NO=2 \n" + + " WHERE C.YCY_STSTEM_ID= '" + hospitalId + "'"; + if (StringUtils.isNotEmpty(exDateStart)) { + sql += " AND A.EXAMINE_DATE>= to_date('" + exDateStart + "','yyyy-MM-dd')"; + } + if (StringUtils.isNotEmpty(exDateEnd)) { + sql += " AND A.EXAMINE_DATE <= to_date('" + exDateEnd + "','yyyy-MM-dd')"; + } + + if (StringUtils.isNotEmpty(name)) { + sql += " AND A.NAME LIKE '%" + name + "%'"; + } + + if (weekStarts != null) { + sql += " AND A.NOW_WEEKS>= " + weekStarts; + } + + if (weekEnds != null) { + sql += " AND A.NOW_WEEKS <= " + weekEnds; + } + + if (StringUtils.isNotEmpty(hbsag)) { + sql += " AND A.HBSAG = " + hbsag; + } + + if (StringUtils.isNotEmpty(hbeag)) { + sql += " AND A.HBEAG = " + hbeag; + } + + if (StringUtils.isNotEmpty(hbeab)) { + sql += " AND A.HBEAB = " + hbeab; + } + + if (StringUtils.isNotEmpty(hbcab)) { + sql += " AND A.HBCAB = " + hbcab; + } + if (StringUtils.isNotEmpty(syphilis)) { + sql += " AND A.SYPHILIS = " + syphilis; + } + + if (StringUtils.isNotEmpty(hiv)) { + sql += " AND A.HIV = " + hiv; + } + + if (StringUtils.isNotEmpty(hcv)) { + sql += " AND A.HCV = " + hcv; + } + if (StringUtils.isNotEmpty(doctorNo)) { + sql += " AND A.DOCTOR_NO = " + doctorNo; + } + + sql += " order by A.EXAMINE_DATE DESC,A.Name ASC,A.EXAMINE_ID DESC "; + + try { + List> datas = JdbcUtil.getListDataBySql(sql); + OutputStream out = httpServletResponse.getOutputStream(); + Map cnames = new LinkedHashMap<>(); + + cnames.put("NAME", "姓名"); + cnames.put("AGE", "年龄"); + cnames.put("NOW_WEEKS", "孕周"); + cnames.put("TEL_NO", "联系方式"); + cnames.put("SUGGESTION", "处理意见"); + cnames.put("HBSAG", "乙肝表面抗原"); + cnames.put("HBSAB", "乙肝表面抗体"); + cnames.put("HBEAG", "乙肝e抗原"); + cnames.put("HBEAB", "乙肝e抗体"); + cnames.put("HBCAB", "乙肝核心抗体"); + cnames.put("SYPHILIS", "梅毒"); + cnames.put("HIV", "HIV"); + cnames.put("HCV", "丙肝"); + cnames.put("NEXT_EXAMINE_DATE", "预约产检日期"); + cnames.put("EXAMINE_HISTORY_NUM", "本院产检次数"); + cnames.put("DOCTOR_NAME", "产检医生"); + cnames.put("BOOKER", "登记人"); + cnames.put("SERVICE_STATUS", "服务类型"); + cnames.put("HIGH_RISK_FACTOR", "高危因素"); + cnames.put("HIGH_RISK_GRADE", "高危等级"); + cnames.put("EDD_DATE", "预产期"); + cnames.put("EXAMINE_DATE", "产检日期"); + cnames.put("HOME_ADDR", "居住地"); + httpServletResponse.setContentType("application/octet-stream"); + httpServletResponse.setCharacterEncoding("UTF-8"); + httpServletResponse.setHeader("Content-Disposition", "attachment;fileName=datas.xls"); + ExcelUtil.toChanExcel(out, datas, cnames); + } catch (Exception e) { + logger.error(e + "", e); + } + } + + /** + * 建档管理页面 + * + * @param bookBuildManagerQueryRequest + * @return + */ + public BaseListResponse queryBookBuild(BookBuildManagerQueryRequest bookBuildManagerQueryRequest, Integer userId) { + PatientsQuery patientsQuery1 = new PatientsQuery(); + patientsQuery1.setYn(YnEnums.YES.getId()); + List buildType = new ArrayList(); + buildType.add(0); + buildType.add(2); + patientsQuery1.setBuildTypeList(buildType); + String hospitalId = autoMatchFacade.getHospitalId(userId); + patientsQuery1.setHospitalId(hospitalId); + patientsQuery1.setNeed("1"); + patientsQuery1.setLimit(bookBuildManagerQueryRequest.getLimit()); + patientsQuery1.setPage(bookBuildManagerQueryRequest.getPage()); + patientsQuery1.setPhone(bookBuildManagerQueryRequest.getPhone()); + patientsQuery1.setCardNo(bookBuildManagerQueryRequest.getCardNo()); + patientsQuery1.setPhone(bookBuildManagerQueryRequest.getPhone()); + + List patientses = yunBookbuildingService.queryPregnantWithQuery(patientsQuery1); + + BookBuildManagerResult bookBuildManagerResult = new BookBuildManagerResult(); + List data = new ArrayList<>(); + for (Patients patients : patientses) { + bookBuildManagerResult.convertToResult(patients); + + } + return new BaseListResponse().setData(data).setErrorcode(ErrorCodeConstants.SUCCESS).setErrormsg("成功"); + } + + public BaseResponse findPatientById(String parentId, Integer userId) { + PatientsQuery patientsQuery = new PatientsQuery(); + patientsQuery.setId(parentId); + patientsQuery.setYn(YnEnums.YES.getId()); + patientsQuery.setHospitalId(autoMatchFacade.getHospitalId(userId)); + PregnantInfoResult result = new PregnantInfoResult(); + SimplePregnantResult patientResult = new SimplePregnantResult(); + List patients = yunBookbuildingService.queryPregnantWithQuery(patientsQuery); + if (patients != null && patients.size() > 0) { + Patients p = patients.get(0); + result = getResult(p); + + patientResult.setId(result.getId()); + patientResult.setPid(result.getPid()); + + patientResult.setPregnantName(result.getPregnantName()); + patientResult.setPregnantPhone(result.getPregnantPhone()); + patientResult.setPregnantAge(DateUtil.getAge(p.getBirth()) + ""); + + patientResult.setPregnantLiveAddr(p.getAddressRegister()); + patientResult.setPregnantLiveProvinceId(p.getProvinceRegisterId()); + patientResult.setPregnantLiveCityId(p.getCityRegisterId()); + patientResult.setPregnantLiveAreaId(p.getAreaRegisterId()); + patientResult.setPregnantLiveStreetId(p.getStreetRegisterId()); + + + patientResult.setPregnantLiveProvince(getBasicConfig(patientResult.getPregnantLiveProvinceId())); + patientResult.setPregnantLiveCity(getBasicConfig(patientResult.getPregnantLiveCityId())); + patientResult.setPregnantLiveArea(getBasicConfig(patientResult.getPregnantLiveAreaId())); + patientResult.setPregnantLiveStreet(getBasicConfig(patientResult.getPregnantLiveStreetId())); + patientResult.setHusbandName(result.getHusbandName()); + //丈夫证件号 + if (StringUtils.isNotEmpty(result.getHusbandCertificateNum()) && result.getHusbandCertificateNum().length() == 18) { + + int years, months, days; + try { + String year = result.getHusbandCertificateNum().substring(6, 10); + String month = result.getHusbandCertificateNum().substring(10, 12); + String day = result.getHusbandCertificateNum().substring(12, 14); + years = Integer.valueOf(year); + months = Integer.valueOf(month); + days = Integer.valueOf(day); + Calendar calendar = Calendar.getInstance(); + calendar.set(years, months - 1, days); + patientResult.setHusbandAge(DateUtil.getAge(calendar.getTime()) + ""); + } catch (Exception e) { + } + } + + patientResult.setHusbandCertificateNum(result.getHusbandCertificateNum()); + patientResult.setHusbandCertificateTypeId(result.getHusbandCertificateTypeId()); + patientResult.setHusbandPhone(result.getHusbandPhone()); + } + // 增加初诊信息,桓台医院打印使用 + AntExChuQuery antExChuQuery = new AntExChuQuery(); + antExChuQuery.setParentId(patientResult.getId()); + antExChuQuery.setYn(YnEnums.YES.getId()); + List antExChuModels = antenatalExaminationService.queryAntExChu(antExChuQuery); + if (CollectionUtils.isNotEmpty(antExChuModels)) { + AntExChuModel antExChuModel = antExChuModels.get(0); + patientResult.setPregnancyTimes(antExChuModel.getPregnancyTimes()); + patientResult.setProdTime(antExChuModel.getProdTime()); + patientResult.setDelivery(antExChuModel.getDelivery()); + patientResult.setPlanedProd(antExChuModel.getPlanedProd()); + } + + BaseObjectResponse objectResponse = new BaseObjectResponse(); + objectResponse.setData(patientResult); + objectResponse.setErrorcode(ErrorCodeConstants.SUCCESS); + objectResponse.setErrormsg("成功"); + return objectResponse; + } + + private String getBasicConfig(String id) { + if (StringUtils.isEmpty(id)) { + return ""; + } + BasicConfig basicConfig = basicConfigService.getOneBasicConfigById(id); + if (null != basicConfig) { + return basicConfig.getName(); + } + return ""; + } + + + + } \ No newline at end of file