@Test public void readJSONReturnsNullWhenDataIsNotArray() { assertNull(this.component.readJSON(new JSONObject("{\"clinical-diagnosis\":true}"))); assertNull(this.component.readJSON(new JSONObject("{\"clinical-diagnosis\":5}"))); assertNull(this.component.readJSON(new JSONObject("{\"clinical-diagnosis\":{}}"))); }
@Override public PatientData<Disorder> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_CLINICAL_DIAGNOSIS)) { return null; } JSONArray inputDisorders = json.optJSONArray(JSON_KEY_CLINICAL_DIAGNOSIS); if (inputDisorders == null) { return null; } List<Disorder> disorders = new ArrayList<>(); for (int i = 0; i < inputDisorders.length(); i++) { JSONObject disorderJSON = inputDisorders.optJSONObject(i); if (disorderJSON == null) { continue; } Disorder phenotipsDisorder = new PhenoTipsDisorder(disorderJSON); disorders.add(phenotipsDisorder); } return new IndexedPatientData<>(getName(), disorders); }
ClinicalDiagnosisController implements PatientDataController<Disorder> { @Override public PatientData<Disorder> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_CLINICAL_DIAGNOSIS)) { return null; } JSONArray inputDisorders = json.optJSONArray(JSON_KEY_CLINICAL_DIAGNOSIS); if (inputDisorders == null) { return null; } List<Disorder> disorders = new ArrayList<>(); for (int i = 0; i < inputDisorders.length(); i++) { JSONObject disorderJSON = inputDisorders.optJSONObject(i); if (disorderJSON == null) { continue; } Disorder phenotipsDisorder = new PhenoTipsDisorder(disorderJSON); disorders.add(phenotipsDisorder); } return new IndexedPatientData<>(getName(), disorders); } }
ClinicalDiagnosisController implements PatientDataController<Disorder> { @Override public PatientData<Disorder> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_CLINICAL_DIAGNOSIS)) { return null; } JSONArray inputDisorders = json.optJSONArray(JSON_KEY_CLINICAL_DIAGNOSIS); if (inputDisorders == null) { return null; } List<Disorder> disorders = new ArrayList<>(); for (int i = 0; i < inputDisorders.length(); i++) { JSONObject disorderJSON = inputDisorders.optJSONObject(i); if (disorderJSON == null) { continue; } Disorder phenotipsDisorder = new PhenoTipsDisorder(disorderJSON); disorders.add(phenotipsDisorder); } return new IndexedPatientData<>(getName(), disorders); }  }
ClinicalDiagnosisController implements PatientDataController<Disorder> { @Override public PatientData<Disorder> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_CLINICAL_DIAGNOSIS)) { return null; } JSONArray inputDisorders = json.optJSONArray(JSON_KEY_CLINICAL_DIAGNOSIS); if (inputDisorders == null) { return null; } List<Disorder> disorders = new ArrayList<>(); for (int i = 0; i < inputDisorders.length(); i++) { JSONObject disorderJSON = inputDisorders.optJSONObject(i); if (disorderJSON == null) { continue; } Disorder phenotipsDisorder = new PhenoTipsDisorder(disorderJSON); disorders.add(phenotipsDisorder); } return new IndexedPatientData<>(getName(), disorders); }  @Override String getName(); @Override IndexedPatientData<Disorder> 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<Disorder> readJSON(JSONObject json); }
ClinicalDiagnosisController implements PatientDataController<Disorder> { @Override public PatientData<Disorder> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_CLINICAL_DIAGNOSIS)) { return null; } JSONArray inputDisorders = json.optJSONArray(JSON_KEY_CLINICAL_DIAGNOSIS); if (inputDisorders == null) { return null; } List<Disorder> disorders = new ArrayList<>(); for (int i = 0; i < inputDisorders.length(); i++) { JSONObject disorderJSON = inputDisorders.optJSONObject(i); if (disorderJSON == null) { continue; } Disorder phenotipsDisorder = new PhenoTipsDisorder(disorderJSON); disorders.add(phenotipsDisorder); } return new IndexedPatientData<>(getName(), disorders); }  @Override String getName(); @Override IndexedPatientData<Disorder> 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<Disorder> readJSON(JSONObject json);  }