/** * Creates an empty sorted set, where {@link VocabularyTerm} objects are sorted by the natural order of their name. * * @return an empty sorted set */ private Set<VocabularyTerm> newSortedSet() { return new TreeSet<>((o1, o2) -> { final String name1 = o1.getName() != null ? o1.getName() : o1.getId(); final String name2 = o2.getName() != null ? o2.getName() : o2.getId(); return name1.compareTo(name2); }); } }
/** * Returns the {@link VocabularyTerm#getName() term name} if it is specified, otherwise returns * {@link VocabularyTerm#getId()}. * * @param term the {@link VocabularyTerm} of interest * @return the name of the term if specified, the ID otherwise */ private String getTermName(@Nonnull final VocabularyTerm term) { final String name = term.getName(); return StringUtils.isNotBlank(name) ? name : term.getId(); } }
@Override public String getName() { if (this.name != null) { return this.name; } try { VocabularyManager vm = ComponentManagerRegistry.getContextComponentManager().getInstance(VocabularyManager.class); VocabularyTerm term = vm.resolveTerm(this.id); if (term != null && StringUtils.isNotEmpty(term.getName())) { this.name = term.getName(); return this.name; } } catch (ComponentLookupException ex) { // Shouldn't happen } return this.id; }
@Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { PatientData<List<VocabularyTerm>> data = patient.getData(DATA_NAME); if (data == null) { return; } Iterator<Entry<String, List<VocabularyTerm>>> iterator = data.dictionaryIterator(); while (iterator.hasNext()) { Entry<String, List<VocabularyTerm>> datum = iterator.next(); if (selectedFieldNames == null || selectedFieldNames.contains(datum.getKey())) { List<VocabularyTerm> terms = datum.getValue(); if (terms == null || terms.isEmpty()) { if (selectedFieldNames != null && selectedFieldNames.contains(datum.getKey())) { json.put(datum.getKey(), new JSONArray()); } continue; } JSONArray elements = new JSONArray(); for (VocabularyTerm term : terms) { JSONObject element = new JSONObject(); element.put(ID_NAME, term.getId()); element.put("label", term.getName()); elements.put(element); } json.put(datum.getKey(), elements); } } }
@Override public String getName() { if (this.name != null) { return this.name; } try { VocabularyManager vm = ComponentManagerRegistry.getContextComponentManager().getInstance(VocabularyManager.class); VocabularyTerm term = vm.resolveTerm(this.id); if (term != null && StringUtils.isNotEmpty(term.getName())) { this.name = term.getName(); return this.name; } } catch (ComponentLookupException ex) { // Shouldn't happen } return this.id; }
@Override public void writeJSON(Patient patient, JSONObject json, Collection<String> selectedFieldNames) { PatientData<List<VocabularyTerm>> data = patient.getData(DATA_NAME); if (data == null) { return; } Iterator<Entry<String, List<VocabularyTerm>>> iterator = data.dictionaryIterator(); while (iterator.hasNext()) { Entry<String, List<VocabularyTerm>> datum = iterator.next(); if (selectedFieldNames == null || selectedFieldNames.contains(datum.getKey())) { List<VocabularyTerm> terms = datum.getValue(); if (terms == null || terms.isEmpty()) { if (selectedFieldNames != null && selectedFieldNames.contains(datum.getKey())) { json.put(datum.getKey(), new JSONArray()); } continue; } JSONArray elements = new JSONArray(); for (VocabularyTerm term : terms) { JSONObject element = new JSONObject(); element.put(ID_NAME, term.getId()); element.put("label", term.getName()); elements.put(element); } json.put(datum.getKey(), elements); } } }
@Override public JSONObject toJSON() { JSONObject json = new JSONObject(); for (Map.Entry<String, ? extends Object> field : getEntrySet()) { addAsCorrectType(json, field.getKey(), field.getValue()); } json.put(TRANSLATED_NAME_KEY, getTranslatedName()); json.put(TRANSLATED_DESCRIPTION_KEY, getTranslatedDescription()); if (this.parents != null && !this.parents.isEmpty()) { JSONArray parentsJson = new JSONArray(); for (VocabularyTerm parent : this.parents) { JSONObject parentJSON = new JSONObject(); parentJSON.put(ID_KEY, parent.getId()); parentJSON.put(NAME_KEY, parent.getName()); parentJSON.put(TRANSLATED_NAME_KEY, parent.getTranslatedName()); parentsJson.put(parentJSON); } json.put("parents", parentsJson); } return json; }
String title = term.getName(); title = title.replace("Abnormality of the ", "").replace("Abnormality of ", ""); title = WordUtils.capitalizeFully(title);
/** * Builds a {@link JSONArray} of JSON representations of term {@link VocabularyTerm} objects. * * @return a {@link JSONArray} of term {@link VocabularyTerm} objects */ private JSONArray buildPhenotypesJSON() { final JSONArray json = new JSONArray(); for (final VocabularyTerm term : getTerms()) { final JSONObject termSummary = new JSONObject(); termSummary.put(ID, term.getId()); termSummary.putOpt(NAME, term.getName()); termSummary.putOpt(NAME_TRANSLATED, term.getTranslatedName()); json.put(termSummary); } return json; }
String title = term.getName(); title = title.replace("Abnormality of the ", "").replace("Abnormality of ", ""); title = WordUtils.capitalizeFully(title);
for (String category : this.categories) { VocabularyTerm term = vm.resolveTerm(category); if (term != null && StringUtils.isNotEmpty(term.getName())) { JSONObject categoryObject = new JSONObject(); categoryObject.put(ID_JSON_KEY_NAME, term.getId()); categoryObject.put(NAME_JSON_KEY_NAME, term.getName()); categoriesList.put(categoryObject);
for (String category : this.categories) { VocabularyTerm term = vm.resolveTerm(category); if (term != null && StringUtils.isNotEmpty(term.getName())) { JSONObject categoryObject = new JSONObject(); categoryObject.put(ID_JSON_KEY_NAME, term.getId()); categoryObject.put(NAME_JSON_KEY_NAME, term.getName()); categoriesList.put(categoryObject);
if (pattern.matcher(term.getName().substring(0, 1)).matches()) { continue;
@Override public VocabularyTermSummary createVocabularyTermRepresentation(VocabularyTerm term) { VocabularyTermSummary rep = new VocabularyTermSummary(); rep.withId(term.getId()); rep.withName(term.getName()); JSONObject jsonObject = term.toJSON(); String symbolKey = "symbol"; if (jsonObject != null && jsonObject.opt(symbolKey) != null) { rep.withSymbol(jsonObject.get(symbolKey).toString()); } rep.withDescription(term.getDescription()); return rep; } }
protected String generateFormField(String[] fieldNames) { if (fieldNames[NO] != null) { return String.format( "<div class='%s%s'><span class='yes-no-picker'>%s%s%s</span> <span title='%s'>%s</span></div>", DEFAULT_CSS_CLASS, this.expandable ? EXPANDABLE_CSS_CLASS : "", generateCheckbox("none", this.value, "", (!isSelected(YES) && !isSelected(NO)), "na", "NA"), generateCheckbox(fieldNames[YES], this.value, this.hint, isSelected(YES), "yes", "Y"), generateCheckbox(fieldNames[NO], this.value, this.hint, isSelected(NO), "no", "N"), this.term == null ? this.title + "\n(custom term)" : (this.term.getName() + (StringUtils.isNotBlank(this.term.getDescription()) ? "\n" + StringEscapeUtils.escapeXml10(this.term.getDescription()) : "")), generateLabel(fieldNames[YES] + '_' + this.value, "yes-no-picker-label", this.title)); } else { return generateCheckbox(fieldNames[YES], this.value, this.hint, isSelected(YES), DEFAULT_CSS_CLASS + (this.expandable ? EXPANDABLE_CSS_CLASS : ""), this.title); } }
protected String generateFormField(String[] fieldNames) { if (fieldNames[NO] != null) { return String.format( "<div class='%s%s'><span class='yes-no-picker'>%s%s%s</span> <span title='%s'>%s</span></div>", DEFAULT_CSS_CLASS, this.expandable ? EXPANDABLE_CSS_CLASS : "", generateCheckbox("none", this.value, "", (!isSelected(YES) && !isSelected(NO)), "na", "NA"), generateCheckbox(fieldNames[YES], this.value, this.hint, isSelected(YES), "yes", "Y"), generateCheckbox(fieldNames[NO], this.value, this.hint, isSelected(NO), "no", "N"), this.term == null ? this.title + "\n(custom term)" : (this.term.getName() + (StringUtils.isNotBlank(this.term.getDescription()) ? "\n" + StringEscapeUtils.escapeXml10(this.term.getDescription()) : "")), generateLabel(fieldNames[YES] + '_' + this.value, "yes-no-picker-label", this.title)); } else { return generateCheckbox(fieldNames[YES], this.value, this.hint, isSelected(YES), DEFAULT_CSS_CLASS + (this.expandable ? EXPANDABLE_CSS_CLASS : ""), this.title); } }