PatientEntityToDetailsTransformer implements Transformer<PatientEntity, PatientDetails> { @Override public PatientDetails transform(final PatientEntity patientEntity) { final PatientDetails patient = new PatientDetails(); String[] address = new String[]{StringUtils.trimToNull(patientEntity.getAddress1()), StringUtils.trimToNull(patientEntity.getAddress2()), StringUtils.trimToNull(patientEntity.getAddress3()), StringUtils.trimToNull(patientEntity.getAddress4()), StringUtils.trimToNull(patientEntity.getAddress5())}; final String name = patientEntity.getFirstName() + " " + patientEntity.getLastName(); final String patientId = patientEntity.getNhsNumber(); patient.setId(String.valueOf(patientEntity.getId())); patient.setName(name); patient.setTitle(patientEntity.getTitle()); patient.setForename(patientEntity.getFirstName()); patient.setSurname(patientEntity.getLastName()); patient.setGender(patientEntity.getGender()); patient.setDateOfBirth(patientEntity.getDateOfBirth()); patient.setNhsNumber(patientId); patient.setPasNumber(patientEntity.getPasNumber()); patient.setAddress(address); patient.setPostcode(patientEntity.getPostcode()); patient.setTelephone(patientEntity.getPhone()); patient.setPasNumber(patientEntity.getPasNumber()); patient.setLastUpdated(patientEntity.getLastUpdated()); patient.setRegistrationStartDateTime(patientEntity.getRegistrationStartDateTime()); patient.setRegistrationEndDateTime(patientEntity.getRegistrationEndDateTime()); patient.setRegistrationStatus(patientEntity.getRegistrationStatus()); patient.setRegistrationType(patientEntity.getRegistrationType()); patient.setMaritalStatus(patientEntity.getMaritalStatus()); patient.setManagingOrganization(patientEntity.getManagingOrganization()); PractitionerEntity gp = patientEntity.getPractitioner(); if (gp != null) { patient.setGpDetails(gp.getNamePrefix() + " " + gp.getNameGiven() + " " + gp.getNameFamily()); patient.setGpId(gp.getId()); } Date deceased = patientEntity.getDeceasedDateTime(); if (deceased != null) { patient.setDeceased(deceased); } patient.setSensitive(patientEntity.isSensitive()); populateTelecoms(patient, patientEntity); return patient; }  @Override PatientDetails transform(final PatientEntity patientEntity);  }
@Test public void shouldRemoveEmptyLinesFromAddressString() { final PatientEntity patientEntity = dummyPatientEntity(); patientEntity.setAddress1("line 1"); patientEntity.setAddress2(null); patientEntity.setAddress3("line 3"); patientEntity.setAddress5(""); patientEntity.setAddress5("line 5"); patientEntity.setPostcode("postcode"); final PatientDetails patientDetails = transformer.transform(patientEntity); assertNotNull(patientDetails); }
@Test public void shouldReturnEmptyMedicationListWhenMedicationSearchThrowsException() { assertNotNull(transformer.transform(dummyPatientEntity())); }