List of usage examples for org.hibernate.criterion Restrictions sqlRestriction
public static Criterion sqlRestriction(String sql)
From source file:org.opennms.web.svclayer.support.DefaultNodeListService.java
License:Open Source License
private static void addCriteriaForCurrentOutages(OnmsCriteria criteria) { /*/* w w w. java2 s .c om*/ * This doesn't work properly if ipInterfaces and/or * monitoredServices have other restrictions. If we are * matching on service ID = 7, but service ID = 1 has an * outage, the node won't show up. */ /* criteria.createAlias("ipInterfaces", "ipInterface"); criteria.createAlias("ipInterfaces.monitoredServices", "monitoredService"); criteria.createAlias("ipInterfaces.monitoredServices.currentOutages", "currentOutages"); criteria.add(Restrictions.isNull("currentOutages.ifRegainedService")); criteria.add(Restrictions.or(Restrictions.isNull("currentOutages.suppressTime"), Restrictions.lt("currentOutages.suppressTime", new Date()))); */ // This SQL restriction does work fine, however criteria.add(Restrictions.sqlRestriction( "{alias}.nodeId in (select ip.nodeId from outages o, ifservices if, ipinterface ip where if.id = o.ifserviceid and ip.id = if.ipinterfaceid and o.ifregainedservice is null and o.suppresstime is null or o.suppresstime < now())")); }
From source file:org.oscarehr.common.dao.DemographicDao.java
License:Open Source License
@SuppressWarnings("unchecked") public List<Demographic> search(ClientSearchFormBean bean, boolean returnOptinsOnly, boolean excludeMerged) { Criteria criteria = getSession().createCriteria(Demographic.class); String firstName = ""; String lastName = ""; String firstNameL = ""; String lastNameL = ""; String bedProgramId = ""; String assignedToProviderNo = ""; String active = ""; String gender = ""; String sql = ""; List<Demographic> results = null; if (bean.getFirstName() != null && bean.getFirstName().length() > 0) { firstName = bean.getFirstName(); // firstName = StringEscapeUtils.escapeSql(firstName); firstNameL = firstName + "%"; }//from www .j a va 2 s . c o m if (bean.getLastName() != null && bean.getLastName().length() > 0) { lastName = bean.getLastName(); // lastName = StringEscapeUtils.escapeSql(lastName); lastNameL = lastName + "%"; } String clientNo = bean.getDemographicNo(); //exclude merged client if (excludeMerged) criteria.add(Expression.eq("merged", Boolean.FALSE)); if (clientNo != null && !"".equals(clientNo)) { if (com.quatro.util.Utility.IsInt(clientNo)) { criteria.add(Expression.eq("DemographicNo", Integer.valueOf(clientNo))); results = criteria.list(); } else { /* invalid client no generates a empty search results */ results = new ArrayList<Demographic>(); } return results; } if (firstName.length() > 0) { // sql = "(LEFT(SOUNDEX(first_name),4) = LEFT(SOUNDEX('" + firstName + "'),4))"; // sql2 = "(LEFT(SOUNDEX(alias),4) = LEFT(SOUNDEX('" + firstName + "'),4))"; // condFirstName = Restrictions.or(Restrictions.ilike("FirstName", firstNameL), Restrictions.sqlRestriction(sql)); // condAlias1 = Restrictions.or(Restrictions.ilike("Alias", firstNameL),Restrictions.sqlRestriction(sql2)); criteria.add(Restrictions.or(Restrictions.or(Restrictions.ilike("LastName", firstNameL), Restrictions.ilike("Alias", firstNameL)), Restrictions.ilike("FirstName", firstNameL))); } if (lastName.length() > 0) { // sql = "(LEFT(SOUNDEX(last_name),4) = LEFT(SOUNDEX('" + lastName + "'),4))"; // sql2 = "(LEFT(SOUNDEX(alias),4) = LEFT(SOUNDEX('" + lastName + "'),4))"; // condLastName = Restrictions.or(Restrictions.ilike("LastName", lastNameL), Restrictions.sqlRestriction(sql)); // condAlias2 = Restrictions.or(Restrictions.ilike("Alias", lastNameL),Restrictions.sqlRestriction(sql2)); criteria.add(Restrictions.or(Restrictions.or(Restrictions.ilike("FirstName", lastNameL), Restrictions.ilike("Alias", lastNameL)), Restrictions.ilike("LastName", lastNameL))); } /* if (firstName.length() > 0 && lastName.length()>0) { criteria.add(Restrictions.or(Restrictions.and(condFirstName, condLastName), Restrictions.or(condAlias1, condAlias2))); } else if (firstName.length() > 0) { criteria.add(Restrictions.or(condFirstName,condAlias1)); } else if (lastName.length()>0) { criteria.add(Restrictions.or(condLastName,condAlias2)); } */ if (bean.getDob() != null && bean.getDob().length() > 0) { criteria.add(Expression.eq("DateOfBirth", MyDateFormat.getCalendar(bean.getDob()))); } if (bean.getHealthCardNumber() != null && bean.getHealthCardNumber().length() > 0) { criteria.add(Expression.eq("Hin", bean.getHealthCardNumber())); } if (bean.getHealthCardVersion() != null && bean.getHealthCardVersion().length() > 0) { criteria.add(Expression.eq("Ver", bean.getHealthCardVersion())); } if (bean.getBedProgramId() != null && bean.getBedProgramId().length() > 0) { bedProgramId = bean.getBedProgramId(); sql = " demographic_no in (select decode(dm.merged_to,null,i.client_id,dm.merged_to) from intake i,demographic_merged dm where i.client_id=dm.demographic_no(+) and i.program_id in (" + bedProgramId + "))"; criteria.add(Restrictions.sqlRestriction(sql)); } if (bean.getAssignedToProviderNo() != null && bean.getAssignedToProviderNo().length() > 0) { assignedToProviderNo = bean.getAssignedToProviderNo(); sql = " demographic_no in (select decode(dm.merged_to,null,a.client_id,dm.merged_to) from admission a,demographic_merged dm where a.client_id=dm.demographic_no(+)and a.primaryWorker='" + assignedToProviderNo + "')"; criteria.add(Restrictions.sqlRestriction(sql)); } active = bean.getActive(); if ("1".equals(active)) { criteria.add(Expression.ge("activeCount", new Integer(1))); } else if ("0".equals(active)) { criteria.add(Expression.eq("activeCount", new Integer(0))); } gender = bean.getGender(); if (gender != null && !"".equals(gender)) { criteria.add(Expression.eq("Sex", gender)); } criteria.addOrder(Order.asc("LastName")); criteria.addOrder(Order.asc("FirstName")); results = criteria.list(); if (log.isDebugEnabled()) { log.debug("search: # of results=" + results.size()); } return results; }
From source file:org.oscarehr.common.dao.DemographicDao.java
License:Open Source License
public List<Demographic> search(ClientSearchFormBean bean) { Criteria criteria = getSession().createCriteria(Demographic.class); String firstName = ""; String lastName = ""; String firstNameL = ""; String lastNameL = ""; String active = ""; String gender = ""; String sql = ""; String sql2 = ""; @SuppressWarnings("unchecked") List<Demographic> results = null; if (bean.getFirstName() != null && bean.getFirstName().length() > 0) { firstName = bean.getFirstName(); firstName = StringEscapeUtils.escapeSql(firstName); firstNameL = "%" + firstName + "%"; }/*from www . j av a 2s .com*/ if (bean.getLastName() != null && bean.getLastName().length() > 0) { lastName = bean.getLastName(); lastName = StringEscapeUtils.escapeSql(lastName); lastNameL = "%" + lastName + "%"; } String clientNo = bean.getDemographicNo(); if (clientNo != null && !"".equals(clientNo)) { if (com.quatro.util.Utility.IsInt(clientNo)) { criteria.add(Expression.eq("DemographicNo", Integer.valueOf(clientNo).intValue())); results = criteria.list(); } else { /* invalid client no generates a empty search results */ results = new ArrayList<Demographic>(); } return results; } LogicalExpression condAlias1 = null; LogicalExpression condAlias2 = null; LogicalExpression condFirstName = null; LogicalExpression condLastName = null; if (firstName.length() > 0) { sql = "(LEFT(SOUNDEX(first_name),2) = LEFT(SOUNDEX('" + firstName + "'),2))"; sql2 = "(LEFT(SOUNDEX(alias),2) = LEFT(SOUNDEX('" + firstName + "'),2))"; condFirstName = Restrictions.or(Restrictions.ilike("FirstName", firstNameL), Restrictions.sqlRestriction(sql)); condAlias1 = Restrictions.or(Restrictions.ilike("Alias", firstNameL), Restrictions.sqlRestriction(sql2)); } if (lastName.length() > 0) { sql = "(LEFT(SOUNDEX(last_name),2) = LEFT(SOUNDEX('" + lastName + "'),2))"; sql2 = "(LEFT(SOUNDEX(alias),2) = LEFT(SOUNDEX('" + lastName + "'),2))"; condLastName = Restrictions.or(Restrictions.ilike("LastName", lastNameL), Restrictions.sqlRestriction(sql)); condAlias2 = Restrictions.or(Restrictions.ilike("Alias", lastNameL), Restrictions.sqlRestriction(sql2)); } if (bean.getChartNo() != null && bean.getChartNo().length() > 0) { criteria.add(Expression.like("ChartNo", "%" + bean.getChartNo() + "%")); } if (!bean.isSearchUsingSoundex()) { if (firstName.length() > 0) { criteria.add(Restrictions.or(Restrictions.ilike("FirstName", firstNameL), Restrictions.ilike("Alias", firstNameL))); } if (lastName.length() > 0) { criteria.add(Restrictions.or(Restrictions.ilike("LastName", lastNameL), Restrictions.ilike("Alias", lastNameL))); } } else { // soundex variation if (firstName.length() > 0) { criteria.add(Restrictions.or(condFirstName, condAlias1)); } if (lastName.length() > 0) { criteria.add(Restrictions.or(condLastName, condAlias2)); } } if (bean.getDob() != null && bean.getDob().length() > 0) { criteria.add(Expression.eq("YearOfBirth", bean.getYearOfBirth())); criteria.add(Expression.eq("MonthOfBirth", bean.getMonthOfBirth())); criteria.add(Expression.eq("DateOfBirth", bean.getDayOfBirth())); } if (bean.getHealthCardNumber() != null && bean.getHealthCardNumber().length() > 0) { criteria.add(Expression.eq("Hin", bean.getHealthCardNumber())); } if (bean.getHealthCardVersion() != null && bean.getHealthCardVersion().length() > 0) { criteria.add(Expression.eq("Ver", bean.getHealthCardVersion())); } if (bean.getChartNo() != null && bean.getChartNo().length() > 0) { criteria.add(Expression.like("ChartNo", "%" + bean.getChartNo() + "%")); } if (!bean.isSearchOutsideDomain()) { // program domain limited search if (bean.getProgramDomain() == null) { bean.setProgramDomain(new ArrayList<ProgramProvider>()); } DetachedCriteria subq = DetachedCriteria.forClass(Admission.class) .setProjection(Property.forName("ClientId")); StringBuilder programIds = new StringBuilder(); for (int x = 0; x < bean.getProgramDomain().size(); x++) { ProgramProvider p = (ProgramProvider) bean.getProgramDomain().get(x); if (x > 0) { programIds.append(","); } programIds.append(p.getProgramId()); } String[] pIds = {}; pIds = programIds.toString().split(","); logger.info("programIds is " + programIds.toString()); if (programIds.length() == 0) { logger.info("provider not staff in any program, ie. can't see ANYONE."); //provider not staff in any program, ie. can't see ANYONE. return new ArrayList<Demographic>(); } Integer[] pIdi = new Integer[pIds.length]; for (int i = 0; i < pIds.length; i++) { pIdi[i] = Integer.parseInt(pIds[i]); } if (pIdi.length > 0) { subq.add(Restrictions.in("ProgramId", pIdi)); } if (bean.getDateFrom() != null && bean.getDateFrom().length() > 0) { Date dt = MyDateFormat.getSysDate(bean.getDateFrom().trim()); subq.add(Restrictions.ge("AdmissionDate", dt)); } if (bean.getDateTo() != null && bean.getDateTo().length() > 0) { Date dt1 = MyDateFormat.getSysDate(bean.getDateTo().trim()); subq.add(Restrictions.le("AdmissionDate", dt1)); } criteria.add(Property.forName("DemographicNo").in(subq)); } active = bean.getActive(); if ("1".equals(active)) { criteria.add(Expression.ge("activeCount", 1)); } else if ("0".equals(active)) { criteria.add(Expression.eq("activeCount", 0)); } gender = bean.getGender(); if (gender != null && !"".equals(gender)) { criteria.add(Expression.eq("Sex", gender)); } criteria.add( Expression.or(Expression.ne("anonymous", "one-time-anonymous"), Expression.isNull("anonymous"))); results = criteria.list(); if (log.isDebugEnabled()) { log.debug("search: # of results=" + results.size()); } return results; }
From source file:org.oscarehr.PMmodule.dao.ProgramDao.java
License:Open Source License
public List<Program> getAllPrograms(String programStatus, String type, Integer facilityId, Integer clientId, String providerNo, Integer shelterId) { Criteria c = getSession().createCriteria(Program.class); if (!(Utility.IsEmpty(programStatus))) { c.add(Restrictions.eq("programStatus", programStatus)); }/*from w w w . jav a2s. c om*/ if (null != type && !("Any".equalsIgnoreCase(type) || "".equals(type))) { c.add(Restrictions.eq("type", type)); } if (null != facilityId && facilityId.intValue() > 0) { c.add(Restrictions.eq("facilityId", facilityId)); } if (null != clientId && clientId.intValue() > 0) { String clientProgram = "id in (select itk.program_id from intake itk where itk.client_id=" + clientId.toString() + ")"; c.add(Restrictions.sqlRestriction(clientProgram)); } c.add(Restrictions.sqlRestriction("id in " + Utility.getUserOrgSqlString(providerNo, shelterId))); c.addOrder(Order.asc("name")); @SuppressWarnings("unchecked") List<Program> list = c.list(); for (int i = 0; i < list.size(); i++) { Program p = list.get(i); if (p.getType().equals(KeyConstants.PROGRAM_TYPE_Service)) p.setNumOfMembers(p.getNumOfIntakes()); } return list; }
From source file:org.oscarehr.PMmodule.dao.ProgramDao.java
License:Open Source License
public List<Program> search(Program program) { if (program == null) { throw new IllegalArgumentException(); }/*w w w . j av a 2s . com*/ boolean isOracle = OscarProperties.getInstance().getDbType().equals("oracle"); Criteria criteria = getSession().createCriteria(Program.class); if (program.getName() != null && program.getName().length() > 0) { String programName = StringEscapeUtils.escapeSql(program.getName()); String sql = ""; if (isOracle) { sql = "((LEFT(SOUNDEX(name),4) = LEFT(SOUNDEX('" + programName + "'),4)))"; criteria.add(Restrictions.or(Restrictions.ilike("name", "%" + programName + "%"), Restrictions.sqlRestriction(sql))); } else { sql = "((LEFT(SOUNDEX(name),4) = LEFT(SOUNDEX('" + programName + "'),4))" + " " + "OR (name like '" + "%" + programName + "%'))"; criteria.add(Restrictions.sqlRestriction(sql)); } } if (program.getType() != null && program.getType().length() > 0) { criteria.add(Expression.eq("type", program.getType())); } if (program.getType() == null || program.getType().equals("") || !program.getType().equals("community")) { criteria.add(Expression.ne("type", "community")); } criteria.add(Expression.eq("programStatus", "active")); if (program.getManOrWoman() != null && program.getManOrWoman().length() > 0) { criteria.add(Expression.eq("manOrWoman", program.getManOrWoman())); } if (program.isTransgender()) { criteria.add(Expression.eq("transgender", true)); } if (program.isFirstNation()) { criteria.add(Expression.eq("firstNation", true)); } if (program.isBedProgramAffiliated()) { criteria.add(Expression.eq("bedProgramAffiliated", true)); } if (program.isAlcohol()) { criteria.add(Expression.eq("alcohol", true)); } if (program.getAbstinenceSupport() != null && program.getAbstinenceSupport().length() > 0) { criteria.add(Expression.eq("abstinenceSupport", program.getAbstinenceSupport())); } if (program.isPhysicalHealth()) { criteria.add(Expression.eq("physicalHealth", true)); } if (program.isHousing()) { criteria.add(Expression.eq("housing", true)); } if (program.isMentalHealth()) { criteria.add(Expression.eq("mentalHealth", true)); } criteria.addOrder(Order.asc("name")); List results = criteria.list(); if (log.isDebugEnabled()) { log.debug("search: # results: " + results.size()); } return results; }
From source file:org.oscarehr.PMmodule.dao.ProgramDao.java
License:Open Source License
public List<Program> searchByFacility(Program program, Integer facilityId) { if (program == null) { throw new IllegalArgumentException(); }/*from w ww . ja va 2 s . c om*/ if (facilityId == null) { throw new IllegalArgumentException(); } boolean isOracle = OscarProperties.getInstance().getDbType().equals("oracle"); Criteria criteria = getSession().createCriteria(Program.class); if (program.getName() != null && program.getName().length() > 0) { String programName = StringEscapeUtils.escapeSql(program.getName()); String sql = ""; if (isOracle) { sql = "((LEFT(SOUNDEX(name),4) = LEFT(SOUNDEX('" + programName + "'),4)))"; criteria.add(Restrictions.or(Restrictions.ilike("name", "%" + programName + "%"), Restrictions.sqlRestriction(sql))); } else { sql = "((LEFT(SOUNDEX(name),4) = LEFT(SOUNDEX('" + programName + "'),4))" + " " + "OR (name like '" + "%" + programName + "%'))"; criteria.add(Restrictions.sqlRestriction(sql)); } } if (program.getType() != null && program.getType().length() > 0) { criteria.add(Expression.eq("type", program.getType())); } if (program.getType() == null || program.getType().equals("") || !program.getType().equals("community")) { criteria.add(Expression.ne("type", "community")); } criteria.add(Expression.eq("programStatus", "active")); if (program.getManOrWoman() != null && program.getManOrWoman().length() > 0) { criteria.add(Expression.eq("manOrWoman", program.getManOrWoman())); } if (program.isTransgender()) { criteria.add(Expression.eq("transgender", true)); } if (program.isFirstNation()) { criteria.add(Expression.eq("firstNation", true)); } if (program.isBedProgramAffiliated()) { criteria.add(Expression.eq("bedProgramAffiliated", true)); } if (program.isAlcohol()) { criteria.add(Expression.eq("alcohol", true)); } if (program.getAbstinenceSupport() != null && program.getAbstinenceSupport().length() > 0) { criteria.add(Expression.eq("abstinenceSupport", program.getAbstinenceSupport())); } if (program.isPhysicalHealth()) { criteria.add(Expression.eq("physicalHealth", true)); } if (program.isHousing()) { criteria.add(Expression.eq("housing", true)); } if (program.isMentalHealth()) { criteria.add(Expression.eq("mentalHealth", true)); } criteria.add(Expression.eq("facilityId", facilityId)); criteria.addOrder(Order.asc("name")); List results = criteria.list(); if (log.isDebugEnabled()) { log.debug("search: # results: " + results.size()); } return results; }
From source file:org.xerela.server.birt.RenderElf.java
License:Mozilla Public License
/** * Render the BIRT intermediate file into the requested output format. * * @param rptDocFile a file containing BIRT intermediate output format * @param format the format specifier ("pdf", "html", "xls", etc.) * @return the file containing the final rendered output * @throws EngineException/*from ww w . j a v a 2 s . co m*/ * @throws IOException */ @SuppressWarnings("unchecked") public static File render(File rptDocFile, int execId, String format) throws EngineException, IOException { File outFile = outputRenderMap.get(execId + format); if (outFile != null && outFile.exists()) { return outFile; } boolean owner = TransactionElf.beginOrJoinTransaction(); try { Session session = BirtActivator.getSessionFactory().getCurrentSession(); Criteria criteria = session.createCriteria(PluginExecRecord.class); criteria.add(Restrictions.sqlRestriction("execution_id = " + execId)); //$NON-NLS-1$ PluginExecRecord pluginExec = (PluginExecRecord) criteria.uniqueResult(); outFile = File.createTempFile("birt", "." + format); //$NON-NLS-1$ //$NON-NLS-2$ outFile.deleteOnExit(); IReportEngine reportEngine = BirtActivator.getReportPluginManager() .getReportEngine(pluginExec.getPluginName()); try { IReportDocument reportDoc = reportEngine.openReportDocument(rptDocFile.getAbsolutePath()); IRenderTask renderTask = reportEngine.createRenderTask(reportDoc); IRenderOption options = new RenderOption(); options.setOutputFileName(outFile.getAbsolutePath()); if ("pdf".equalsIgnoreCase(format)) //$NON-NLS-1$ { reportEngine.getConfig().getAppContext().put(EngineConstants.APPCONTEXT_CHART_RESOLUTION, Integer.valueOf(600)); options.setOutputFormat(IRenderOption.OUTPUT_FORMAT_PDF); PDFRenderOption pdfOptions = new PDFRenderOption(options); pdfOptions.setOption(IPDFRenderOption.FIT_TO_PAGE, new Boolean(true)); pdfOptions.setOption(IPDFRenderOption.PAGEBREAK_PAGINATION_ONLY, new Boolean(false)); renderTask.setRenderOption(pdfOptions); } else if ("html".equalsIgnoreCase(format)) //$NON-NLS-1$ { options.setOutputFormat(IRenderOption.OUTPUT_FORMAT_HTML); HTMLRenderOption htmlOptions = new HTMLRenderOption(options); htmlOptions.setSupportedImageFormats("PNG"); //$NON-NLS-1$ htmlOptions.setBaseImageURL(String.format("pluginDetail?executionId=%d&image=", execId)); //$NON-NLS-1$ htmlOptions.setImageHandler(new HTMLImageHandler(outFile.getName().replace("." + format, ""))); //$NON-NLS-1$ //$NON-NLS-2$ renderTask.setRenderOption(htmlOptions); } renderTask.render(); renderTask.close(); if (!outFile.exists() || outFile.length() == 0) { LOGGER.error("Zero length report output file."); //$NON-NLS-1$ } outputRenderMap.put(execId + format, outFile); } finally { reportEngine.destroy(); } } finally { if (owner) { TransactionElf.commit(); } } return outFile; }
From source file:to.etc.domui.hibernate.model.CriteriaCreatingVisitor.java
License:Open Source License
@Override public void visitUnaryNode(final QUnaryNode n) throws Exception { switch (n.getOperation()) { default://from w w w . java 2 s . c o m throw new IllegalStateException("Unsupported UNARY operation: " + n.getOperation()); case SQL: if (n.getNode() instanceof QLiteral) { QLiteral l = (QLiteral) n.getNode(); String s = (String) l.getValue(); m_last = Restrictions.sqlRestriction(s); return; } break; case NOT: n.getNode().visit(this); m_last = Restrictions.not(m_last); return; } throw new IllegalStateException("Unsupported UNARY operation: " + n.getOperation()); }
From source file:to.etc.domui.hibernate.model.CriteriaCreatingVisitor.java
License:Open Source License
@Override public void visitSqlRestriction(@NonNull QSqlRestriction v) throws Exception { if (v.getParameters().length == 0) { m_last = Restrictions.sqlRestriction(v.getSql()); return;// w ww. j a va2 s . c o m } //-- Parameterized SQL query -> convert to Hibernate types. Type[] htar = new Type[v.getParameters().length]; for (int i = 0; i < v.getTypes().length; i++) { Class<?> c = v.getTypes()[i]; if (c == null) throw new QQuerySyntaxException("Type array for SQLRestriction cannot contain null"); org.hibernate.TypeHelper th = m_session.getTypeHelper(); Type t = th.basic(c.getName()); if (null == t) { throw new QQuerySyntaxException( "Type[" + i + "] in type array (a " + c + ") is not a proper Hibernate type"); } htar[i] = t; } m_last = Restrictions.sqlRestriction(v.getSql(), v.getParameters(), htar); }
From source file:uk.org.openeyes.BiometryFunctions.java
/** * * * @return OphinbiometryImportedEvents//w w w . j av a2s. co m */ private OphinbiometryImportedEvents processImportedEvent() { OphinbiometryImportedEvents importedEvent = null; DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Criteria currentEvent = session.createCriteria(OphinbiometryImportedEvents.class); // For IOL Master 700 we can use the Device Serial Number and Acquisition Datetime fields to check if it's the same study if (eventStudy.getDeviceType().equals("IOLM700")) { currentEvent.add(Restrictions.eq("deviceSerialNumber", eventStudy.getDeviceSerial())); currentEvent.add(Restrictions.eq("acquisitionDatetime", eventStudy.getAcquisitionDateTime())); currentEvent.add(Restrictions.sqlRestriction( "event_id = (SELECT max(event_id) FROM ophinbiometry_imported_events WHERE device_serial_number='" + eventStudy.getDeviceSerial() + "' AND acquisition_datetime='" + eventStudy.getAcquisitionDateTime() + "')")); } else if (eventStudy.getDeviceType().equals("IOLM500")) { currentEvent.add(Restrictions.eq("studyId", eventStudy.getStudyInstanceID())); currentEvent.add(Restrictions.eq("seriesId", eventStudy.getSeriesInstanceID())); currentEvent.add(Restrictions.eq("surgeonName", eventStudy.getSurgeonName())); currentEvent.add(Restrictions.sqlRestriction( "event_id = (SELECT max(event_id) FROM ophinbiometry_imported_events WHERE study_id='" + eventStudy.getStudyInstanceID() + "' AND series_id='" + eventStudy.getSeriesInstanceID() + "' AND surgeon_name='" + eventStudy.getSurgeonName() + "')")); } // we should check if event is deleted, and we should create a new one if yes if (!currentEvent.list().isEmpty()) { importedEvent = (OphinbiometryImportedEvents) currentEvent.list().get(0); // if the event is in deleted state we cerate a new record if (importedEvent.getEventId().getDeleted() == 0) { dicomLogger.addToRawOutput("StudyID exists in database, merging with existing event..."); isNewEvent = false; // we decide if the imported file content time is newer then the stored content date if (importedEvent.getContentDateTime() != null) { Calendar lastContentDateTime = new GregorianCalendar(); Calendar studyContentDateTime = new GregorianCalendar(); try { lastContentDateTime .setTime(df.parse(getSQLFormattedDate(importedEvent.getContentDateTime()))); studyContentDateTime .setTime(df.parse(getSQLFormattedDate(eventStudy.getContentDateTime().getTime()))); } catch (ParseException ex) { Logger.getLogger(BiometryFunctions.class.getName()).log(Level.SEVERE, null, ex); } if (studyContentDateTime.after(lastContentDateTime)) { try { importedEvent.setContentDateTime( df.parse(getSQLFormattedDate(eventStudy.getContentDateTime().getTime()))); } catch (ParseException ex) { ex.printStackTrace(); } importedEvent.setIsMerged(true); dicomLogger.addToRawOutput( "Event content date and time is newer then the stored values, updating existing measuerements..."); } } } else { isNewEvent = true; } } if (isNewEvent) { Event newEvent = createNewEvent(); importedEvent = createNewImportedEvent(newEvent); } return importedEvent; }