@Test public void readJSONReturnsAllDates() { JSONObject json = new JSONObject(); PhenoTipsDate birthDate = new PhenoTipsDate("1990-11-12"); PhenoTipsDate deathDate = new PhenoTipsDate(new Date(999999999)); PhenoTipsDate examDate = new PhenoTipsDate(new JSONObject("{'year': 1990, 'month': 11, day: 6}")); json.put(DatesController.PATIENT_DATEOFBIRTH_FIELDNAME, birthDate.toJSON()); json.put(DatesController.PATIENT_DATEOFDEATH_FIELDNAME, deathDate.toJSON()); json.put(DatesController.PATIENT_EXAMDATE_FIELDNAME, examDate.toJSON()); PatientData<PhenoTipsDate> result = this.component.readJSON(json); Assert.assertEquals(birthDate.toString(), result.get(DatesController.PATIENT_DATEOFBIRTH_FIELDNAME).toString()); Assert.assertEquals(deathDate.toString(), result.get(DatesController.PATIENT_DATEOFDEATH_FIELDNAME).toString()); Assert.assertEquals(examDate.toString(), result.get(DatesController.PATIENT_EXAMDATE_FIELDNAME).toString()); PhenoTipsDate birthDateOldStyle = new PhenoTipsDate(new JSONObject("{'decade': '1990s'}")); PhenoTipsDate deathDateOldStyle = new PhenoTipsDate(new JSONObject("{'decade': '1990s', 'year': '1995'}")); JSONObject json2 = new JSONObject(); json2.put(DatesController.PATIENT_DATEOFBIRTH_FIELDNAME, birthDateOldStyle.toJSON()); json2.put(DatesController.PATIENT_DATEOFDEATH_FIELDNAME, deathDateOldStyle.toJSON()); PatientData<PhenoTipsDate> result2 = this.component.readJSON(json2); Assert.assertEquals(birthDateOldStyle.toString(), result2.get(DatesController.PATIENT_DATEOFBIRTH_FIELDNAME).toString()); Assert.assertEquals(deathDateOldStyle.toString(), result2.get(DatesController.PATIENT_DATEOFDEATH_FIELDNAME).toString()); }
@Override public PatientData<PhenoTipsDate> readJSON(JSONObject json) { Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String property : this.getPatientDocumentProperties()) { String jsonFieldName = getJSONFieldName(property); if (json.has(jsonFieldName)) { JSONObject dateAsObject = json.optJSONObject(jsonFieldName); if (dateAsObject != null) { result.put(property, new PhenoTipsDate(dateAsObject)); } else { result.put(property, new PhenoTipsDate(json.optString(jsonFieldName, null))); } } } if (result.isEmpty()) { return null; } else { return new DictionaryPatientData<>(DATA_NAME, result); } }
DatesController implements PatientDataController<PhenoTipsDate> { @Override public PatientData<PhenoTipsDate> readJSON(JSONObject json) { Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String property : this.getPatientDocumentProperties()) { String jsonFieldName = getJSONFieldName(property); if (json.has(jsonFieldName)) { JSONObject dateAsObject = json.optJSONObject(jsonFieldName); if (dateAsObject != null) { result.put(property, new PhenoTipsDate(dateAsObject)); } else { result.put(property, new PhenoTipsDate(json.optString(jsonFieldName, null))); } } } if (result.isEmpty()) { return null; } else { return new DictionaryPatientData<>(DATA_NAME, result); } } }
DatesController implements PatientDataController<PhenoTipsDate> { @Override public PatientData<PhenoTipsDate> readJSON(JSONObject json) { Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String property : this.getPatientDocumentProperties()) { String jsonFieldName = getJSONFieldName(property); if (json.has(jsonFieldName)) { JSONObject dateAsObject = json.optJSONObject(jsonFieldName); if (dateAsObject != null) { result.put(property, new PhenoTipsDate(dateAsObject)); } else { result.put(property, new PhenoTipsDate(json.optString(jsonFieldName, null))); } } } if (result.isEmpty()) { return null; } else { return new DictionaryPatientData<>(DATA_NAME, result); } }  }
DatesController implements PatientDataController<PhenoTipsDate> { @Override public PatientData<PhenoTipsDate> readJSON(JSONObject json) { Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String property : this.getPatientDocumentProperties()) { String jsonFieldName = getJSONFieldName(property); if (json.has(jsonFieldName)) { JSONObject dateAsObject = json.optJSONObject(jsonFieldName); if (dateAsObject != null) { result.put(property, new PhenoTipsDate(dateAsObject)); } else { result.put(property, new PhenoTipsDate(json.optString(jsonFieldName, null))); } } } if (result.isEmpty()) { return null; } else { return new DictionaryPatientData<>(DATA_NAME, result); } }  @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> readJSON(JSONObject json) { Map<String, PhenoTipsDate> result = new LinkedHashMap<>(); for (String property : this.getPatientDocumentProperties()) { String jsonFieldName = getJSONFieldName(property); if (json.has(jsonFieldName)) { JSONObject dateAsObject = json.optJSONObject(jsonFieldName); if (dateAsObject != null) { result.put(property, new PhenoTipsDate(dateAsObject)); } else { result.put(property, new PhenoTipsDate(json.optString(jsonFieldName, null))); } } } if (result.isEmpty()) { return null; } else { return new DictionaryPatientData<>(DATA_NAME, result); } }  @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();  }