Search in sources :

Example 1 with PractitionerEntity

use of uk.gov.hscic.practitioner.PractitionerEntity in project gpconnect-demonstrator by nhsconnect.

the class PatientDetailsToEntityTransformer method transform.

@Override
public PatientEntity transform(PatientDetails patientDetails) {
    PatientEntity patientEntity = null;
    if (patientDetails != null) {
        patientEntity = new PatientEntity();
        String[] address = patientDetails.getAddress();
        if (address != null) {
            patientEntity.setAddress1(address[0]);
            patientEntity.setAddress2(address[1]);
            patientEntity.setAddress3(address[2]);
            patientEntity.setAddress4(address[3]);
            patientEntity.setAddress5(address[4]);
        }
        patientEntity.setPostcode(patientDetails.getPostcode());
        if (patientDetails.getGpDetails() != null) {
            List<PractitionerEntity> gpList = practitionerRepository.findByUserId(patientDetails.getGpDetails());
            if (gpList.size() == 1) {
                patientEntity.setPractitioner(gpList.get(0));
            } else if (gpList.size() > 1) {
                throw new IllegalStateException(String.format("Invalid number of GPs associated with patient - (first name - %s, last name - %s). Expected - 1. Actual - %d", patientDetails.getForename(), patientDetails.getSurname(), gpList.size()));
            }
        }
        Date deceased = patientEntity.getDeceasedDateTime();
        if (deceased != null) {
            patientEntity.setDeceasedDateTime(deceased);
        }
        patientEntity.setNhsNumber(patientDetails.getNhsNumber());
        patientEntity.setDateOfBirth(patientDetails.getDateOfBirth());
        patientEntity.setFirstName(patientDetails.getForename());
        patientEntity.setGender(patientDetails.getGender());
        patientEntity.setId(patientDetails.getId() != null ? Long.parseLong(patientDetails.getId()) : null);
        patientEntity.setLastName(patientDetails.getSurname());
        patientEntity.setLastUpdated(patientDetails.getLastUpdated());
        patientEntity.setNhsNumber(patientDetails.getNhsNumber());
        patientEntity.setPasNumber(patientDetails.getPasNumber());
        patientEntity.setPhone(patientDetails.getTelephone());
        patientEntity.setTitle(patientDetails.getTitle());
        patientEntity.setRegistrationStartDateTime(patientDetails.getRegistrationStartDateTime());
        patientEntity.setRegistrationEndDateTime(patientDetails.getRegistrationEndDateTime());
        patientEntity.setRegistrationStatus(patientDetails.getRegistrationStatus());
        patientEntity.setRegistrationType(patientDetails.getRegistrationType());
        patientEntity.setMaritalStatus(patientDetails.getMaritalStatus());
        patientEntity.setManagingOrganization(patientDetails.getManagingOrganization());
        patientEntity.setSensitive(patientDetails.isSensitive());
        populateTelecoms(patientDetails, patientEntity);
    }
    return patientEntity;
}
Also used : PractitionerEntity(uk.gov.hscic.practitioner.PractitionerEntity) Date(java.util.Date)

Example 2 with PractitionerEntity

use of uk.gov.hscic.practitioner.PractitionerEntity in project gpconnect-demonstrator by nhsconnect.

the class PatientEntityToDetailsTransformer method transform.

@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;
}
Also used : PatientDetails(uk.gov.hscic.model.patient.PatientDetails) PractitionerEntity(uk.gov.hscic.practitioner.PractitionerEntity) Date(java.util.Date)

Example 3 with PractitionerEntity

use of uk.gov.hscic.practitioner.PractitionerEntity in project gpconnect-demonstrator by nhsconnect.

the class PatientEntityToDetailsTransformerTest method dummyPatientEntity.

private PatientEntity dummyPatientEntity() {
    final PatientEntity patient = new PatientEntity();
    patient.setNhsNumber(PATIENT_ID);
    patient.setPractitioner(new PractitionerEntity());
    return patient;
}
Also used : PractitionerEntity(uk.gov.hscic.practitioner.PractitionerEntity)

Aggregations

PractitionerEntity (uk.gov.hscic.practitioner.PractitionerEntity)3 Date (java.util.Date)2 PatientDetails (uk.gov.hscic.model.patient.PatientDetails)1