List of usage examples for java.util Calendar WEEK_OF_YEAR
int WEEK_OF_YEAR
To view the source code for java.util Calendar WEEK_OF_YEAR.
Click Source Link
get
and set
indicating the week number within the current year. From source file:org.openmrs.module.clinicalsummary.rule.reminder.peds.polymerase.BaselinePolymeraseReminderRule.java
/** * @see org.openmrs.logic.Rule#eval(org.openmrs.logic.LogicContext, Integer, java.util.Map) *//*from ww w . ja v a 2s.c o m*/ @Override protected Result evaluate(final LogicContext context, final Integer patientId, final Map<String, Object> parameters) throws LogicException { Result result = new Result(); Patient patient = Context.getPatientService().getPatient(patientId); if (patient.getBirthdate() != null) { Calendar calendar = Calendar.getInstance(); // 18 months after birth date calendar.setTime(patient.getBirthdate()); calendar.add(Calendar.MONTH, 18); Date eighteenMonths = calendar.getTime(); // 6 weeks after birth date calendar.setTime(patient.getBirthdate()); calendar.add(Calendar.WEEK_OF_YEAR, 6); Date sixWeeks = calendar.getTime(); if (sixWeeks.before(new Date()) && eighteenMonths.after(new Date())) { ValidPolymeraseRule validPolymeraseRule = new ValidPolymeraseRule(); // only pull the positive and negative results parameters.put(EvaluableConstants.OBS_FETCH_SIZE, 1); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList(EvaluableNameConstants.POSITIVE, EvaluableNameConstants.NEGATIVE)); parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList(EvaluableNameConstants.HIV_DNA_POLYMERASE_CHAIN_REACTION_QUALITATIVE)); Result validPolymeraseResults = validPolymeraseRule.eval(context, patientId, parameters); if (CollectionUtils.isEmpty(validPolymeraseResults)) { // get the latest test ordered parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList(EvaluableNameConstants.TESTS_ORDERED)); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList(EvaluableNameConstants.HIV_DNA_POLYMERASE_CHAIN_REACTION_QUALITATIVE)); ObsWithRestrictionRule obsWithRestrictionRule = new ObsWithStringRestrictionRule(); Result testResults = obsWithRestrictionRule.eval(context, patientId, parameters); calendar.setTime(patient.getBirthdate()); calendar.add(Calendar.WEEK_OF_YEAR, 4); Date fourWeeks = calendar.getTime(); calendar.setTime(new Date()); calendar.add(Calendar.MONTH, -6); Date sixMonthsAgo = calendar.getTime(); // if no test or the test was ordered more than six months ago, then show the reminder if (CollectionUtils.isEmpty(testResults) || testResults.getResultDate().before(sixMonthsAgo) || testResults.getResultDate().before(fourWeeks)) result.add(new Result( String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); } } } return result; }
From source file:verdandi.model.CurrentWeekModel.java
public void addToCurrentWeek(int diff) { LOG.debug("Add to current week: " + diff); cal.add(Calendar.WEEK_OF_YEAR, diff); fireCurrentWeekChanged(); }
From source file:verdandi.model.WeekSelectorModel.java
private String getDateValue() { StringBuffer buf = new StringBuffer(); Calendar cal = (Calendar) parent.getCurrentWeek().clone(); buf.append(WEEK_OF_YEAR_PREFIX);//from w w w. j a v a 2s .c o m if (cal.get(Calendar.WEEK_OF_YEAR) < 10) { buf.append("0"); } buf.append(cal.get(Calendar.WEEK_OF_YEAR)); buf.append(": "); cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY); buf.append(dfmt.format(cal.getTime())); buf.append(" - "); cal.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY); buf.append(dfmt.format(cal.getTime())); return buf.toString(); }
From source file:com.hurence.logisland.utils.DateUtils.java
/** * Compute the week number of parameter date * * @param date//from w w w . ja v a 2s . com * @return Week number : ex 13 */ public static int getWeekNumberFromDate(Date date) { if (date != null) { Calendar calendar = Calendar.getInstance(); calendar.setFirstDayOfWeek(Calendar.MONDAY); calendar.setTime(date); return calendar.get(Calendar.WEEK_OF_YEAR); } else { return 0; } }
From source file:org.openmrs.module.clinicalsummary.rule.reminder.peds.polymerase.RepeatPolymeraseReminderRule.java
/** * @see org.openmrs.logic.Rule#eval(org.openmrs.logic.LogicContext, Integer, java.util.Map) *///from w w w . j a v a 2 s. c om @Override protected Result evaluate(final LogicContext context, final Integer patientId, final Map<String, Object> parameters) throws LogicException { Result result = new Result(); Patient patient = Context.getPatientService().getPatient(patientId); if (patient.getBirthdate() != null) { Calendar calendar = Calendar.getInstance(); // 18 months after birth date calendar.setTime(patient.getBirthdate()); calendar.add(Calendar.MONTH, 18); Date eighteenMonths = calendar.getTime(); // 6 weeks after birth date calendar.setTime(patient.getBirthdate()); calendar.add(Calendar.WEEK_OF_YEAR, 6); Date sixWeeks = calendar.getTime(); if (sixWeeks.before(new Date()) && eighteenMonths.after(new Date())) { ValidPolymeraseRule validPolymeraseRule = new ValidPolymeraseRule(); // only pull the positive and negative results parameters.put(EvaluableConstants.OBS_FETCH_SIZE, 2); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList(EvaluableNameConstants.POSITIVE, EvaluableNameConstants.NEGATIVE)); parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList(EvaluableNameConstants.HIV_DNA_POLYMERASE_CHAIN_REACTION_QUALITATIVE)); Result validPolymeraseResults = validPolymeraseRule.eval(context, patientId, parameters); if (CollectionUtils.isNotEmpty(validPolymeraseResults) && CollectionUtils.size(validPolymeraseResults) < 2) { Result validPolymeraseResult = validPolymeraseResults.latest(); // get the latest test ordered parameters.put(EvaluableConstants.OBS_CONCEPT, Arrays.asList(EvaluableNameConstants.TESTS_ORDERED)); parameters.put(EvaluableConstants.OBS_VALUE_CODED, Arrays.asList(EvaluableNameConstants.HIV_DNA_POLYMERASE_CHAIN_REACTION_QUALITATIVE)); ObsWithRestrictionRule obsWithRestrictionRule = new ObsWithStringRestrictionRule(); Result testResults = obsWithRestrictionRule.eval(context, patientId, parameters); calendar.setTime(patient.getBirthdate()); calendar.add(Calendar.WEEK_OF_YEAR, 4); Date fourWeeks = calendar.getTime(); calendar.setTime(new Date()); calendar.add(Calendar.MONTH, -6); Date sixMonthsAgo = calendar.getTime(); int pendingCount = 0; for (Result testResult : testResults) { // test is valid if it's performed after four weeks and after six months ago and not the same with the date of the result if (testResult.getResultDate().after(sixMonthsAgo) && testResult.getResultDate().after(fourWeeks) && !DateUtils.isSameDay(testResult.getResultDate(), validPolymeraseResult.getResultDate())) pendingCount++; } if (pendingCount + validPolymeraseResults.size() < 2) result.add(new Result( String.valueOf(parameters.get(ReminderParameters.DISPLAYED_REMINDER_TEXT)))); } } } return result; }
From source file:com.oneops.search.msg.processor.ReleaseMessageProcessor.java
private void indexSnapshot(CmsRelease release) { try {//from w ww. ja v a 2 s . co m if (!"closed".equalsIgnoreCase(release.getReleaseState())) { logger.info("Release is not closed. Won't do snapshot"); return; } if (release.getNsPath().endsWith("bom")) return; // ignore bom release Calendar cal = new GregorianCalendar(); cal.add(Calendar.WEEK_OF_YEAR, -2); long snapshotTimestamp = cal.getTime().getTime(); long hits = client.prepareSearch("cms-201*").setSearchType(SearchType.COUNT).setTypes(SNAPSHOT) .setQuery(boolQuery().must(QueryBuilders.rangeQuery("timestamp").from(snapshotTimestamp)) .must(QueryBuilders.termQuery("namespace.keyword", release.getNsPath()))) .execute().actionGet().getHits().getTotalHits(); logger.info("hits:" + hits); if (hits > 0) { logger.info("there was a snapshot done recently, so won'd do another one. "); return; } String url = (release.getNsPath().endsWith("manifest") ? manifestSnapshotURL : designSnapshotURL) + release.getNsPath(); // set snapshot URL based on release type logger.info("Retrieving snapshot for:" + url + " expected release:" + release.getReleaseId()); String message = Request.Get(url).addHeader("Content-Type", "application/json").execute() .returnContent().asString(); long releaseId = new JsonParser().parse(message).getAsJsonObject().get("release").getAsLong(); if (releaseId > release.getReleaseId()) { logger.warn("Snapshot is dirty, so discarding. Was expecting release:" + release.getReleaseId() + " snapshot has rfcs from release:" + releaseId); } else { indexer.index(String.valueOf(release.getReleaseId()), SNAPSHOT, message); logger.info("Snapshot indexed for release ID: " + release.getReleaseId()); } } catch (Exception e) { logger.error("Error while retrieving snapshot" + e.getMessage(), e); } }
From source file:com.baidu.rigel.biplatform.ac.util.TimeDimensionUtils.java
/** * ??//from w w w . j a va2 s . c om * * @param timeStr * @param timeType ?? * @param timeFormat ?? * @return timeMember ?member * @throws ParseException parse? */ public static MiniCubeMember createTimeMember(String timeStr, TimeType timeType, String timeFormat) throws ParseException { if (StringUtils.isBlank(timeStr) && timeType == null) { throw new IllegalArgumentException( "timeStr is blank or timeType is null, timeStr:" + timeStr + " timeType:" + timeType); } Calendar calendar = null; String dateFormat = StringUtils.isBlank(timeFormat) ? timeType.getFormat() : timeFormat; if (dateFormat.toUpperCase().contains("QN")) { int year = Integer.parseInt(timeStr.substring(0, 4)); int quarter = Integer.parseInt(timeStr.substring(5)); // Calendar?1 int month = (quarter - 1) * 3; calendar = new GregorianCalendar(year, month, 1); } else { SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); Date date = sdf.parse(timeStr); calendar = Calendar.getInstance(); calendar.setTime(date); } int quarter = calendar.get(Calendar.MONTH) / 3 + 1; String caption = null; MiniCubeLevel level = new MiniCubeLevel("level_" + timeType); if (timeType.equals(TimeType.TimeYear)) { caption = calendar.get(Calendar.YEAR) + ""; level.setType(LevelType.TIME_YEARS); } else if (timeType.equals(TimeType.TimeQuarter)) { caption = calendar.get(Calendar.YEAR) + "_Q" + quarter; level.setType(LevelType.TIME_QUARTERS); } else if (timeType.equals(TimeType.TimeMonth)) { caption = calendar.get(Calendar.YEAR) + "_" + (calendar.get(Calendar.MONTH) + 1); level.setType(LevelType.TIME_MONTHS); } else if (timeType.equals(TimeType.TimeWeekly)) { caption = calendar.get(Calendar.YEAR) + "_W" + calendar.get(Calendar.WEEK_OF_YEAR); level.setType(LevelType.TIME_WEEKS); } else if (timeType.equals(TimeType.TimeDay)) { caption = DEFAULT_SIMPLE_DATEFORMAT.format(calendar.getTime()); level.setType(LevelType.TIME_DAYS); } MiniCubeMember member = new MiniCubeMember(timeStr); member.setCaption(caption); member.setVisible(true); member.setLevel(level); LOG.info("time member:" + member); return member; }
From source file:org.oscarehr.common.service.AcceptableUseAgreementManager.java
public static Date getAgreementCutoffDate() { Calendar cal = GregorianCalendar.getInstance(); Property latestProperty = findLatestProperty(); if (latestProperty == null) { //Default to one year cal.add(Calendar.YEAR, -1); return cal.getTime(); }//from w ww .j a va2s . c om if ("aua_valid_from".equals(latestProperty.getName())) { //2012-09-20 01.08.30 SimpleDateFormat dateTimeFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); try { Date validFromTime = dateTimeFormatter.parse(latestProperty.getValue()); cal.setTimeInMillis(validFromTime.getTime()); } catch (Exception e) { logger.error("Error: parsing aua_valid_from date " + latestProperty.getName(), e); } } else { String val = latestProperty.getValue(); String[] splitVal = val.split(" "); int duration = Integer.parseInt(splitVal[0]); duration = duration * -1; int period = Calendar.YEAR; if ("month".equals(splitVal[1])) { period = Calendar.MONTH; } else if ("weeks".equals(splitVal[1])) { period = Calendar.WEEK_OF_YEAR; } else if ("days".equals(splitVal[1])) { period = Calendar.DAY_OF_YEAR; } cal.add(period, duration); } return cal.getTime(); }
From source file:com.aurel.track.fieldType.runtime.matchers.run.DateMatcherRT.java
/** * Reinitialize dayBegin and dayEnd// w w w .j a v a2 s . com */ @Override public void setMatchValue(Object matcherValue) { super.setMatchValue(matcherValue); if (relation == MatchRelations.LATER_AS_LASTLOGIN && matcherContext != null) { matcherValue = matcherContext.getLastLoggedDate(); } Calendar calendaMatcherValue = new GregorianCalendar(matcherContext.getLocale()); calendaMatcherValue.setTime(new Date()); calendaMatcherValue = CalendarUtil.clearTime(calendaMatcherValue); int firstDayOfWeek = calendaMatcherValue.getFirstDayOfWeek(); switch (relation) { case MatchRelations.THIS_WEEK: calendaMatcherValue.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); dayBegin = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.WEEK_OF_YEAR, 1); calendaMatcherValue.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); dayEnd = calendaMatcherValue.getTime(); return; case MatchRelations.LAST_WEEK: calendaMatcherValue.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); dayEnd = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.WEEK_OF_YEAR, -1); calendaMatcherValue.set(Calendar.DAY_OF_WEEK, firstDayOfWeek); dayBegin = calendaMatcherValue.getTime(); return; case MatchRelations.THIS_MONTH: calendaMatcherValue.set(Calendar.DAY_OF_MONTH, 1); dayBegin = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.MONTH, 1); calendaMatcherValue.set(Calendar.DAY_OF_MONTH, 1); dayEnd = calendaMatcherValue.getTime(); return; case MatchRelations.LAST_MONTH: calendaMatcherValue.set(Calendar.DAY_OF_MONTH, 1); dayEnd = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.MONTH, -1); calendaMatcherValue.set(Calendar.DAY_OF_MONTH, 1); dayBegin = calendaMatcherValue.getTime(); return; } if (matcherValue == null) { return; } //reinitialize dayBegin and dayEnd Date matcherValueDate = null; Integer matcherValueInteger = null; switch (relation) { case MatchRelations.MORE_THAN_DAYS_AGO: case MatchRelations.MORE_THAN_EQUAL_DAYS_AGO: case MatchRelations.LESS_THAN_DAYS_AGO: case MatchRelations.LESS_THAN_EQUAL_DAYS_AGO: try { matcherValueInteger = (Integer) matchValue; } catch (Exception e) { LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName() + " to Integer failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } calendaMatcherValue.setTime(new Date()); if (matcherValueInteger != null) { int matcherValueInt = matcherValueInteger.intValue(); if (relation == MatchRelations.MORE_THAN_EQUAL_DAYS_AGO) { matcherValueInt--; } if (relation == MatchRelations.LESS_THAN_EQUAL_DAYS_AGO) { matcherValueInt++; } calendaMatcherValue.add(Calendar.DATE, -matcherValueInt); } break; case MatchRelations.IN_MORE_THAN_DAYS: case MatchRelations.IN_MORE_THAN_EQUAL_DAYS: case MatchRelations.IN_LESS_THAN_DAYS: case MatchRelations.IN_LESS_THAN_EQUAL_DAYS: try { matcherValueInteger = (Integer) matchValue; } catch (Exception e) { LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName() + " to Integer failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } calendaMatcherValue.setTime(new Date()); if (matcherValueInteger != null) { int matcherValueInt = matcherValueInteger.intValue(); if (relation == MatchRelations.IN_MORE_THAN_EQUAL_DAYS) { matcherValueInt--; } if (relation == MatchRelations.IN_LESS_THAN_EQUAL_DAYS) { matcherValueInt++; } calendaMatcherValue.add(Calendar.DATE, matcherValueInt); } break; case MatchRelations.EQUAL_DATE: case MatchRelations.NOT_EQUAL_DATE: case MatchRelations.GREATHER_THAN_DATE: case MatchRelations.GREATHER_THAN_EQUAL_DATE: case MatchRelations.LESS_THAN_DATE: case MatchRelations.LESS_THAN_EQUAL_DATE: try { matcherValueDate = (Date) matchValue; } catch (Exception e) { LOGGER.warn("Converting the matcher value " + matchValue + " of type " + matchValue.getClass().getName() + " to Date failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } if (matcherValueDate != null) { calendaMatcherValue.setTime(matcherValueDate); if (relation == MatchRelations.GREATHER_THAN_EQUAL_DATE) { calendaMatcherValue.add(Calendar.DATE, -1); } else { if (relation == MatchRelations.LESS_THAN_EQUAL_DATE) { calendaMatcherValue.add(Calendar.DATE, 1); } } } break; case MatchRelations.LATER_AS_LASTLOGIN: if (matcherContext != null) { dayBegin = matcherContext.getLastLoggedDate(); dayEnd = matcherContext.getLastLoggedDate(); } //return because later the dayBegin and dayEnd will be assigned again return; } calendaMatcherValue = CalendarUtil.clearTime(calendaMatcherValue); dayBegin = calendaMatcherValue.getTime(); calendaMatcherValue.add(Calendar.DATE, 1); dayEnd = calendaMatcherValue.getTime(); }
From source file:org.openmrs.module.dhisreport.scheduler.PostToDhisTask.java
public void execute() { log.debug("executing hello world task"); // get all reports DHIS2ReportingService service = Context.getService(DHIS2ReportingService.class); Collection<ReportDefinition> reportdefs = service.getAllReportDefinitions(); // iterate over each report String urlParameters = null;// www. jav a 2s.co m // get location for the report/hospital List<Location> locations = Context.getLocationService().getAllLocations(); String orgUnit = null; Integer reportId = null; String dateStr = null; String freq = null; String resultDestination = "post"; for (Location location : locations) { // System.out.println( "location information UUID-" + // location.getUuid() + ":display string-" // + location.getDisplayString() + ":" ); if (location.getDisplayString().contains("[")) { String temp = location.getDisplayString(); orgUnit = location.getDisplayString().substring((temp.indexOf("[") + 1), (temp.indexOf("]"))); // System.out.println( "Current Location ID-" + orgUnit ); } } Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); // Note: zero based! int week = cal.get(Calendar.WEEK_OF_YEAR); for (ReportDefinition reports : reportdefs) // while ( !reportdefs.isEmpty() ) { // Iterator<ReportDefinition> reportiterator = reportdefs.iterator(); // ReportDefinition reports = reportiterator.next(); reportId = reports.getId(); // System.out.println( "reportId is-" + reportId ); freq = reports.getPeriodType(); try { if (freq.equalsIgnoreCase("Monthly")) { if (month == 0) month = 12; dateStr = year + "-" + Integer.toString((month)); } if (freq.equalsIgnoreCase("Weekly")) { if (week > 10) dateStr = year + "-" + "W" + Integer.toString((week - 1)); else dateStr = year + "-" + "W0" + Integer.toString((week - 1)); } // System.out.println( "Date String-" + dateStr ); urlParameters = "location=" + orgUnit + "&frequency=" + freq + "&date=" + dateStr + "&resultDestination=" + resultDestination + "&reportDefinition_id=" + reportId.toString(); // location=DDU01&frequency=monthly&date=2013-Mar&resultDestination=post&reportDefinition_id=58 int reponsecode = sendPost(urlParameters); // if ( reponsecode == 400 ) // { // reportdefs.remove( reports ); // } Thread.sleep(5000); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); // System.out.println( "Enterted Catch for report =" + reportId ); continue; } } //outer // get parameter for each report // send post request for each report super.startExecuting(); }