Skip to content
Snippets Groups Projects
Commit 93fa95f8 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

single appointment might have multiple types of examination

parent ffeba171
No related branches found
No related tags found
1 merge request!1Appointments dev
......@@ -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);
}
}
}
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;
}
}
......@@ -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;
......
......@@ -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;
}
......
......@@ -6,6 +6,8 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({ CellParserTest.class, //
RedcapParserTest.class, //
SubjectDaoTest.class, //
XlsxCalendarProcessorTest.class, //
})
......
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;
}
};
......@@ -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;
}
}
......@@ -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++;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment