public String updatePatient(Patient patient, String parentId) throws ParentNotFoundException { String savedPatientId = allPatients.update(patient); Patient savedPatient = getPatientByMotechId(savedPatientId); Relationship relationship = allPatients.getMotherRelationship(savedPatient.getMrsPatient().getPerson()); if (relationship != null && StringUtils.isEmpty(parentId)) { allPatients.voidMotherChildRelationship(savedPatient.getMrsPatient().getPerson()); } if (relationship == null && StringUtils.isNotEmpty(parentId)) { createRelationship(parentId, savedPatientId); } if (relationship != null && StringUtils.isNotEmpty(parentId)) { updateRelationship(parentId, savedPatient, relationship); } return savedPatientId; }