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

Merge branch 'appointments-dev' into 'master'

Appointments dev

See merge request !1
parents 77471d99 3c3e9265
No related branches found
Tags v0.1.2
1 merge request!1Appointments dev
Showing
with 1442 additions and 0 deletions
# Disable virtualenv # Disable virtualenv
env/* env/*
# Disable migration files
smash/web/migrations/*
# Folder with db statics (dev mode)
smash/~/
# Disable python bytecode # Disable python bytecode
*.pyc *.pyc
# Disable local developer settings # Disable local developer settings
local_settings.py local_settings.py
#tmp files
appointment-import/testFiles/~*
appointment-import/tmp.sql
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
/target/
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>appointment-import</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>smash</groupId>
<artifactId>appointment-import</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>appointment-import</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>smash.appointment.parse.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
package smash.appointment.parse;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
public class AppointmentDao {
Logger logger = Logger.getLogger(AppointmentDao.class);
private List<AppointmentEntry> appointments = new ArrayList<>();
public void addAppointments(List<AppointmentEntry> appointmentsToAdd) {
for (AppointmentEntry appointmentEntry : appointmentsToAdd) {
addAppointment(appointmentEntry);
}
}
/**
* @return the appointments
* @see #appointments
*/
public List<AppointmentEntry> getAppointments() {
return appointments;
}
/**
* @param appointments
* the appointments to set
* @see #appointments
*/
public void setAppointments(List<AppointmentEntry> appointments) {
this.appointments = appointments;
}
public List<Visit> getVisits() {
List<Visit> result = new ArrayList<>();
Map<Subject, List<AppointmentEntry>> subjectAppointments = new HashMap<>();
for (AppointmentEntry entry : appointments) {
if (subjectAppointments.get(entry.getSubject()) == null) {
subjectAppointments.put(entry.getSubject(), new ArrayList<AppointmentEntry>());
}
subjectAppointments.get(entry.getSubject()).add(entry);
}
for (Subject subject : subjectAppointments.keySet()) {
result.addAll(getVisitsForSubject(subject, subjectAppointments.get(subject)));
}
return result;
}
private List<Visit> getVisitsForSubject(Subject subject, List<AppointmentEntry> list) {
Comparator<AppointmentEntry> comparator = new Comparator<AppointmentEntry>() {
@Override
public int compare(AppointmentEntry o1, AppointmentEntry o2) {
String date1 = o1.getDay().substring(0, 10);
String date2 = o2.getDay().substring(0, 10);
if (date1.compareTo(date2) == 0) {
if (o1.getTypes().contains(AppointmentType.LEVEL_A) || o1.getTypes().contains(AppointmentType.LEVEL_A_TQ)) {
return -1;
} else if (o2.getTypes().contains(AppointmentType.LEVEL_A) || o2.getTypes().contains(AppointmentType.LEVEL_A_TQ)) {
return 1;
} else {
return 0;
}
} else {
return date1.compareTo(date2);
}
}
};
Collections.sort(list, comparator);
List<Visit> result = new ArrayList<>();
Visit currentVisit = new Visit(subject);
for (AppointmentEntry appointmentEntry : list) {
if (appointmentEntry.getTypes().contains(AppointmentType.LEVEL_A) || appointmentEntry.getTypes().contains(AppointmentType.LEVEL_A_TQ)) {
if (currentVisit.getAppointments().size() > 0) {
result.add(currentVisit);
}
currentVisit = new Visit(subject);
currentVisit.addAppointment(appointmentEntry);
} else {
String date = currentVisit.getLastAppointmentDate();
if (date.equals(appointmentEntry.getDay().substring(0, 10))) {
currentVisit.getLastAppointment().addTypes(appointmentEntry.getTypes());
String source = appointmentEntry.getSource() + "\n"+currentVisit.getLastAppointment().getSource();
currentVisit.getLastAppointment().setSource(source);
} else {
currentVisit.addAppointment(appointmentEntry);
}
}
}
if (currentVisit.getAppointments().size() > 0) {
result.add(currentVisit);
}
return result;
}
public void addAppointment(AppointmentEntry appointment) {
appointments.add(appointment);
}
}
package smash.appointment.parse;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class AppointmentEntry {
private String day;
private String time;
private String duration;
private Subject subject;
private Set<AppointmentType> types = new HashSet<>();
private String source;
/**
* @return the time
* @see #time
*/
public String getTime() {
if (time == null || time.trim().isEmpty()) {
return "09:00";
} else {
return time;
}
}
/**
* @param time
* the time to set
* @see #time
*/
public void setTime(String time) {
this.time = time;
}
/**
* @return the subject
* @see #subject
*/
public Subject getSubject() {
return subject;
}
/**
* @param subject
* the subject to set
* @see #subject
*/
public void setSubject(Subject subject) {
this.subject = subject;
}
/**
* @return the type
* @see #type
*/
public Set<AppointmentType> getTypes() {
return types;
}
/**
* @param type
* the type to set
* @see #type
*/
public void addType(AppointmentType type) {
this.types.add(type);
}
/**
* @return the day
* @see #day
*/
public String getDay() {
return day;
}
/**
* @param day
* the day to set
* @see #day
*/
public void setDay(String day) {
this.day = day;
}
/**
* @return the source
* @see #source
*/
public String getSource() {
return source;
}
/**
* @param source
* the source to set
* @see #source
*/
public void setSource(String source) {
this.source = source;
}
@Override
public String toString() {
return day + " " + time + " " + subject + " " + types + "\t\t[source: " + source + "]";
}
/**
* @return the duration
* @see #duration
*/
public String getDuration() {
if (duration == null || duration.trim().isEmpty()) {
int count = 0;
for (AppointmentType type : types) {
count += type.getTime();
}
return count + "";
}
return duration;
}
/**
* @param duration
* the duration to set
* @see #duration
*/
public void setDuration(String duration) {
this.duration = duration;
}
public void addTypes(AppointmentType[] typesToAdd) {
for (AppointmentType appointmentType : typesToAdd) {
addType(appointmentType);
}
}
public void addTypes(Collection<AppointmentType> typesToAdd) {
for (AppointmentType appointmentType : typesToAdd) {
addType(appointmentType);
}
}
}
package smash.appointment.parse;
public class AppointmentSqlExporter extends SqlExporter {
public String toSql(AppointmentEntry appointment, boolean isFinished) {
StringBuilder result = new StringBuilder("");
result.append("insert into web_appointment (");
result.append("datetime_when, ");
result.append("length, ");
result.append("is_finished, ");
result.append("comment, ");
result.append("visit_id) ");
result.append("values (");
result.append(getStringVal(appointment.getDay() + " " + appointment.getTime()+"+00") + ",");
result.append(getStringVal(appointment.getDuration()) + ",");
result.append(isFinished + ",");
result.append(getStringVal(appointment.getSource()) + ",");
result.append("(select max(id) from web_visit)");
result.append(");");
for (AppointmentType type : appointment.getTypes()) {
result.append("insert into web_appointment_appointment_types (");
result.append("appointment_id, ");
result.append("appointmenttype_id) ");
result.append("values (");
result.append("(select max(id) from web_appointment),");
result.append("(select id from web_appointmenttype where code=" + getStringVal(type.getAbbreviation()) + ") ");
result.append(");");
}
return result.toString();
}
}
package smash.appointment.parse;
public enum AppointmentType {
LEVEL_BV(90,"BV"), //
LEVEL_BG(30,"BG"), //
LEVEL_SB(30,"SB"), //
LEVEL_A_TQ(120,"A_TQ"), //
LEVEL_A(120,"A"), //
LEVEL_B(90,"B"), //
LEVEL_B_M_POWER(70,"mPower"), //
OTHER(60,"OTHER"), //
;
private int time;
private String abbreviation;
private AppointmentType(int defaultTime, String abbreviation) {
this.time=defaultTime;
this.abbreviation=abbreviation;
}
public int getTime() {
return time;
}
public String getAbbreviation() {
return abbreviation;
}
}
package smash.appointment.parse;
public enum AppointmentTypeCollection {
LEVEL_A_BV_BG(new AppointmentType[] { AppointmentType.LEVEL_A, AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG }, //
new String[] { "BV + BG + neuro level A" }), //
LEVEL_A_B(new AppointmentType[] { AppointmentType.LEVEL_A, AppointmentType.LEVEL_B }, //
new String[] { "level B + level A neuro" }), //
LEVEL_B_BV_SB(new AppointmentType[] { AppointmentType.LEVEL_B, AppointmentType.LEVEL_BV, AppointmentType.LEVEL_SB }, //
new String[] { "level B + BV + SB" }), //
LEVEL_B_BV_BG(new AppointmentType[] { AppointmentType.LEVEL_B, AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG }, //
new String[] { "level B + BV + BG" }), //
LEVEL_B_BG(new AppointmentType[] { AppointmentType.LEVEL_B, AppointmentType.LEVEL_BG }, //
new String[] { "level B + BG" }), //
LEVEL_B_BV(new AppointmentType[] { AppointmentType.LEVEL_B, AppointmentType.LEVEL_BV }, //
new String[] { "level B + BV" }), //
LEVEL_BV_BG_SB_MPOWER(
new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG, AppointmentType.LEVEL_SB, AppointmentType.LEVEL_B_M_POWER, }, //
new String[] { "evel BV + BG + SB + mPower", "BV + BG + SB + mPower" }), //
LEVEL_BG_SB_MPOWER(
new AppointmentType[] { AppointmentType.LEVEL_BG, AppointmentType.LEVEL_SB, AppointmentType.LEVEL_B_M_POWER, }, //
new String[] { "level BG + SB + mPower" }), //
LEVEL_BV_BG_SB(new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG, AppointmentType.LEVEL_SB }, //
new String[] { "evel BV + BG + SB", "BV + BG + SB" }), //
LEVEL_BV_SB(new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_SB }, //
new String[] { "evel BV + SB", "BV + SB" }), //
LEVEL_BV_BG(new AppointmentType[] { AppointmentType.LEVEL_BV, AppointmentType.LEVEL_BG }, //
new String[] { "evel BV + BG", "BV + BG" }), //
LEVEL_BG_SB(new AppointmentType[] { AppointmentType.LEVEL_BG, AppointmentType.LEVEL_SB }, //
new String[] { "evel BG + SB", "BG + SB" }), //
LEVEL_BV(new AppointmentType[] { AppointmentType.LEVEL_BV }, //
new String[] { "evel BV", "BV" }), //
LEVEL_BG(new AppointmentType[] { AppointmentType.LEVEL_BG }, //
new String[] { "evel BG", "BG" }), //
LEVEL_SB(new AppointmentType[] { AppointmentType.LEVEL_SB }, //
new String[] { "evel SB", "SB" }), //
LEVEL_A_TQ(new AppointmentType[] { AppointmentType.LEVEL_A_TQ }, //
new String[] { "TQ" }), //
LEVEL_A(new AppointmentType[] { AppointmentType.LEVEL_A }, //
new String[] { "level A" }), //
LEVEL_B(new AppointmentType[] { AppointmentType.LEVEL_B }, //
new String[] { "evel B" }), //
LEVEL_B_M_POWER(new AppointmentType[] { AppointmentType.LEVEL_B_M_POWER }, //
new String[] { "mPower" }), //
OTHER(new AppointmentType[] {}, //
new String[] {}), //
;
private String[] queryStrings;
private AppointmentType[] types;
private AppointmentTypeCollection(AppointmentType[] types, String[] queryStrings) {
this.queryStrings = queryStrings;
this.types = types;
}
/**
* @return the queryStrings
* @see #queryStrings
*/
public String[] getQueryStrings() {
return queryStrings;
}
/**
* @return the types
* @see #types
*/
public AppointmentType[] getTypes() {
return types;
}
}
package smash.appointment.parse;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.log4j.Logger;
public class CellParser {
Logger logger = Logger.getLogger(CellParser.class);
private SubjectDao subjectDao;
Pattern timePattern = Pattern.compile("^[0-9][0-9]\\:[0-9][0-9]");
public String extractTime(String content) {
String result = null;
Matcher matcher = timePattern.matcher(content);
if (matcher.find()) {
result = matcher.group();
}
return result;
}
public String removeTime(String content) {
Matcher matcher = timePattern.matcher(content);
if (matcher.find()) {
content = matcher.replaceFirst("").trim();
}
return content;
}
public AppointmentEntry parseAppointment(String query, String defaultTime) {
AppointmentEntry result = new AppointmentEntry();
String time = extractTime(query);
if (time != null) {
query = removeTime(query);
} else {
time = defaultTime;
}
result.setTime(time);
Subject subject = extractSubject(query);
result.setSubject(subject);
AppointmentTypeCollection type = extractType(query);
if (type == null) {
result.addType(AppointmentType.OTHER);
} else {
result.addTypes(type.getTypes());
}
result.setSource(query);
return result;
}
private AppointmentTypeCollection extractType(String query) {
String simplifiedQuery = Utils.simplifyString(query);
AppointmentTypeCollection result = null;
String usedString = null;
for (AppointmentTypeCollection type : AppointmentTypeCollection.values()) {
boolean matchFound = false;
for (String string : type.getQueryStrings()) {
if (!matchFound) {
String simplifiedString = Utils.simplifyString(string);
if (simplifiedQuery.contains(simplifiedString)) {
matchFound = true;
if (result == null) {
result = type;
usedString = string;
} else {
if (string.contains(usedString)) {
result = type;
usedString = string;
} else if (usedString.contains(string)) {
// new one is a substring of old
} else { // if there is no substring then we might have a problem
AppointmentTypeCollection newType = result;
if (usedString.length() < string.length()) {
usedString = string;
newType = type;
}
logger.warn("More than one type possible for query: " + query + ". Type 1: " + result + ". Type 2: " + type + ". Choosing: " + newType);
result = newType;
}
}
}
}
}
}
return result;
}
private Subject extractSubject(String query) {
Subject result = null;
String simplifiedQuery = Utils.simplifyString(query);
SubjectIndexer[] mainIndices = new SubjectIndexer[] { //
new NameSurnameIndexer(), //
new SurnameNameIndexer(), //
new NdNumberIndexer(),//
};
result = getByIndices(query, simplifiedQuery, mainIndices);
if (result == null) {
SubjectIndexer[] secondaryIndices = new SubjectIndexer[] { //
new SurnameIndexer(), //
};
result = getByIndices(query, simplifiedQuery, secondaryIndices);
}
return result;
}
private Subject getByIndices(String query, String simplifiedQuery, SubjectIndexer[] mainIndices) {
Subject result = null;
for (Subject subject : subjectDao.getSubjects()) {
boolean matchFound = false;
for (SubjectIndexer indexer : mainIndices) {
if (!matchFound) {
if (indexer.match(subject, simplifiedQuery)) {
matchFound = true;
if (result == null) {
result = subject;
} else {
Subject newResult = result;
if (indexer.isBetter(subject, result)) {
newResult = subject;
}
logger.warn(
"[" + indexer.getClass().getSimpleName() + "]" + "More than one subject possible for query: " + query + ". Subject 1: " + result
+ ". Subject 2: " + subject + ". Choosing: " + newResult);
result = newResult;
}
}
}
}
}
return result;
}
/**
* @return the subjectDao
* @see #subjectDao
*/
public SubjectDao getSubjectDao() {
return subjectDao;
}
/**
* @param subjectDao
* the subjectDao to set
* @see #subjectDao
*/
public void setSubjectDao(SubjectDao subjectDao) {
this.subjectDao = subjectDao;
}
}
package smash.appointment.parse;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.poi.ss.usermodel.Row;
public class LihControlMappingParser extends SubjectParser {
@Override
protected String parseScreeningNumber(Row row) {
String number = getString(row.getCell(0));
if (number.trim().isEmpty()) {
return "";
} else {
if (number.length() == 1) {
number = "00" + number;
} else if (number.length() == 2) {
number = "0" + number;
}
return "L-" + number;
}
}
@Override
protected String parseName(Row row) {
return getString(row.getCell(8));
}
@Override
protected String parseSurname(Row row) {
return getString(row.getCell(9));
}
@Override
protected String parseNdNumber(Row row) {
String number = getString(row.getCell(7));
if (number.equalsIgnoreCase("PK") ||number.equalsIgnoreCase("CHEM") || number.equalsIgnoreCase("Flying Team")) {
number = "";
}
return number;
}
@Override
protected String getSheetName() {
return "Sheet1";
}
@Override
protected int getInitRow() {
return 1;
}
@Override
protected String parseBirthDate(Row row) {
return "";
}
@Override
protected String parsemPowerId(Row row) {
return "";
}
@Override
protected String parseAddDate(Row row) {
return getDate(row.getCell(1), Calendar.getInstance());
}
@Override
protected String parseReferal(Row row) {
return "";
}
@Override
protected String parseDiagnosisYear(Row row) {
return "";
}
@Override
protected String parseMail(Row row) {
return "";
}
@Override
protected String parsePhone3(Row row) {
return "";
}
@Override
protected String parsePhone2(Row row) {
return "";
}
@Override
protected String parsePhone1(Row row) {
return getString(row.getCell(10));
}
@Override
protected String parseCity(Row row) {
return "";
}
@Override
protected String parseCountry(Row row) {
return "";
}
@Override
protected String parseZipCode(Row row) {
return "";
}
@Override
protected String parseAddress(Row row) {
return "";
}
@Override
protected String parseRemarks(Row row) {
return "";
}
@Override
protected String parseDiagnosis(Row row) {
return "";
}
@Override
protected SubjectType parseType(Row row) {
return SubjectType.CONTROL;
}
@Override
protected List<String> parseLanguages(Row row) {
return new ArrayList<>();
}
@Override
protected String parseToBeSeenAt(Row row) {
return "L";
}
@Override
protected boolean parseDead(Row row) {
return false;
}
@Override
protected boolean parseResigned(Row row) {
return false;
}
}
package smash.appointment.parse;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.poi.ss.usermodel.Row;
public class LihControlParser extends SubjectParser {
@Override
protected String parseScreeningNumber(Row row) {
String number = getString(row.getCell(0));
if (number.trim().isEmpty()) {
return "";
} else {
return "L-" + number;
}
}
@Override
protected String parseName(Row row) {
return getString(row.getCell(2));
}
@Override
protected String parseSurname(Row row) {
return getString(row.getCell(1));
}
@Override
protected String parseNdNumber(Row row) {
return "";
}
@Override
protected String getSheetName() {
return "Screening log";
}
@Override
protected int getInitRow() {
return 1;
}
@Override
protected String parseBirthDate(Row row) {
return getDate(row.getCell(5), null);
}
@Override
protected String parsemPowerId(Row row) {
return "";
}
private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd");
@Override
protected String parseAddDate(Row row) {
return DATE_FORMATTER.format(Calendar.getInstance().getTime());
}
@Override
protected String parseReferal(Row row) {
return "";
}
@Override
protected String parseDiagnosisYear(Row row) {
return "";
}
@Override
protected String parseMail(Row row) {
return getString(row.getCell(8));
}
@Override
protected String parsePhone3(Row row) {
return "";
}
@Override
protected String parsePhone2(Row row) {
return getString(row.getCell(7));
}
@Override
protected String parsePhone1(Row row) {
return getString(row.getCell(6));
}
@Override
protected String parseCity(Row row) {
return getString(row.getCell(12));
}
@Override
protected String parseCountry(Row row) {
return "";
}
@Override
protected String parseZipCode(Row row) {
return getString(row.getCell(11));
}
@Override
protected String parseAddress(Row row) {
return getString(row.getCell(9)) + ", " + getString(row.getCell(10));
}
@Override
protected String parseRemarks(Row row) {
List<String> remarks = new ArrayList<>();
String info = getString(row.getCell(4));
if (!info.trim().isEmpty()) {
remarks.add("PD family relation=" + info);
}
remarks.add(getString(row.getCell(13)));
remarks.add(getComments(row.getCell(14)));
remarks.add(getComments(row.getCell(15)));
remarks.add(getComments(row.getCell(16)));
remarks.add(getString(row.getCell(18)));
remarks.add(getString(row.getCell(19)));
String result = "";
for (String string : remarks) {
if (!string.trim().isEmpty()) {
result += string.trim() + "\n";
}
}
return result;
}
@Override
protected String parseDiagnosis(Row row) {
return "";
}
@Override
protected SubjectType parseType(Row row) {
return SubjectType.CONTROL;
}
@Override
protected List<String> parseLanguages(Row row) {
List<String> result = new ArrayList<>();
String languages = getString(row.getCell(3));
String langAbbreviations[] = new String[] {};
if (languages.indexOf(",") >= 0) {
langAbbreviations = languages.split(",");
} else if (languages.indexOf("+") >= 0) {
langAbbreviations = languages.split("\\+");
} else {
langAbbreviations = languages.split("/");
}
for (String string : langAbbreviations) {
if (!string.trim().isEmpty()) {
result.add(getMappedLanguage(string.trim()));
}
}
return result;
}
protected String getMappedLanguage(String abbreviation) {
switch (abbreviation.toUpperCase()) {
case ("F"):
return "French";
case ("D"):
return "German";
case ("GB"):
return "English";
case ("P"):
return "Portuguese";
case ("PT"):
return "Portuguese";
case ("ENG"):
return "English";
case ("EN"):
return "English";
case ("FR"):
return "French";
case ("L"):
return "Luxembourgish";
case ("LUX"):
return "Luxembourgish";
}
logger.warn("Unknown language abbreviation: " + abbreviation);
return "";
}
@Override
protected String parseToBeSeenAt(Row row) {
return "L";
}
@Override
protected boolean parseDead(Row row) {
return false;
}
@Override
protected boolean parseResigned(Row row) {
return false;
}
}
package smash.appointment.parse;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.log4j.Logger;
public class Main {
private static Logger logger = Logger.getLogger(Main.class);
SubjectDao subjectDao = new SubjectDao();
AppointmentDao appointmentDao = new AppointmentDao();
public void run(String[] args) throws Exception {
Options options = new Options();
Option agenda = Option.builder().required().argName("file").hasArg().desc("PRC agenda").longOpt("agenda").build();
Option subjects = Option.builder().required().argName("file").hasArg().desc("PRC subjects").longOpt("subjects").build();
Option controls = Option.builder().required().argName("file").hasArg().desc("PRC controls").longOpt("controls").build();
Option flyingTeam = Option.builder().required().argName("file").hasArg().desc("PRC flying-team").longOpt("flying-team").build();
Option lihControls = Option.builder().required().argName("file").hasArg().desc("LIH controls").longOpt("lih-controls").build();
Option lihMappingControls = Option.builder().required().argName("file").hasArg().desc("LIH controls mapping").longOpt("lih-mapping").build();
Option redCap = Option.builder().required().argName("file").hasArg().desc("RedCap appointments").longOpt("red-cap").build();
options.addOption(agenda);
options.addOption(subjects);
options.addOption(controls);
options.addOption(flyingTeam);
options.addOption(lihControls);
options.addOption(lihMappingControls);
options.addOption(redCap);
CommandLineParser parser = new DefaultParser();
try {
CommandLine line = parser.parse(options, args);
String subjectsFile = line.getOptionValue("subjects");
for (Subject subject : processPrcSubjects(subjectsFile)) {
subjectDao.addSubject(subject, "[" + subjectsFile + ";" + subject.getScreeningNumber() + ";" + subject.getName() + " " + subject.getSurname() + "]");
}
String controlsFile = line.getOptionValue("controls");
for (Subject subject : processPrcControls(controlsFile)) {
subjectDao.addSubject(subject, "[" + controlsFile + ";" + subject.getScreeningNumber() + ";" + subject.getName() + " " + subject.getSurname() + "]");
}
String flyingTeamFile = line.getOptionValue("flying-team");
for (Subject subject : processFlyingTeamControls(flyingTeamFile)) {
subjectDao.addSubject(subject, "[" + flyingTeamFile + ";" + subject.getScreeningNumber() + ";" + subject.getName() + " " + subject.getSurname() + "]");
}
String lihMappingControlsFile = line.getOptionValue("lih-mapping");
for (Subject subject : processLihMappingControls(lihMappingControlsFile)) {
subjectDao.addSubject(
subject, "[" + lihMappingControlsFile + ";" + subject.getScreeningNumber() + ";" + subject.getName() + " " + subject.getSurname() + "]");
}
String lihControlsFile = line.getOptionValue("lih-controls");
for (Subject subject : processLihControls(lihControlsFile)) {
subjectDao
.addSubject(subject, "[" + lihControlsFile + ";" + subject.getScreeningNumber() + ";" + subject.getName() + " " + subject.getSurname() + "]");
}
subjectDao.addSubject(Visit.UNKNOWN, "");
String agendaFile = line.getOptionValue("agenda");
Calendar today = Calendar.getInstance();
today.set(Calendar.HOUR, 5);
appointmentDao.addAppointments(processPrcAppointments(agendaFile, today));
String redCapFile = line.getOptionValue("red-cap");
appointmentDao.addAppointments(processRedCapAppointments(redCapFile));
System.out.println("delete from web_appointment_appointment_types;");
System.out.println("delete from web_subject_languages;");
System.out.println("delete from web_appointment;");
System.out.println("delete from web_visit;");
System.out.println("delete from web_subject;");
SubjectSqlExporter subjectSqlExporter = new SubjectSqlExporter();
// logger.debug("SUBJECTS: ");
for (Subject subject : subjectDao.getSubjects()) {
System.out.println(subjectSqlExporter.toSql(subject));
}
VisitSqlExporter visitSqlExporter = new VisitSqlExporter();
List<Visit> visits = appointmentDao.getVisits();
for (int i = 0; i < visits.size(); i++) {
Visit visit = visits.get(i);
boolean finished = false;
if (i < visits.size() - 1) {
if (visit.getSubject().equals(visits.get(i + 1).getSubject())) {
finished = true;
}
}
System.out.println(visitSqlExporter.toSql(visit, finished));
}
} catch (ParseException exp) {
System.out.println(exp.getMessage());
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("java -jar file.jar", options);
}
}
private List<AppointmentEntry> processRedCapAppointments(String agendaFile) throws Exception{
RedcapParser parser = new RedcapParser();
parser.setSubjectDao(subjectDao);
return parser.parse(agendaFile);
}
private List<Subject> processLihMappingControls(String lihMappingControlsFile) throws Exception {
LihControlMappingParser parser = new LihControlMappingParser();
return parser.processExcel(lihMappingControlsFile);
}
private List<Subject> processLihControls(String lihControlsFile) throws Exception {
LihControlParser parser = new LihControlParser();
return parser.processExcel(lihControlsFile);
}
private List<Subject> processFlyingTeamControls(String flyingTeamFile) throws Exception {
PrcFlyingParser parser = new PrcFlyingParser();
return parser.processExcel(flyingTeamFile);
}
private List<Subject> processPrcControls(String controlsFile) throws Exception {
PrcControlParser parser = new PrcControlParser();
return parser.processExcel(controlsFile);
}
private List<AppointmentEntry> processPrcAppointments(String agendaFile, Calendar minDate) throws Exception {
XlsxCalendarProcessor processor = new XlsxCalendarProcessor();
processor.setSubjectDao(subjectDao);
List<AppointmentEntry> entries = processor.processExcel(agendaFile, minDate);
return entries;
}
public static void main(String[] args) throws Exception {
new Main().run(args);
}
private List<Subject> processPrcSubjects(String subjectsFile) throws Exception {
PrcSubjectsParser parser = new PrcSubjectsParser();
return parser.processExcel(subjectsFile);
}
}
package smash.appointment.parse;
public class NameSurnameIndexer extends SubjectIndexer {
public String getIndexedString(Subject subject) {
return Utils.simplifyString(subject.getName() + subject.getSurname());
}
}
package smash.appointment.parse;
public class NdNumberIndexer extends SubjectIndexer {
public String getIndexedString(Subject subject) {
return Utils.simplifyString(subject.getNdNumber());
}
}
package smash.appointment.parse;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
public class PrcControlParser extends SubjectParser {
@Override
protected String parseScreeningNumber(Row row) {
String number = getString(row.getCell(16));
if (number.trim().isEmpty()) {
return "";
} else {
if (number.length() == 1) {
number = "00" + number;
} else if (number.length() == 2) {
number = "0" + number;
}
return "P-" + number;
}
}
@Override
protected String parseName(Row row) {
return getString(row.getCell(1));
}
@Override
protected String parseSurname(Row row) {
return getString(row.getCell(0));
}
@Override
protected String parseNdNumber(Row row) {
return getString(row.getCell(14));
}
@Override
protected String getSheetName() {
return "Contrôles";
}
@Override
protected int getInitRow() {
return 1;
}
@Override
protected String parseBirthDate(Row row) {
return "";
}
@Override
protected String parsemPowerId(Row row) {
return "";
}
@Override
protected String parseAddDate(Row row) {
return getDate(row.getCell(8), Calendar.getInstance());
}
@Override
protected String parseReferal(Row row) {
return "";
}
@Override
protected String parseDiagnosisYear(Row row) {
return "";
}
@Override
protected String parseMail(Row row) {
return getString(row.getCell(5));
}
@Override
protected String parsePhone3(Row row) {
String phones[] = getPhones(row);
if (phones.length > 2) {
return phones[2].trim();
}
return "";
}
private String[] getPhones(Row row) {
return getString(row.getCell(4)).split("/");
}
@Override
protected String parsePhone2(Row row) {
String phones[] = getPhones(row);
if (phones.length > 1) {
return phones[1].trim();
}
return "";
}
@Override
protected String parsePhone1(Row row) {
String phones[] = getPhones(row);
return phones[0].trim();
}
@Override
protected String parseCity(Row row) {
String string = getString(row.getCell(3));
int spaceIndex = string.indexOf(" ");
if (spaceIndex > 0) {
return string.substring(spaceIndex).trim();
}
return string;
}
@Override
protected String parseCountry(Row row) {
return "";
}
@Override
protected String parseZipCode(Row row) {
String string = getString(row.getCell(3));
int spaceIndex = string.indexOf(" ");
if (spaceIndex > 0) {
return string.substring(0,spaceIndex);
}
return "";
}
@Override
protected String parseAddress(Row row) {
return getString(row.getCell(2));
}
@Override
protected String parseRemarks(Row row) {
String remark1 = getString(row.getCell(9));
String remark2 = "";
String result = "";
if (!remark1.trim().isEmpty()) {
result = result + remark1 + "\n";
}
if (!remark2.trim().isEmpty()) {
result = result + remark2 + "\n";
}
return result;
}
@Override
protected String parseDiagnosis(Row row) {
return "";
}
@Override
protected SubjectType parseType(Row row) {
return SubjectType.CONTROL;
}
@Override
protected List<String> parseLanguages(Row row) {
return new ArrayList<>();
}
@Override
protected String parseToBeSeenAt(Row row) {
return "P";
}
@Override
protected boolean parseDead(Row row) {
return false;
}
@Override
protected boolean parseResigned(Row row) {
return false;
}
}
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