/** * Saves the {@code date} data for some {@code property} into the object containing patient {@code data}. * * @param data the {@link BaseObject} where new data will be saved * @param date the updated {@link PhenoTipsDate date} data for {@code property} * @param property the patient document property of interest */ private void saveDateData( @Nonnull final BaseObject data, @Nullable final PhenoTipsDate date, @Nonnull final String property) { // note: `date` may be null if data is missing if (CORRESPONDING_ASENTERED_FIELDNAMES.containsKey(property)) { final String dateStr = date == null ? StringUtils.EMPTY : date.toString(); data.setStringValue(CORRESPONDING_ASENTERED_FIELDNAMES.get(property), dateStr); } // if date is not a valid/complete date, toEarliestPossibleISODate() will return null // and date will be effectively "unset" final Date dateObj = date == null ? null : date.toEarliestPossibleISODate(); data.setDateValue(property, dateObj); }
@Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { // this controller is only activated if a deprecated field is explicitly requested if (selectedFieldNames == null) { return; } DateFormat dateFormat = new SimpleDateFormat(this.configurationManager.getActiveConfiguration().getISODateFormat()); PatientData<PhenoTipsDate> datesData = patient.getData(DATA_NAME); boolean noData = (datesData == null || !datesData.isNamed()); for (String propertyName : this.getPatientDocumentProperties()) { // only a subset of fields was explicitly requested, and this field is not included if (!selectedFieldNames.contains(getControllingFieldName(propertyName))) { continue; } PhenoTipsDate data = noData ? null : datesData.get(propertyName); json.put(getJSONFieldName(propertyName), ((data == null || !data.isSet()) ? "" : dateFormat.format(data.toEarliestPossibleISODate()))); } }
@Override public void save(Patient patient, DocumentModelBridge doc) { BaseObject data = ((XWikiDocument) doc).getXObject(Patient.CLASS_REFERENCE); if (data == null) { throw new NullPointerException(ERROR_MESSAGE_NO_PATIENT_CLASS); } PatientData<PhenoTipsDate> dates = patient.getData(DATA_NAME); if (!dates.isNamed()) { throw new IllegalArgumentException(ERROR_MESSAGE_DATA_IN_MEMORY_IN_WRONG_FORMAT); } for (String propertyName : this.getPatientDocumentProperties()) { if (dates.containsKey(propertyName)) { PhenoTipsDate date = dates.get(propertyName); // note: `date` may be null if data is missing if (CORRESPONDING_ASENTERED_FIELDNAMES.containsKey(propertyName)) { data.setStringValue(CORRESPONDING_ASENTERED_FIELDNAMES.get(propertyName), (date == null ? "" : date.toString())); } // if date is not a valid/complete date, toEarliestPossibleISODate() will return null // and date will be effectively "unset" data.setDateValue(propertyName, (date == null ? null : date.toEarliestPossibleISODate())); } } }
@Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { // this controller is only activated if a deprecated field is explicitly requested if (selectedFieldNames == null) { return; } DateFormat dateFormat = new SimpleDateFormat(this.configurationManager.getActiveConfiguration().getISODateFormat()); PatientData<PhenoTipsDate> datesData = patient.getData(DATA_NAME); boolean noData = (datesData == null || !datesData.isNamed()); for (String propertyName : this.getPatientDocumentProperties()) { // only a subset of fields was explicitly requested, and this field is not included if (!selectedFieldNames.contains(getControllingFieldName(propertyName))) { continue; } PhenoTipsDate data = noData ? null : datesData.get(propertyName); json.put(getJSONFieldName(propertyName), ((data == null || !data.isSet()) ? "" : dateFormat.format(data.toEarliestPossibleISODate()))); } }
PhenoTipsDate dob = patient.<PhenoTipsDate>getData("dates").get("date_of_birth"); DataCell cell; if (dob != null && dob.toEarliestPossibleISODate() != null) { SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd"); cell = new DataCell(format.format(dob.toEarliestPossibleISODate()), x, 0); } else { cell = new DataCell("", x, 0);
PhenoTipsDate dob = patient.<PhenoTipsDate>getData("dates").get("date_of_birth"); DataCell cell; if (dob != null && dob.toEarliestPossibleISODate() != null) { SimpleDateFormat format = new SimpleDateFormat("yyyy.MM.dd"); cell = new DataCell(format.format(dob.toEarliestPossibleISODate()), x, 0); } else { cell = new DataCell("", x, 0);