From 93fa95f8ce2112066d9b83a13615a21cf158dd96 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Thu, 23 Feb 2017 18:47:28 +0100 Subject: [PATCH] single appointment might have multiple types of examination --- .../appointment/parse/AppointmentEntry.java | 29 +++++++---- .../appointment/parse/AppointmentType.java | 39 ++++----------- .../smash/appointment/parse/CellParser.java | 15 +++--- .../smash/appointment/parse/RedcapParser.java | 12 ++--- .../smash/appointment/parse/AllTests.java | 2 + .../appointment/parse/CellParseTestCase.java | 12 ++--- .../appointment/parse/CellParserTest.java | 50 ++++++++++++++----- .../appointment/parse/RedcapParserTest.java | 13 +++-- 8 files changed, 93 insertions(+), 79 deletions(-) diff --git a/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java b/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java index 2268c902..b6e87286 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java +++ b/appointment-import/src/main/java/smash/appointment/parse/AppointmentEntry.java @@ -4,12 +4,12 @@ import java.util.ArrayList; import java.util.List; public class AppointmentEntry { - private String day; - private String time; - private String duration; - private Subject subject; - private AppointmentType type; - private String source; + private String day; + private String time; + private String duration; + private Subject subject; + private List<AppointmentType> types = new ArrayList<>(); + private String source; /** * @return the time @@ -49,8 +49,8 @@ public class AppointmentEntry { * @return the type * @see #type */ - public AppointmentType getType() { - return type; + public List<AppointmentType> getTypes() { + return types; } /** @@ -58,8 +58,8 @@ public class AppointmentEntry { * the type to set * @see #type */ - public void setType(AppointmentType type) { - this.type = type; + public void addType(AppointmentType type) { + this.types.add(type); } /** @@ -98,7 +98,7 @@ public class AppointmentEntry { @Override public String toString() { - return day + " " + time + " " + subject + " " + type + "\t\t[source: " + source + "]"; + return day + " " + time + " " + subject + " " + types + "\t\t[source: " + source + "]"; } /** @@ -117,4 +117,11 @@ public class AppointmentEntry { public void setDuration(String duration) { this.duration = duration; } + + public void addTypes(AppointmentType[] typesToAdd) { + for (AppointmentType appointmentType : typesToAdd) { + addType(appointmentType); + } + + } } diff --git a/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java b/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java index 9660b8e6..5f232b0a 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java +++ b/appointment-import/src/main/java/smash/appointment/parse/AppointmentType.java @@ -1,36 +1,15 @@ package smash.appointment.parse; public enum AppointmentType { - - //most complex should be first - LEVEL_BV_BG_SB_MPOWER(new String[] {"evel BV + BG + SB + mPower", "BV + BG + SB + mPower"}), // - LEVEL_BV_BG_SB(new String[] { "evel BV + BG + SB","BV + BG + SB" }), // - LEVEL_BV_SB(new String[] { "evel BV + SB","BV + SB" }), // - LEVEL_BV_BG(new String[] { "evel BV + BG","BV + BG" }), // - LEVEL_BG_SB(new String[] { "evel BG + SB","BG + SB" }), // - LEVEL_BV(new String[] { "evel BV", "BV" }), // - LEVEL_BG(new String[] { "evel BG","BG" }), // - LEVEL_SB(new String[] { "evel SB", "SB" }), // - - LEVEL_A_TQ(new String[] { "TQ" }), // - LEVEL_A(new String[] { "level A" }), // - LEVEL_B(new String[] { "evel B" }), // - LEVEL_B_M_POWER(new String[] { "mPower" }), // - OTHER(new String[] {}), // + LEVEL_BV(), // + LEVEL_BG(), // + LEVEL_SB(), // + + LEVEL_A_TQ(), // + LEVEL_A(), // + LEVEL_B(), // + LEVEL_B_M_POWER(), // + OTHER(), // ; - private String[] queryStrings; - - private AppointmentType(String[] queryStrings) { - this.queryStrings = queryStrings; - - } - - /** - * @return the queryStrings - * @see #queryStrings - */ - public String[] getQueryStrings() { - return queryStrings; - } } diff --git a/appointment-import/src/main/java/smash/appointment/parse/CellParser.java b/appointment-import/src/main/java/smash/appointment/parse/CellParser.java index 3093c7d7..01be5b86 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/CellParser.java +++ b/appointment-import/src/main/java/smash/appointment/parse/CellParser.java @@ -43,23 +43,24 @@ public class CellParser { Subject subject = extractSubject(query); result.setSubject(subject); - AppointmentType type = extractType(query); + AppointmentTypeCollection type = extractType(query); if (type == null) { - type = AppointmentType.OTHER; + result.addType(AppointmentType.OTHER); + } else { + result.addTypes(type.getTypes()); } - result.setType(type); result.setSource(query); return result; } - private AppointmentType extractType(String query) { + private AppointmentTypeCollection extractType(String query) { String simplifiedQuery = Utils.simplifyString(query); - AppointmentType result = null; + AppointmentTypeCollection result = null; String usedString = null; - for (AppointmentType type : AppointmentType.values()) { + for (AppointmentTypeCollection type : AppointmentTypeCollection.values()) { boolean matchFound = false; for (String string : type.getQueryStrings()) { if (!matchFound) { @@ -77,7 +78,7 @@ public class CellParser { } else if (usedString.contains(string)) { // new one is a substring of old } else { // if there is no substring then we might have a problem - AppointmentType newType = result; + AppointmentTypeCollection newType = result; if (usedString.length() < string.length()) { usedString = string; newType = type; diff --git a/appointment-import/src/main/java/smash/appointment/parse/RedcapParser.java b/appointment-import/src/main/java/smash/appointment/parse/RedcapParser.java index 2e8cbc2f..89eb6edd 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/RedcapParser.java +++ b/appointment-import/src/main/java/smash/appointment/parse/RedcapParser.java @@ -86,7 +86,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_B_M_POWER); + entry.addType(AppointmentType.LEVEL_B_M_POWER); return entry; } @@ -96,7 +96,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_SB); + entry.addType(AppointmentType.LEVEL_SB); return entry; } @@ -110,7 +110,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_BV); + entry.addType(AppointmentType.LEVEL_BV); return entry; } @@ -124,7 +124,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_BG); + entry.addType(AppointmentType.LEVEL_BG); return entry; } @@ -138,7 +138,7 @@ public class RedcapParser { entry.setDay(date); entry.setSubject(subject); entry.setSource("Imported from RedCap"); - entry.setType(AppointmentType.LEVEL_B); + entry.addType(AppointmentType.LEVEL_B); return entry; } @@ -156,7 +156,7 @@ public class RedcapParser { entry.setSubject(subject); entry.setSource("Imported from RedCap"); entry.setTime(time); - entry.setType(AppointmentType.LEVEL_A); + entry.addType(AppointmentType.LEVEL_A); return entry; } diff --git a/appointment-import/src/test/java/smash/appointment/parse/AllTests.java b/appointment-import/src/test/java/smash/appointment/parse/AllTests.java index 80dc2e92..be53066b 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/AllTests.java +++ b/appointment-import/src/test/java/smash/appointment/parse/AllTests.java @@ -6,6 +6,8 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ CellParserTest.class, // + RedcapParserTest.class, // + SubjectDaoTest.class, // XlsxCalendarProcessorTest.class, // }) diff --git a/appointment-import/src/test/java/smash/appointment/parse/CellParseTestCase.java b/appointment-import/src/test/java/smash/appointment/parse/CellParseTestCase.java index 5bc51566..a43dcbc5 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/CellParseTestCase.java +++ b/appointment-import/src/test/java/smash/appointment/parse/CellParseTestCase.java @@ -1,15 +1,15 @@ package smash.appointment.parse; class CellParseTestCase { - String query; - Subject subject; - String time; - AppointmentType type; + String query; + Subject subject; + String time; + AppointmentType[] types; - public CellParseTestCase(String query, Subject subject, String time, AppointmentType type) { + public CellParseTestCase(String query, Subject subject, String time, AppointmentType[] types) { this.query = query; this.subject = subject; this.time = time; - this.type = type; + this.types = types; } }; diff --git a/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java b/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java index 9178b38a..c4cb6ce9 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java +++ b/appointment-import/src/test/java/smash/appointment/parse/CellParserTest.java @@ -2,9 +2,12 @@ package smash.appointment.parse; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Map; import org.apache.log4j.Logger; import org.junit.Before; @@ -25,17 +28,25 @@ public class CellParserTest extends TestBase { testCases = new ArrayList<CellParseTestCase>(); - testCases.add(new CellParseTestCase("Piotr Gawron level A FU V3", piotrGawron, null, AppointmentType.LEVEL_A)); - testCases.add(new CellParseTestCase("09:00 Jan Kowalski-Nowak level A", janKowalskiNowak, "09:00", AppointmentType.LEVEL_A)); - testCases.add(new CellParseTestCase("ND0002 l664574645 (sms)evel BV © + SB ©", janKowalskiNowak, null, AppointmentType.LEVEL_BV_SB)); - testCases.add(new CellParseTestCase("ND0001 654654631 level B ©", piotrGawron, null, AppointmentType.LEVEL_B)); - testCases.add(new CellParseTestCase("John Doe BV + BG + SB", johnDoe, null, AppointmentType.LEVEL_BV_BG_SB)); - testCases.add(new CellParseTestCase("Kowalski-Nowak m-Power", janKowalskiNowak, null, AppointmentType.LEVEL_B_M_POWER)); - testCases.add(new CellParseTestCase("ND0004 Name BV ©", cateKowalsky, null, AppointmentType.LEVEL_BV)); - testCases.add(new CellParseTestCase("ND0004 level BV (c) + SB ©", cateKowalsky, null, AppointmentType.LEVEL_BV_SB)); - testCases.add(new CellParseTestCase("Cate Kowalsky level BV + BG + SB + m-Power", cateKowalsky, null, AppointmentType.LEVEL_BV_BG_SB_MPOWER)); - testCases.add(new CellParseTestCase("sb name level A", null, null, AppointmentType.LEVEL_A)); - testCases.add(new CellParseTestCase("Andrew Dude level A FU V3", andrewDude, null, AppointmentType.LEVEL_A)); + testCases.add(new CellParseTestCase("Piotr Gawron level A FU V3", piotrGawron, null, new AppointmentType[] { AppointmentType.LEVEL_A })); + testCases.add(new CellParseTestCase("09:00 Jan Kowalski-Nowak level A", janKowalskiNowak, "09:00", new AppointmentType[] { AppointmentType.LEVEL_A })); + testCases.add( + new CellParseTestCase( + "ND0002 l664574645 (sms)evel BV © + SB ©", janKowalskiNowak, null, new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_SB })); + testCases.add(new CellParseTestCase("ND0001 654654631 level B ©", piotrGawron, null, new AppointmentType[] { AppointmentType.LEVEL_B })); + testCases.add( + new CellParseTestCase( + "John Doe BV + BG + SB", johnDoe, null, new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG, AppointmentType.LEVEL_SB })); + testCases.add(new CellParseTestCase("Kowalski-Nowak m-Power", janKowalskiNowak, null, new AppointmentType[] { AppointmentType.LEVEL_B_M_POWER })); + testCases.add(new CellParseTestCase("ND0004 Name BV ©", cateKowalsky, null, new AppointmentType[] { AppointmentType.LEVEL_BV })); + testCases.add( + new CellParseTestCase("ND0004 level BV (c) + SB ©", cateKowalsky, null, new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_SB })); + testCases.add( + new CellParseTestCase( + "Cate Kowalsky level BV + BG + SB + m-Power", cateKowalsky, null, + new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG, AppointmentType.LEVEL_SB, AppointmentType.LEVEL_B_M_POWER })); + testCases.add(new CellParseTestCase("sb name level A", null, null, new AppointmentType[] { AppointmentType.LEVEL_A })); + testCases.add(new CellParseTestCase("Andrew Dude level A FU V3", andrewDude, null, new AppointmentType[] { AppointmentType.LEVEL_A })); } @Test @@ -75,8 +86,23 @@ public class CellParserTest extends TestBase { assertEquals("Invalid time parsed from query (default value expected): " + testCase.query, defaultTime, appointment.getTime()); } assertEquals("Invalid subject parsed from query: " + testCase.query, testCase.subject, appointment.getSubject()); - assertEquals("Invalid type parsed from query: " + testCase.query, testCase.type, appointment.getType()); + assertTrue("Invalid type parsed from query: " + testCase.query, equalTypes(Arrays.asList(testCase.types), appointment.getTypes())); } } + private boolean equalTypes(List<AppointmentType> types, List<AppointmentType> types2) { + for (AppointmentType type: types) { + if (!types2.contains(type)) { + return false; + } + } + for (AppointmentType type: types2) { + if (!types.contains(type)) { + return false; + } + } + + return true; + } + } diff --git a/appointment-import/src/test/java/smash/appointment/parse/RedcapParserTest.java b/appointment-import/src/test/java/smash/appointment/parse/RedcapParserTest.java index 33a72db1..e912829f 100644 --- a/appointment-import/src/test/java/smash/appointment/parse/RedcapParserTest.java +++ b/appointment-import/src/test/java/smash/appointment/parse/RedcapParserTest.java @@ -43,23 +43,22 @@ public class RedcapParserTest extends TestBase{ int levelSBCount = 0; int levelMPowerCount = 0; for (AppointmentEntry appointmentEntry : entries) { - logger.debug(appointmentEntry); - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_A)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_A)) { levelACount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_B)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_B)) { levelBCount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_BG)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_BG)) { levelBGCount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_BV)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_BV)) { levelBVCount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_SB)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_SB)) { levelSBCount++; } - if (appointmentEntry.getType().equals(AppointmentType.LEVEL_B_M_POWER)) { + if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_B_M_POWER)) { levelMPowerCount++; } } -- GitLab