Search in sources :

Example 1 with PatientIdentifier

use of org.openmrs.PatientIdentifier in project openmrs-module-pihcore by PIH.

the class AssignDossierNumber method afterPatientCreated.

@Override
public synchronized void afterPatientCreated(Patient patient, Map<String, String[]> map) {
    PatientIdentifierType dossierIdentifierType = MetadataUtils.existing(PatientIdentifierType.class, PihHaitiPatientIdentifierTypes.DOSSIER_NUMBER.uuid());
    Location medicalRecordLocation = getMedicalRecordLocation();
    String dossierId = "";
    dossierId = identifierSourceService.generateIdentifier(dossierIdentifierType, medicalRecordLocation, "generating a new dossier number");
    // double check to make sure this identifier is not in use--since manual entry is allowed, it could be
    while (dossierIdentifierInUse(dossierId, dossierIdentifierType, medicalRecordLocation)) {
        log.error("Attempted to generate duplicate dossier identifier " + dossierId);
        dossierId = identifierSourceService.generateIdentifier(dossierIdentifierType, medicalRecordLocation, "generating a new dossier number");
    }
    if (StringUtils.isBlank(dossierId)) {
        throw new APIException("Unable to generate dossier number for patient " + patient);
    }
    PatientIdentifier dossierIdentifier = new PatientIdentifier(dossierId, dossierIdentifierType, medicalRecordLocation);
    patient.addIdentifier(dossierIdentifier);
    patientService.savePatientIdentifier(dossierIdentifier);
}
Also used : APIException(org.openmrs.api.APIException) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location)

Example 2 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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;
}
Also used : Concept(org.openmrs.Concept) PersonName(org.openmrs.PersonName) PersonAddress(org.openmrs.PersonAddress) TreeSet(java.util.TreeSet) Patient(org.openmrs.Patient) Date(java.util.Date) PatientIdentifierType(org.openmrs.PatientIdentifierType) PatientIdentifier(org.openmrs.PatientIdentifier) Location(org.openmrs.Location)

Example 3 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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);
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 4 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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);
}
Also used : PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Example 5 with PatientIdentifier

use of org.openmrs.PatientIdentifier 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"));
}
Also used : Errors(org.springframework.validation.Errors) BindException(org.springframework.validation.BindException) PatientIdentifier(org.openmrs.PatientIdentifier) PatientIdentifierType(org.openmrs.PatientIdentifierType) Test(org.junit.Test) BaseContextSensitiveTest(org.openmrs.test.BaseContextSensitiveTest)

Aggregations

PatientIdentifier (org.openmrs.PatientIdentifier)103 Test (org.junit.Test)86 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)74 Patient (org.openmrs.Patient)59 PatientIdentifierType (org.openmrs.PatientIdentifierType)51 PatientServiceImplTest (org.openmrs.api.impl.PatientServiceImplTest)47 Location (org.openmrs.Location)26 PersonName (org.openmrs.PersonName)19 Date (java.util.Date)15 PersonAddress (org.openmrs.PersonAddress)10 ArrayList (java.util.ArrayList)9 BindException (org.springframework.validation.BindException)8 User (org.openmrs.User)7 Errors (org.springframework.validation.Errors)7 Person (org.openmrs.Person)5 PatientIdentifierException (org.openmrs.api.PatientIdentifierException)5 HL7Exception (ca.uhn.hl7v2.HL7Exception)3 ApplicationException (ca.uhn.hl7v2.app.ApplicationException)3 CX (ca.uhn.hl7v2.model.v25.datatype.CX)3 Concept (org.openmrs.Concept)3