@Override public PatientData<String> readJSON(JSONObject json) { if (!json.has(DATA_NAME)) { return null; } List<String> result = new ArrayList<>(); Object allergiesValue = json.get(DATA_NAME); if (allergiesValue instanceof JSONArray) { JSONArray allergiesJsonArray = (JSONArray) allergiesValue; for (Object allergy : allergiesJsonArray) { result.add(String.valueOf(allergy)); } } return new IndexedPatientData<>(DATA_NAME, result); } }
@Override public PatientData<String> readJSON(JSONObject json) { if (!json.has(DATA_NAME)) { return null; } List<String> result = new ArrayList<>(); Object allergiesValue = json.get(DATA_NAME); if (allergiesValue instanceof JSONArray) { JSONArray allergiesJsonArray = (JSONArray) allergiesValue; for (Object allergy : allergiesJsonArray) { result.add(String.valueOf(allergy)); } } return new IndexedPatientData<>(DATA_NAME, result); } }
@Override public PatientData<Pair<String, String>> readJSON(@Nullable final JSONObject json) { if (json == null || !json.has(IDENTIFIERS_STRING)) { return null; } List<Pair<String, String>> identifiers = toIdentifiers(json.optJSONArray(IDENTIFIERS_STRING)); if (identifiers == null || identifiers.isEmpty()) { return null; } return new IndexedPatientData<>(CONTROLLER_NAME, identifiers); }
@SuppressWarnings("unchecked") @Override public <T> PatientData<T> getData(String name) { // TODO: somehow reuse GeneController.load()? if (name == "genes") { Set<? extends MatchingPatientGene> genes = this.genes; List<Map<String, String>> allGenes = new LinkedList<>(); for (MatchingPatientGene gene : genes) { Map<String, String> singleGene = new LinkedHashMap<>(); singleGene.put("gene", gene.getName()); allGenes.add(singleGene); } return (PatientData<T>) new IndexedPatientData<>("genes", allGenes); } if (name == "contact") { return (PatientData<T>) new IndexedPatientData<>("contact", Collections.singletonList(this.contactInfo)); } return null; }
@Override public PatientData<Medication> readJSON(JSONObject json) { if (json == null || json.length() == 0) { return null; } JSONArray data = json.optJSONArray(DATA_NAME); if (data == null || data.length() == 0) { return null; } List<Medication> result = new LinkedList<>(); for (int i = 0; i < data.length(); ++i) { JSONObject datum = data.getJSONObject(i); result.add(new Medication(datum)); } return new IndexedPatientData<>(DATA_NAME, result); }
@Override public PatientData<Medication> readJSON(JSONObject json) { if (json == null || json.length() == 0) { return null; } JSONArray data = json.optJSONArray(DATA_NAME); if (data == null || data.length() == 0) { return null; } List<Medication> result = new LinkedList<>(); for (int i = 0; i < data.length(); ++i) { JSONObject datum = data.getJSONObject(i); result.add(new Medication(datum)); } return new IndexedPatientData<>(DATA_NAME, result); }
@Override public PatientData<Attachment> readJSON(JSONObject json) { if (!json.has(DATA_NAME) || json.optJSONArray(DATA_NAME) == null) { return null; } List<Attachment> result = new ArrayList<>(); JSONArray reports = json.getJSONArray(DATA_NAME); for (Object report : reports) { Attachment next = this.adapter.fromJSON((JSONObject) report); if (next != null) { result.add(next); } } return new IndexedPatientData<>(getName(), result); }
@Override public PatientData<ContactInfo> load(Patient patient) { List<ContactInfo> contacts = this.contactsManager.getAll(patient); if (contacts == null || contacts.isEmpty()) { return null; } return new IndexedPatientData<>(getName(), contacts); }
@Override public PatientData<Attachment> readJSON(JSONObject json) { if (!json.has(DATA_NAME) || json.optJSONArray(DATA_NAME) == null) { return null; } List<Attachment> result = new ArrayList<>(); JSONArray files = json.getJSONArray(DATA_NAME); for (Object file : files) { Attachment next = this.adapter.fromJSON((JSONObject) file); if (next != null) { result.add(next); } } return new IndexedPatientData<>(getName(), result); }
@Override public PatientData<Attachment> readJSON(JSONObject json) { if (!json.has(DATA_NAME) || json.optJSONArray(DATA_NAME) == null) { return null; } List<Attachment> result = new ArrayList<>(); JSONArray images = json.getJSONArray(DATA_NAME); for (Object image : images) { Attachment next = this.adapter.fromJSON((JSONObject) image); if (next != null) { result.add(next); } } return new IndexedPatientData<>(getName(), result); }
@Override public PatientData<ContactInfo> load(Patient patient) { List<ContactInfo> contacts = this.contactsManager.getAll(patient); if (contacts == null || contacts.isEmpty()) { return null; } return new IndexedPatientData<>(getName(), contacts); }
@Override public PatientData<Feature> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_FEATURES) && !json.has(JSON_KEY_NON_STANDARD_FEATURES)) { return null; } try { // keep this instance of PhenotipsPatient in sync with the document: reset features List<Feature> features = new ArrayList<>(); addFeaturesFromJSON(features, json.optJSONArray(JSON_KEY_FEATURES)); addFeaturesFromJSON(features, json.optJSONArray(JSON_KEY_NON_STANDARD_FEATURES)); return new IndexedPatientData<>(getName(), features); } catch (Exception e) { this.logger.error("Failed to update patient features from JSON: [{}]", e.getMessage(), e); return null; } }
@Override public PatientData<Disorder> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_DISORDERS)) { return null; } try { JSONArray inputDisorders = json.optJSONArray(JSON_KEY_DISORDERS); if (inputDisorders == null) { return null; } // keep this instance of PhenotipsPatient in sync with the document: reset disorders 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); } catch (Exception e) { this.logger.error("Could not load disorders from JSON: [{}]", e.getMessage(), e); return null; } }
@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 public PatientData<Pair<String, String>> load(final Patient patient) { try { final XWikiDocument doc = patient.getXDocument(); final List<BaseObject> eidXWikiObjects = doc.getXObjects(IDENTIFIER_CLASS_REFERENCE); if (CollectionUtils.isEmpty(eidXWikiObjects)) { return null; } // Get data for all identifiers. final List<Pair<String, String>> allIdentifiers = toIdentifiers(eidXWikiObjects); // Return as a patient data class, or null if no identifiers are recorded. return allIdentifiers.isEmpty() ? null : new IndexedPatientData<>(CONTROLLER_NAME, allIdentifiers); } catch (Exception e) { this.logger.error("Could not find requested document or some unforeseen " + "error has occurred during controller loading ", e.getMessage()); } return null; }
@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 public PatientData<Disorder> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_DISORDERS)) { return null; } try { JSONArray inputDisorders = json.optJSONArray(JSON_KEY_DISORDERS); if (inputDisorders == null) { return null; } // keep this instance of PhenotipsPatient in sync with the document: reset disorders 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); } catch (Exception e) { this.logger.error("Could not load disorders from JSON: [{}]", e.getMessage(), e); return null; } }
@Override public PatientData<Feature> readJSON(JSONObject json) { if (json == null || !json.has(JSON_KEY_FEATURES) && !json.has(JSON_KEY_NON_STANDARD_FEATURES)) { return null; } try { JSONArray jsonFeatures = joinArrays(json.optJSONArray(JSON_KEY_FEATURES), json.optJSONArray(JSON_KEY_NON_STANDARD_FEATURES)); // keep this instance of PhenotipsPatient in sync with the document: reset features List<Feature> features = new ArrayList<>(); for (int i = 0; i < jsonFeatures.length(); i++) { JSONObject featureInJSON = jsonFeatures.optJSONObject(i); if (featureInJSON == null) { continue; } Feature phenotipsFeature = new PhenoTipsFeature(featureInJSON); features.add(phenotipsFeature); } return new IndexedPatientData<>(getName(), features); } catch (Exception e) { this.logger.error("Failed to update patient features from JSON: [{}]", e.getMessage(), e); return null; } }
@Override public PatientData<Gene> readJSON(JSONObject json) { if (json == null || !(json.has(GENES_STRING) || json.has(JSON_SOLVED_KEY) || json.has(JSON_REJECTEDGENES_KEY))) { return null; } try { List<Gene> accumulatedGenes = new LinkedList<>(); parseGenesJson(json, accumulatedGenes); // v1.2.x json compatibility parseRejectedGenes(json, accumulatedGenes); parseSolvedGene(json, accumulatedGenes); return new IndexedPatientData<>(getName(), accumulatedGenes); } catch (Exception e) { this.logger.error("Could not load genes from JSON: [{}]", e.getMessage(), e); return null; } }
return new IndexedPatientData<>(getName(), allVariants); } catch (Exception e) { this.logger.error("Could not load variants from JSON", e.getMessage());