|
1 | 1 | package org.bahmni.module.hip.web.service; |
2 | 2 |
|
3 | | -import org.bahmni.module.bahmnicore.contract.patient.response.PatientResponse; |
4 | | -import org.bahmni.module.bahmnicore.dao.PatientDao; |
| 3 | +import org.apache.commons.lang3.StringUtils; |
| 4 | +import org.bahmni.module.bahmnicommons.api.contract.patient.PatientSearchParameters; |
| 5 | +import org.bahmni.module.bahmnicommons.api.contract.patient.response.PatientResponse; |
| 6 | +import org.bahmni.module.bahmnicommons.api.dao.PatientDao; |
| 7 | +import org.bahmni.module.bahmnicommons.api.visitlocation.BahmniVisitLocationServiceImpl; |
5 | 8 | import org.bahmni.module.hip.Config; |
6 | 9 | import org.bahmni.module.hip.api.dao.ExistingPatientDao; |
7 | 10 | import org.bahmni.module.hip.web.client.model.Status; |
8 | 11 | import org.bahmni.module.hip.web.model.ExistingPatient; |
| 12 | +import org.openmrs.Location; |
9 | 13 | import org.openmrs.Patient; |
10 | 14 | import org.openmrs.PatientIdentifier; |
11 | 15 | import org.openmrs.api.LocationService; |
12 | 16 | import org.openmrs.api.PatientService; |
| 17 | +import org.openmrs.api.context.Context; |
13 | 18 | import org.springframework.beans.factory.annotation.Autowired; |
14 | 19 | import org.springframework.stereotype.Service; |
15 | 20 |
|
|
19 | 24 | import java.util.HashSet; |
20 | 25 | import java.util.List; |
21 | 26 | import java.util.Set; |
| 27 | +import java.util.function.Supplier; |
22 | 28 |
|
23 | 29 |
|
24 | 30 | @Service |
@@ -130,9 +136,11 @@ private List<PatientResponse> getPatients(String patientName, int patientYearOfB |
130 | 136 | } |
131 | 137 |
|
132 | 138 | private List<PatientResponse> filterPatientsByName(String patientName) { |
133 | | - return patientDao.getPatients("", patientName, null, null, "", 100, 0, |
134 | | - null, "", null, null, null, |
135 | | - locationService.getLocation(Config.LOCATION.getValue()).getUuid(), false, false); |
| 139 | + PatientSearchParameters searchParameters = getPatientSearchParameters(patientName); |
| 140 | + Supplier<Location> visitLocation = () -> getVisitLocation(searchParameters.getLoginLocationUuid()); |
| 141 | + Supplier<List<String>> configuredAddressFields = () -> patientDao.getConfiguredPatientAddressFields(); |
| 142 | + |
| 143 | + return patientDao.getPatients(searchParameters, visitLocation, configuredAddressFields); |
136 | 144 | } |
137 | 145 |
|
138 | 146 |
|
@@ -219,4 +227,34 @@ public boolean isHealthIdVoided(String uuid){ |
219 | 227 | } |
220 | 228 | return false; |
221 | 229 | } |
| 230 | + |
| 231 | + private PatientSearchParameters getPatientSearchParameters(String patientName) { |
| 232 | + PatientSearchParameters searchParameters = new PatientSearchParameters(); |
| 233 | + searchParameters.setIdentifier(""); |
| 234 | + searchParameters.setName(patientName); |
| 235 | + searchParameters.setCustomAttribute(null); |
| 236 | + |
| 237 | + searchParameters.setAddressFieldName(null); |
| 238 | + searchParameters.setAddressFieldValue(""); |
| 239 | + searchParameters.setLength(100); |
| 240 | + searchParameters.setStart(0); |
| 241 | + |
| 242 | + searchParameters.setPatientAttributes(null); |
| 243 | + searchParameters.setProgramAttributeFieldName(""); |
| 244 | + searchParameters.setProgramAttributeFieldValue(null); |
| 245 | + searchParameters.setAddressSearchResultFields(null); |
| 246 | + searchParameters.setPatientSearchResultFields(null); |
| 247 | + |
| 248 | + searchParameters.setLoginLocationUuid(locationService.getLocation(Config.LOCATION.getValue()).getUuid()); |
| 249 | + searchParameters.setFilterPatientsByLocation(false); |
| 250 | + searchParameters.setFilterOnAllIdentifiers(false); |
| 251 | + return searchParameters; |
| 252 | + } |
| 253 | + private Location getVisitLocation(String loginLocationUuid) { |
| 254 | + if (StringUtils.isBlank(loginLocationUuid)) { |
| 255 | + return null; |
| 256 | + } |
| 257 | + BahmniVisitLocationServiceImpl bahmniVisitLocationService = new BahmniVisitLocationServiceImpl(Context.getLocationService()); |
| 258 | + return bahmniVisitLocationService.getVisitLocation(loginLocationUuid); |
| 259 | + } |
222 | 260 | } |
0 commit comments