Skip to content

Commit 2a0bbd3

Browse files
authored
Merge pull request #87 from BahmniIndiaDistro/BAH-2536
BAH-2536 | Patient Dao changes from Bahmni Commons
2 parents a883022 + c25a2a1 commit 2a0bbd3

4 files changed

Lines changed: 58 additions & 5 deletions

File tree

omod/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@
8484
</exclusions>
8585
</dependency>
8686

87+
<dependency>
88+
<groupId>org.bahmni.module</groupId>
89+
<artifactId>bahmni-commons-api</artifactId>
90+
</dependency>
91+
8792
<dependency>
8893
<groupId>org.projectlombok</groupId>
8994
<artifactId>lombok</artifactId>

omod/src/main/java/org/bahmni/module/hip/web/service/ExistingPatientService.java

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package org.bahmni.module.hip.web.service;
22

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;
58
import org.bahmni.module.hip.Config;
69
import org.bahmni.module.hip.api.dao.ExistingPatientDao;
710
import org.bahmni.module.hip.web.client.model.Status;
811
import org.bahmni.module.hip.web.model.ExistingPatient;
12+
import org.openmrs.Location;
913
import org.openmrs.Patient;
1014
import org.openmrs.PatientIdentifier;
1115
import org.openmrs.api.LocationService;
1216
import org.openmrs.api.PatientService;
17+
import org.openmrs.api.context.Context;
1318
import org.springframework.beans.factory.annotation.Autowired;
1419
import org.springframework.stereotype.Service;
1520

@@ -19,6 +24,7 @@
1924
import java.util.HashSet;
2025
import java.util.List;
2126
import java.util.Set;
27+
import java.util.function.Supplier;
2228

2329

2430
@Service
@@ -130,9 +136,11 @@ private List<PatientResponse> getPatients(String patientName, int patientYearOfB
130136
}
131137

132138
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);
136144
}
137145

138146

@@ -219,4 +227,34 @@ public boolean isHealthIdVoided(String uuid){
219227
}
220228
return false;
221229
}
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+
}
222260
}

omod/src/main/resources/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<require_module version="1.5.0">org.openmrs.module.fhir2</require_module>
2626
<require_module>org.openmrs.module.emrapi</require_module>
2727
<require_module>org.bahmni.module.bahmnicore</require_module>
28+
<require_module>org.bahmni.module.bahmnicommons</require_module>
2829
</require_modules>
2930

3031
<!-- AOP

pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2424
<openmrs.platform.version>2.4.2</openmrs.platform.version>
2525
<hapifhirVersion>5.0.0</hapifhirVersion>
26+
<bahmniCommons.version>1.0.0-SNAPSHOT</bahmniCommons.version>
2627
</properties>
2728

2829

@@ -124,6 +125,14 @@
124125
<version>2.29.0</version>
125126
<scope>provided</scope>
126127
</dependency>
128+
129+
<dependency>
130+
<groupId>org.bahmni.module</groupId>
131+
<artifactId>bahmni-commons-api</artifactId>
132+
<type>jar</type>
133+
<version>${bahmniCommons.version}</version>
134+
<scope>provided</scope>
135+
</dependency>
127136
</dependencies>
128137

129138
</dependencyManagement>

0 commit comments

Comments
 (0)