Search in sources :

Example 1 with ContactPointUse

use of org.hl7.fhir.dstu3.model.ContactPoint.ContactPointUse in project gpconnect-demonstrator by nhsconnect.

the class PatientResourceProvider method validateTelecomAndAddress.

private void validateTelecomAndAddress(Patient patient) {
    // 0..1 of phone - (not nec. temp),  0..1 of email
    HashSet<ContactPointUse> phoneUse = new HashSet<>();
    int emailCount = 0;
    for (ContactPoint telecom : patient.getTelecom()) {
        if (telecom.hasSystem()) {
            if (telecom.getSystem() != null) {
                switch(telecom.getSystem()) {
                    case PHONE:
                        if (telecom.hasUse()) {
                            switch(telecom.getUse()) {
                                case HOME:
                                case WORK:
                                case MOBILE:
                                case TEMP:
                                    if (!phoneUse.contains(telecom.getUse())) {
                                        phoneUse.add(telecom.getUse());
                                    } else {
                                        throwInvalidRequest400_BadRequestException("Only one Telecom of type phone with use type " + telecom.getUse().toString().toLowerCase() + " is allowed in a register patient request.");
                                    }
                                    break;
                                default:
                                    throwInvalidRequest400_BadRequestException("Invalid Telecom of type phone use type " + telecom.getUse().toString().toLowerCase() + " in a register patient request.");
                            }
                        } else {
                            throwInvalidRequest400_BadRequestException("Invalid Telecom - no Use type provided in a register patient request.");
                        }
                        break;
                    case EMAIL:
                        if (++emailCount > 1) {
                            throwInvalidRequest400_BadRequestException("Only one Telecom of type " + "email" + " is allowed in a register patient request.");
                        }
                        break;
                    default:
                        throwInvalidRequest400_BadRequestException("Telecom system is missing in a register patient request.");
                }
            }
        } else {
            throwInvalidRequest400_BadRequestException("Telecom system is missing in a register patient request.");
        }
    }
    // iterate telcom
    // count by useType - Only the first address is persisted at present
    HashSet<AddressUse> useTypeCount = new HashSet<>();
    for (Address address : patient.getAddress()) {
        AddressUse useType = address.getUse();
        // #189 address use types work and old are not allowed
        if (useType == WORK || useType == OLD) {
            throwUnprocessableEntity422_InvalidResourceException("Address use type " + useType + " cannot be sent in a register patient request.");
        }
        if (!useTypeCount.contains(useType)) {
            useTypeCount.add(useType);
        } else {
            // #174 Only a single address of each usetype may be sent
            throwUnprocessableEntity422_InvalidResourceException("Only a single address of each use type can be sent in a register patient request.");
        }
    }
// for address
}
Also used : ContactPointUse(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointUse) AddressUse(org.hl7.fhir.dstu3.model.Address.AddressUse)

Aggregations

AddressUse (org.hl7.fhir.dstu3.model.Address.AddressUse)1 ContactPointUse (org.hl7.fhir.dstu3.model.ContactPoint.ContactPointUse)1