PatientProfileDtoToPatientMapper implements
		DtoToDomainEntityMapper<PatientProfileDto, Patient> { @Override public Patient map(PatientProfileDto patientDto) { Patient patient = null; if (patientDto.getUsername() == null) { if (patientDto.getId() != null) { patient = patientRepository.findOne(patientDto.getId()); } else { patient = new Patient(); } } else { patient = patientRepository .findByUsername(patientDto.getUsername()); } patient.setFirstName(patientDto.getFirstName()); patient.setLastName(patientDto.getLastName()); patient.setEmail(patientDto.getEmail()); patient.setBirthDay(patientDto.getBirthDate()); set(patient::setSocialSecurityNumber, patientDto::getSocialSecurityNumber); if (StringUtils.hasText(patientDto.getTelephoneTelephone())) { Telephone telephone = new Telephone(); telephone.setTelephone(patientDto.getTelephoneTelephone()); patient.setTelephone(telephone); } else { patient.setTelephone(null); } if (StringUtils.hasText(patientDto.getAddressStreetAddressLine()) || StringUtils.hasText(patientDto.getAddressCity()) || StringUtils.hasText(patientDto.getAddressStateCode()) || StringUtils.hasText(patientDto.getAddressPostalCode())) { Address address = new Address(); address.setStreetAddressLine(patientDto .getAddressStreetAddressLine()); address.setCity(patientDto.getAddressCity()); address.setStateCode(stateCodeRepository.findByCode(patientDto .getAddressStateCode())); address.setPostalCode(patientDto.getAddressPostalCode()); address.setCountryCode(countryCodeRepository.findByCode(patientDto .getAddressCountryCode())); patient.setAddress(address); } else { patient.setAddress(null); } if (StringUtils.hasText(patientDto.getAdministrativeGenderCode())) { AdministrativeGenderCode administrativeGenderCode = administrativeGenderCodeRepository .findByCode(patientDto.getAdministrativeGenderCode()); patient.setAdministrativeGenderCode(administrativeGenderCode); } else { patient.setAdministrativeGenderCode(null); } if (patientDto.getLanguageCode() != null && StringUtils.hasText(patientDto.getLanguageCode().getCode())) { patient.setLanguageCode(languageCodeRepository .findByCode(patientDto.getLanguageCode().getCode())); } else { patient.setLanguageCode(null); } if (patientDto.getMaritalStatusCode() != null && StringUtils.hasText(patientDto.getMaritalStatusCode() .getCode())) { patient.setMaritalStatusCode(maritalStatusCodeRepository .findByCode(patientDto.getMaritalStatusCode().getCode())); } else { patient.setMaritalStatusCode(null); } if (patientDto.getRaceCode() != null && StringUtils.hasText(patientDto.getRaceCode().getCode())) { patient.setRaceCode(raceCodeRepository.findByCode(patientDto .getRaceCode().getCode())); } else { patient.setRaceCode(null); } if (patientDto.getReligiousAffiliationCode() != null && StringUtils.hasText(patientDto.getReligiousAffiliationCode() .getCode())) { patient.setReligiousAffiliationCode(religiousAffiliationCodeRepository .findByCode(patientDto.getReligiousAffiliationCode() .getCode())); } else { patient.setReligiousAffiliationCode(null); } return patient; } PatientProfileDtoToPatientMapper(
			PatientRepository patientRepository,
			StateCodeRepository stateCodeRepository,
			CountryCodeRepository countryCodeRepository,
			AdministrativeGenderCodeRepository administrativeGenderCodeRepository,
			LanguageCodeRepository languageCodeRepository,
			MaritalStatusCodeRepository maritalStatusCodeRepository,
			RaceCodeRepository raceCodeRepository,
			ReligiousAffiliationCodeRepository religiousAffiliationCodeRepository); @Override Patient map(PatientProfileDto patientDto);  }
@Test public void testMap_Given_Null_Username_And_Null_Patient_Id() { PatientProfileDto patientDto = mock(PatientProfileDto.class); when(patientDto.getUsername()).thenReturn(null); when(patientDto.getId()).thenReturn(null); final String firstName = "Firstname"; when(patientDto.getFirstName()).thenReturn(firstName); Patient patient = sut.map(patientDto); assertEquals(firstName, patient.getFirstName()); }
@Test public void testMap_Given_Username() { final String username = "username"; PatientProfileDto patientDto = mock(PatientProfileDto.class); when(patientDto.getUsername()).thenReturn(username); Patient patient = mock(Patient.class); when(patientRepository.findByUsername(username)).thenReturn(patient); final String firstName = "Firstname"; when(patientDto.getFirstName()).thenReturn(firstName); Patient result = sut.map(patientDto); assertEquals(patient, result); }
@Ignore("MRN is not passed via UI anymore") @Test public void testMap_Given_MedicalRecordNumber() { final String username = "username"; PatientProfileDto patientDto = mock(PatientProfileDto.class); when(patientDto.getUsername()).thenReturn(username); Patient patient = new Patient(); when(patientRepository.findByUsername(username)).thenReturn(patient); final String mrn = "mrn"; when(patientDto.getMedicalRecordNumber()).thenReturn(mrn); Patient result = sut.map(patientDto); assertEquals(patient, result); assertEquals(mrn, result.getMedicalRecordNumber()); }
@Ignore("EID is not passed via UI anymore") @Test public void testMap_Given_EnterpriseIdentifier() { final String username = "username"; PatientProfileDto patientDto = mock(PatientProfileDto.class); when(patientDto.getUsername()).thenReturn(username); Patient patient = new Patient(); when(patientRepository.findByUsername(username)).thenReturn(patient); final String eid = "eid"; when(patientDto.getEnterpriseIdentifier()).thenReturn(eid); Patient result = sut.map(patientDto); assertEquals(patient, result); assertEquals(eid, result.getEnterpriseIdentifier()); }
@Test public void test_General_Case() { final String username = "username"; PatientProfileDto patientDto = mock(PatientProfileDto.class); when(patientDto.getUsername()).thenReturn(username); Patient patient = mock(Patient.class); when(patientRepository.findByUsername(username)).thenReturn(patient); final String firstName = "Firstname"; when(patientDto.getFirstName()).thenReturn(firstName); when(patientDto.getSocialSecurityNumber()).thenReturn("111-11-1111"); when(patientDto.getTelephoneTelephone()).thenReturn("111-111-1111"); when(patientDto.getAddressStreetAddressLine()) .thenReturn("addressLine"); when(patientDto.getAddressCity()).thenReturn("NewYork"); when(patientDto.getAddressStateCode()).thenReturn("NY"); when(patientDto.getAddressPostalCode()).thenReturn("11111"); when(patientDto.getAdministrativeGenderCode()).thenReturn("M"); LookupDto languageCode = mock(LookupDto.class); when(languageCode.getCode()).thenReturn("US"); when(patientDto.getLanguageCode()).thenReturn(languageCode); LookupDto maritalStatusCode = mock(LookupDto.class); when(maritalStatusCode.getCode()).thenReturn("single"); when(patientDto.getMaritalStatusCode()).thenReturn(maritalStatusCode); LookupDto raceCode = mock(LookupDto.class); when(raceCode.getCode()).thenReturn("Asian"); when(patientDto.getRaceCode()).thenReturn(raceCode); LookupDto affiliationCode = mock(LookupDto.class); when(affiliationCode.getCode()).thenReturn("affi"); when(patientDto.getReligiousAffiliationCode()).thenReturn( affiliationCode); Set<IndividualProvider> providers = new HashSet<IndividualProvider>(); for (int i = 0; i < 3; i++) { IndividualProvider individualProvider = mock(IndividualProvider.class); providers.add(individualProvider); } when(patientDto.getIndividualProviders()).thenReturn(providers); Patient result = sut.map(patientDto); assertEquals(patient, result); }