Bladeren bron

添加用药记录

yeshijie 8 jaren geleden
bovenliggende
commit
16c4613fcb

+ 1 - 0
patient-co-figure/src/main/java/com/yihu/figure/config/SwaggerConfig.java

@ -44,6 +44,7 @@ public class SwaggerConfig extends WebMvcConfigurerAdapter {
                        regex("/portrait/.*"),
                        regex("/patient/.*"),
                        regex("/disease/.*"),
                        regex("/medicine/.*"),
                        regex("/health/.*")
                ))
                .build()

+ 43 - 0
patient-co-figure/src/main/java/com/yihu/figure/controller/drug/MedicineController.java

@ -0,0 +1,43 @@
package com.yihu.figure.controller.drug;
import com.yihu.figure.controller.BaseController;
import com.yihu.figure.service.drug.MedicineRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.ResponseBody;
/**
 * Created by yeshijie on 2017/3/13.
 */
@Controller
@RequestMapping(value = "/medicine/")
@Api(description = "用药记录接口")
public class MedicineController extends BaseController{
    @Autowired
    private MedicineRecordService medicineRecordService;
    /**
     * 获取基位用药记录
     * @return
     */
    @RequestMapping(value="getJwDrugList" ,method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取基位用药记录")
    public String getJwDrugList(){
        try{
            medicineRecordService.getJwDrugList();
            return write(200,"生成成功");
        }catch (Exception e){
            e.printStackTrace();
            return error(-1, "生成失败");
        }
    }
}

+ 10 - 0
patient-co-figure/src/main/java/com/yihu/figure/dao/drug/MedicineDetailDao.java

@ -0,0 +1,10 @@
package com.yihu.figure.dao.drug;
import com.yihu.figure.model.drug.MedicineDetail;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by yeshijie on 2017/3/13.
 */
public interface MedicineDetailDao extends PagingAndSortingRepository<MedicineDetail, Long> {
}

+ 10 - 0
patient-co-figure/src/main/java/com/yihu/figure/dao/drug/MedicineRecordDao.java

@ -0,0 +1,10 @@
package com.yihu.figure.dao.drug;
import com.yihu.figure.model.drug.MedicineRecord;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by yeshijie on 2017/3/13.
 */
public interface MedicineRecordDao extends PagingAndSortingRepository<MedicineRecord, Long> {
}

+ 56 - 0
patient-co-figure/src/main/java/com/yihu/figure/model/drug/MedicineDetail.java

@ -0,0 +1,56 @@
package com.yihu.figure.model.drug;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.figure.model.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by yeshijie on 2017/3/13.
 */
@Entity
@Table(name = "figure_medicine_detail")
public class MedicineDetail extends IdEntity{
    private String medicineRecordCode;//用药记录id
    private String medicineCode;//药品code
    private String medicineName;//药品名称
    private Date czrq;
    public String getMedicineRecordCode() {
        return medicineRecordCode;
    }
    public void setMedicineRecordCode(String medicineRecordCode) {
        this.medicineRecordCode = medicineRecordCode;
    }
    @Column(name = "medicine_code")
    public String getMedicineCode() {
        return medicineCode;
    }
    public void setMedicineCode(String medicineCode) {
        this.medicineCode = medicineCode;
    }
    @Column(name = "medicine_name")
    public String getMedicineName() {
        return medicineName;
    }
    public void setMedicineName(String medicineName) {
        this.medicineName = medicineName;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 136 - 0
patient-co-figure/src/main/java/com/yihu/figure/model/drug/MedicineRecord.java

@ -0,0 +1,136 @@
package com.yihu.figure.model.drug;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.figure.model.IdEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
/**
 * Created by yeshijie on 2017/3/13.
 */
@Entity
@Table(name = "figure_medicine_record")
public class MedicineRecord extends IdEntity{
    private String code;
    private String serial;//'文档序号'
    private Integer orgId;//'机构ID'
    private String catalogCode;//''档案类型''
    private Date endTime;//''事件时间''
    private String orgName;//''机构名称''
    private String unionssid;//'文档序号'
    private Date ehrCommitTime;//''提交时间''
    private String type;//''事件类型1门诊2住院3体检''
    private String event;//''事件号''
    private String xmanId;//
    private String patient;//患者code
    private Date czrq;
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getSerial() {
        return serial;
    }
    public void setSerial(String serial) {
        this.serial = serial;
    }
    public Integer getOrgId() {
        return orgId;
    }
    public void setOrgId(Integer orgId) {
        this.orgId = orgId;
    }
    @Column(name = "catalog_code")
    public String getCatalogCode() {
        return catalogCode;
    }
    public void setCatalogCode(String catalogCode) {
        this.catalogCode = catalogCode;
    }
    public Date getEndTime() {
        return endTime;
    }
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }
    public String getOrgName() {
        return orgName;
    }
    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }
    public String getUnionssid() {
        return unionssid;
    }
    public void setUnionssid(String unionssid) {
        this.unionssid = unionssid;
    }
    public Date getEhrCommitTime() {
        return ehrCommitTime;
    }
    public void setEhrCommitTime(Date ehrCommitTime) {
        this.ehrCommitTime = ehrCommitTime;
    }
    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public String getEvent() {
        return event;
    }
    public void setEvent(String event) {
        this.event = event;
    }
    public String getXmanId() {
        return xmanId;
    }
    public void setXmanId(String xmanId) {
        this.xmanId = xmanId;
    }
    public String getPatient() {
        return patient;
    }
    public void setPatient(String patient) {
        this.patient = patient;
    }
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    public Date getCzrq() {
        return czrq;
    }
    public void setCzrq(Date czrq) {
        this.czrq = czrq;
    }
}

+ 16 - 0
patient-co-figure/src/main/java/com/yihu/figure/service/drug/MedicineDetailService.java

@ -0,0 +1,16 @@
package com.yihu.figure.service.drug;
import com.yihu.figure.service.BaseService;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
/**
 * Created by yeshijie on 2017/3/13.
 */
@Component
@Transactional(rollbackOn = Exception.class)
public class MedicineDetailService extends BaseService{
}

+ 166 - 0
patient-co-figure/src/main/java/com/yihu/figure/service/drug/MedicineRecordService.java

@ -0,0 +1,166 @@
package com.yihu.figure.service.drug;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.figure.dao.drug.MedicineDetailDao;
import com.yihu.figure.dao.drug.MedicineRecordDao;
import com.yihu.figure.dao.patient.PatientInfoDao;
import com.yihu.figure.model.drug.MedicineDetail;
import com.yihu.figure.model.drug.MedicineRecord;
import com.yihu.figure.model.patient.PatientInfo;
import com.yihu.figure.service.BaseService;
import com.yihu.figure.util.DateUtil;
import com.yihu.figure.util.HttpUtil;
import com.yihu.figure.util.MapUtill;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.transaction.Transactional;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * Created by yeshijie on 2017/3/13.
 */
@Component
@Transactional(rollbackOn = Exception.class)
public class MedicineRecordService extends BaseService{
    @Autowired
    private MedicineRecordDao medicineRecordDao;
    @Autowired
    private MedicineDetailDao medicineDetailDao;
    @Autowired
    private PatientInfoDao patientInfoDao;
    ObjectMapper objectMapper = new ObjectMapper();
    /**
     * 获取基位用药记录
     */
    public void getJwDrugList() throws Exception{
        List<PatientInfo> patientInfoList = patientInfoDao.findAllPatient();
        List<MedicineDetail> medicineDetailList = new ArrayList<>();
        List<MedicineRecord> medicineRecordList = new ArrayList<>();
        MedicineDetail detail = null;
        MedicineRecord record = null;
        for (PatientInfo patientInfo:patientInfoList){
            String drugs = getJwDrugList(patientInfo.getSsc());
            System.out.println(drugs);
            if(!StringUtils.isEmpty(drugs)){
                JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, Map.class);
                List<Map<String,Object>> list = objectMapper.readValue(drugs,javaType);
                if(list!=null&&list.size()>0){
                    for (Map<String, Object> map:list){
                        String XMAN_ID = MapUtill.getMapString(map,"XMAN_ID");
                        String EVENT = MapUtill.getMapString(map,"EVENT");
                        Integer ORG_ID = MapUtill.getMapInt(map,"ORG_ID");
                        Integer TYPE = MapUtill.getMapInt(map,"TYPE");
                        Integer SERIAL = MapUtill.getMapInt(map,"SERIAL");
                        String END_TIME = MapUtill.getMapString(map,"END_TIME");
                        String CATALOG_CODE = MapUtill.getMapString(map,"CATALOG_CODE");
                        String EHR_COMMIT_TIME = MapUtill.getMapString(map,"EHR_COMMIT_TIME");
                        String UNIONSSID = MapUtill.getMapString(map,"UNIONSSID");
                        String ORG_NAME = MapUtill.getMapString(map,"ORG_NAME");
                        record = new MedicineRecord();
                        record.setCzrq(new Date());
                        record.setCode(getCode());
                        record.setCatalogCode(CATALOG_CODE);
                        record.setEhrCommitTime(DateUtil.strToDate(EHR_COMMIT_TIME));
                        record.setEndTime(DateUtil.strToDate(END_TIME));
                        record.setEvent(EVENT);
                        record.setOrgId(ORG_ID);
                        record.setOrgName(ORG_NAME);
                        record.setPatient(patientInfo.getCode());
                        record.setSerial(SERIAL+"");
                        record.setType(TYPE+"");
                        record.setUnionssid(UNIONSSID);
                        record.setXmanId(XMAN_ID);
                        medicineRecordList.add(record);
                        if(!"[]".equals(MapUtill.getMapString(map,"MEDICINE"))){
                            List<Map<String, Object>> detailList = (List<Map<String, Object>>)map.get("MEDICINE");
                            if(detailList!=null&&detailList.size()>0){
                                for (Map<String, Object> drug:detailList){
                                    String MEDICINE_NAME = MapUtill.getMapString(drug,"MEDICINE_NAME");
                                    String MEDICINE_CODE = MapUtill.getMapString(drug,"MEDICINE_CODE");
                                    if(!StringUtils.isEmpty(MEDICINE_NAME)){
                                        detail = new MedicineDetail();
                                        detail.setCzrq(new Date());
                                        detail.setMedicineCode(MEDICINE_CODE);
                                        detail.setMedicineName(MEDICINE_NAME);
                                        detail.setMedicineRecordCode(record.getCode());
                                        medicineDetailList.add(detail);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if(medicineDetailList.size()>0){
            medicineDetailDao.save(medicineDetailList);
        }
        if(medicineRecordList.size()>0){
            medicineRecordDao.save(medicineRecordList);
        }
    }
    private static String getJwDrugList(String strSSID){
        String drugUrl = "http://www.xmtyw.cn/wlyy/wlyy_service/record/drug";
        String params = "strSSID="+strSSID+"&startNum=1&endNum=100";
        String userAgent = "\"uid\":\"5fa5e88f7a4111e69f7c005056850d66\",\"doctorType\":3,\"name\":\"丘新花\",\"photo\":\"../../../images/d-male.png\",\"id\":2807,\"hospital\":\"ac02a9b87a3611e69f7c005056850d66\",\"userRole\":[{\"code\":\"350200\",\"name\":\"厦门市卫生与计划生育委员会\",\"areas\":\"350200\"}],\"token\":\"bdbe1d142e330a0e060f70489e383e86\"";
        String re = HttpUtil.sendGet(drugUrl,params,userAgent);
        JSONObject json = new JSONObject(re);
        int status = json.getInt("status");
        if(status==200){
            return json.getString("data");
        }
        return re;
    }
    public static void main(String[] args) throws Exception{
        String ssc = "D24500557";
        String drugs = getJwDrugList(ssc);
        ObjectMapper objectMapper = new ObjectMapper();
        try{
            JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, Map.class);
            List<Map<String,Object>> list = objectMapper.readValue(drugs,javaType);
            if(list!=null&&list.size()>0){
                for (Map<String, Object> map:list){
                    String XMAN_ID = MapUtill.getMapString(map,"XMAN_ID");
                    String EVENT = MapUtill.getMapString(map,"EVENT");
                    Integer ORG_ID = MapUtill.getMapInt(map,"ORG_ID");
                    Integer TYPE = MapUtill.getMapInt(map,"TYPE");
                    Integer SERIAL = MapUtill.getMapInt(map,"SERIAL");
                    String END_TIME = MapUtill.getMapString(map,"END_TIME");
                    String CATALOG_CODE = MapUtill.getMapString(map,"CATALOG_CODE");
                    String EHR_COMMIT_TIME = MapUtill.getMapString(map,"EHR_COMMIT_TIME");
                    String UNIONSSID = MapUtill.getMapString(map,"UNIONSSID");
                    String ORG_NAME = MapUtill.getMapString(map,"ORG_NAME");
                    if(!"[]".equals(MapUtill.getMapString(map,"MEDICINE"))){
                        List<Map<String, Object>> detailList = (List<Map<String, Object>>)map.get("MEDICINE");
                        if(detailList!=null&&detailList.size()>0){
                            for (Map<String, Object> drug:detailList){
                                String MEDICINE_NAME = MapUtill.getMapString(map,"MEDICINE_NAME");
                                String MEDICINE_CODE = MapUtill.getMapString(map,"MEDICINE_CODE");
                            }
                        }
                        System.out.println(detailList.size());
                    }
                }
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}

+ 175 - 0
patient-co-figure/src/main/java/com/yihu/figure/util/HttpUtil.java

@ -0,0 +1,175 @@
package com.yihu.figure.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
/*
 * MD5 算法
 */
public class HttpUtil {
	private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
	/**
	 * 向指定URL发送GET方法的请求
	 *
	 * @param url
	 *            发送请求的URL
	 * @param param
	 *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
	 * @return URL 所代表远程资源的响应结果
	 */
	public static String sendGet(String url, String param,String userAgent) {
		String result = "";
		BufferedReader in = null;
		try {
			String urlNameString = url + "?" + param;
			URL realUrl = new URL(urlNameString);
			// 打开和URL之间的连接
			URLConnection connection = realUrl.openConnection();
			// 设置通用的请求属性
			connection.setRequestProperty("accept", "*/*");
			connection.setRequestProperty("connection", "Keep-Alive");
//			connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			connection.setRequestProperty("user-agent", userAgent);
			// 建立实际的连接
			connection.connect();
			// 定义 BufferedReader输入流来读取URL的响应
			in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += line;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return result;
	}
	/**
	 * 向指定 URL 发送POST方法的请求
	 *
	 * @param url
	 *            发送请求的 URL带上参数
	 * @param param
	 *            POST参数。
	 * @return 所代表远程资源的响应结果
	 */
	public static String sendPost(String url, String param) {
		StringBuffer buffer = new StringBuffer();
		PrintWriter out = null;
		BufferedReader in = null;
		HttpURLConnection conn = null;
		try {
			URL realUrl = new URL(url);
			// 打开和URL之间的连接
			conn = (HttpURLConnection) realUrl.openConnection();
			conn.setRequestMethod("POST");
			conn.setConnectTimeout(5000);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.setUseCaches(false);
			conn.setRequestProperty("Content-Type", "application/text");
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
			osw.write(param.toString());
			osw.flush();
			// 读取返回内容
			BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
			String temp;
			while ((temp = br.readLine()) != null) {
				buffer.append(temp);
				buffer.append("\n");
			}
		} catch (Exception e) {
			logger.error("push message error:", e);
		} finally {
			try {
				if (out != null) {
					out.close();
				}
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		return buffer.toString();
	}
	/**
	 * 向指定 URL 发送POST方法的请求
	 *
	 * @param url 发送请求的 URL带上参数
	 * @param param POST参数。
	 * @param charset 编码格式
	 * @return 所代表远程资源的响应结果
	 */
	public static String sendPost(String url, String param, String charset) {
		StringBuffer buffer = new StringBuffer();
		PrintWriter out = null;
		BufferedReader in = null;
		HttpURLConnection conn = null;
		try {
			URL realUrl = new URL(url);
			// 打开和URL之间的连接
			conn = (HttpURLConnection) realUrl.openConnection();
			conn.setRequestMethod("POST");
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.setUseCaches(false);
			conn.setRequestProperty("Content-Type", "application/text");
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream(), charset);
			osw.write(param.toString());
			osw.flush();
			// 读取返回内容
			BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));
			String temp;
			while ((temp = br.readLine()) != null) {
				buffer.append(temp);
				buffer.append("\n");
			}
		} catch (Exception e) {
			logger.error("push message error:", e);
		} finally {
			try {
				if (out != null) {
					out.close();
				}
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		return buffer.toString();
	}
	public static void main(String[] args) {
	}
}

+ 51 - 0
patient-co-figure/src/main/java/com/yihu/figure/util/MapUtill.java

@ -0,0 +1,51 @@
package com.yihu.figure.util;
import java.util.Map;
/**
 * Created by yeshijie on 2017/3/7.
 */
public class MapUtill {
    /**
     * map获取字符串
     * @param map
     * @param key
     * @return
     */
    public static String getMapString(Map<String,Object> map, String key){
        Object o = map.get(key);
        if(o==null){
            return null;
        }
        return  o.toString();
    }
    /**
     * map获取int
     * @param map
     * @param key
     * @return
     */
    public static Integer getMapInt(Map<String,Object> map,String key){
        Object o = map.get(key);
        if(o==null){
            return null;
        }
        return Integer.parseInt(o.toString());
    }
    /**
     * map获取long
     * @param map
     * @param key
     * @return
     */
    public static Long getMapLong(Map<String,Object> map,String key){
        Object o = map.get(key);
        if(o==null){
            return null;
        }
        return Long.parseLong(o.toString());
    }
}