@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()); }
@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 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 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); }
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); }
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);  }