use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientSearchCriteriaTest method getSearchMode_shouldIdentifySearchByIdentifierAndIdentifierTypeList.
/**
* @see PatientSearchCriteria#getSearchMode(String, String, java.util.List, boolean)
*/
@Test
public void getSearchMode_shouldIdentifySearchByIdentifierAndIdentifierTypeList() {
List<PatientIdentifierType> patientIdentifierTypeList = new ArrayList<>();
patientIdentifierTypeList.add(new PatientIdentifierType());
Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_IDENTIFIER, patientSearchCriteria.getSearchMode(null, "identifier", patientIdentifierTypeList, false));
Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_IDENTIFIER, patientSearchCriteria.getSearchMode("", "identifier", patientIdentifierTypeList, false));
Assert.assertEquals(PatientSearchMode.PATIENT_SEARCH_BY_IDENTIFIER, patientSearchCriteria.getSearchMode(" \n\t", "identifier", patientIdentifierTypeList, false));
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class PatientServiceImplTest method checkPatientIdentifiers_shouldNotThrowMissingRequiredIdentifierGivenRequiredIdentifierTypesArePresent.
@Test
public void checkPatientIdentifiers_shouldNotThrowMissingRequiredIdentifierGivenRequiredIdentifierTypesArePresent() throws Exception {
// given
final String typeUuid = "equal type uuid";
final PatientIdentifierType requiredIdentifierType = new PatientIdentifierType(12345);
requiredIdentifierType.setUuid(typeUuid);
final PatientIdentifierType patientIdentifierType = new PatientIdentifierType(12345);
patientIdentifierType.setUuid(typeUuid);
final List<PatientIdentifierType> requiredTypes = new ArrayList<>();
requiredTypes.add(requiredIdentifierType);
when(patientDaoMock.getPatientIdentifierTypes(any(), any(), any(), any())).thenReturn(requiredTypes);
final Patient patientWithIdentifiers = new Patient();
patientWithIdentifiers.addIdentifier(new PatientIdentifier("some identifier", patientIdentifierType, mock(Location.class)));
final PatientIdentifierType anotherPatientIdentifier = new PatientIdentifierType(2345);
anotherPatientIdentifier.setUuid("another type uuid");
patientWithIdentifiers.addIdentifier(new PatientIdentifier("some identifier", anotherPatientIdentifier, mock(Location.class)));
// when
patientService.checkPatientIdentifiers(patientWithIdentifiers);
// then no exception
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class HibernatePatientDAOTest method getPatientIdentifiers_shouldGetByIdentifierType.
@Test
public void getPatientIdentifiers_shouldGetByIdentifierType() {
List<PatientIdentifierType> identifierTypes = singletonList(new PatientIdentifierType(2));
List<PatientIdentifier> identifiers = hibernatePatientDao.getPatientIdentifiers(null, identifierTypes, emptyList(), emptyList(), null);
List<Integer> identifierIds = identifiers.stream().map(PatientIdentifier::getId).collect(Collectors.toList());
Assert.assertEquals(2, identifiers.size());
Assert.assertThat(identifierIds, hasItems(1, 3));
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class ValidateUtilTest method validateFieldLength_shouldReturnImmediatelyIfValidationIsDisabledAndHaveNoErrors.
/**
* @see ValidateUtil#validateFieldLengths(org.springframework.validation.Errors, Class, String...)
*/
@Test
public void validateFieldLength_shouldReturnImmediatelyIfValidationIsDisabledAndHaveNoErrors() {
Boolean prevVal = ValidateUtil.getDisableValidation();
ValidateUtil.setDisableValidation(true);
PatientIdentifierType patientIdentifierType = new PatientIdentifierType();
patientIdentifierType.setName("asdfghjkl asdfghjkl asdfghjkl asdfghjkl asdfghjkl +1");
BindException errors = new BindException(patientIdentifierType, "patientIdentifierType");
ValidateUtil.validateFieldLengths(errors, PatientIdentifierType.class, "name");
assertFalse(errors.hasFieldErrors("name"));
ValidateUtil.setDisableValidation(prevVal);
}
use of org.openmrs.PatientIdentifierType in project openmrs-core by openmrs.
the class HL7ServiceImpl method resolvePersonFromIdentifiers.
/**
* @param identifiers CX identifier list from an identifier (either PID or NK1)
* @return The internal id number of the Patient based on one of the given identifiers, or null
* if the patient is not found
* @throws HL7Exception
*/
@Override
@Transactional(readOnly = true)
public Person resolvePersonFromIdentifiers(CX[] identifiers) throws HL7Exception {
// give up if no identifiers exist
if (identifiers.length < 1) {
throw new HL7Exception("Missing patient identifier in PID segment");
}
// Take the first uniquely matching identifier
for (CX identifier : identifiers) {
String hl7PersonId = identifier.getIDNumber().getValue();
// TODO if 1st component is blank, check 2nd and 3rd of assigning
// authority
String assigningAuthority = identifier.getAssigningAuthority().getNamespaceID().getValue();
if (StringUtils.isNotBlank(assigningAuthority)) {
// Assigning authority defined
try {
PatientIdentifierType pit = Context.getPatientService().getPatientIdentifierTypeByName(assigningAuthority);
if (pit == null) {
// there is no matching PatientIdentifierType
if (assigningAuthority.equals(HL7Constants.HL7_AUTHORITY_UUID)) {
// the identifier is a UUID
Person p = Context.getPersonService().getPersonByUuid(hl7PersonId);
if (p != null) {
return p;
}
log.warn("Can't find person for UUID '" + hl7PersonId + "'");
// skip identifiers with unknown type
continue;
} else if (assigningAuthority.equals(HL7Constants.HL7_AUTHORITY_LOCAL)) {
// the ID is internal (local)
String idType = identifier.getIdentifierTypeCode().getValue();
try {
if (idType.equals(HL7Constants.HL7_ID_PERSON)) {
Integer pid = Integer.parseInt(hl7PersonId);
// patient_id == person_id, so just look for
// the person
Person p = Context.getPersonService().getPerson(pid);
if (p != null) {
return p;
}
} else if (idType.equals(HL7Constants.HL7_ID_PATIENT)) {
Integer pid = Integer.parseInt(hl7PersonId);
// patient_id == person_id, so just look for
// the person
Patient p = Context.getPatientService().getPatient(pid);
if (p != null) {
return p;
}
}
} catch (NumberFormatException e) {
}
log.warn("Can't find Local identifier of '" + hl7PersonId + "'");
// skip identifiers with unknown type
continue;
}
log.warn("Can't find PatientIdentifierType named '" + assigningAuthority + "'");
// skip identifiers with unknown type
continue;
}
List<PatientIdentifier> matchingIds = Context.getPatientService().getPatientIdentifiers(hl7PersonId, Collections.singletonList(pit), null, null, null);
if (matchingIds == null || matchingIds.isEmpty()) {
// no matches
log.warn("NO matches found for " + hl7PersonId);
// try next identifier
continue;
} else if (matchingIds.size() == 1) {
// unique match -- we're done
return matchingIds.get(0).getPatient();
} else {
// ambiguous identifier
log.debug("Ambiguous identifier in PID. " + matchingIds.size() + " matches for identifier '" + hl7PersonId + "' of type '" + pit + "'");
// try next identifier
continue;
}
} catch (Exception e) {
log.error("Error resolving patient identifier '" + hl7PersonId + "' for assigning authority '" + assigningAuthority + "'", e);
continue;
}
} else {
try {
log.debug("CX contains ID '" + hl7PersonId + "' without assigning authority -- assuming patient.patient_id");
return Context.getPatientService().getPatient(Integer.parseInt(hl7PersonId));
} catch (NumberFormatException e) {
log.warn("Invalid patient ID '" + hl7PersonId + "'");
}
}
}
return null;
}
Aggregations