/** * Get a metadatum element from one of the features. * * @param toFind the type of metadatum to get * @param lookIn the feature to get from, may be {@code null} * @return the metadatum specified in the feature, or {@code null} if it does not exist */ private FeatureMetadatum getMetadatumIfExists(String toFind, Feature lookIn) { return lookIn != null && lookIn.getMetadata() != null ? lookIn.getMetadata().get(toFind) : null; }
/** creates & returns a new JSON array of all patient features (as JSON objects). */ private JSONArray featuresToJSON(PatientData<Feature> data, Collection<String> selectedFields) { JSONArray featuresJSON = new JSONArray(); if (data != null) { Iterator<Feature> iterator = data.iterator(); while (iterator.hasNext()) { Feature phenotype = iterator.next(); if (StringUtils.isBlank(phenotype.getId()) || !isFieldIncluded(selectedFields, phenotype.getType())) { continue; } JSONObject featureJSON = phenotype.toJSON(); if (featureJSON != null) { featuresJSON.put(featureJSON); } } } return featuresJSON; }
private void readPhenotypes(Patient patient) { List<Map<String, String>> predefined = new LinkedList<>(); List<Map<String, String>> freeText = new LinkedList<>(); Set<? extends Feature> features = patient.getFeatures(); for (Feature feature : features) { Map<String, String> item = new HashMap<>(); item.put(NAME_FIELD, feature.getName()); item.put(OBSERVED_FIELD, feature.isPresent() ? OBSERVED : NOT_OBSERVED); String id = feature.getId(); if (StringUtils.isEmpty(id)) { freeText.add(item); } else { item.put(ID_FIELD, id); predefined.add(item); } } Collections.sort(predefined, PHENOTYPES_COMPARATOR); Collections.sort(freeText, PHENOTYPES_COMPARATOR); this.phenotypes = new HashMap<>(); this.phenotypes.put(PREDEFINED, predefined); this.phenotypes.put(FREE_TEXT, freeText); }
x = 0; if (!Boolean.valueOf(feature.isPresent()).equals(lastStatus)) { lastSection = ""; DataCell cell = new DataCell(feature.isPresent() ? this.translationManager.translate("yes") : this.translationManager.translate("no"), lastStatus = feature.isPresent(); cell.addStyle(lastStatus ? StyleOption.YES : StyleOption.NO); section.addCell(cell); String currentSection = sectionFeatureLookup.get(feature.getId()); if (!StringUtils.equals(currentSection, lastSection)) { DataCell cell = new DataCell(currentSection, x, y); DataCell cell = new DataCell(feature.getName(), x, y, StyleOption.FEATURE_SEPARATOR); section.addCell(cell); x++; DataCell cell = new DataCell(feature.getId(), x, y, StyleOption.FEATURE_SEPARATOR); section.addCell(cell); x++; Collection<? extends FeatureMetadatum> featureMetadatum = feature.getMetadata().values(); Boolean metaPresent = !featureMetadatum.isEmpty(); int offset = 0;
result.element("id", this.match.getId()); result.element("name", this.match.getName()); result.element("type", this.match.getType()); if (!this.match.isPresent()) { result.element("isPresent", false); result.element("queryId", this.reference.getId()); result.element("queryType", this.reference.getType());
@Override public String getId() { return this.access.isOpenAccess() && this.match != null ? this.match.getId() : null; }
while (iterator.hasNext()) { Feature feature = iterator.next(); String featureType = feature.getType(); if (!feature.isPresent()) { featureType = PhenoTipsFeature.NEGATIVE_PHENOTYPE_PREFIX + featureType; featuresMap.get(featureType).add(feature.getValue()); } else { List<String> newFeatureType = new LinkedList<>(); newFeatureType.add(feature.getValue()); featuresMap.put(featureType, newFeatureType);
private static String observedStatusToJSONString(Feature feature) { if (feature.isPresent()) { return ApiConfiguration.JSON_FEATURE_OBSERVED_YES; } return ApiConfiguration.JSON_FEATURE_OBSERVED_NO; }
private JSONArray features(Patient patient) { JSONArray features = new JSONArray(); for (Feature patientFeature : patient.getFeatures()) { String featureId = patientFeature.getId(); if (featureId.isEmpty() || !this.hpoTerm.matcher(featureId).matches()) { this.logger.error("Patient feature parser: ignoring term with non-HPO id [{}]", featureId); continue; } JSONObject featureJson = new JSONObject(); featureJson.put(ApiConfiguration.JSON_FEATURE_ID, featureId); featureJson.put(ApiConfiguration.JSON_FEATURE_OBSERVED, observedStatusToJSONString(patientFeature)); Map<String, ? extends FeatureMetadatum> metadata = patientFeature.getMetadata(); FeatureMetadatum ageOfOnset = metadata.get(ApplicationConfiguration.FEATURE_METADATA_AGEOFONSET); if (ageOfOnset != null) { featureJson.put(ApiConfiguration.JSON_FEATURE_AGE_OF_ONSET, ageOfOnset.getId()); } features.put(featureJson); } return features; }
/** * Converts and adds {@code features} to sets of present {@code retrievedPresentTerms terms} and absent * {@code retrievedAbsentTerms terms}. * * @param features a collection of {@link Feature} objects * @param retrievedPresentTerms a set of present {@link VocabularyTerm} objects * @param retrievedAbsentTerms a set of absent {@link VocabularyTerm} objects */ private void addTermsFromFeatures( @Nonnull final Collection<? extends Feature> features, @Nonnull final Set<VocabularyTerm> retrievedPresentTerms, @Nonnull final Set<VocabularyTerm> retrievedAbsentTerms) { for (final Feature feature : features) { final VocabularyTerm term = this.vocabularyManager.resolveTerm(feature.getValue()); if (term != null) { if (feature.isPresent()) { retrievedPresentTerms.add(term); } else { retrievedAbsentTerms.add(term); } } } } }
/** * Updates metadata for a {@code feature}. * * @param doc the {@link XWikiDocument} object for the patient * @param feature the {@link Feature} of interest * @param context the {@link XWikiContext} * @throws XWikiException if meta data cannot be updated */ private void updateMetaData( @Nonnull final XWikiDocument doc, @Nonnull final Feature feature, @Nonnull final XWikiContext context) throws XWikiException { @SuppressWarnings("unchecked") final Map<String, FeatureMetadatum> metadata = (Map<String, FeatureMetadatum>) feature.getMetadata(); if (!metadata.isEmpty() || !feature.getNotes().isEmpty()) { final BaseObject metaObject = doc.newXObject(FeatureMetadatum.CLASS_REFERENCE, context); metaObject.set(PhenoTipsFeature.META_PROPERTY_NAME, feature.getPropertyName(), context); metaObject.set(PhenoTipsFeature.META_PROPERTY_VALUE, feature.getValue(), context); metadata.forEach((type, metadatum) -> metaObject.set(type, metadatum.getId(), context)); metaObject.set("comments", feature.getNotes(), context); } }
/** * Updates categories for a {@code feature}. * * @param doc the {@link XWikiDocument} object for the patient * @param feature the {@link Feature} of interest * @param context the {@link XWikiContext} * @throws XWikiException if categories cannot be updated */ private void updateCategories( @Nonnull final XWikiDocument doc, @Nonnull final Feature feature, @Nonnull final XWikiContext context) throws XWikiException { final List<String> categories = feature.getCategories(); if (!categories.isEmpty()) { final BaseObject categoriesObject = doc.newXObject(PhenoTipsFeature.CATEGORY_CLASS_REFERENCE, context); categoriesObject.set(PhenoTipsFeature.META_PROPERTY_NAME, feature.getPropertyName(), context); categoriesObject.set(PhenoTipsFeature.META_PROPERTY_VALUE, feature.getValue(), context); categoriesObject.set(PhenoTipsFeature.META_PROPERTY_CATEGORIES, categories, context); } } }
@Override public String getName() { return this.access.isOpenAccess() && this.match != null ? this.match.getName() : null; }
/** * Saves data for provided {@code feature}, and returns its value. * * @param doc the {@link XWikiDocument} object for the patient * @param feature the {@link Feature} of interest * @param context the {@link XWikiContext} * @return the {@code feature} value */ private String saveFeatureAndGetValue( @Nonnull final XWikiDocument doc, @Nonnull final Feature feature, @Nonnull final XWikiContext context) { try { updateMetaData(doc, feature, context); updateCategories(doc, feature, context); } catch (final Exception e) { this.logger.error("Failed to update phenotypes: [{}]", e.getMessage()); } return feature.getValue(); }
JSONArray featuresJSON = new JSONArray(); for (Feature feature : features) { featuresJSON.add(feature.toJSON());
x = 0; if (!Boolean.valueOf(feature.isPresent()).equals(lastStatus)) { DataCell cell = new DataCell(feature.isPresent() ? this.translationManager.translate("yes") : this.translationManager.translate("no"), cell.addStyle(StyleOption.YES_NO_SEPARATOR); lastStatus = feature.isPresent(); cell.addStyle(lastStatus ? StyleOption.YES : StyleOption.NO); section.addCell(cell); section.addCell(new DataCell(feature.getName(), ++x, y, StyleOption.FEATURE_SEPARATOR)); section.addCell(new DataCell(feature.getId(), ++x, y, StyleOption.FEATURE_SEPARATOR)); ++y;