/** * Copies an instance of {@link Consent} to a new instance. * * @param status the consent whose state is to be copied * @return an instance which is identical to the `from` instance */ @Override public Consent copy(ConsentStatus status) { Consent copy = new DefaultConsent( this.getId(), this.getLabel(), this.getDescription(), this.isRequired(), this.getFields()); copy.setStatus(status); return copy; } }
@Override public JSONObject toJSON() { JSONObject json = new JSONObject(); json.put(JSON_KEY_ID, this.getId()); json.put(JSON_KEY_LABEL, this.getLabel()); json.put(JSON_KEY_DESCRIPTION, this.getDescription()); json.put(JSON_KEY_ISREQUIRED, this.isRequired()); json.put(JSON_KEY_STATUS, this.getStatus().toString()); if (this.formFields != null) { JSONArray fields = new JSONArray(this.formFields); json.put(JSON_KEY_FIELDS, fields); } return json; }
/** * @param id consent id * @param label consent label/title (required) * @param description consent detailed description (optional, may be null) * @param required when true, no interaction with a document is allowed until this consent is granted * @param formFields form fields which are only available when this consent is granted */ public DefaultConsent(String id, String label, String description, boolean required, List<String> formFields) { this.id = id; this.label = label; this.description = processDescription(description); this.required = required; this.formFields = (formFields == null) ? null : Collections.unmodifiableList(formFields); validate(); }
/** * A constructor from JSON representation. * * @param consentJSON JSON in the format produced by toJSON() */ public DefaultConsent(JSONObject consentJSON) { this.id = consentJSON.optString(JSON_KEY_ID); this.label = consentJSON.optString(JSON_KEY_LABEL); this.description = processDescription(consentJSON.optString(JSON_KEY_DESCRIPTION)); this.required = consentJSON.optBoolean(JSON_KEY_ISREQUIRED); setStatus(ConsentStatus.fromString(consentJSON.optString(JSON_KEY_ISREQUIRED))); JSONArray fields = consentJSON.optJSONArray(JSON_KEY_FIELDS); if (fields == null) { this.formFields = null; } else { this.formFields = new LinkedList<>(); for (Object field : fields) { this.formFields.add((String) field); } } validate(); }
@Override public Set<Consent> fromJSON(JSONArray consentsJSON) { if (consentsJSON == null) { return null; } Set<Consent> result = new LinkedHashSet<>(); for (int i = 0; i < consentsJSON.length(); i++) { JSONObject consentJSON = consentsJSON.optJSONObject(i); if (consentJSON != null) { result.add(new DefaultConsent(consentJSON)); } } return result; } }
@Override public boolean isGranted() { return this.getStatus() == ConsentStatus.YES; }
this.description = processDescription(consentJSON.optString(JSON_KEY_DESCRIPTION)); this.required = consentJSON.optBoolean(JSON_KEY_ISREQUIRED); setStatus(ConsentStatus.fromString(consentJSON.optString(JSON_KEY_STATUS))); JSONArray dFields = consentJSON.optJSONArray(JSON_KEY_DATAFIELDS); JSONArray fields = consentJSON.optJSONArray(JSON_KEY_FIELDS); validate();
@Override public Set<Consent> fromJSON(JSONArray consentsJSON) { if (consentsJSON == null) { return null; } Set<Consent> result = new LinkedHashSet<>(); for (int i = 0; i < consentsJSON.length(); i++) { JSONObject consentJSON = consentsJSON.optJSONObject(i); if (consentJSON != null) { result.add(new DefaultConsent(consentJSON)); } } return result; } }
@Override public boolean isGranted() { return this.getStatus() == ConsentStatus.YES; }
/** * Copies an instance of {@link Consent} to a new instance. * * @param status the consent whose state is to be copied * @return an instance which is identical to the `from` instance */ @Override public Consent copy(ConsentStatus status) { Consent copy = new DefaultConsent( this.getId(), this.getLabel(), this.getDescription(), this.isRequired(), this.getDataFields(), this.getFields()); copy.setStatus(status); return copy; } }
@Override public JSONObject toJSON() { JSONObject json = new JSONObject(); json.put(JSON_KEY_ID, this.getId()); json.put(JSON_KEY_LABEL, this.getLabel()); json.put(JSON_KEY_DESCRIPTION, this.getDescription()); json.put(JSON_KEY_ISREQUIRED, this.isRequired()); json.put(JSON_KEY_STATUS, this.getStatus().toString()); if (this.dataFields != null) { JSONArray dFields = new JSONArray(this.dataFields); json.put(JSON_KEY_DATAFIELDS, dFields); } if (this.formFields != null) { JSONArray fields = new JSONArray(this.formFields); json.put(JSON_KEY_FIELDS, fields); } return json; }
/** * @param id consent id * @param label consent label/title (required) * @param description consent detailed description (optional, may be null) * @param required when true, no interaction with a document is allowed until this consent is granted * @param dataFields a list of values present in the UI Extensions * @param formFields form fields which are only available when this consent is granted */ public DefaultConsent(String id, String label, String description, boolean required, List<String> dataFields, List<String> formFields) { this.id = id; this.label = label; this.description = processDescription(description); this.required = required; this.dataFields = (dataFields == null) ? null : Collections.unmodifiableList(dataFields); this.formFields = (formFields == null) ? null : Collections.unmodifiableList(formFields); validate(); }
@SuppressWarnings("unchecked") private Consent fromXWikiConsentConfiguration(BaseObject xwikiConsent, XWikiDocument configDoc) { try { String id = xwikiConsent.getStringValue("id"); String label = cleanDescription( configDoc.display("label", RENDERING_MODE, xwikiConsent, this.contextProvider.get()), true); if (label == null || label.length() == 0) { label = id + " " + this.translationManager.translate("PhenoTips.PatientConsentManager_emptyLabelPostfix"); } String description = cleanDescription( configDoc.display("description", RENDERING_MODE, xwikiConsent, this.contextProvider.get()), false); boolean required = intToBool(xwikiConsent.getIntValue("required")); boolean affectsFields = intToBool(xwikiConsent.getIntValue("affectsFields")); List<String> formFields = null; if (affectsFields) { formFields = xwikiConsent.getListValue("fields"); } return new DefaultConsent(id, label, description, required, formFields); } catch (Exception ex) { this.logger.error("A patient consent is improperly configured: {}", ex.getMessage()); } return null; }
@SuppressWarnings("unchecked") private Consent fromXWikiConsentConfiguration(BaseObject xwikiConsent, XWikiDocument configDoc) { try { String id = xwikiConsent.getStringValue("id"); String label = cleanDescription( configDoc.display("label", RENDERING_MODE, xwikiConsent, this.contextProvider.get()), true); if (label == null || label.length() == 0) { label = id + " " + this.translationManager.translate("phenotips.consents.label.empty"); } String description = cleanDescription( configDoc.display("description", RENDERING_MODE, xwikiConsent, this.contextProvider.get()), false); boolean required = intToBool(xwikiConsent.getIntValue("required")); boolean affectsFields = intToBool(xwikiConsent.getIntValue("affectsFields")); List<String> formFields = null; List<String> dataFields = null; if (affectsFields) { dataFields = new LinkedList<>(); formFields = xwikiConsent.getListValue(FIELDS); fetchConsentFields(formFields, dataFields); } return new DefaultConsent(id, label, description, required, dataFields, formFields); } catch (Exception ex) { this.logger.error("A patient consent is improperly configured: {}", ex.getMessage()); } return null; }