List<EndOfLifeCareDocumentFormalCarer> formalCarers = new ArrayList<EndOfLifeCareDocumentFormalCarer>();
for (EOLPatientRelationships relationshipList : relationships) {
for (RelatedPersonDetails personDetails : relationshipList.getRelationships().getRelatedPerson()) {
PatientRelationshipParticipantRole person = personDetails.getParticipant();
if (person.getPersonRole() != null) {
JobRoleName role = (JobRoleName)HelperUtils.safelyMapCodedValueToVocabEntry(
person.getPersonRole(), JobRoleName._NR0010, "RelatedPersonJobRole", parseExceptions, true);
JobRoleName associatedRole = null;
if (person.getAssociatedJobRole() != null) {
associatedRole = (JobRoleName)HelperUtils.safelyMapCodedValueToVocabEntry(
person.getAssociatedJobRole(), JobRoleName._NR0010, "RelatedPersonAssociatedJobRole", parseExceptions, true);
}
// Main informal carer (name, tel)
if (role.sameAs(JobRoleName._MainInformalCarer)) {
fields.setMainInformalCarerName(person.getPersonName());
fields.setMainInformalCarerTel(TemplateParsingHelper.getTel(person, "MainInformalCarerTel"));
}
// Usual GP (name, practice id, practice name, address, tel, fax)
else if (role.sameAs(JobRoleName._GeneralMedicalPractitioner)) {
fields.setUsualGPName(person.getPersonName());
fields.setUsualGPTelephone(TemplateParsingHelper.getTel(person, "UsualGPTelephone"));
fields.setUsualGPFax(TemplateParsingHelper.getFax(person, "UsualGPFax"));
fields.setUsualGPAddress(TemplateParsingHelper.getAddress(person));
fields.setUsualGPODSCode(TemplateParsingHelper.getODSID(person, "UsualGPODSCode", parseExceptions));
fields.setUsualGPOrgName(TemplateParsingHelper.getOrgName(person));
}
// Key Worker (id, name, role, org id, org name, address, tel)
else if (role.sameAs(JobRoleName._KeyWorker)) {
fields.setKeyWorkerName(person.getPersonName());
fields.setKeyWorkerSDSID(TemplateParsingHelper.getSDSID(person, "KeyWorkerID", parseExceptions));
fields.setKeyWorkerTelephone(TemplateParsingHelper.getTel(person, "KeyWorkerTelephone"));
fields.setKeyWorkerAddress(TemplateParsingHelper.getAddress(person));
fields.setKeyWorkerOrgID(TemplateParsingHelper.getODSID(person, "KeyWorkerOrgID", parseExceptions));
fields.setKeyWorkerOrgName(TemplateParsingHelper.getOrgName(person));
fields.setKeyWorkerJobRole(associatedRole);
}
// Formal Carers 0..N (name, role, tel)
else if (role.sameAs(JobRoleName._FormalCarer)) {
EndOfLifeCareDocumentFormalCarer carerentry = new EndOfLifeCareDocumentFormalCarer();
carerentry.setName(person.getPersonName());
carerentry.setTelephone(TemplateParsingHelper.getTel(person, "FormalCarerTelephone"));
carerentry.setRole(associatedRole);
formalCarers.add(carerentry);
}
// Lasting power of attorney (name, tel)
// We only need to populate this if it hasn't already been populated from
// the actual LPA section in the document (which it should have been!)
else if (role.sameAs(JobRoleName._LPAwithauthority)) {
if (fields.getLPAName() == null) {
fields.setLPAName(person.getPersonName());
}
if (fields.getLPATelephone() == null) {
fields.setLPATelephone(TemplateParsingHelper.getTel(person, "LPATelephone"));
}
}
// Additional person to involve in decisions (name, tel)
else if (role.sameAs(JobRoleName._Additionalpersontobeinvolvedindecisions)) {
if (fields.getAdditionalPersonToInvolve() != null && fields.getAdditionalPersonToInvolve2() != null) {
// We already appear to have two additional people, so we will have to assum this
// is a third one, and ignore it
} else if (fields.getAdditionalPersonToInvolve() == null) {
// First additional person to involve in decisions (name, tel)
fields.setAdditionalPersonToInvolve(person.getPersonName());
fields.setAdditionalPersonToInvolveTel(TemplateParsingHelper.getTel(person, "AdditionalPersonToInvolveTel"));
} else {
// Second additional person to involve in decisions (name, tel)
fields.setAdditionalPersonToInvolve2(person.getPersonName());
fields.setAdditionalPersonToInvolve2Tel(TemplateParsingHelper.getTel(person, "AdditionalPersonToInvolve2Tel"));
}
}
// Senior Responsible Clinician (name, id, role, org name, org id, add, tel)
// We only need to populate this if it hasn't already been populated from as the author
// of the DNACPR section in the document (which it may have been if there is a DNACPR decision recorded)
else if (role.sameAs(JobRoleName._SeniorResponsibleClinician)) {
fields.setSeniorResponsibleClinicianName(person.getPersonName());
fields.setSeniorResponsibleClinicianSDSID(TemplateParsingHelper.getSDSID(person, "SeniorResponsibleClinicianSDSID", parseExceptions));
fields.setSeniorResponsibleClinicianTelephone(TemplateParsingHelper.getTel(person, "SeniorResponsibleClinicianTelephone"));
fields.setSeniorResponsibleClinicianAddress(TemplateParsingHelper.getAddress(person));
fields.setSeniorResponsibleClinicianORGID(TemplateParsingHelper.getODSID(person, "SeniorResponsibleClinicianORGID", parseExceptions));
fields.setSeniorResponsibleClinicianORGName(TemplateParsingHelper.getOrgName(person));