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

export to sql adapted to new django model

parent 16ff9ff6
No related branches found
No related tags found
1 merge request!2Appointments dev
......@@ -12,6 +12,8 @@ public class AppointmentEntry {
private Subject subject;
private Set<AppointmentType> types = new HashSet<>();
private String source;
private String location;
/**
* @return the time
......@@ -144,4 +146,20 @@ public class AppointmentEntry {
}
}
/**
* @return the location
* @see #location
*/
public String getLocation() {
return location;
}
/**
* @param location the location to set
* @see #location
*/
public void setLocation(String location) {
this.location = location;
}
}
package smash.appointment.parse;
import java.util.Calendar;
public class AppointmentSqlExporter extends SqlExporter {
public String toSql(AppointmentEntry appointment, boolean isFinished) {
public String toSql(AppointmentEntry appointment) {
StringBuilder result = new StringBuilder("");
result.append("insert into web_appointment (");
result.append("datetime_when, ");
result.append("length, ");
result.append("is_finished, ");
result.append("status, ");
result.append("comment, ");
result.append("location_id, ");
result.append("visit_id) ");
result.append("values (");
result.append(getStringVal(appointment.getDay() + " " + appointment.getTime()+"+00") + ",");
result.append(getStringVal(appointment.getDay() + " " + appointment.getTime() + "+00") + ",");
result.append(getStringVal(appointment.getDuration()) + ",");
result.append(isFinished + ",");
if (isBefore(appointment, Calendar.getInstance())) {
result.append("'FINISHED',");
} else {
result.append("'SCHEDULED',");
}
result.append(getStringVal(appointment.getSource()) + ",");
switch (appointment.getLocation().substring(0, 1)) {
case ("L"):
result.append("(select id from web_location where name = 'LIH'),");
break;
case ("F"):
result.append("(select id from web_location where name = 'Flying Team'),");
break;
case ("P"):
result.append("(select id from web_location where name = 'PRC'),");
break;
default:
throw new RuntimeException("Unknown location: " + appointment.getLocation());
}
result.append("(select max(id) from web_visit)");
result.append(");");
result.append(");\n");
for (AppointmentType type : appointment.getTypes()) {
result.append("insert into web_appointment_appointment_types (");
result.append("\tinsert 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(");");
result.append(");\n");
}
return result.toString();
......
......@@ -42,6 +42,11 @@ public class CellParser {
Subject subject = extractSubject(query);
result.setSubject(subject);
if (subject!=null) {
result.setLocation(subject.getToBeSeenAt());
} else {
result.setLocation("PRC");
}
AppointmentTypeCollection type = extractType(query);
if (type == null) {
......
......@@ -84,6 +84,7 @@ public class RedcapCalendarParser {
if (subject != null && !subject.getToBeSeenAt().equalsIgnoreCase("LIH")) {
return null;
}
result.setLocation("LIH");
result.setDay(day);
result.setTime(time);
result.setSource("From redcap: " + query);
......
......@@ -92,6 +92,7 @@ public class RedcapParser {
entry.setSubject(subject);
entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_B_M_POWER);
entry.setLocation(subject.getToBeSeenAt());
return entry;
}
......@@ -102,6 +103,7 @@ public class RedcapParser {
entry.setSubject(subject);
entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_SB);
entry.setLocation(subject.getToBeSeenAt());
return entry;
}
......@@ -116,6 +118,7 @@ public class RedcapParser {
entry.setSubject(subject);
entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_BV);
entry.setLocation(subject.getToBeSeenAt());
return entry;
}
......@@ -130,6 +133,7 @@ public class RedcapParser {
entry.setSubject(subject);
entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_BG);
entry.setLocation(subject.getToBeSeenAt());
return entry;
}
......@@ -144,6 +148,7 @@ public class RedcapParser {
entry.setSubject(subject);
entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_B);
entry.setLocation(subject.getToBeSeenAt());
return entry;
}
......@@ -162,6 +167,7 @@ public class RedcapParser {
entry.setSource("Imported from RedCap");
entry.setTime(time);
entry.addType(AppointmentType.LEVEL_A);
entry.setLocation(subject.getToBeSeenAt());
return entry;
}
......
......@@ -25,7 +25,7 @@ public class SubjectSqlExporter extends SqlExporter {
result.append("nd_number,");
result.append("mpower_id,");
result.append("screening_number,");
result.append("default_appointment_location,");
result.append("default_location_id,");
result.append("type,");
result.append("dead,");
result.append("resigned,");
......@@ -51,7 +51,20 @@ public class SubjectSqlExporter extends SqlExporter {
result.append(getStringVal(subject.getNdNumber()) + ",");
result.append(getStringVal(subject.getmPowerId()) + ",");
result.append(getStringVal(subject.getScreeningNumber()) + ",");
result.append(getStringVal(subject.getToBeSeenAt()) + ",");
switch (subject.getToBeSeenAt()) {
case ("L"):
result.append("(select id from web_location where name = 'LIH'),");
break;
case ("F"):
result.append("(select id from web_location where name = 'Flying Team'),");
break;
case ("P"):
result.append("(select id from web_location where name = 'PRC'),");
break;
default:
throw new RuntimeException("Unknown location: " + subject.getToBeSeenAt());
}
result.append(getStringVal(subject.getType().toString().substring(0, 1)) + ",");
result.append(subject.isDead() + ",");
result.append(subject.isResigned() + ",");
......
......@@ -24,7 +24,7 @@ public class VisitSqlExporter extends SqlExporter {
boolean entryFinished= isFinished;
if (isBefore(entry, Calendar.getInstance()))
entryFinished=true;
result.append(appointmentSqlExporter.toSql(entry, entryFinished)+"\n");
result.append(appointmentSqlExporter.toSql(entry)+"\n");
}
return result.toString();
......
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