@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 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; } }
@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; }
@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; }
/** * 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; } }
/** * 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; } }