@Override public String getId() { return this.family.getId(); }
@Override public Map<String, Object> provideMetadata(PrimaryEntity entity) { if (entity instanceof Patient) { Family f = this.familyRepository.getFamilyForPatient((Patient) entity); if (f != null) { return Collections.singletonMap("family", f.getId()); } } return Collections.emptyMap(); } }
/** * Deletes a family record, modifying all member patient records to reflect the change. No patient records are * deleted. * * @param family the family record to delete * @return {@code true} if successful; {@code false} if the user does not have the right to delete the family record * or the deletion fails */ public boolean delete(Family family) { return deleteFamily(family.getId(), false); }
/** * 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_WARNING, 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; }
/** * 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; }
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()); } }
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.getDocumentReference())) { 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()); } }
@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 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; } }
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 synchronized Family create(final DocumentReference creator) { try { final XWikiContext context = this.xcontextProvider.get(); final Family family = super.create(creator); final XWikiDocument doc = family.getXDocument(); if (doc.getXObject(Owner.CLASS_REFERENCE) == null) { // add owner reference to family - only if no owner already exist, e.g. from FamilyTemplate doc.newXObject(Owner.CLASS_REFERENCE, context).set(OWNER, creator == null ? StringUtils.EMPTY : this.entitySerializer.serialize(creator), context); } // Adding identifier to family doc.getXObject(Family.CLASS_REFERENCE).setLongValue(IDENTIFIER, Integer.parseInt(family.getId().replaceAll("\\D++", StringUtils.EMPTY))); context.getWiki().saveDocument(doc, context); return family; } catch (Exception ex) { this.logger.warn("Failed to create family: {}", ex.getMessage(), ex); return null; } }
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; }
/** * Create a new search result from a family and permissions. * * @param family contains the details of the family found * @param requiredPermission permission to extract the URL from */ public FamilySearchResult(Family family, String requiredPermission) { this.externalId = family.getExternalId(); this.id = family.getId(); this.reference = family.getDocumentReference().toString(); this.url = family.getURL(requiredPermission); setBasicDescription(); }
/** * 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(); }
private void checkIfPatientCanBeRemovedFromFamily(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.getDocumentReference())) { throw new PTNotEnoughPermissionsOnPatientException(Right.EDIT, patient.getId()); } }
@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); }
private void checkIfPatientCanBeRemovedFromFamily(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()); } }
private boolean setPedigreeObject(Family family, Pedigree pedigree, XWikiContext context) { if (pedigree == null) { this.logger.error("Can not set NULL pedigree for family [{}]", family.getId()); return false; } BaseObject pedigreeObject = family.getDocument().getXObject(Pedigree.CLASS_REFERENCE); pedigreeObject.set(Pedigree.IMAGE, ((pedigree == null) ? "" : pedigree.getImage(null)), context); pedigreeObject.set(Pedigree.DATA, ((pedigree == null) ? "" : pedigree.getData().toString()), context); // update proband ID every time pedigree is changed BaseObject familyClassObject = family.getDocument().getXObject(Family.CLASS_REFERENCE); if (familyClassObject != null) { String probandId = pedigree.getProbandId(); if (!StringUtils.isEmpty(probandId)) { Patient patient = this.patientRepository.get(probandId); familyClassObject.setStringValue("proband_id", (patient == null) ? "" : patient.getDocument() .toString()); } else { familyClassObject.setStringValue("proband_id", ""); } } return true; }
private void checkValidity(Family family, List<String> newMembers, User updatingUser) throws PTException { // Checks that current user has edit permissions on family if (!this.authorizationService.hasAccess(updatingUser, Right.EDIT, family.getDocumentReference())) { throw new PTNotEnoughPermissionsOnFamilyException(Right.EDIT, family.getId()); } String duplicateID = this.findDuplicate(newMembers); if (duplicateID != null) { throw new PTPedigreeContainesSamePatientMultipleTimesException(duplicateID); } // Check if every new member can be added to the family if (newMembers != null) { for (String patientId : newMembers) { Patient patient = this.patientRepository.get(patientId); checkIfPatientCanBeAddedToFamily(family, patient, updatingUser); } } }
private void checkValidity(Family family, List<String> newMembers, User updatingUser) throws PTException { // Checks that current user has edit permissions on family if (!this.authorizationService.hasAccess(updatingUser, Right.EDIT, family.getDocumentReference())) { throw new PTNotEnoughPermissionsOnFamilyException(Right.EDIT, family.getId()); } String duplicateID = this.findDuplicate(newMembers); if (duplicateID != null) { throw new PTPedigreeContainesSamePatientMultipleTimesException(duplicateID); } // Check if every new member can be added to the family if (newMembers != null) { for (String patientId : newMembers) { Patient patient = this.patientRepository.get(patientId); checkIfPatientCanBeAddedToFamily(family, patient, updatingUser); } } }