use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PersonServiceTest method createTestPatient.
/*
* Helper to create patient that does not have any existing relationships. Returns created Patient.
*/
private Patient createTestPatient() {
Patient patient = new Patient();
PersonName pName = new PersonName();
pName.setGivenName("Tom");
pName.setMiddleName("E.");
pName.setFamilyName("Patient");
patient.addName(pName);
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);
patient.setBirthdate(new Date());
patient.setBirthdateEstimated(true);
patient.setDeathDate(new Date());
patient.setCauseOfDeath(new Concept(1));
patient.setGender("male");
List<PatientIdentifierType> patientIdTypes = ps.getAllPatientIdentifierTypes();
assertNotNull(patientIdTypes);
PatientIdentifier patientIdentifier = new PatientIdentifier();
patientIdentifier.setIdentifier("123-0");
patientIdentifier.setIdentifierType(patientIdTypes.get(0));
patientIdentifier.setLocation(new Location(1));
patientIdentifier.setPreferred(true);
Set<PatientIdentifier> patientIdentifiers = new TreeSet<>();
patientIdentifiers.add(patientIdentifier);
patient.setIdentifiers(patientIdentifiers);
ps.savePatient(patient);
return patient;
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientIdentifierValidatorTest method validateIdentifier_shouldPassIfLocationBehaviorIsRequiredAndLocationIsNull.
/**
* @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
*/
@Test(expected = PatientIdentifierException.class)
public void validateIdentifier_shouldPassIfLocationBehaviorIsRequiredAndLocationIsNull() {
PatientIdentifier pi = new PatientIdentifier("1TU-8", new PatientIdentifierType(1), null);
PatientIdentifierType idType = pi.getIdentifierType();
idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.REQUIRED);
PatientIdentifierValidator.validateIdentifier(pi);
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientIdentifierValidatorTest method validateIdentifier_shouldPassIfLocationBehaviorIsNotUsedAndLocationIsNull.
/**
* @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
*/
@Test
public void validateIdentifier_shouldPassIfLocationBehaviorIsNotUsedAndLocationIsNull() {
PatientIdentifier pi = new PatientIdentifier("1TU-8", new PatientIdentifierType(1), null);
PatientIdentifierType idType = pi.getIdentifierType();
idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED);
PatientIdentifierValidator.validateIdentifier(pi);
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientIdentifierValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see PatientIdentifierValidator#validateIdentifier(PatientIdentifier)
*/
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
PatientIdentifier pi = new PatientIdentifier("too long text too long text too long text too long text", new PatientIdentifierType(1), null);
PatientIdentifierType idType = pi.getIdentifierType();
idType.setLocationBehavior(PatientIdentifierType.LocationBehavior.NOT_USED);
pi.setVoidReason("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(pi, "pi");
new PatientIdentifierValidator().validate(pi, errors);
Assert.assertTrue(errors.hasFieldErrors("identifier"));
Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientValidatorTest method validate_shouldFailValidationIfFieldLengthsAreNotCorrect.
/**
* @see PatientValidator#validate(Object,Errors)
*/
@Override
@Test
public void validate_shouldFailValidationIfFieldLengthsAreNotCorrect() {
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);
patient.setVoidReason("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(patient, "patient");
validator.validate(patient, errors);
Assert.assertTrue(errors.hasFieldErrors("voidReason"));
}
Aggregations