Skip to content

Commit

Permalink
Include currentDateTime for provider shift validation
Browse files Browse the repository at this point in the history
  • Loading branch information
umair-fayaz committed Mar 22, 2024
1 parent b208b49 commit 29ae167
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public interface WardDAO {

List<AdmittedPatient> getAdmittedPatients(Location location, Provider provider, Date currentDateTime, String sortBy);

WardPatientsSummary getWardPatientSummary(Location location, Provider provider);
WardPatientsSummary getWardPatientSummary(Location location, Provider provider, Date currentDateTime);

}
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,43 @@ public List<AdmittedPatient> getAdmittedPatients(Location location, Provider pro
}

@Override
public WardPatientsSummary getWardPatientSummary(Location location, Provider provider) {
public WardPatientsSummary getWardPatientSummary(Location location, Provider provider, Date dateTime) {
Session session = this.sessionFactory.getCurrentSession();
try {
Query query = session.createQuery(
"SELECT NEW org.openmrs.module.ipd.api.model.WardPatientsSummary(" +
"COUNT(assignment) AS totalPatients, " +
"COUNT(DISTINCT CASE WHEN ctp.provider = :provider THEN assignment.patient ELSE null END) AS totalProviderPatients) " +
"FROM org.openmrs.module.bedmanagement.entity.BedPatientAssignment assignment " +
"JOIN org.openmrs.module.bedmanagement.entity.BedLocationMapping locmap ON locmap.bed = assignment.bed " +
"JOIN org.openmrs.Location l ON locmap.location = l " +
"JOIN org.openmrs.Visit v ON v.patient = assignment.patient " +
"LEFT JOIN CareTeam careTeam ON careTeam.patient = v.patient " +
"LEFT JOIN careTeam.participants ctp " +
"WHERE assignment.endDatetime IS NULL AND v.stopDatetime IS NULL AND l.parentLocation = :location AND (ctp.provider IS NULL OR ctp.provider = :provider)");
Query totalPatientsQuery = session.createQuery(
"SELECT COUNT(assignment) " +
"FROM org.openmrs.module.bedmanagement.entity.BedPatientAssignment assignment " +
"JOIN org.openmrs.module.bedmanagement.entity.BedLocationMapping locmap ON locmap.bed = assignment.bed " +
"JOIN org.openmrs.Location l ON locmap.location = l " +
"JOIN org.openmrs.Visit v ON v.patient = assignment.patient " +
"WHERE assignment.endDatetime IS NULL AND v.stopDatetime IS NULL AND l.parentLocation = :location"
);

totalPatientsQuery.setParameter("location", location);

Long totalPatients = (Long) totalPatientsQuery.uniqueResult();

Query totalProviderPatientsQuery = session.createQuery(
"SELECT COUNT(DISTINCT CASE WHEN ctp.provider = :provider THEN assignment.patient ELSE null END) " +
"FROM org.openmrs.module.bedmanagement.entity.BedPatientAssignment assignment " +
"JOIN org.openmrs.module.bedmanagement.entity.BedLocationMapping locmap ON locmap.bed = assignment.bed " +
"JOIN org.openmrs.Location l ON locmap.location = l " +
"JOIN org.openmrs.Visit v ON v.patient = assignment.patient " +
"LEFT JOIN CareTeam careTeam ON careTeam.patient = v.patient " +
"LEFT JOIN careTeam.participants ctp ON ctp.voided = 0 " +
"WHERE assignment.endDatetime IS NULL AND v.stopDatetime IS NULL AND l.parentLocation = :location " +
"AND (ctp.provider = :provider AND :dateTime BETWEEN ctp.startTime AND ctp.endTime)"
);

query.setParameter("location", location);
query.setParameter("provider", provider);
totalProviderPatientsQuery.setParameter("location", location);
totalProviderPatientsQuery.setParameter("provider", provider);
totalProviderPatientsQuery.setParameter("dateTime", dateTime);

Long totalProviderPatients = (Long) totalProviderPatientsQuery.uniqueResult();

return (WardPatientsSummary) query.getSingleResult();
return new WardPatientsSummary(totalPatients, totalProviderPatients);
} catch (Exception e) {
log.error("Exception at WardDAO getAdmittedPatients ", e.getStackTrace());
log.error("Exception at WardDAO getAdmittedPatients ", e);
}

return new WardPatientsSummary();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public WardServiceImpl(WardDAO wardDAO) {
public WardPatientsSummary getIPDWardPatientSummary(String wardUuid, String providerUuid) {
Location location= Context.getService(LocationService.class).getLocationByUuid(wardUuid);
Provider provider = Context.getProviderService().getProviderByUuid(providerUuid);
return wardDAO.getWardPatientSummary(location, provider);
Date currentDateTime = new Date();
return wardDAO.getWardPatientSummary(location, provider, currentDateTime);
}

@Override
Expand Down

0 comments on commit 29ae167

Please sign in to comment.