diff --git a/appointment-import/src/main/java/smash/appointment/parse/PrcSubjectsParser.java b/appointment-import/src/main/java/smash/appointment/parse/PrcSubjectsParser.java new file mode 100644 index 0000000000000000000000000000000000000000..155399ce2e6053b7f51c659fd5adf3a595467394 --- /dev/null +++ b/appointment-import/src/main/java/smash/appointment/parse/PrcSubjectsParser.java @@ -0,0 +1,127 @@ +package smash.appointment.parse; + +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; + +public class PrcSubjectsParser extends SubjectParser { + + @Override + protected String parseScreeningNumber(Row row) { + return "P-" + getString(row.getCell(25)); + } + + @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(22)); + } + + @Override + protected String getSheetName() { + return "Feuil1"; + } + + @Override + protected int getInitRow() { + return 1; + } + + @Override + protected String parseBirthDate(Row row) { + String date = getString(row.getCell(27)).replaceAll(" ", ""); + String year = date.substring(0, 4); + String month = date.substring(4, 6); + String day = date.substring(6, 8); + return year + "-" + month + "-" + day; + } + + @Override + protected String parsemPowerId(Row row) { + return getString(row.getCell(23)); + } + + @Override + protected String parseAddDate(Row row) { + return getDate(row.getCell(14)); + } + + @Override + protected String parseReferal(Row row) { + return getString(row.getCell(13)); + } + + @Override + protected String parseDiagnosisYear(Row row) { + return getString(row.getCell(11)); + } + + @Override + protected String parseMail(Row row) { + return getString(row.getCell(10)); + } + + @Override + protected String parsePhone3(Row row) { + return getString(row.getCell(9)); + } + + @Override + protected String parsePhone2(Row row) { + return getString(row.getCell(8)); + } + + @Override + protected String parsePhone1(Row row) { + return getString(row.getCell(7)); + } + + @Override + protected String parseCity(Row row) { + return getString(row.getCell(5)); + } + + @Override + protected String parseCountry(Row row) { + return getString(row.getCell(6)); + } + + @Override + protected String parseZipCode(Row row) { + return getString(row.getCell(4)); + } + + @Override + protected String parseAddress(Row row) { + return getString(row.getCell(3)); + } + + @Override + protected String parseRemarks(Row row) { + String remark1 = getString(row.getCell(2)); + String remark2 = getString(row.getCell(20)); + + 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 getString(row.getCell(12)); + } + +} diff --git a/appointment-import/src/main/java/smash/appointment/parse/Subject.java b/appointment-import/src/main/java/smash/appointment/parse/Subject.java index 92c2ab9fac6b8ba21d1e01164bb41541fd6676ed..70d873342b25adc01f15db582a0856874661393a 100644 --- a/appointment-import/src/main/java/smash/appointment/parse/Subject.java +++ b/appointment-import/src/main/java/smash/appointment/parse/Subject.java @@ -13,7 +13,21 @@ public class Subject { private String ndNumber; private String screeningNumber; private String sex; + private String remarks; private String birthDate; + private String address; + private String zipCode; + private String country; + private String city; + private String phone1; + private String phone2; + private String phone3; + private String mail; + private String diagnosisYear; + private String diagnosis; + private String referal; + private String addDate; + private String mPowerId; private List<String> languages = new ArrayList<>(); @@ -153,4 +167,228 @@ public class Subject { this.languages = languages; } + /** + * @return the remarks + * @see #remarks + */ + public String getRemarks() { + return remarks; + } + + /** + * @param remarks the remarks to set + * @see #remarks + */ + public void setRemarks(String remarks) { + this.remarks = remarks; + } + + /** + * @return the address + * @see #address + */ + public String getAddress() { + return address; + } + + /** + * @param address the address to set + * @see #address + */ + public void setAddress(String address) { + this.address = address; + } + + /** + * @return the zipCode + * @see #zipCode + */ + public String getZipCode() { + return zipCode; + } + + /** + * @param zipCode the zipCode to set + * @see #zipCode + */ + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } + + /** + * @return the country + * @see #country + */ + public String getCountry() { + return country; + } + + /** + * @param country the country to set + * @see #country + */ + public void setCountry(String country) { + this.country = country; + } + + /** + * @return the city + * @see #city + */ + public String getCity() { + return city; + } + + /** + * @param city the city to set + * @see #city + */ + public void setCity(String city) { + this.city = city; + } + + /** + * @return the phone1 + * @see #phone1 + */ + public String getPhone1() { + return phone1; + } + + /** + * @param phone1 the phone1 to set + * @see #phone1 + */ + public void setPhone1(String phone1) { + this.phone1 = phone1; + } + + /** + * @return the phone2 + * @see #phone2 + */ + public String getPhone2() { + return phone2; + } + + /** + * @param phone2 the phone2 to set + * @see #phone2 + */ + public void setPhone2(String phone2) { + this.phone2 = phone2; + } + + /** + * @return the phone3 + * @see #phone3 + */ + public String getPhone3() { + return phone3; + } + + /** + * @param phone3 the phone3 to set + * @see #phone3 + */ + public void setPhone3(String phone3) { + this.phone3 = phone3; + } + + /** + * @return the mail + * @see #mail + */ + public String getMail() { + return mail; + } + + /** + * @param mail the mail to set + * @see #mail + */ + public void setMail(String mail) { + this.mail = mail; + } + + /** + * @return the diagnosisYear + * @see #diagnosisYear + */ + public String getDiagnosisYear() { + return diagnosisYear; + } + + /** + * @param diagnosisYear the diagnosisYear to set + * @see #diagnosisYear + */ + public void setDiagnosisYear(String diagnosisYear) { + this.diagnosisYear = diagnosisYear; + } + + /** + * @return the diagnosis + * @see #diagnosis + */ + public String getDiagnosis() { + return diagnosis; + } + + /** + * @param diagnosis the diagnosis to set + * @see #diagnosis + */ + public void setDiagnosis(String diagnosis) { + this.diagnosis = diagnosis; + } + + /** + * @return the referal + * @see #referal + */ + public String getReferal() { + return referal; + } + + /** + * @param referal the referal to set + * @see #referal + */ + public void setReferal(String referal) { + this.referal = referal; + } + + /** + * @return the mPowerId + * @see #mPowerId + */ + public String getmPowerId() { + return mPowerId; + } + + /** + * @param mPowerId the mPowerId to set + * @see #mPowerId + */ + public void setmPowerId(String mPowerId) { + this.mPowerId = mPowerId; + } + + /** + * @return the addDate + * @see #addDate + */ + public String getAddDate() { + return addDate; + } + + /** + * @param addDate the addDate to set + * @see #addDate + */ + public void setAddDate(String addDate) { + this.addDate = addDate; + } + } diff --git a/appointment-import/src/main/java/smash/appointment/parse/SubjectParser.java b/appointment-import/src/main/java/smash/appointment/parse/SubjectParser.java new file mode 100644 index 0000000000000000000000000000000000000000..498dc9604683024bbb99d90367f47b507a6c8385 --- /dev/null +++ b/appointment-import/src/main/java/smash/appointment/parse/SubjectParser.java @@ -0,0 +1,147 @@ +package smash.appointment.parse; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.log4j.Logger; +import org.apache.poi.EncryptedDocumentException; +import org.apache.poi.hssf.usermodel.HSSFDateUtil; +import org.apache.poi.openxml4j.exceptions.InvalidFormatException; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.DataFormatter; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.WorkbookFactory; + +public abstract class SubjectParser { + private static final SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("yyyy-MM-dd"); + Logger logger = Logger.getLogger(SubjectParser.class); + DataFormatter df = new DataFormatter(); + + public List<Subject> processExcel(String filename) throws EncryptedDocumentException, InvalidFormatException, IOException, ParseException { + List<Subject> result = new ArrayList<>(); + InputStream inp = new FileInputStream(filename); + Workbook workbook = WorkbookFactory.create(inp); + Iterator<Sheet> sheetIter = workbook.sheetIterator(); + while (sheetIter.hasNext()) { + Sheet sheet = sheetIter.next(); + String name = sheet.getSheetName().trim(); + if (name.trim().toLowerCase().equals(getSheetName().toLowerCase())) { + result.addAll(processSheet(sheet)); + } else { + logger.debug(filename + "Skipping sheet: " + name); + } + } + return result; + } + + private List<Subject> processSheet(Sheet sheet) { + List<Subject> result = new ArrayList<>(); + int rowCount = sheet.getPhysicalNumberOfRows(); + for (int rowId = getInitRow(); rowId < rowCount; rowId++) { + Row subjectRow = sheet.getRow(rowId); + Subject subject = parseSubject(subjectRow); + if (subject != null) { + result.add(subject); + } + } + return result; + } + + private Subject parseSubject(Row row) { + String screeningNumber = parseScreeningNumber(row); + if (screeningNumber == null || screeningNumber.isEmpty()) { + return null; + } + String name = parseName(row); + String surname = parseSurname(row); + String ndNumber = parseNdNumber(row); + Subject result = new Subject(name, surname, ndNumber, screeningNumber); + + result.setRemarks(parseRemarks(row)); + result.setAddress(parseAddress(row)); + result.setZipCode(parseZipCode(row)); + result.setCity(parseCity(row)); + result.setCountry(parseCountry(row)); + result.setPhone1(parsePhone1(row)); + result.setPhone2(parsePhone2(row)); + result.setPhone3(parsePhone3(row)); + result.setMail(parseMail(row)); + result.setDiagnosisYear(parseDiagnosisYear(row)); + result.setDiagnosis(parseDiagnosis(row)); + result.setReferal(parseReferal(row)); + result.setAddDate(parseAddDate(row)); + result.setmPowerId(parsemPowerId(row)); + result.setBirthDate(parseBirthDate(row)); + + return result; + } + + protected abstract String parseBirthDate(Row row); + + protected abstract String parsemPowerId(Row row); + + protected abstract String parseAddDate(Row row); + + protected abstract String parseReferal(Row row); + + protected abstract String parseDiagnosisYear(Row row); + + protected abstract String parseDiagnosis(Row row); + + protected abstract String parseMail(Row row); + + protected abstract String parsePhone3(Row row); + + protected abstract String parsePhone2(Row row); + + protected abstract String parsePhone1(Row row); + + protected abstract String parseCity(Row row); + + protected abstract String parseCountry(Row row); + + protected abstract String parseZipCode(Row row); + + protected abstract String parseAddress(Row row); + + protected abstract String parseRemarks(Row row); + + protected abstract String parseScreeningNumber(Row row); + + protected abstract String parseName(Row row); + + protected abstract String parseSurname(Row row); + + protected abstract String parseNdNumber(Row row); + + protected abstract String getSheetName(); + + protected abstract int getInitRow(); + + protected String getString(Cell cell) { + if (cell.getCellTypeEnum().equals(CellType.NUMERIC)) { + return df.formatCellValue(cell).trim(); + } + return cell.getStringCellValue().trim(); + } + + protected String getDate(Cell cell) { + String result = null; + if (HSSFDateUtil.isCellDateFormatted(cell)) { + result = DATE_FORMATTER.format(cell.getDateCellValue()); + } else { + result = getString(cell); + } + return result; + } + +} 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 be53066bf67243f20b17db09c78442986f2a6e74..a22dce9b64c0508438cad80742eebcb0c031447b 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,7 @@ import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) @SuiteClasses({ CellParserTest.class, // + PrcSubjectsParserTest.class, // RedcapParserTest.class, // SubjectDaoTest.class, // diff --git a/appointment-import/src/test/java/smash/appointment/parse/PrcSubjectsParserTest.java b/appointment-import/src/test/java/smash/appointment/parse/PrcSubjectsParserTest.java new file mode 100644 index 0000000000000000000000000000000000000000..255d939bba3b06288931d1e28c3be21c105acc20 --- /dev/null +++ b/appointment-import/src/test/java/smash/appointment/parse/PrcSubjectsParserTest.java @@ -0,0 +1,60 @@ +package smash.appointment.parse; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.apache.log4j.Logger; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +public class PrcSubjectsParserTest extends TestBase { + Logger logger = Logger.getLogger(PrcSubjectsParserTest.class); + + PrcSubjectsParser processor = new PrcSubjectsParser(); + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() { + super.setUp(); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void test() throws Exception { + List<Subject> entries = processor.processExcel("testFiles/prcSubjectsExample.xlsx"); + assertTrue(entries.size() > 0); + + Subject subject = entries.get(0); + assertEquals("P-111", subject.getScreeningNumber()); + assertEquals("abcdef", subject.getSurname()); + assertEquals("Piotr", subject.getName()); + assertTrue(subject.getRemarks().contains("this is remark")); + assertEquals("Jaskolki, 6", subject.getAddress()); + assertEquals("D-66636", subject.getZipCode()); + assertEquals("Trier", subject.getCity()); + assertEquals("Deutschland", subject.getCountry()); + assertEquals("0049 12 34 556 76", subject.getPhone1()); + assertEquals("tel2", subject.getPhone2()); + assertEquals("tel3", subject.getPhone3()); + assertEquals("piotr.cos@uni.lu", subject.getMail()); + assertEquals("1999", subject.getDiagnosisYear()); + assertEquals("unknown", subject.getDiagnosis()); + assertEquals("PG", subject.getReferal()); + assertEquals("2015-10-14", subject.getAddDate()); + assertTrue(subject.getRemarks().contains("Questionnaires OK")); + assertEquals("ND1111", subject.getNdNumber()); + assertEquals("m_id", subject.getmPowerId()); + assertEquals("1972-01-02", subject.getBirthDate()); + } + +} diff --git a/appointment-import/testFiles/prcSubjectsExample.xlsx b/appointment-import/testFiles/prcSubjectsExample.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..78e43d92529273733c3e26a0b37fa2d6983b5485 Binary files /dev/null and b/appointment-import/testFiles/prcSubjectsExample.xlsx differ