@Test public void loadDoesNotReturnNullDates() { doReturn(null).when(this.data).getDateValue(anyString()); doReturn(null).when(this.data).getStringValue(anyString()); PatientData<PhenoTipsDate> result = this.component.load(this.patient); Assert.assertEquals(0, result.size()); }
@Override public PatientData<PhenoTipsDate> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String propertyName : getPatientDocumentProperties()) { String dateAsEntered = CORRESPONDING_ASENTERED_FIELDNAMES.containsKey(propertyName) ? data.getStringValue(CORRESPONDING_ASENTERED_FIELDNAMES.get(propertyName)) : null; if (!StringUtils.isEmpty(dateAsEntered)) { try { JSONObject dateAsEnteredJSON = new JSONObject(dateAsEntered); result.put(propertyName, new PhenoTipsDate(dateAsEnteredJSON)); } catch (Exception ex) { this.logger.error("Could not process date-as-entered for {}: [{}]", propertyName, ex.getMessage()); } } else { Date date = data.getDateValue(propertyName); if (date != null) { result.put(propertyName, new PhenoTipsDate(date)); } } } return new DictionaryPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }
DatesController implements PatientDataController<PhenoTipsDate> { @Override public PatientData<PhenoTipsDate> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String propertyName : getPatientDocumentProperties()) { String dateAsEntered = CORRESPONDING_ASENTERED_FIELDNAMES.containsKey(propertyName) ? data.getStringValue(CORRESPONDING_ASENTERED_FIELDNAMES.get(propertyName)) : null; if (!StringUtils.isEmpty(dateAsEntered)) { try { JSONObject dateAsEnteredJSON = new JSONObject(dateAsEntered); result.put(propertyName, new PhenoTipsDate(dateAsEnteredJSON)); } catch (Exception ex) { this.logger.error("Could not process date-as-entered for {}: [{}]", propertyName, ex.getMessage()); } } else { Date date = data.getDateValue(propertyName); if (date != null) { result.put(propertyName, new PhenoTipsDate(date)); } } } return new DictionaryPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; } }
DatesController implements PatientDataController<PhenoTipsDate> { @Override public PatientData<PhenoTipsDate> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String propertyName : getPatientDocumentProperties()) { String dateAsEntered = CORRESPONDING_ASENTERED_FIELDNAMES.containsKey(propertyName) ? data.getStringValue(CORRESPONDING_ASENTERED_FIELDNAMES.get(propertyName)) : null; if (!StringUtils.isEmpty(dateAsEntered)) { try { JSONObject dateAsEnteredJSON = new JSONObject(dateAsEntered); result.put(propertyName, new PhenoTipsDate(dateAsEnteredJSON)); } catch (Exception ex) { this.logger.error("Could not process date-as-entered for {}: [{}]", propertyName, ex.getMessage()); } } else { Date date = data.getDateValue(propertyName); if (date != null) { result.put(propertyName, new PhenoTipsDate(date)); } } } return new DictionaryPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  }
DatesController implements PatientDataController<PhenoTipsDate> { @Override public PatientData<PhenoTipsDate> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String propertyName : getPatientDocumentProperties()) { String dateAsEntered = CORRESPONDING_ASENTERED_FIELDNAMES.containsKey(propertyName) ? data.getStringValue(CORRESPONDING_ASENTERED_FIELDNAMES.get(propertyName)) : null; if (!StringUtils.isEmpty(dateAsEntered)) { try { JSONObject dateAsEnteredJSON = new JSONObject(dateAsEntered); result.put(propertyName, new PhenoTipsDate(dateAsEnteredJSON)); } catch (Exception ex) { this.logger.error("Could not process date-as-entered for {}: [{}]", propertyName, ex.getMessage()); } } else { Date date = data.getDateValue(propertyName); if (date != null) { result.put(propertyName, new PhenoTipsDate(date)); } } } return new DictionaryPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  @Override PatientData<PhenoTipsDate> load(Patient patient); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override void writeJSON(Patient patient, JSONObject json); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<PhenoTipsDate> readJSON(JSONObject json); @Override String getName(); }
DatesController implements PatientDataController<PhenoTipsDate> { @Override public PatientData<PhenoTipsDate> load(Patient patient) { try { XWikiDocument doc = patient.getXDocument(); BaseObject data = doc.getXObject(Patient.CLASS_REFERENCE); if (data == null) { return null; } Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String propertyName : getPatientDocumentProperties()) { String dateAsEntered = CORRESPONDING_ASENTERED_FIELDNAMES.containsKey(propertyName) ? data.getStringValue(CORRESPONDING_ASENTERED_FIELDNAMES.get(propertyName)) : null; if (!StringUtils.isEmpty(dateAsEntered)) { try { JSONObject dateAsEnteredJSON = new JSONObject(dateAsEntered); result.put(propertyName, new PhenoTipsDate(dateAsEnteredJSON)); } catch (Exception ex) { this.logger.error("Could not process date-as-entered for {}: [{}]", propertyName, ex.getMessage()); } } else { Date date = data.getDateValue(propertyName); if (date != null) { result.put(propertyName, new PhenoTipsDate(date)); } } } return new DictionaryPatientData<>(DATA_NAME, result); } catch (Exception e) { this.logger.error(ERROR_MESSAGE_LOAD_FAILED, e.getMessage()); } return null; }  @Override PatientData<PhenoTipsDate> load(Patient patient); @Override void save(Patient patient); @Override void save(@Nonnull final Patient patient, @Nonnull final PatientWritePolicy policy); @Override void writeJSON(Patient patient, JSONObject json); @Override void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames); @Override PatientData<PhenoTipsDate> readJSON(JSONObject json); @Override String getName();  }