From ab59740c7b66b2db99916c44e1bb9565299c3e6e Mon Sep 17 00:00:00 2001 From: Michael Seaton Date: Wed, 23 Oct 2024 07:28:44 -0400 Subject: [PATCH] RA-2057 - Similar patient searching should support matching on patient identifiers (#149) --- .../MatchingPatientsFragmentController.java | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/MatchingPatientsFragmentController.java b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/MatchingPatientsFragmentController.java index f5b9a947..bacb27a0 100644 --- a/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/MatchingPatientsFragmentController.java +++ b/omod/src/main/java/org/openmrs/module/registrationapp/fragment/controller/MatchingPatientsFragmentController.java @@ -13,16 +13,21 @@ */ package org.openmrs.module.registrationapp.fragment.controller; +import org.apache.commons.lang.StringUtils; import org.codehaus.jackson.JsonNode; import org.openmrs.Patient; import org.openmrs.PatientIdentifier; import org.openmrs.PatientIdentifierType; import org.openmrs.PersonAddress; import org.openmrs.PersonName; +import org.openmrs.api.AdministrationService; import org.openmrs.api.PatientService; +import org.openmrs.api.context.Context; import org.openmrs.module.appframework.domain.AppDescriptor; import org.openmrs.module.appframework.service.AppFrameworkService; import org.openmrs.module.appui.UiSessionContext; +import org.openmrs.module.idgen.IdentifierSource; +import org.openmrs.module.idgen.service.IdentifierSourceService; import org.openmrs.module.registrationapp.form.RegisterPatientFormBuilder; import org.openmrs.module.registrationapp.model.Field; import org.openmrs.module.registrationapp.model.NavigableFormStructure; @@ -143,9 +148,39 @@ private void addToPatient(Patient patient, AppDescriptor app, PersonName name, P patient.addName(name); patient.addAddress(address); + RegisterPatientFormBuilder.resolvePersonAttributeFields(formStructure, patient, request.getParameterMap()); + + // Patient Identifiers + List fields = formStructure.getFields(); + if (fields != null) { + for (Field field : fields) { + if (StringUtils.equals(field.getType(), "patientIdentifier")) { + String identifier = request.getParameter(field.getFormFieldName()); + if (StringUtils.isNotBlank(identifier)) { + PatientIdentifierType identifierType = Context.getPatientService().getPatientIdentifierTypeByUuid(field.getUuid()); + patient.addIdentifier(new PatientIdentifier(identifier, identifierType, null)); + } + } + } + } - if (formStructure != null) { - RegisterPatientFormBuilder.resolvePersonAttributeFields(formStructure, patient, request.getParameterMap()); + String patientIdentifier = request.getParameter("patientIdentifier"); + if (StringUtils.isNotBlank(patientIdentifier)) { + IdentifierSourceService iss = Context.getService(IdentifierSourceService.class); + AdministrationService adminService = Context.getService(AdministrationService.class); + String idSourceId = adminService.getGlobalProperty("registrationcore.identifierSourceId"); + if (StringUtils.isNotBlank(idSourceId)) { + IdentifierSource source; + try { + source = iss.getIdentifierSource(Integer.parseInt(idSourceId)); + } + catch (Exception e) { + source = iss.getIdentifierSourceByUuid(idSourceId); + } + if (source != null) { + patient.addIdentifier(new PatientIdentifier(patientIdentifier, source.getIdentifierType(), null)); + } + } } }