Search in sources :

Example 6 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientValidatorTest method validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred.

@Test
public void validate_shouldNotFailWhenPatientHasOnlyOneIdentifierAndItsNotPreferred() {
    PatientIdentifierType patientIdentifierType = Context.getPatientService().getAllPatientIdentifierTypes(false).get(0);
    Patient patient = new Patient();
    PersonName pName = new PersonName();
    pName.setGivenName("Tom");
    pName.setMiddleName("E.");
    pName.setFamilyName("Patient");
    patient.addName(pName);
    patient.setGender("male");
    PersonAddress pAddress = new PersonAddress();
    pAddress.setAddress1("123 My street");
    pAddress.setAddress2("Apt 402");
    pAddress.setCityVillage("Anywhere city");
    pAddress.setCountry("Some Country");
    Set<PersonAddress> pAddressList = patient.getAddresses();
    pAddressList.add(pAddress);
    patient.setAddresses(pAddressList);
    patient.addAddress(pAddress);
    PatientIdentifier patientIdentifier1 = new PatientIdentifier();
    patientIdentifier1.setLocation(new Location(1));
    patientIdentifier1.setIdentifier("012345678");
    patientIdentifier1.setDateCreated(new Date());
    patientIdentifier1.setIdentifierType(patientIdentifierType);
    patient.addIdentifier(patientIdentifier1);
    Errors errors = new BindException(patient, "patient");
    validator.validate(patient, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) Patient(org.openmrs.Patient) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Date(java.util.Date) Location(org.openmrs.Location) Test(org.junit.Test)

Example 7 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientIdentifierTypeValidatorTest method validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues.

/**
 * @see PatientIdentifierTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldPassValidationIfAllRequiredFieldsHaveProperValues() {
    PatientIdentifierType type = new PatientIdentifierType();
    type.setName("restraining");
    type.setDescription(":(");
    Errors errors = new BindException(type, "type");
    new PatientIdentifierTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 8 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientIdentifierTypeValidatorTest method validate_shouldPassValidationIfRegExFieldLengthIsNotTooLong.

/**
 * @see	PatientIdentifierTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldPassValidationIfRegExFieldLengthIsNotTooLong() {
    PatientIdentifierType type = new PatientIdentifierType();
    type.setName("Martin");
    type.setDescription("helps");
    String valid50charInput = "12345678901234567890123456789012345678901234567890";
    type.setFormat(valid50charInput);
    Errors errors = new BindException(type, "type");
    new PatientIdentifierTypeValidator().validate(type, errors);
    Assert.assertFalse(errors.hasErrors());
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 9 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientIdentifierTypeValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.

/**
 * @see PatientIdentifierTypeValidator#validate(Object,Errors)
 */
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
    PatientIdentifierType type = new PatientIdentifierType();
    type.setName("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    type.setFormat("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    type.setFormatDescription("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    type.setValidator("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    type.setRetireReason("too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text too long text");
    Errors errors = new BindException(type, "type");
    new PatientIdentifierTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasFieldErrors("name"));
    Assert.assertTrue(errors.hasFieldErrors("format"));
    Assert.assertTrue(errors.hasFieldErrors("formatDescription"));
    Assert.assertTrue(errors.hasFieldErrors("validator"));
    Assert.assertTrue(errors.hasFieldErrors("retireReason"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 10 with PatientIdentifierType

use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.

the class PatientIdentifierTypeValidatorTest method validate_shouldFailValidationIfNameFieldLengthIsTooLong.

/**
 * @see	PatientIdentifierTypeValidator#validate(Object, org.springframework.validation.Errors)
 */
@Test
public void validate_shouldFailValidationIfNameFieldLengthIsTooLong() {
    PatientIdentifierType type = new PatientIdentifierType();
    String invalid51charInput = "123456789012345678901234567890123456789012345678901";
    type.setName(invalid51charInput);
    type.setDescription("helps");
    type.setFormat("format");
    Errors errors = new BindException(type, "type");
    new PatientIdentifierTypeValidator().validate(type, errors);
    Assert.assertTrue(errors.hasErrors());
    Assert.assertEquals(1, errors.getFieldErrorCount("name"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

PatientIdentifierType (org.openmrs.PatientIdentifierType)131 Test (org.junit.Test)99 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)88 PatientIdentifier (org.openmrs.PatientIdentifier)56 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)53 Patient (org.openmrs.Patient)37 Location (org.openmrs.Location)29 ArrayList (java.util.ArrayList)20 BindException (org.springframework.validation.BindException)17 Errors (org.springframework.validation.Errors)14 Date (java.util.Date)13 PersonName (org.openmrs.PersonName)13 User (org.openmrs.User)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Concept (org.openmrs.Concept)6 Person (org.openmrs.Person)5 HashMap (java.util.HashMap)4 PersonAddress (org.openmrs.PersonAddress)4 PatientServiceTest (org.openmrs.api.PatientServiceTest)4 HL7Exception (ca.uhn.hl7v2.HL7Exception)3