查询的方法
public List<DrugPrescMasterVO> findHerbalDrugReturn(String patientId, String prescNo, String storageCode, Integer prescSource, Integer displayTime,Integer isYfTy) { StringBuffer sb = new StringBuffer(); sb.append("select distinct "); sb.append("dpm.*, "); sb.append("dd.dept_name as orderd_dept_name, "); sb.append("odm.USER_DESCRIPTION as USER_DESCRIPTION, "); sb.append("odm.TCM_DECOCTION_INDICATOR as TCM_DECOCTION_INDICATOR, "); sb.append("odm.PROPORTION_CONCENTRATION as PROPORTION_CONCENTRATION "); sb.append("from drug_presc_master dpm "); sb.append("inner join drug_presc_detail dpd on dpm.presc_id = dpm.presc_id "); sb.append("and dpd.PRESC_INDICATOR = dpm.PRESC_INDICATOR "); sb.append("and dpd.PRESC_DATE = dpm.PRESC_DATE "); sb.append("left join dept_dict dd on dd.dept_code = dpm.ORDERED_BY "); sb.append("left join orders_drug_master odm on odm.presc_no = dpm.presc_no "); sb.append("where dpm.DISPENSARY = '" + storageCode + "' "); if (!Strings.isNullOrEmpty(patientId)) { sb.append("and dpm.patient_id = '" + patientId + "' "); } if (!Strings.isNullOrEmpty(prescNo)) { sb.append("and dpm.presc_no = '" + prescNo + "' "); } if (prescSource != null) { sb.append("and dpm.presc_source = '" + prescSource + "' "); } if(isYfTy!=null && isYfTy.intValue()==1){//药房退药页面发起 sb.append("and dpm.doctor_return_repetition >0 "); //药房不主动发起退药,只查询由医生站发起的 } sb.append("and dpm.PRESC_INDICATOR = '1' "); sb.append("and dpm.PRESC_TYPE = '1' "); sb.append("and dpm.INVALID_INDICATOR = '0' "); sb.append("and (dpd.DISPENSING_FLAG <> -1 or dpd.DISPENSING_FLAG is null) "); if (null != displayTime && displayTime > 0) { Calendar now = Calendar.getInstance(); SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); now.setTime(new Date()); now.add(Calendar.DATE, 1); now.set(Calendar.HOUR_OF_DAY, 0); now.set(Calendar.MINUTE, 0); now.set(Calendar.SECOND, 0); Calendar beginDate = Calendar.getInstance(); beginDate.setTime(new Date()); beginDate.add(Calendar.DATE, -displayTime + 1); beginDate.set(Calendar.HOUR_OF_DAY, 0); beginDate.set(Calendar.MINUTE, 0); beginDate.set(Calendar.SECOND, 0); sb.append(" and dpm.PRESC_DATE >= TO_DATE('").append(format.format(beginDate.getTime())).append("', 'yyyyMMddHH24MIss')"); sb.append(" and dpm.PRESC_DATE < TO_DATE('").append(format.format(now.getTime())).append("', 'yyyyMMddHH24MIss')"); } sb.append("order by dpm.presc_date desc "); Query query = createNativeQuery(sb.toString()); query.unwrap(SQLQuery.class).setResultTransformer(new AliasToBeanResultTransformer(DrugPrescMasterVO.class)); List<DrugPrescMasterVO> drugPrescMasterVOList = query.getResultList(); return drugPrescMasterVOList; }
查询的sql
select distinct dpm.*, dd.dept_name as orderd_dept_name, odm.USER_DESCRIPTION as USER_DESCRIPTION, odm.TCM_DECOCTION_INDICATOR as TCM_DECOCTION_INDICATOR, odm.PROPORTION_CONCENTRATION as PROPORTION_CONCENTRATION from drug_presc_master dpm inner join drug_presc_detail dpd on dpm.presc_id = dpm.presc_id and dpd.PRESC_INDICATOR = dpm.PRESC_INDICATOR and dpd.PRESC_DATE = dpm.PRESC_DATE left join dept_dict dd on dd.dept_code = dpm.ORDERED_BY left join orders_drug_master odm on odm.presc_no = dpm.presc_no where dpm.DISPENSARY = 'A02030090200' and dpm.patient_id = '10000141' and dpm.presc_source = '0' and dpm.PRESC_INDICATOR = '1' and dpm.PRESC_TYPE = '1' and dpm.INVALID_INDICATOR = '0' and (dpd.DISPENSING_FLAG <> -1 or dpd.DISPENSING_FLAG is null) and dpm.PRESC_DATE >= TO_DATE('20171012000000', 'yyyyMMddHH24MIss') and dpm.PRESC_DATE < TO_DATE('20171015000000', 'yyyyMMddHH24MIss') order by dpm.presc_date desc;
sql解释在http://www.cnblogs.com/ms-grf/p/7667316.html
Query 所属的jar:hibernate-jpa-2.1-api-1.0.0.Final.jar
SQLQuery 所属的jar:hibernate-core-5.0.1.Final.jar
上面红色的相关内容
DrugPrescMasterVO.class
package com.heren.his.domain.vo.drug; import com.heren.his.domain.entity.drug.DrugPrescDetail; import javax.persistence.Column; import java.util.Date; import java.util.List; public class DrugPrescMasterVO { private String prescId; private String prescNo; private Integer prescIndicator; private Date prescDate; private String dispensary; private String patientId; private String name; private String identityName; private String chargeType; private String unitInContract; private Integer prescType; private String prescAttr; private Integer prescSource; private Integer repetition; private Double costs; private Double payments; private String orderedBy; private String prescribedBy; private String prescribedName; private String deployEmpId; private String deployEmpName; private String dispensingEmpId; private String dispensingEmpName; private Integer invalidIndicator; private String memo; private String orderedByName; private String namePhonetic; //流水号 private String visitNo; //开单科室名称 private String orderdDeptName; //用法描述 private String userDescription; //中草药配比浓度 private String proportionConcentration; //代煎标志 private Integer tcmDecoctionIndicator; //本地科室 private String storageCode; //新剂数 private Integer newRepetition; //医生退药付数 private Integer doctorReturnRepetition; //处方特定类型 private Integer prescSpecType; //强制代煎药标识(望江山模式) private Integer forceTcmDecoction=0; // 护理单元名称 private String wardName; // 床位号 private Integer bedNo; // 床位名称 private String bedLabel; // 住院号 private String inpNo; public DrugPrescMasterVO(String prescNo, Integer prescIndicator, Date prescDate, String dispensary, String patientId, String name, String identityName, String chargeType, String unitInContract, Integer prescType, String prescAttr, Integer prescSource, Integer repetition, Double costs, Double payments, String orderedBy, String prescribedBy, String prescribedName, String deployEmpId, String deployEmpName, String dispensingEmpId, String dispensingEmpName, Integer invalidIndicator, String memo, String orderedByName, String namePhonetic) { this.prescNo = prescNo; this.prescIndicator = prescIndicator; this.prescDate = prescDate; this.dispensary = dispensary; this.patientId = patientId; this.name = name; this.identityName = identityName; this.chargeType = chargeType; this.unitInContract = unitInContract; this.prescType = prescType; this.prescAttr = prescAttr; this.prescSource = prescSource; this.repetition = repetition; this.costs = costs; this.payments = payments; this.orderedBy = orderedBy; this.prescribedBy = prescribedBy; this.prescribedName = prescribedName; this.deployEmpId = deployEmpId; this.deployEmpName = deployEmpName; this.dispensingEmpId = dispensingEmpId; this.dispensingEmpName = dispensingEmpName; this.invalidIndicator = invalidIndicator; this.memo = memo; this.orderedByName = orderedByName; this.namePhonetic = namePhonetic; } public DrugPrescMasterVO(String prescId, String prescNo, Integer prescIndicator, Date prescDate, String dispensary, String patientId, String name, String identityName, String chargeType, String unitInContract, Integer prescType, String prescAttr, Integer prescSource, Integer repetition, Double costs, Double payments, String orderedBy, String prescribedBy, String prescribedName, String deployEmpId, String deployEmpName, String dispensingEmpId, String dispensingEmpName, Integer invalidIndicator, String memo, String orderedByName, String namePhonetic) { this.prescId = prescId; this.prescNo = prescNo; this.prescIndicator = prescIndicator; this.prescDate = prescDate; this.dispensary = dispensary; this.patientId = patientId; this.name = name; this.identityName = identityName; this.chargeType = chargeType; this.unitInContract = unitInContract; this.prescType = prescType; this.prescAttr = prescAttr; this.prescSource = prescSource; this.repetition = repetition; this.costs = costs; this.payments = payments; this.orderedBy = orderedBy; this.prescribedBy = prescribedBy; this.prescribedName = prescribedName; this.deployEmpId = deployEmpId; this.deployEmpName = deployEmpName; this.dispensingEmpId = dispensingEmpId; this.dispensingEmpName = dispensingEmpName; this.invalidIndicator = invalidIndicator; this.memo = memo; this.orderedByName = orderedByName; this.namePhonetic = namePhonetic; } public DrugPrescMasterVO() { } public String getPrescId() { return prescId; } public void setPrescId(String prescId) { this.prescId = prescId; } public String getPrescNo() { return prescNo; } public void setPrescNo(String prescNo) { this.prescNo = prescNo; } public Integer getPrescIndicator() { return prescIndicator; } public void setPrescIndicator(Integer prescIndicator) { this.prescIndicator = prescIndicator; } public Date getPrescDate() { return prescDate; } public void setPrescDate(Date prescDate) { this.prescDate = prescDate; } public String getDispensary() { return dispensary; } public void setDispensary(String dispensary) { this.dispensary = dispensary; } public String getPatientId() { return patientId; } public void setPatientId(String patientId) { this.patientId = patientId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getIdentityName() { return identityName; } public void setIdentityName(String identityName) { this.identityName = identityName; } public String getChargeType() { return chargeType; } public void setChargeType(String chargeType) { this.chargeType = chargeType; } public String getUnitInContract() { return unitInContract; } public void setUnitInContract(String unitInContract) { this.unitInContract = unitInContract; } public Integer getPrescType() { return prescType; } public void setPrescType(Integer prescType) { this.prescType = prescType; } public String getPrescAttr() { return prescAttr; } public void setPrescAttr(String prescAttr) { this.prescAttr = prescAttr; } public Integer getPrescSource() { return prescSource; } public void setPrescSource(Integer prescSource) { this.prescSource = prescSource; } public Integer getRepetition() { return repetition; } public void setRepetition(Integer repetition) { this.repetition = repetition; } public Double getCosts() { return costs; } public void setCosts(Double costs) { this.costs = costs; } public Double getPayments() { return payments; } public void setPayments(Double payments) { this.payments = payments; } public String getOrderedBy() { return orderedBy; } public void setOrderedBy(String orderedBy) { this.orderedBy = orderedBy; } public String getPrescribedBy() { return prescribedBy; } public void setPrescribedBy(String prescribedBy) { this.prescribedBy = prescribedBy; } public String getPrescribedName() { return prescribedName; } public void setPrescribedName(String prescribedName) { this.prescribedName = prescribedName; } public String getDeployEmpId() { return deployEmpId; } public void setDeployEmpId(String deployEmpId) { this.deployEmpId = deployEmpId; } public String getDeployEmpName() { return deployEmpName; } public void setDeployEmpName(String deployEmpName) { this.deployEmpName = deployEmpName; } public String getDispensingEmpId() { return dispensingEmpId; } public void setDispensingEmpId(String dispensingEmpId) { this.dispensingEmpId = dispensingEmpId; } public String getDispensingEmpName() { return dispensingEmpName; } public void setDispensingEmpName(String dispensingEmpName) { this.dispensingEmpName = dispensingEmpName; } public Integer getInvalidIndicator() { return invalidIndicator; } public void setInvalidIndicator(Integer invalidIndicator) { this.invalidIndicator = invalidIndicator; } public String getMemo() { return memo; } public void setMemo(String memo) { this.memo = memo; } public String getOrderedByName() { return orderedByName; } public void setOrderedByName(String orderedByName) { this.orderedByName = orderedByName; } public String getNamePhonetic() { return namePhonetic; } public String getVisitNo() { return visitNo; } public void setVisitNo(String visitNo) { this.visitNo = visitNo; } public void setNamePhonetic(String namePhonetic) { this.namePhonetic = namePhonetic; } public String getUserDescription() { return userDescription; } public void setUserDescription(String userDescription) { this.userDescription = userDescription; } public String getProportionConcentration() { return proportionConcentration; } public void setProportionConcentration(String proportionConcentration) { this.proportionConcentration = proportionConcentration; } public Integer getTcmDecoctionIndicator() { return tcmDecoctionIndicator; } public void setTcmDecoctionIndicator(Integer tcmDecoctionIndicator) { this.tcmDecoctionIndicator = tcmDecoctionIndicator; } public String getOrderdDeptName() { return orderdDeptName; } public void setOrderdDeptName(String orderdDeptName) { this.orderdDeptName = orderdDeptName; } public String getStorageCode() { return storageCode; } public void setStorageCode(String storageCode) { this.storageCode = storageCode; } public Integer getNewRepetition() { return newRepetition; } public void setNewRepetition(Integer newRepetition) { this.newRepetition = newRepetition; } public Integer getDoctorReturnRepetition() { return doctorReturnRepetition; } public void setDoctorReturnRepetition(Integer doctorReturnRepetition) { this.doctorReturnRepetition = doctorReturnRepetition; } public Integer getPrescSpecType() { return prescSpecType; } public void setPrescSpecType(Integer prescSpecType) { this.prescSpecType = prescSpecType; } public Integer getForceTcmDecoction() { return forceTcmDecoction; } public void setForceTcmDecoction(Integer forceTcmDecoction) { this.forceTcmDecoction = forceTcmDecoction; } public String getWardName() { return wardName; } public void setWardName(String wardName) { this.wardName = wardName; } public Integer getBedNo() { return bedNo; } public void setBedNo(Integer bedNo) { this.bedNo = bedNo; } public String getBedLabel() { return bedLabel; } public void setBedLabel(String bedLabel) { this.bedLabel = bedLabel; } public String getInpNo() { return inpNo; } public void setInpNo(String inpNo) { this.inpNo = inpNo; } }