@Override public boolean forceRemoveAllMembers(Family family, User updatingUser) { if (!this.authorizationService.hasAccess(updatingUser, Right.EDIT, family.getDocumentReference())) { return false; } try { for (Patient patient : family.getMembers()) { // remove the member without updating family document (use "batch mode") // since we don't care about it as it will be removed anyway this.removeMember(family, patient, updatingUser, true); } return true; } catch (PTException ex) { this.logger.error("Failed to unlink all patients for the family [{}]: {}", family.getId(), ex.getMessage()); return false; } }
@Override public JSONObject toJSON() { return this.family.toJSON(); }
/** * returns information about the family in JSON format. * * @param family family * @return JSON object with family information */ public JSONObject toJSON(Family family) { JSONObject familyJSON = new JSONObject(); familyJSON.put(FAMILY_ID, family.getId()); familyJSON.put(FAMILY_EXTERNAL_ID, family.getExternalId()); familyJSON.put(FAMILY_HAS_SENSITIVE_DATA, family.containsSensitiveData()); familyJSON.put(FAMILY_SENSITIVE_DATA_MESSAGE, family.getWarningMessage()); JSONArray patientsJSONArray = new JSONArray(); for (Patient patient : family.getMembers()) { JSONObject patientJSON = getPatientInformationAsJSON(patient); patientsJSONArray.put(patientJSON); } familyJSON.put(FAMILY_MEMBERS, patientsJSONArray); return familyJSON; }
/** * Create a new search result from a family and permissions. * * @param family contains the details of the family found * @param requiredPermissions permissions to extract the URL from */ public FamilySearchResult(Family family, String requiredPermissions) { this.externalId = family.getExternalId(); this.id = family.getId(); this.reference = family.getDocumentReference().toString(); this.url = family.getURL(requiredPermissions); setBasicDescription(); }
@Override public JSONObject toJSON() { JSONObject response = new JSONObject(); response.put("family", this.family.toJSON()); // a new family may not have a pedigree Pedigree pedigree = this.family.getPedigree(); response.put("pedigree", (pedigree == null) ? null : pedigree.getData()); return response; }
private void checkIfPatientCanBeAddedToFamily(Family family, Patient patient, User updatingUser) throws PTException { // check rights if (!this.authorizationService.hasAccess(updatingUser, Right.EDIT, family.getDocumentReference())) { throw new PTNotEnoughPermissionsOnFamilyException(Right.EDIT, family.getId()); } if (!this.authorizationService.hasAccess(updatingUser, Right.EDIT, patient.getDocument())) { throw new PTNotEnoughPermissionsOnPatientException(Right.EDIT, patient.getId()); } // check for logical problems: patient in another family Family familyForLinkedPatient = this.getFamilyForPatient(patient); if (familyForLinkedPatient != null && !familyForLinkedPatient.getId().equals(family.getId())) { throw new PTPatientAlreadyInAnotherFamilyException(patient.getId(), familyForLinkedPatient.getId()); } }
List<String> members = family.getMembersIds(); if (members.contains(patientLinkString(patient))) { this.logger.error("Patient [{}] already a member of the same family, not adding", patientId); if (!this.setFamilyReference(patientDocument, family.getXDocument(), context)) { throw new PTInternalErrorException(); if (!savePatientDocument(patientDocument, "added to family " + family.getId(), context)) { throw new PTInternalErrorException(); Pedigree pedigree = family.getPedigree(); if (pedigree != null) { pedigree.addLink(patientId); if (!this.setPedigreeObject(family, pedigree, context)) { this.logger.error("Could not add patient [{}] to pedigree in the family [{}]", patientId, family.getId()); throw new PTInternalErrorException(); BaseObject familyObject = family.getXDocument().getXObject(Family.CLASS_REFERENCE); familyObject.set(PhenotipsFamily.FAMILY_MEMBERS_FIELD, members, context);
@Override public DocumentReference getDocument() { return this.family.getDocumentReference(); }
@Override public Response getFamily(String id) { this.logger.warn("Retrieving family record [{}] via REST", id); Family family = this.repository.get(id); if (family == null) { this.logger.warn(NO_SUCH_FAMILY_ERROR_MESSAGE, id); return Response.status(Status.NOT_FOUND).build(); } User currentUser = this.users.getCurrentUser(); if (!this.access.hasAccess(currentUser, Right.VIEW, family.getDocumentReference())) { this.logger.error("View access denied to user [{}] on family record [{}]", currentUser, id); return Response.status(Status.FORBIDDEN).build(); } JSONObject json = family.toJSON(); json.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return Response.ok(json, MediaType.APPLICATION_JSON_TYPE).build(); }
@Override public synchronized boolean deleteFamily(Family family, User updatingUser, boolean deleteAllMembers) { if (!canDeleteFamily(family, updatingUser, deleteAllMembers, false)) { return false; } if (deleteAllMembers) { for (Patient patient : family.getMembers()) { if (!this.patientRepository.delete(patient)) { this.logger.error("Failed to delete patient [{}] - deletion of family [{}] aborted", patient.getId(), family.getId()); return false; } } } else if (!this.forceRemoveAllMembers(family, updatingUser)) { return false; } try { XWikiContext context = this.provider.get(); XWiki xwiki = context.getWiki(); xwiki.deleteDocument(xwiki.getDocument(family.getDocument(), context), context); } catch (XWikiException ex) { this.logger.error("Failed to delete family document [{}]: {}", family.getId(), ex.getMessage()); return false; } return true; }
List<String> members = family.getMembersIds(); if (!members.contains(patientLinkString(patient))) { this.logger.error("Can't remove patient [{}] from framily [{}]: patient not a member of the family", patientId, family.getId()); throw new PTPatientNotInFamilyException(patientId); Pedigree pedigree = family.getPedigree(); if (pedigree != null) { pedigree.removeLink(patientId); if (!this.setPedigreeObject(family, pedigree, context)) { this.logger.error("Could not remove patient [{}] from pedigree from the family [{}]", patientId, family.getId()); throw new PTInternalErrorException(); BaseObject familyObject = family.getDocument().getXObject(Family.CLASS_REFERENCE); familyObject.set(PhenotipsFamily.FAMILY_MEMBERS_FIELD, members, context);
private synchronized boolean saveFamilyDocument(Family family, String documentHistoryComment, XWikiContext context) { try { family.getXDocument().setAuthorReference(context.getUserReference()); context.getWiki().saveDocument(family.getXDocument(), documentHistoryComment, context); } catch (XWikiException e) { this.logger.error("Error saving family [{}] document for commit {}: [{}]", family.getId(), documentHistoryComment, e.getMessage()); return false; } return true; }
@Override public String getId() { return this.family.getId(); }
@Override public List<Patient> getMembers() { List<Patient> members = this.family.getMembers(); return members.stream() .map(SecurePatient::new) .collect(Collectors.toCollection(LinkedList::new)); }
@Override public synchronized boolean delete(final Family family, boolean deleteAllMembers) { // TODO: Should there be a SecureFamilyRepository to perform these checks (similar to SecurePatientRepository)? final User currentUser = this.userManager.getCurrentUser(); if (!canDeleteFamily(family, currentUser, deleteAllMembers, false)) { return false; } if (deleteAllMembers) { for (Patient patient : family.getMembers()) { if (!this.patientRepository.delete(patient)) { this.logger.error("Failed to delete patient [{}] - deletion of family [{}] aborted", patient.getId(), family.getId()); return false; } } } else if (!this.forceRemoveAllMembers(family, currentUser)) { return false; } return super.delete(family); }
List<String> members = family.getMembersIds(); if (members.contains(patientLinkString(patient))) { this.logger.error("Patient [{}] already a member of the same family, not adding", patientId); if (!this.setFamilyReference(patientDocument, family.getDocument(), context)) { throw new PTInternalErrorException(); if (!savePatientDocument(patientDocument, "added to family " + family.getId(), context)) { throw new PTInternalErrorException(); BaseObject familyObject = family.getDocument().getXObject(Family.CLASS_REFERENCE); familyObject.set(PhenotipsFamily.FAMILY_MEMBERS_FIELD, members, context);
private synchronized boolean saveFamilyDocument(Family family, String documentHistoryComment, XWikiContext context) { try { family.getDocument().setAuthorReference(context.getUserReference()); context.getWiki().saveDocument(family.getDocument(), documentHistoryComment, context); } catch (XWikiException e) { this.logger.error("Error saving family [{}] document for commit {}: [{}]", family.getId(), documentHistoryComment, e.getMessage()); return false; } return true; }
List<String> oldMembers = family.getMembersIds(); boolean firstPedigree = (family.getPedigree() == null); if (firstPedigree && StringUtils.isEmpty(family.getExternalId())) {
/** * For every family member, read users and groups that have either view or edit edit access on the patient, then * gives the sam elevel of access on the family for those users and groups. After performing this method, if p is a * member of the family, and x has level y access on p, x has level y access on the family. The user who is the * owner of the family always has full access to the family. Note that the document is not saved to disk, changes * are only made for the provided Family object and its in-memory copy of the corresponding XWiki document. * * @param family to update permissions * @param context XWiki context to be used. The documnt will not be saved to disk, only changes in memory for the * family document given will be made */ public void updatePermissions(Family family, XWikiContext context) { XWiki wiki = context.getWiki(); List<Patient> members = family.getMembers(); this.updatePermissionsForOneRightLevel(VIEW_RIGHTS, members, family.getDocument(), wiki, context); // setting view-edit rights after view rights makes sure if a user has edit rights on one patient // and view rights on another the user still gets edit permissions for the family this.updatePermissionsForOneRightLevel(VIEWEDIT_RIGHTS, members, family.getDocument(), wiki, context); DocumentReference creatorReference = family.getDocument().getCreatorReference(); this.setOwnerPermissionsForUser(creatorReference == null ? "" : creatorReference.toString(), family.getDocument(), context); }
@Override public Map<String, Map<String, String>> getMedicalReports() { return this.family.getMedicalReports(); }