Browse Source

长处方相关接口

trick9191 7 years ago
parent
commit
714a04aef8

+ 4 - 0
common/common-entity/src/main/java/com/yihu/wlyy/entity/patient/prescription/PrescriptionReasonDict.java

@ -2,11 +2,15 @@ package com.yihu.wlyy.entity.patient.prescription;
import com.yihu.wlyy.entity.IdEntity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by Trick on 2017/8/26.
 */
@Entity
@Table(name = "wlyy_prescription_Reason_dict")
public class PrescriptionReasonDict extends IdEntity {
    private String code;//编码code

+ 3 - 1
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/prescription/PrescriptionReasonDictDao.java

@ -11,5 +11,7 @@ import java.util.List;
 */
public interface PrescriptionReasonDictDao extends PagingAndSortingRepository<PrescriptionReasonDict, Long>, JpaSpecificationExecutor<PrescriptionReasonDict> {
    List<PrescriptionReasonDict> findByTypeOrderBySortAsc(String type);
    List<PrescriptionReasonDict> findByTypeOrderBySortAsc(Integer type);
    PrescriptionReasonDict findByTypeAndCode(Integer type,String code);
}

+ 12 - 0
patient-co/patient-co-wlyy-job/src/main/java/com/yihu/wlyy/repository/prescription/PrescriptionReviewedReasonDao.java

@ -0,0 +1,12 @@
package com.yihu.wlyy.repository.prescription;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionReasonDict;
import com.yihu.wlyy.entity.patient.prescription.PrescriptionReviewedReason;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by Trick on 2017/8/26.
 */
public interface PrescriptionReviewedReasonDao  extends PagingAndSortingRepository<PrescriptionReviewedReason, Long>, JpaSpecificationExecutor<PrescriptionReviewedReason> {
}

+ 2 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/event/ApplicationEvent.java

@ -1,9 +1,7 @@
package com.yihu.wlyy.event;
import com.yihu.wlyy.redis.RedisThread;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;
@ -15,8 +13,8 @@ import org.springframework.stereotype.Service;
public class ApplicationEvent implements ApplicationListener<ContextRefreshedEvent> {
    private Logger logger = LoggerFactory.getLogger(ApplicationEvent.class);
    @Autowired
    private RedisThread redisThread;
//    @Autowired
//    private RedisThread redisThread;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent ContextRefreshedEvent) {

+ 101 - 101
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/redis/RedisMsgPubSubListener.java

@ -1,101 +1,101 @@
package com.yihu.wlyy.redis;
import com.yihu.wlyy.service.app.prescription.PrescriptionInfoService;
import com.yihu.wlyy.service.app.prescription.PrescriptionService;
import com.yihu.wlyy.util.HttpUtil;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisPubSub;
/**
 * Created by Trick on 2017/8/7.
 */
@Component
public class RedisMsgPubSubListener extends JedisPubSub {
    @Autowired
    private PrescriptionInfoService prescriptionInfoService;
    @Autowired
    private PrescriptionService prescriptionService;
    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
    @Override
    public void unsubscribe() {
        super.unsubscribe();
    }
    @Override
    public void unsubscribe(String... channels) {
        super.unsubscribe(channels);
    }
    @Override
    public void subscribe(String... channels) {
        super.subscribe(channels);
    }
    @Override
    public void psubscribe(String... patterns) {
        super.psubscribe(patterns);
    }
    @Override
    public void punsubscribe() {
        super.punsubscribe();
    }
    @Override
    public void punsubscribe(String... patterns) {
        super.punsubscribe(patterns);
    }
    @Override
    public void onMessage(String channel, String message) {
        logger.info("redis_onMessage...:"+message);
        //this.unsubscribe();
        try{
            JSONObject json = new JSONObject(message);
            String title =  json.getString("title");
            if("redisAddPrescription".equals(title)){
                logger.info(json.toString());
                //审核消息发送
                prescriptionInfoService.onMesSquareState(message);
            }else if("dispensingComplete".equals(title)){//配药完成
                //药品配送完成,提醒取药
                String prescriptionCode = json.getString("prescription");
                prescriptionService.dispensingComplete(prescriptionCode);
            }
        }catch (Exception e){
            logger.error("redis_error...",e);
        }
    }
    @Override
    public void onPMessage(String pattern, String channel, String message) {
    }
    @Override
    public void onSubscribe(String channel, int subscribedChannels) {
        //System.out.println("channel:" + channel + "is been subscribed:" + subscribedChannels);
    }
    @Override
    public void onPUnsubscribe(String pattern, int subscribedChannels) {
    }
    @Override
    public void onPSubscribe(String pattern, int subscribedChannels) {
    }
    @Override
    public void onUnsubscribe(String channel, int subscribedChannels) {
        System.out.println("channel:" + channel + "is been unsubscribed:" + subscribedChannels);
    }
}
//package com.yihu.wlyy.redis;
//
//import com.yihu.wlyy.service.app.prescription.PrescriptionInfoService;
//import com.yihu.wlyy.service.app.prescription.PrescriptionService;
//import com.yihu.wlyy.util.HttpUtil;
//import org.json.JSONObject;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import redis.clients.jedis.JedisPubSub;
//
///**
// * Created by Trick on 2017/8/7.
// */
//@Component
//public class RedisMsgPubSubListener extends JedisPubSub {
//
//    @Autowired
//    private PrescriptionInfoService prescriptionInfoService;
//    @Autowired
//    private PrescriptionService prescriptionService;
//
//    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
//
//    @Override
//    public void unsubscribe() {
//        super.unsubscribe();
//    }
//
//    @Override
//    public void unsubscribe(String... channels) {
//        super.unsubscribe(channels);
//    }
//
//    @Override
//    public void subscribe(String... channels) {
//        super.subscribe(channels);
//    }
//
//    @Override
//    public void psubscribe(String... patterns) {
//        super.psubscribe(patterns);
//    }
//
//    @Override
//    public void punsubscribe() {
//        super.punsubscribe();
//    }
//
//    @Override
//    public void punsubscribe(String... patterns) {
//        super.punsubscribe(patterns);
//    }
//
//    @Override
//    public void onMessage(String channel, String message) {
//        logger.info("redis_onMessage...:"+message);
//        //this.unsubscribe();
//        try{
//            JSONObject json = new JSONObject(message);
//            String title =  json.getString("title");
//            if("redisAddPrescription".equals(title)){
//                logger.info(json.toString());
//                //审核消息发送
//                prescriptionInfoService.onMesSquareState(message);
//            }else if("dispensingComplete".equals(title)){//配药完成
//                //药品配送完成,提醒取药
//                String prescriptionCode = json.getString("prescription");
//                prescriptionService.dispensingComplete(prescriptionCode);
//            }
//        }catch (Exception e){
//            logger.error("redis_error...",e);
//        }
//    }
//
//    @Override
//    public void onPMessage(String pattern, String channel, String message) {
//
//    }
//
//    @Override
//    public void onSubscribe(String channel, int subscribedChannels) {
//        //System.out.println("channel:" + channel + "is been subscribed:" + subscribedChannels);
//    }
//
//    @Override
//    public void onPUnsubscribe(String pattern, int subscribedChannels) {
//
//    }
//
//    @Override
//    public void onPSubscribe(String pattern, int subscribedChannels) {
//
//    }
//
//    @Override
//    public void onUnsubscribe(String channel, int subscribedChannels) {
//        System.out.println("channel:" + channel + "is been unsubscribed:" + subscribedChannels);
//    }
//}

+ 44 - 44
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/redis/RedisThread.java

@ -1,44 +1,44 @@
package com.yihu.wlyy.redis;
import com.yihu.wlyy.service.app.prescription.PrescriptionService;
import com.yihu.wlyy.util.SystemConf;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
/**
 * Created by Trick on 2017/8/7.
 */
@Component
public class RedisThread implements Runnable {
    @Value("${spring.redis.host}")
    private String url;
    @Autowired
    private RedisMsgPubSubListener redisMsgPubSubListener;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private PrescriptionService prescriptionService;
    @Override
    public void run() {
        String key = SystemConf.getInstance().getSystemProperties().getProperty("redis_prescription_title");
        while (true){
            redisTemplate.watch(key);
            String message = redisTemplate.opsForList().rightPop(key);
            redisTemplate.unwatch();
            if(StringUtils.isEmpty(message)){
                try{
                    Thread.sleep(1000L);//如果没有读取到记录,等待1秒
                }catch (Exception e){
                    e.printStackTrace();
                }
            }else {
                prescriptionService.redisMessage(message);
            }
        }
    }
}
//package com.yihu.wlyy.redis;
//
//import com.yihu.wlyy.service.app.prescription.PrescriptionService;
//import com.yihu.wlyy.util.SystemConf;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.data.redis.core.StringRedisTemplate;
//import org.springframework.stereotype.Component;
//
///**
// * Created by Trick on 2017/8/7.
// */
//@Component
//public class RedisThread implements Runnable {
//
//    @Value("${spring.redis.host}")
//    private String url;
//    @Autowired
//    private RedisMsgPubSubListener redisMsgPubSubListener;
//    @Autowired
//    private StringRedisTemplate redisTemplate;
//    @Autowired
//    private PrescriptionService prescriptionService;
//
//    @Override
//    public void run() {
//        String key = SystemConf.getInstance().getSystemProperties().getProperty("redis_prescription_title");
//        while (true){
//            redisTemplate.watch(key);
//            String message = redisTemplate.opsForList().rightPop(key);
//            redisTemplate.unwatch();
//            if(StringUtils.isEmpty(message)){
//                try{
//                    Thread.sleep(1000L);//如果没有读取到记录,等待1秒
//                }catch (Exception e){
//                    e.printStackTrace();
//                }
//            }else {
//                prescriptionService.redisMessage(message);
//            }
//        }
//    }
//}

+ 55 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prescription/PrescriptionInfoService.java

@ -90,6 +90,12 @@ public class PrescriptionInfoService extends BaseService {
    private PrescriptionExpressageService expressageService;
    @Autowired
    private PrescriptionService prescriptionService;
    @Autowired
    private PrescriptionReasonDictDao prescriptionReasonDictDao;
    @Autowired
    private PrescriptionReviewedReasonDao prescriptionReviewedReasonDao;
    @Autowired
    private PrescriptionAdjustReasonDao prescriptionAdjustReasonDao;
    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
@ -567,7 +573,7 @@ public class PrescriptionInfoService extends BaseService {
            pre_sql.append(" AND pr.patient = ?");
            params.add(patient);
        }
        pre_sql.append(" GROUP BY pr.code ORDER BY pr.min_drug_day-TIMESTAMPDIFF(DAY, pr.pres_create_time, NOW()) ASC");
        pre_sql.append(" GROUP BY pr.code ORDER BY pr.min_drug_day-TIMESTAMPDIFF(DAY, pr.pres_create_time, NOW()),pr.create_time ASC");
        if (page != null && page > 0 && size != null && size > 0) {
            pre_sql.append(" LIMIT " + (page - 1) * size + "," + size);
        }
@ -608,7 +614,7 @@ public class PrescriptionInfoService extends BaseService {
        return rs;
    }
    public int reviewPrescription(String code, String reason, String state, String dept, String registerFee, String rateTypeCode) throws Exception {
    public int reviewPrescription(String code, String reason,String reasonCode, String state, String dept, String registerFee, String rateTypeCode) throws Exception {
        if (StringUtils.isNotBlank(state)) {
            Prescription p = prescriptionDao.findByCode(code);
            //更新审核记录
@ -628,6 +634,8 @@ public class PrescriptionInfoService extends BaseService {
                reviewed.setReason(reason);
                reviewed.setReviewedTime(new Date());
                reviewed.setStatus(PrescriptionReviewed.PrescriptionReviewedStatus.reviewed_fail.getValue());
                //保存审核不通过原因
                saveReviewedReason(reasonCode,reviewed.getCode(),code);
                //修改系统的续方消息的审核状态
                messageDao.updatePreScriptionMessage(p.getConsult(), "2", 6);
@ -669,7 +677,7 @@ public class PrescriptionInfoService extends BaseService {
        return 0;
    }
    public int updatePresInfo(String code, String infos, String diagnosis, String reason) {
    public int updatePresInfo(String code, String infos, String diagnosis, String reason,String reasonCode) {
        if (StringUtils.isNotBlank(code) && StringUtils.isNotBlank(infos)) {
            //同步智业接口
            upload();
@ -741,11 +749,48 @@ public class PrescriptionInfoService extends BaseService {
            prescriptionAdjust.setPrescriptionCode(code);
            prescriptionAdjustDao.save(prescriptionAdjust);
            //保存原因
            saveAjustReason(reasonCode,prescriptionAdjust,code);
            return 1;
        }
        return 0;
    }
    public void saveAjustReason(String reasonCode,PrescriptionAdjust prescriptionAdjust,String code){
        if(StringUtils.isNotBlank(reasonCode)){
            String reasoncodes[] = reasonCode.split(",");
            for(int i=0;i<reasoncodes.length;i++){
                PrescriptionReasonDict  dict =  prescriptionReasonDictDao.findByTypeAndCode(0,reasoncodes[i]);
                PrescriptionAdjustReason prescriptionAdjustReason = new PrescriptionAdjustReason();
                prescriptionAdjustReason.setCode(getCode());
                prescriptionAdjustReason.setPrescriptionCode(code);
                prescriptionAdjustReason.setAdjustCode(prescriptionAdjust.getCode());
                prescriptionAdjustReason.setReasonCode(reasoncodes[i]);
                prescriptionAdjustReason.setReasonValue(dict.getValue());
                prescriptionAdjustReason.setCreateTime(new Date());
                prescriptionAdjustReasonDao.save(prescriptionAdjustReason);
            }
        }
    }
    public void saveReviewedReason(String reasonCode,String reviewedCode ,String code){
        if(StringUtils.isNotBlank(reasonCode)){
            String reasoncodes[] = reasonCode.split(",");
            for(int i=0;i<reasoncodes.length;i++){
                PrescriptionReasonDict  dict =  prescriptionReasonDictDao.findByTypeAndCode(0,reasoncodes[i]);
                PrescriptionReviewedReason prescriptionReviewedReason = new PrescriptionReviewedReason();
                prescriptionReviewedReason.setCode(getCode());
                prescriptionReviewedReason.setPrescriptionCode(code);
                prescriptionReviewedReason.setReviewedCode(reviewedCode);
                prescriptionReviewedReason.setReasonCode(reasoncodes[i]);
                prescriptionReviewedReason.setReasonValue(dict.getValue());
                prescriptionReviewedReason.setCreateTime(new Date());
                prescriptionReviewedReasonDao.save(prescriptionReviewedReason);
            }
        }
    }
    public String upload() {
        return null;
    }
@ -1237,6 +1282,7 @@ public class PrescriptionInfoService extends BaseService {
    /**
     * @param doctor
     * @return
     * @throws Exception
     */
    public com.alibaba.fastjson.JSONArray getPrescriptionTemp(String doctor) throws Exception {
@ -1319,4 +1365,10 @@ public class PrescriptionInfoService extends BaseService {
        List<Map<String, Object>> rs = jdbcTemplate.queryForList(sql.toString(),new Object[]{code});
        return rs;
    }
    public List<PrescriptionReasonDict> getReasonByType(Integer type){
        List<PrescriptionReasonDict> list =  prescriptionReasonDictDao.findByTypeOrderBySortAsc(type);
        return list;
    }
}

+ 9 - 9
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/jw/JwPrescriptionService.java

@ -89,15 +89,15 @@ public class JwPrescriptionService {
        params.add(new BasicNameValuePair("applyTimeFrom", applyTimeFrom));
        params.add(new BasicNameValuePair("applyTimeEnd", applyTimeEnd));
        String response = httpClientUtil.post(url, params, "UTF-8");
//        String sql = "SELECT h.response from wlyy_http_log h WHERE h.id = 806287";
//        List<Map<String ,Object>> list = jdbcTemplate.queryForList(sql);
//        String response = list.get(0).get("response").toString();
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("status",200);
//        jsonObject.put("data",response);
//        response = jsonObject.toString();
    //    String response = httpClientUtil.post(url, params, "UTF-8");
        String sql = "SELECT h.response from wlyy_http_log h WHERE h.id = 806287";
        List<Map<String ,Object>> list = jdbcTemplate.queryForList(sql);
        String response = list.get(0).get("response").toString();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",200);
        jsonObject.put("data",response);
        response = jsonObject.toString();
        return response;
    }

+ 18 - 4
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/doctor/prescription/PrescriptionInfoController.java

@ -97,12 +97,13 @@ public class PrescriptionInfoController extends BaseController {
    @ObserverRequired
    public String reviewPrescription(@RequestParam(required = true) @ApiParam(value = "续方CODE", name = "code") String code,
                                     @RequestParam(required = false) @ApiParam(value = "不同意原因", name = "reason") String reason,
                                     @RequestParam(required = false) @ApiParam(value = "不同意原因CODE", name = "reasonCode") String reasonCode,
                                     @RequestParam(required = false) @ApiParam(value = "1同意,2不同意", name = "state") String state,
                                     @RequestParam(required = false) @ApiParam(value = "科室", name = "dept") String dept,
                                     @RequestParam(required = false) @ApiParam(value = "诊金", name = "registerFee") String registerFee,
                                     @RequestParam(required = false) @ApiParam(value = "诊金类型", name = "rateTypeCode") String rateTypeCode) {
        try {
            int rs = prescriptionInfoService.reviewPrescription(code, reason, state, dept, registerFee, rateTypeCode);
            int rs = prescriptionInfoService.reviewPrescription(code, reason,reasonCode, state, dept, registerFee, rateTypeCode);
            if (rs == 0) {
                return write(200, "开方失败!", "data", rs);
            } else {
@ -120,9 +121,10 @@ public class PrescriptionInfoController extends BaseController {
    public String updatePresInfo(@RequestParam(required = true) @ApiParam(value = "续方CODE", name = "code") String code,
                                 @RequestParam(required = true) @ApiParam(value = "续方药品JSON", name = "infos") String infos,
                                 @RequestParam(required = false) @ApiParam(value = "疾病JSON", name = "diagnosis") String diagnosis,
                                 @RequestParam(required = false) @ApiParam(value = "调整原因", name = "reason") String reason) {
                                 @RequestParam(required = false) @ApiParam(value = "调整原因", name = "reason") String reason,
                                 @RequestParam(required = false) @ApiParam(value = "调整原因标签Code,用,分割", name = "reasonCode") String reasonCode) {
        try {
            return write(200, "操作成功!", "data", prescriptionInfoService.updatePresInfo(code, infos, diagnosis, reason));
            return write(200, "操作成功!", "data", prescriptionInfoService.updatePresInfo(code, infos, diagnosis, reason,reasonCode));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
@ -465,7 +467,7 @@ public class PrescriptionInfoController extends BaseController {
    @RequestMapping(value = "/getPhysicInfo", method = RequestMethod.GET)
    @ApiOperation(value = "获取药品信息")
    public String getPhysicInfo(String code) {
    public String getPhysicInfo(@RequestParam(required = true) @ApiParam(name = "code", value = "药品code") String code) {
        try {
            return write(200, "查询成功!", "data", prescriptionInfoService.getPhysicInfo(code));
        } catch (Exception e) {
@ -473,4 +475,16 @@ public class PrescriptionInfoController extends BaseController {
            return error(-1, "查询失败!");
        }
    }
    @RequestMapping(value = "/getReasonByType", method = RequestMethod.GET)
    @ApiOperation(value = "获取原因")
    public String getReasonByType(@RequestParam(required = true) @ApiParam(name = "code", value = "类型:0 审核原因标签;1 调整原因标签") Integer type) {
        try {
            return write(200, "查询成功!", "data", prescriptionInfoService.getReasonByType(type));
        } catch (Exception e) {
            error(e);
            return error(-1, "查询失败!");
        }
    }
}