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 { ...@@ -12,6 +12,8 @@ public class AppointmentEntry {
private Subject subject; private Subject subject;
private Set<AppointmentType> types = new HashSet<>(); private Set<AppointmentType> types = new HashSet<>();
private String source; private String source;
private String location;
/** /**
* @return the time * @return the time
...@@ -144,4 +146,20 @@ public class AppointmentEntry { ...@@ -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; package smash.appointment.parse;
import java.util.Calendar;
public class AppointmentSqlExporter extends SqlExporter { public class AppointmentSqlExporter extends SqlExporter {
public String toSql(AppointmentEntry appointment, boolean isFinished) { public String toSql(AppointmentEntry appointment) {
StringBuilder result = new StringBuilder(""); StringBuilder result = new StringBuilder("");
result.append("insert into web_appointment ("); result.append("insert into web_appointment (");
result.append("datetime_when, "); result.append("datetime_when, ");
result.append("length, "); result.append("length, ");
result.append("is_finished, "); result.append("status, ");
result.append("comment, "); result.append("comment, ");
result.append("location_id, ");
result.append("visit_id) "); result.append("visit_id) ");
result.append("values ("); 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(getStringVal(appointment.getDuration()) + ",");
result.append(isFinished + ","); if (isBefore(appointment, Calendar.getInstance())) {
result.append("'FINISHED',");
} else {
result.append("'SCHEDULED',");
}
result.append(getStringVal(appointment.getSource()) + ","); 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("(select max(id) from web_visit)");
result.append(");"); result.append(");\n");
for (AppointmentType type : appointment.getTypes()) { 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("appointment_id, ");
result.append("appointmenttype_id) "); result.append("appointmenttype_id) ");
result.append("values ("); result.append("values (");
result.append("(select max(id) from web_appointment),"); result.append("(select max(id) from web_appointment),");
result.append("(select id from web_appointmenttype where code=" + getStringVal(type.getAbbreviation()) + ") "); result.append("(select id from web_appointmenttype where code=" + getStringVal(type.getAbbreviation()) + ") ");
result.append(");"); result.append(");\n");
} }
return result.toString(); return result.toString();
......
...@@ -42,6 +42,11 @@ public class CellParser { ...@@ -42,6 +42,11 @@ public class CellParser {
Subject subject = extractSubject(query); Subject subject = extractSubject(query);
result.setSubject(subject); result.setSubject(subject);
if (subject!=null) {
result.setLocation(subject.getToBeSeenAt());
} else {
result.setLocation("PRC");
}
AppointmentTypeCollection type = extractType(query); AppointmentTypeCollection type = extractType(query);
if (type == null) { if (type == null) {
......
...@@ -84,6 +84,7 @@ public class RedcapCalendarParser { ...@@ -84,6 +84,7 @@ public class RedcapCalendarParser {
if (subject != null && !subject.getToBeSeenAt().equalsIgnoreCase("LIH")) { if (subject != null && !subject.getToBeSeenAt().equalsIgnoreCase("LIH")) {
return null; return null;
} }
result.setLocation("LIH");
result.setDay(day); result.setDay(day);
result.setTime(time); result.setTime(time);
result.setSource("From redcap: " + query); result.setSource("From redcap: " + query);
......
...@@ -92,6 +92,7 @@ public class RedcapParser { ...@@ -92,6 +92,7 @@ public class RedcapParser {
entry.setSubject(subject); entry.setSubject(subject);
entry.setSource("Imported from RedCap"); entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_B_M_POWER); entry.addType(AppointmentType.LEVEL_B_M_POWER);
entry.setLocation(subject.getToBeSeenAt());
return entry; return entry;
} }
...@@ -102,6 +103,7 @@ public class RedcapParser { ...@@ -102,6 +103,7 @@ public class RedcapParser {
entry.setSubject(subject); entry.setSubject(subject);
entry.setSource("Imported from RedCap"); entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_SB); entry.addType(AppointmentType.LEVEL_SB);
entry.setLocation(subject.getToBeSeenAt());
return entry; return entry;
} }
...@@ -116,6 +118,7 @@ public class RedcapParser { ...@@ -116,6 +118,7 @@ public class RedcapParser {
entry.setSubject(subject); entry.setSubject(subject);
entry.setSource("Imported from RedCap"); entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_BV); entry.addType(AppointmentType.LEVEL_BV);
entry.setLocation(subject.getToBeSeenAt());
return entry; return entry;
} }
...@@ -130,6 +133,7 @@ public class RedcapParser { ...@@ -130,6 +133,7 @@ public class RedcapParser {
entry.setSubject(subject); entry.setSubject(subject);
entry.setSource("Imported from RedCap"); entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_BG); entry.addType(AppointmentType.LEVEL_BG);
entry.setLocation(subject.getToBeSeenAt());
return entry; return entry;
} }
...@@ -144,6 +148,7 @@ public class RedcapParser { ...@@ -144,6 +148,7 @@ public class RedcapParser {
entry.setSubject(subject); entry.setSubject(subject);
entry.setSource("Imported from RedCap"); entry.setSource("Imported from RedCap");
entry.addType(AppointmentType.LEVEL_B); entry.addType(AppointmentType.LEVEL_B);
entry.setLocation(subject.getToBeSeenAt());
return entry; return entry;
} }
...@@ -162,6 +167,7 @@ public class RedcapParser { ...@@ -162,6 +167,7 @@ public class RedcapParser {
entry.setSource("Imported from RedCap"); entry.setSource("Imported from RedCap");
entry.setTime(time); entry.setTime(time);
entry.addType(AppointmentType.LEVEL_A); entry.addType(AppointmentType.LEVEL_A);
entry.setLocation(subject.getToBeSeenAt());
return entry; return entry;
} }
......
...@@ -25,7 +25,7 @@ public class SubjectSqlExporter extends SqlExporter { ...@@ -25,7 +25,7 @@ public class SubjectSqlExporter extends SqlExporter {
result.append("nd_number,"); result.append("nd_number,");
result.append("mpower_id,"); result.append("mpower_id,");
result.append("screening_number,"); result.append("screening_number,");
result.append("default_appointment_location,"); result.append("default_location_id,");
result.append("type,"); result.append("type,");
result.append("dead,"); result.append("dead,");
result.append("resigned,"); result.append("resigned,");
...@@ -51,7 +51,20 @@ public class SubjectSqlExporter extends SqlExporter { ...@@ -51,7 +51,20 @@ public class SubjectSqlExporter extends SqlExporter {
result.append(getStringVal(subject.getNdNumber()) + ","); result.append(getStringVal(subject.getNdNumber()) + ",");
result.append(getStringVal(subject.getmPowerId()) + ","); result.append(getStringVal(subject.getmPowerId()) + ",");
result.append(getStringVal(subject.getScreeningNumber()) + ","); 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(getStringVal(subject.getType().toString().substring(0, 1)) + ",");
result.append(subject.isDead() + ","); result.append(subject.isDead() + ",");
result.append(subject.isResigned() + ","); result.append(subject.isResigned() + ",");
......
...@@ -24,7 +24,7 @@ public class VisitSqlExporter extends SqlExporter { ...@@ -24,7 +24,7 @@ public class VisitSqlExporter extends SqlExporter {
boolean entryFinished= isFinished; boolean entryFinished= isFinished;
if (isBefore(entry, Calendar.getInstance())) if (isBefore(entry, Calendar.getInstance()))
entryFinished=true; entryFinished=true;
result.append(appointmentSqlExporter.toSql(entry, entryFinished)+"\n"); result.append(appointmentSqlExporter.toSql(entry)+"\n");
} }
return result.toString(); 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