Skip to content

Commit

Permalink
OP-1130 improve JPA methods - opd package (#1139)
Browse files Browse the repository at this point in the history
* OP-1130 improve JPA methods - opd package

* Update Tests.java
  • Loading branch information
dbmalkovsky authored Oct 27, 2023
1 parent 582af20 commit f82b49e
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 105 deletions.
32 changes: 15 additions & 17 deletions src/main/java/org/isf/opd/manager/OpdBrowserManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected void setPatientConsistency(Opd opd) {
* Verify if the object is valid for CRUD and return a list of errors, if any
*
* @param opd
* @param insert <code>true</code> or updated <code>false</code>
* @param insert {@code true} or updated {@code false}
* @throws OHDataValidationException
*/
protected void validateOpd(Opd opd, boolean insert) throws OHDataValidationException {
Expand Down Expand Up @@ -122,8 +122,8 @@ protected void validateOpd(Opd opd, boolean insert) throws OHDataValidationExcep
/**
* Return all Opds of today or since one week ago
*
* @param oneWeek - if <code>true</code> return the last week, only today otherwise.
* @return the list of Opds. It could be <code>null</code>.
* @param oneWeek - if {@code true} return the last week, only today otherwise.
* @return the list of Opds. It could be {@code null}.
* @throws OHServiceException
*/
public List<Opd> getOpd(boolean oneWeek) throws OHServiceException {
Expand All @@ -143,7 +143,7 @@ public List<Opd> getOpd(boolean oneWeek) throws OHServiceException {
* @param sex
* @param newPatient
* @param user
* @return the list of Opds. It could be <code>null</code>.
* @return the list of Opds. It could be {@code null}.
* @throws OHServiceException
*/
public List<Opd> getOpd(Ward ward, String diseaseTypeCode, String diseaseCode, LocalDate dateFrom, LocalDate dateTo, int ageFrom, int ageTo, char sex, char newPatient, String user) throws OHServiceException {
Expand All @@ -155,7 +155,7 @@ public List<Opd> getOpd(Ward ward, String diseaseTypeCode, String diseaseCode, L
*
* @param patientcode - the patient ID
* @return the list of {@link Opd}s associated to specified patient ID.
* the whole list of {@link Opd}s if <code>0</code> is passed.
* the whole list of {@link Opd}s if {@code 0} is passed.
* @throws OHServiceException
*/
public List<Opd> getOpdList(int patientcode) throws OHServiceException {
Expand All @@ -166,7 +166,7 @@ public List<Opd> getOpdList(int patientcode) throws OHServiceException {
* Insert a new item in the db
*
* @param opd an {@link Opd}
* @return <code>true</code> if the item has been inserted
* @return {@code true} if the item has been inserted
* @throws OHServiceException
*/
public Opd newOpd(Opd opd) throws OHServiceException {
Expand All @@ -191,18 +191,17 @@ public Opd updateOpd(Opd opd) throws OHServiceException {
* Delete an {@link Opd} from the db
*
* @param opd - the {@link Opd} to delete
* @return <code>true</code> if the item has been deleted. <code>false</code> otherwise.
* @throws OHServiceException
*/
public boolean deleteOpd(Opd opd) throws OHServiceException {
return ioOperations.deleteOpd(opd);
public void deleteOpd(Opd opd) throws OHServiceException {
ioOperations.deleteOpd(opd);
}

/**
* Returns the max progressive number within specified year or within current year if <code>0</code>.
* Returns the max progressive number within specified year or within current year if {@code 0}.
*
* @param year
* @return <code>int</code> - the progressive number in the year
* @return {@code int} - the progressive number in the year
* @throws OHServiceException
*/
public int getProgYear(int year) throws OHServiceException {
Expand All @@ -213,7 +212,7 @@ public int getProgYear(int year) throws OHServiceException {
* Return the last {@link Opd} in time associated with specified patient ID.
*
* @param patientcode - the patient ID
* @return last Opd associated with specified patient ID or <code>null</code>
* @return last Opd associated with specified patient ID or {@code null}
* @throws OHServiceException
*/
public Opd getLastOpd(int patientcode) throws OHServiceException {
Expand All @@ -225,9 +224,9 @@ public Opd getLastOpd(int patientcode) throws OHServiceException {
*
* @param opdNum - the OPD progressive in year
* @param year - the year
* @return <code>true</code> if the given number exists in year, <code>false</code> otherwise
* @return {@code true} if the given number exists in year, {@code false} otherwise
*/
public Boolean isExistOpdNum(int opdNum, int year) throws OHServiceException {
public boolean isExistOpdNum(int opdNum, int year) throws OHServiceException {
return ioOperations.isExistOpdNum(opdNum, year);
}

Expand Down Expand Up @@ -255,19 +254,18 @@ public List<Opd> getOpdByProgYear(int code) {
* Returns {@link List} of {@link Opd}s associated to specified patient ID with page info.
*
* @param ward - the ward of opd
* @param diseaseType - the disease type
* @param diseaseTypeCode - the disease type
* @param diseaseCode - the Code of disease
* @param dateFrom
* @param dateTo
* @param ageFrom
* @param ageTo
* @param sex
* @param newPatient
* @param user
* @param page
* @param size
* @return the list of {@link Opd}s associated to specified patient ID.
* the whole list of {@link Opd}s if <code>0</code> is passed.
* the whole list of {@link Opd}s if {@code 0} is passed.
* @throws OHServiceException
*/
public PagedResponse<Opd> getOpdPageable(Ward ward, String diseaseTypeCode, String diseaseCode, LocalDate dateFrom, LocalDate dateTo, int ageFrom, int ageTo, char sex, char newPatient, int page, int size) throws OHServiceException {
Expand Down
63 changes: 30 additions & 33 deletions src/main/java/org/isf/opd/service/OpdIoOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.List;
import java.util.Optional;

import org.isf.distype.model.DiseaseType;
import org.isf.generaldata.MessageBundle;
import org.isf.opd.model.Opd;
import org.isf.utils.db.TranslateOHServiceException;
Expand Down Expand Up @@ -55,7 +54,7 @@
* - fix: getSurgery() method should not add 1 day to toDate
* 05/09/2008 - alex - added method for patient related Opd query
* 05/01/2009 - ross - fix: in insert, referralfrom was written both in referralfrom and referralto
* 09/01/2009 - fabrizio - Modified queried to accomodate type change of date field in Opd class.
* 09/01/2009 - fabrizio - Modified queried to accommodate type change of date field in Opd class.
* Modified construction of queries, concatenation is performed with
* StringBuilders instead than operator +. Removed some nested try-catch
* blocks. Modified methods to format dates.
Expand All @@ -70,10 +69,10 @@ public class OpdIoOperations {
private OpdIoOperationRepository repository;

/**
* Return all Opds of today or one week ago
* Return all {@link Opd}s for today or one week ago.
*
* @param oneWeek - if <code>true</code> return the last week, only today otherwise.
* @return the list of Opds. It could be <code>empty</code>.
* @param oneWeek - if {@code true} return the last week, only today otherwise.
* @return the list of Opds. It could be {@code empty}.
* @throws OHServiceException
*/
public List<Opd> getOpdList(boolean oneWeek) throws OHServiceException {
Expand All @@ -87,7 +86,7 @@ public List<Opd> getOpdList(boolean oneWeek) throws OHServiceException {
}

/**
* Return all {@link Opd}s within specified dates and parameters
* Return all {@link Opd}s within specified dates and parameters.
*
* @param ward
* @param diseaseTypeCode
Expand All @@ -99,7 +98,7 @@ public List<Opd> getOpdList(boolean oneWeek) throws OHServiceException {
* @param sex
* @param newPatient
* @param user
* @return the list of Opds. It could be <code>empty</code>.
* @return the list of Opds. It could be {@code empty}.
* @throws OHServiceException
*/
public List<Opd> getOpdList(
Expand All @@ -117,11 +116,11 @@ public List<Opd> getOpdList(
}

/**
* Return all {@link Opd}s associated to specified patient ID
* Return all {@link Opd}s associated to specified patient ID.
*
* @param patID - the patient ID
* @return the list of {@link Opd}s associated to specified patient ID.
* the whole list of {@link Opd}s if <code>0</code> is passed.
* the whole list of {@link Opd}s if {@code 0} is passed.
* @throws OHServiceException
*/
public List<Opd> getOpdList(int patID) throws OHServiceException {
Expand All @@ -131,44 +130,42 @@ public List<Opd> getOpdList(int patID) throws OHServiceException {
}

/**
* Insert a new item in the db
* Insert a new {@link Opd} into the db.
*
* @param opd - an {@link Opd}
* @return <code>true</code> if the item has been inserted
* @return the newly inserted {@link Opd} object.
* @throws OHServiceException
*/
public Opd newOpd(Opd opd) throws OHServiceException {
return repository.save(opd);
}

/**
* Modify an {@link Opd} in the db
* Modify an {@link Opd} in the db.
*
* @param opd - an {@link Opd}
* @return the updated {@link Opd}.
* @return the updated {@link Opd} object.
* @throws OHServiceException
*/
public Opd updateOpd(Opd opd) throws OHServiceException {
return repository.save(opd);
}

/**
* Delete an {@link Opd} from the db
* Delete an {@link Opd} from the db.
*
* @param opd - the {@link Opd} to delete
* @return <code>true</code> if the item has been deleted. <code>false</code> otherwise.
* @throws OHServiceException
* @throws OHServiceException
*/
public boolean deleteOpd(Opd opd) throws OHServiceException {
public void deleteOpd(Opd opd) throws OHServiceException {
repository.delete(opd);
return true;
}

/**
* Returns the max progressive number within specified year or within current year if <code>0</code>.
* Returns the max progressive number within specified year or within current year if {@code 0}.
*
* @param year
* @return <code>int</code> - the progressive number in the year
* @return {@code int} - the progressive number in the year
* @throws OHServiceException
*/
public int getProgYear(int year) throws OHServiceException {
Expand All @@ -182,7 +179,7 @@ public int getProgYear(int year) throws OHServiceException {
* Return the last {@link Opd} in time associated with specified patient ID.
*
* @param patID - the patient ID
* @return last Opd associated with specified patient ID or <code>null</code>
* @return last Opd associated with specified patient ID or {@code null}
* @throws OHServiceException
*/
public Opd getLastOpd(int patID) throws OHServiceException {
Expand All @@ -191,33 +188,33 @@ public Opd getLastOpd(int patID) throws OHServiceException {
}

/**
* Checks if the code is already in use
* Checks if the code is already in use.
*
* @param code - the opd code
* @return <code>true</code> if the code is already in use, <code>false</code> otherwise
* @return {@code true} if the code is already in use, {@code false} otherwise
* @throws OHServiceException
*/
public boolean isCodePresent(Integer code) throws OHServiceException {
return repository.existsById(code);
}

/**
* Check if the given {@code opdNum} does already exist for the give {@code year}
* Check if the given {@code opdNum} does already exist for the given {@code year}.
*
* @param opdNum - the OPD progressive in year
* @param year - the year
* @return <code>true</code> if the given number exists in year, <code>false</code> otherwise
* @return {@code true} if the given number exists in year, {@code false} otherwise
* @throws OHServiceException
*/
public Boolean isExistOpdNum(int opdNum, int year) throws OHServiceException {
public boolean isExistOpdNum(int opdNum, int year) throws OHServiceException {
List<Opd> opds = year == 0 ?
repository.findByProgYear(opdNum) :
repository.findByProgYearAndDateBetween(opdNum, LocalDateTime.of(year, 1, 1, 0, 0), LocalDateTime.of(year + 1, 1, 1, 0, 0));
return !opds.isEmpty();
}

/**
* Get an OPD by its code
* Get an {@link Opd} by its code.
* @param code - the OPD code
* @return an OPD or {@code null}
*/
Expand All @@ -226,7 +223,7 @@ public Optional<Opd> getOpdById(Integer code) {
}

/**
* Get a list of OPD with specified Progressive in Year number
* Get a list of {@link Opd}s with the specified Progressive in Year number.
* @param code - the OPD code
* @return a list of OPD or an empty list
*/
Expand All @@ -235,10 +232,10 @@ public List<Opd> getOpdByProgYear(Integer code) {
}

/**
* Retrieves a page of {@link Opd}s within specified dates and parameters
* Retrieves a page of {@link Opd}s within specified dates and parameters.
*
* @param ward
* @param diseaseType
* @param ward
* @param diseaseTypeCode
* @param diseaseCode
* @param dateFrom
* @param dateTo
Expand Down Expand Up @@ -268,9 +265,9 @@ public PagedResponse<Opd> getOpdListPageable(
Pageable pageRequest = PageRequest.of(page, size);
List<Opd> ops = this.getOpdList(ward, diseaseTypeCode, diseaseCode, dateFrom, dateTo, ageFrom, ageTo, sex, newPatient, null);
int start = (int) pageRequest.getOffset();
int end = Math.min((start + pageRequest.getPageSize()), ops.size());
int end = Math.min(start + pageRequest.getPageSize(), ops.size());
List<Opd> pageContent = ops.subList(start, end);
return setPaginationData(new PageImpl<Opd>(pageContent, pageRequest, ops.size()));
return setPaginationData(new PageImpl<>(pageContent, pageRequest, ops.size()));
}

PagedResponse<Opd> setPaginationData(Page<Opd> pages) {
Expand Down
Loading

0 comments on commit f82b49e

Please sign in to comment.