private List<Sprint> getSprints() throws ParseException { List<Sprint> sprints = new ArrayList<>(); Sprint sprint = new Sprint(); sprint.setDonePoints(40l); sprint.setId(1l); sprint.setFinalDate(DateUtils.parseDate("30/07/2012", "dd/MM/yyyy")); sprints.add(sprint); sprint = new Sprint(); sprint.setDonePoints(5l); sprint.setId(2l); sprint.setFinalDate(DateUtils.parseDate("30/08/2012", "dd/MM/yyyy")); sprints.add(sprint); sprint = new Sprint(); sprint.setDonePoints(52l); sprint.setId(3l); sprint.setFinalDate(DateUtils.parseDate("30/09/2012", "dd/MM/yyyy")); sprints.add(sprint); sprint = new Sprint(); sprint.setDonePoints(39l); sprint.setId(4l); sprint.setFinalDate(DateUtils.parseDate("30/10/2012", "dd/MM/yyyy")); sprints.add(sprint); sprint = new Sprint(); sprint.setDonePoints(47l); sprint.setId(5l); sprint.setFinalDate(DateUtils.parseDate("30/11/2012", "dd/MM/yyyy")); sprints.add(sprint); return sprints; }
@Override public final int compare(String[] o1, String[] o2) { String t1 = o1[this.index]; String t2 = o2[this.index]; if (StringUtils.isEmpty(t1) && StringUtils.isEmpty(t2)) { return 0; } if (StringUtils.isEmpty(t1)) { return 1; } if (StringUtils.isEmpty(t2)) { return -1; } if (StringUtils.isNumeric(t1) && StringUtils.isNumeric(t2)) { // 数値文字列の場合 Long o1l = Long.valueOf(t1); Long o2l = Long.valueOf(t2); return this.compareTo(o1l, o2l, this.order); } else if (t1.matches("(?:\\d+日)?(?:\\d+時間)?(?:\\d+分)?(?:\\d+秒)?")) { try { // 時刻文字列の場合 // SimpleDateFormatは24時間超えるような時刻でも正しく?パースしてくれる Date o1date = DateUtils.parseDate(t1, "ss秒", "mm分ss秒", "HH時間mm分", "dd日HH時間mm分"); Date o2date = DateUtils.parseDate(t2, "ss秒", "mm分ss秒", "HH時間mm分", "dd日HH時間mm分"); return this.compareTo(o1date, o2date, this.order); } catch (ParseException e) { e.printStackTrace(); } } // 文字列の場合 return this.compareTo(t1, t2, this.order); }
public static Integer getAcceptMonth(String dateStr, String parsePatterns) throws ParseException { if (parsePatterns == null) parsePatterns = "yyyyMMddHHmmss"; Date date = DateUtils.parseDate(dateStr, parsePatterns); Calendar calendar = Calendar.getInstance(); calendar.setTime(date); return new Integer(calendar.get(Calendar.MONTH) + 1); }
/** * 将字符串形式的时间表示解析为日期时间对象 * * @param timeString * @return */ public static Date parseTime(String timeString) { try { return org.apache.commons.lang3.time.DateUtils.parseDate( timeString, new String[] {"hh:mm:ss", "h:m:s", "hh:mm", "h:m"}); } catch (ParseException e) { return null; } }
/** * 将字符串形式的日期表示解析为日期对象 * * @param dateString * @return */ public static Date parseDate(String dateString) { try { return org.apache.commons.lang3.time.DateUtils.parseDate( dateString, new String[] {"yyyy-MM-dd", "yyyy-M-d", "yyyy-MM-d", "yyyy-M-dd"}); } catch (ParseException e) { return null; } }
private TimelineItem createTimelineItem(String str) throws ParseException { final Date date = DateUtils.parseDate(str, "yyyy-MM-dd"); return new TimelineItem() { @Override public Date getDate() { return date; } }; }
public Date getDateFromTiffDateStr(String dateStr) { Date parsedDate = null; try { parsedDate = DateUtils.parseDate(dateStr, new String[] {"yyyy:MM:dd HH:mm:ss"}); } catch (ParseException e) { e.printStackTrace(); } return parsedDate; }
public static void main(String[] args) throws IOException, ParseException { ObjectMapper objectMapper = new ObjectMapper(); CrawlerIndex crawlerIndex = new CrawlerIndex(); List<Weibo> weibos = Lists.newArrayList(); // 关键词搜索微博 int total = crawlerIndex.search( "", 0, 5, weibos, "repostcount", SortOrder.DESC, DateUtils.parseDate("20150528 000000", "yyyyMMdd HHmmss"), DateUtils.parseDate("20150529 000000", "yyyyMMdd HHmmss"), true, 0); System.out.println(total); System.out.println(objectMapper.writeValueAsString(weibos.get(0))); // 搜索一段时间的微博 weibos = Lists.newArrayList(); total = crawlerIndex.search( null, 0, 5, weibos, "repostcount", SortOrder.DESC, DateUtils.parseDate("20150528 000000", "yyyyMMdd HHmmss"), DateUtils.parseDate("20150529 000000", "yyyyMMdd HHmmss"), true, 0); System.out.println(total); System.out.println(objectMapper.writeValueAsString(weibos.get(0))); // 按用户ID搜索微博 weibos = Lists.newArrayList(); total = crawlerIndex.searchByUid( "2028810631", 0, 5, weibos, "repostcount", SortOrder.DESC, DateUtils.parseDate("20150528 000000", "yyyyMMdd HHmmss"), DateUtils.parseDate("20150529 000000", "yyyyMMdd HHmmss")); System.out.println("按用户名搜索微博 " + total); System.out.println(objectMapper.writeValueAsString(weibos.get(0))); // 通过id找微博 Long id = 3847603911216922L; Weibo w = crawlerIndex.getWeibo(id.toString()); System.out.println("!!!" + objectMapper.writeValueAsString(w)); // 找转发 crawlerIndex.findAllReposts(w); // w.setReposts(Lists.<Weibo> newArrayList()); System.out.println(objectMapper.writeValueAsString(w)); }
@Test public void shouldReturnTotalOfPointsInBacklogInSprint() throws Exception { // 2 - total de pontos no backlog no sprint // TODO em portugues o comentario ?? when(sprintService.getAllSprints()).thenReturn(getSprints()); when(storyService.getStories(StoryStatus.BACKLOG)).thenReturn(getStories()); List<Temp> temps = statisticallyService.get(); verify(sprintService).getAllSprints(); verify(storyService).getStories(StoryStatus.BACKLOG); System.out.println( DateUtils.parseDate("05/07/2012", "dd/MM/yyyy") .compareTo(DateUtils.parseDate("04/07/2012", "dd/MM/yyyy"))); assertEquals(new Integer(50), temps.get(0).getPointsInBacklog()); assertEquals(new Integer(100), temps.get(1).getPointsInBacklog()); assertEquals(new Integer(120), temps.get(2).getPointsInBacklog()); assertEquals(new Integer(140), temps.get(3).getPointsInBacklog()); assertEquals(new Integer(250), temps.get(4).getPointsInBacklog()); }
@Test public void shouldAddDiagnosesAdObservation() throws Exception { executeDataSet("baseMetaData.xml"); executeDataSet("diagnosisMetaData.xml"); executeDataSet("shouldAddDiagnosisAsObservation.xml"); String cancerDiagnosisUuid = "d102c80f-1yz9-4da3-bb88-8122ce8868dh"; String encounterDateTime = "2005-01-02T00:00:00.000+0000"; String diagnosisDateTime = "2005-01-02T01:00:00.000+0000"; String postData = "{" + "\"patientUuid\" : \"a76e8d23-0c38-408c-b2a8-ea5540f01b51\", " + "\"visitTypeUuid\" : \"b45ca846-c79a-11e2-b0c0-8e397087571c\", " + "\"encounterTypeUuid\": \"2b377dba-62c3-4e53-91ef-b51c68899891\", " + "\"encounterDateTime\" : \"" + encounterDateTime + "\", " + "\"diagnoses\":[" + "{\"order\":\"PRIMARY\", \"certainty\": \"CONFIRMED\", \"codedAnswer\": { \"uuid\": \"" + cancerDiagnosisUuid + "\"}, \"diagnosisDateTime\": \"" + diagnosisDateTime + "\" }" + "]" + "}"; EncounterTransaction response = deserialize( handle(newPostRequest("/rest/emrapi/encounter", postData)), EncounterTransaction.class); Visit visit = visitService.getVisitByUuid(response.getVisitUuid()); Encounter encounter = visit.getEncounters().iterator().next(); Set<Obs> obsAtTopLevel = encounter.getObsAtTopLevel(false); assertEquals(1, obsAtTopLevel.size()); Obs parentObservation = obsAtTopLevel.iterator().next(); assertTrue(parentObservation.isObsGrouping()); assertEquals( DateUtils.parseDate(diagnosisDateTime, dateTimeFormat), parentObservation.getObsDatetime()); Set<Obs> diagnosisObservationGroupMembers = parentObservation.getGroupMembers(); assertEquals(3, diagnosisObservationGroupMembers.size()); ArrayList<String> valueCodedNames = getValuCodedNames(diagnosisObservationGroupMembers); assertTrue(valueCodedNames.contains("Confirmed")); assertTrue(valueCodedNames.contains("Primary")); assertTrue(valueCodedNames.contains("Cancer")); }
/** * Convert String to Date * * @param value * @return * @throws ParseException */ private Date doConvertToDate(Object value) throws ParseException { Date result = null; if (value instanceof String) { result = DateUtils.parseDate( (String) value, new String[] { DATE_PATTERN, DATETIME_PATTERN, DATETIME_PATTERN_NO_SECOND, MONTH_PATTERN }); // all patterns failed, try a milliseconds constructor if (result == null && StringUtils.isNotEmpty((String) value)) { try { result = new Date(new Long((String) value).longValue()); } catch (Exception e) { logger.error("Converting from milliseconds to Date fails!"); e.printStackTrace(); } } } else if (value instanceof Object[]) { // let's try to convert the first element only Object[] array = (Object[]) value; if (array.length >= 1) { value = array[0]; result = doConvertToDate(value); } } else if (Date.class.isAssignableFrom(value.getClass())) { result = (Date) value; } return result; }
public static Date parseDate(final String source) throws ParseException { return DateUtils.parseDate(source, SyncopeConstants.DATE_PATTERNS); }
private IssueEvent createIssueEvent(String str) throws ParseException { IssueEvent event = new IssueEvent(); event.created = DateUtils.parseDate(str, "yyyy-MM-dd"); return event; }
private IssueComment createIssueComment(String str) throws ParseException { IssueComment comment = new IssueComment(); comment.createdDate = DateUtils.parseDate(str, "yyyy-MM-dd"); return comment; }
@Test public void shouldGetEncounterTransactionByDate() throws Exception { executeDataSet("baseMetaData.xml"); executeDataSet("dispositionMetaData.xml"); executeDataSet("diagnosisMetaData.xml"); executeDataSet("shouldGetEncounterTransactionByDate.xml"); String dispositionDateTime = "2005-01-01T01:00:00.000+0000"; String encounter1PostData = "{" + "\"patientUuid\" : \"a76e8d23-0c38-408c-b2a8-ea5540f01b51\", " + "\"visitTypeUuid\" : \"b45ca846-c79a-11e2-b0c0-8e397087571c\", " + "\"encounterTypeUuid\": \"4f3c2244-9d6a-439e-b88a-6e8873489ea7\", " + "\"encounterDateTime\" : \"2004-01-01T10:00:00.000+0000\" " + "}"; EncounterTransaction encounter1Response = deserialize( handle(newPostRequest("/rest/emrapi/encounter", encounter1PostData)), EncounterTransaction.class); String cancerDiagnosisUuid = "d102c80f-1yz9-4da3-bb88-8122ce8868dh"; String malariaDiagnosisUuid = "604dcce9-bcd9-48a8-b2f5-112743cf1db8"; String visitUuid = encounter1Response.getVisitUuid(); String encounter2PostData = "{" + "\"patientUuid\" : \"a76e8d23-0c38-408c-b2a8-ea5540f01b51\", " + "\"visitTypeUuid\" : \"b45ca846-c79a-11e2-b0c0-8e397087571c\", " + "\"visitUuid\": \"" + visitUuid + "\", " + "\"encounterTypeUuid\": \"2b377dba-62c3-4e53-91ef-b51c68899891\", " + "\"encounterDateTime\" : \"2005-01-01T10:00:00.000+0000\", " + "\"observations\":[" + "{\"" + "concept\":{\"uuid\": \"4f3c2244-9d6a-439e-b88a-6e8873489ea7\"}, " + "\"groupMembers\" : [{\"concept\":{\"uuid\": \"82e5f23e-e0b3-4e53-b6bb-c09c1c7fb8b0\"}, \"value\":20, \"comment\":\"overweight\" }] " + "}" + "]," + "\"diagnoses\":[" + "{\"order\":\"PRIMARY\", \"certainty\": \"CONFIRMED\", \"codedAnswer\": { \"uuid\": \"" + cancerDiagnosisUuid + "\"} }," + "{\"order\":\"PRIMARY\", \"certainty\": \"CONFIRMED\", \"codedAnswer\": { \"uuid\": \"" + malariaDiagnosisUuid + "\"} }" + "], " + "\"disposition\": {" + " \"code\": \"ADMIT\"," + " \"dispositionDateTime\": \"" + dispositionDateTime + "\"," + " \"additionalObs\": [" + " {" + " \"value\": \"Admit him to ICU.\"," + " \"concept\": {" + " \"uuid\": \"9169366f-3c7f-11e3-8f4c-005056823ee5\"," + " \"name\": \"Disposition Note\"" + " }" + " }" + " ]" + "}" + "}"; EncounterTransaction encounter2Response = deserialize( handle(newPostRequest("/rest/emrapi/encounter", encounter2PostData)), EncounterTransaction.class); assertEquals(encounter1Response.getVisitUuid(), encounter2Response.getVisitUuid()); assertNotEquals(encounter1Response.getEncounterUuid(), encounter2Response.getEncounterUuid()); List<EncounterTransaction> encounterTransactions = deserialize( handle( newGetRequest( "/rest/emrapi/encounter", new Parameter[] { new Parameter("visitUuid", visitUuid), new Parameter("encounterDate", "2005-01-01"), new Parameter("includeAll", "false") })), new TypeReference<List<EncounterTransaction>>() {}); assertEquals(1, encounterTransactions.size()); EncounterTransaction fetchedEncounterTransaction = encounterTransactions.get(0); assertEquals(visitUuid, fetchedEncounterTransaction.getVisitUuid()); assertEquals( "a76e8d23-0c38-408c-b2a8-ea5540f01b51", fetchedEncounterTransaction.getPatientUuid()); assertEquals( "b45ca846-c79a-11e2-b0c0-8e397087571c", fetchedEncounterTransaction.getVisitTypeUuid()); assertEquals( "2b377dba-62c3-4e53-91ef-b51c68899891", fetchedEncounterTransaction.getEncounterTypeUuid()); assertEquals( "2005-01-01", new SimpleDateFormat("yyyy-MM-dd") .format(fetchedEncounterTransaction.getEncounterDateTime())); // Assert Observations assertEquals(1, fetchedEncounterTransaction.getObservations().size()); assertEquals( "4f3c2244-9d6a-439e-b88a-6e8873489ea7", fetchedEncounterTransaction.getObservations().get(0).getConcept().getUuid()); assertEquals(1, fetchedEncounterTransaction.getObservations().get(0).getGroupMembers().size()); assertEquals( "82e5f23e-e0b3-4e53-b6bb-c09c1c7fb8b0", fetchedEncounterTransaction .getObservations() .get(0) .getGroupMembers() .get(0) .getConcept() .getUuid()); assertEquals( 20.0, fetchedEncounterTransaction.getObservations().get(0).getGroupMembers().get(0).getValue()); // Assert Diagnosis data assertEquals(2, fetchedEncounterTransaction.getDiagnoses().size()); EncounterTransaction.Diagnosis cancerDiagnosis = getDiagnosisByUuid(fetchedEncounterTransaction.getDiagnoses(), cancerDiagnosisUuid); assertNotNull(cancerDiagnosis); assertEquals("PRIMARY", cancerDiagnosis.getOrder()); assertEquals("CONFIRMED", cancerDiagnosis.getCertainty()); assertEquals(cancerDiagnosisUuid, cancerDiagnosis.getCodedAnswer().getUuid()); assertNotNull( getDiagnosisByUuid(fetchedEncounterTransaction.getDiagnoses(), malariaDiagnosisUuid)); // Assert Disposition data EncounterTransaction.Disposition fetchedDisposition = fetchedEncounterTransaction.getDisposition(); assertEquals("ADMIT", fetchedDisposition.getCode()); assertEquals( DateUtils.parseDate(dispositionDateTime, dateTimeFormat), fetchedDisposition.getDispositionDateTime()); assertNotNull(fetchedDisposition.getExistingObs()); assertEquals(1, fetchedDisposition.getAdditionalObs().size()); assertEquals("Admit him to ICU.", fetchedDisposition.getAdditionalObs().get(0).getValue()); assertEquals( "Disposition Note", fetchedDisposition.getAdditionalObs().get(0).getConcept().getName()); }
private List<Story> getStories() throws ParseException { List<Story> stories = new ArrayList<>(); // */07/2012 >> 50 points in backlog stories.add(new Story(null, null, null, DateUtils.parseDate("05/07/2012", "dd/MM/yyyy"), 10)); stories.add(new Story(null, null, null, DateUtils.parseDate("10/07/2012", "dd/MM/yyyy"), 10)); stories.add(new Story(null, null, null, DateUtils.parseDate("15/07/2012", "dd/MM/yyyy"), 10)); stories.add(new Story(null, null, null, DateUtils.parseDate("25/07/2012", "dd/MM/yyyy"), 10)); stories.add(new Story(null, null, null, DateUtils.parseDate("30/07/2012", "dd/MM/yyyy"), 10)); // */08/2012 >> + 50 points in backlog >> TOTAL = 100 points stories.add(new Story(null, null, null, DateUtils.parseDate("05/08/2012", "dd/MM/yyyy"), 20)); stories.add(new Story(null, null, null, DateUtils.parseDate("10/08/2012", "dd/MM/yyyy"), 20)); stories.add(new Story(null, null, null, DateUtils.parseDate("30/08/2012", "dd/MM/yyyy"), 10)); // */09/2012 >> + 20 points in backlog >> TOTAL = 120 points stories.add(new Story(null, null, null, DateUtils.parseDate("05/09/2012", "dd/MM/yyyy"), 5)); stories.add(new Story(null, null, null, DateUtils.parseDate("10/09/2012", "dd/MM/yyyy"), 5)); stories.add(new Story(null, null, null, DateUtils.parseDate("30/09/2012", "dd/MM/yyyy"), 10)); // */10/2012 >> + 20 points in backlog >> TOTAL = 140 points stories.add(new Story(null, null, null, DateUtils.parseDate("05/10/2012", "dd/MM/yyyy"), 5)); stories.add(new Story(null, null, null, DateUtils.parseDate("10/10/2012", "dd/MM/yyyy"), 5)); stories.add(new Story(null, null, null, DateUtils.parseDate("30/10/2012", "dd/MM/yyyy"), 10)); // */11/2012 >> + 110 points in backlog >> TOTAL = 250 points stories.add(new Story(null, null, null, DateUtils.parseDate("05/11/2012", "dd/MM/yyyy"), 20)); stories.add(new Story(null, null, null, DateUtils.parseDate("10/11/2012", "dd/MM/yyyy"), 20)); stories.add(new Story(null, null, null, DateUtils.parseDate("15/11/2012", "dd/MM/yyyy"), 20)); stories.add(new Story(null, null, null, DateUtils.parseDate("15/11/2012", "dd/MM/yyyy"), 20)); stories.add(new Story(null, null, null, DateUtils.parseDate("15/11/2012", "dd/MM/yyyy"), 20)); stories.add(new Story(null, null, null, DateUtils.parseDate("30/11/2012", "dd/MM/yyyy"), 10)); return stories; }