Skip to content

Commit

Permalink
Merge branch 'develop' into dependabot/maven/io.github.openfeign-feig…
Browse files Browse the repository at this point in the history
…n-gson-13.0
  • Loading branch information
dbmalkovsky authored Oct 27, 2023
2 parents caf00d6 + f82b49e commit 4d1c9c0
Show file tree
Hide file tree
Showing 15 changed files with 657 additions and 599 deletions.
191 changes: 98 additions & 93 deletions src/main/java/org/isf/lab/manager/LabManager.java

Large diffs are not rendered by default.

154 changes: 80 additions & 74 deletions src/main/java/org/isf/lab/service/LabIoOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.isf.patient.model.Patient;
import org.isf.utils.db.TranslateOHServiceException;
import org.isf.utils.exception.OHServiceException;
import org.isf.utils.exception.model.OHExceptionMessage;
import org.isf.utils.pagination.PageInfo;
import org.isf.utils.pagination.PagedResponse;
import org.isf.utils.time.TimeTools;
Expand Down Expand Up @@ -73,9 +74,10 @@ public class LabIoOperations {
private LabRowIoOperationRepository rowRepository;

/**
* Return a list of results ({@link LaboratoryRow}s) for passed lab entry.
* Return a list of results ({@link LaboratoryRow}s) for passed lab code.
*
* @param code - the {@link Laboratory} record ID.
* @return the list of {@link LaboratoryRow}s. It could be <code>empty</code>
* @return the list of {@link LaboratoryRow}s. It could be {@code empty}
* @throws OHServiceException
*/
public List<LaboratoryRow> getLabRow(Integer code) throws OHServiceException {
Expand All @@ -85,15 +87,15 @@ public List<LaboratoryRow> getLabRow(Integer code) throws OHServiceException {
/**
* Return the list of exams ({@link Laboratory}s) divided by pages.
*
* @param onWeek
* @param oneWeek
* @param pageNo
* @param pageSize
* @return the list of {@link Laboratory}s (could be empty)
* @throws OHServiceException
*/
public List<Laboratory> getLaboratory(boolean onWeek, int pageNo, int pageSize) throws OHServiceException {
public List<Laboratory> getLaboratory(boolean oneWeek, int pageNo, int pageSize) throws OHServiceException {
Pageable pageable = PageRequest.of(pageNo, pageSize);
if (onWeek) {
if (oneWeek) {
LocalDateTime time2 = TimeTools.getDateToday24();
LocalDateTime time1 = time2.minusWeeks(1);
return repository.findByLabDateBetweenOrderByLabDateDesc(time1, time2, pageable).getContent();
Expand All @@ -115,7 +117,8 @@ public PagedResponse<Laboratory> getLaboratoryPageable(boolean oneWeek, int page
}

/**
* Return the whole list of exams ({@link Laboratory}s) within last week.
* Return the whole list of exams ({@link Laboratory}s) within the last week.
*
* @return the list of {@link Laboratory}s
* @throws OHServiceException
*/
Expand All @@ -126,8 +129,9 @@ public List<Laboratory> getLaboratory() throws OHServiceException {
}

/**
* Return a list of exams ({@link Laboratory}s) between specified dates and matching passed exam name
* @param exam - the exam name as <code>String</code>
* Return a list of exams ({@link Laboratory}s) between specified dates and matching passed exam name.
*
* @param exam - the exam name as {@code String}
* @param dateFrom - the lower date for the range
* @param dateTo - the highest date for the range
* @return the list of {@link Laboratory}s
Expand All @@ -142,8 +146,9 @@ public List<Laboratory> getLaboratory(String exam, LocalDateTime dateFrom, Local
}

/**
* Return a list of exams ({@link Laboratory}s) between specified dates and matching passed exam name
* @param exam - the exam name as <code>String</code>
* Return a list of exams ({@link Laboratory}s) between specified dates and matching passed exam name.
*
* @param exam - the exam name as {@code String}
* @param dateFrom - the lower date for the range
* @param dateTo - the highest date for the range
* @param patient - the object of patient
Expand All @@ -153,23 +158,24 @@ public List<Laboratory> getLaboratory(String exam, LocalDateTime dateFrom, Local
public List<Laboratory> getLaboratory(String exam, LocalDateTime dateFrom, LocalDateTime dateTo, Patient patient) throws OHServiceException {
List<Laboratory> laboritories = new ArrayList<>();

if (!exam.equals("") && patient != null) {
if (!exam.isEmpty() && patient != null) {
laboritories = repository.findByLabDateBetweenAndExamDescriptionAndPatientCode(dateFrom, dateTo, exam, patient.getCode());
}
if (!exam.equals("") && patient == null) {
if (!exam.isEmpty() && patient == null) {
laboritories = repository.findByLabDateBetweenAndExam_DescriptionOrderByLabDateDesc(dateFrom, dateTo, exam);
}
if (patient != null && exam.equals("")) {
if (patient != null && exam.isEmpty()) {
laboritories = repository.findByLabDateBetweenAndPatientCode(dateFrom, dateTo, patient.getCode());
}
if (patient == null && exam.equals("")) {
if (patient == null && exam.isEmpty()) {
laboritories = repository.findByLabDateBetweenOrderByLabDateDesc(dateFrom, dateTo);
}
return laboritories;
}

/**
* Return a list of exams ({@link Laboratory}s) related to a {@link Patient}.
*
* @param aPatient - the {@link Patient}.
* @return the list of {@link Laboratory}s related to the {@link Patient}.
* @throws OHServiceException
Expand All @@ -179,8 +185,8 @@ public List<Laboratory> getLaboratory(Patient aPatient) throws OHServiceExceptio
}

/**
* Return a list of exams suitable for printing ({@link LaboratoryForPrint}s)
* within last year
* Return a list of exams suitable for printing ({@link LaboratoryForPrint}s) within the last week.
*
* @return the list of {@link LaboratoryForPrint}s
* @throws OHServiceException
*/
Expand All @@ -192,8 +198,9 @@ public List<LaboratoryForPrint> getLaboratoryForPrint() throws OHServiceExceptio

/**
* Return a list of exams suitable for printing ({@link LaboratoryForPrint}s)
* between specified dates and matching passed exam name
* @param exam - the exam name as <code>String</code>
* between specified dates and matching passed exam name.
*
* @param exam - the exam name as {@code String}
* @param dateFrom - the lower date for the range
* @param dateTo - the highest date for the range
* @return the list of {@link LaboratoryForPrint}s
Expand Down Expand Up @@ -229,57 +236,55 @@ public List<LaboratoryForPrint> getLaboratoryForPrint(String exam, LocalDateTime
}

/**
* Insert a Laboratory exam {@link Laboratory} and return generated key. No commit is performed.
* Insert a new Laboratory exam {@link Laboratory} and return the generated laboratory code.
*
* @param laboratory - the {@link Laboratory} to insert
* @return the generated key
* @return the newly persisted {@link Laboratory} object.
* @throws OHServiceException
*/
private Integer newLaboratory(Laboratory laboratory) throws OHServiceException {
Laboratory savedLaboratory = repository.save(laboratory);
return savedLaboratory.getCode();
private Laboratory newLaboratory(Laboratory laboratory) throws OHServiceException {
return repository.save(laboratory);
}

/**
* Inserts one Laboratory exam {@link Laboratory} (Procedure One)
*
* @param laboratory - the {@link Laboratory} to insert
* @return <code>true</code> if the exam has been inserted, <code>false</code> otherwise
* @return the newly persisted {@link Laboratory} object.
* @throws OHServiceException
*/
public boolean newLabFirstProcedure(Laboratory laboratory) throws OHServiceException {
return newLaboratory(laboratory) > 0;
public Laboratory newLabFirstProcedure(Laboratory laboratory) throws OHServiceException {
return newLaboratory(laboratory);
}

/**
* Inserts one Laboratory exam {@link Laboratory} with multiple results (Procedure Two)
*
* @param laboratory - the {@link Laboratory} to insert
* @param labRow - the list of results ({@link String}s)
* @return <code>true</code> if the exam has been inserted with all its results, <code>false</code> otherwise
* @return the newly persisted {@link Laboratory} object.
* @throws OHServiceException
*/
public boolean newLabSecondProcedure(Laboratory laboratory, List<String> labRow) throws OHServiceException {
boolean result = true;

int newCode = newLaboratory(laboratory);
if (newCode > 0) {
public Laboratory newLabSecondProcedure(Laboratory laboratory, List<String> labRow) throws OHServiceException {
Laboratory newLaboratory = newLaboratory(laboratory);
if (newLaboratory.getCode() > 0) {
for (String aLabRow : labRow) {
LaboratoryRow laboratoryRow = new LaboratoryRow();
laboratoryRow.setLabId(laboratory);
laboratoryRow.setDescription(aLabRow);

LaboratoryRow savedLaboratoryRow = rowRepository.save(laboratoryRow);
result = result && (savedLaboratoryRow != null);
rowRepository.save(laboratoryRow);
}
}
return result;
return newLaboratory;
}

/**
* Return a list of exams suitable for printing ({@link LaboratoryForPrint}s)
* between specified dates and matching passed exam name
* @param exam - the exam name as <code>String</code>
* @param dateFrom - the lower date for the range
* @param dateTo - the highest date for the range
* between specified dates and matching passed exam name.
*
* @param exam - the exam name as {@code String}
* @param dateFrom - the starting date for the date range
* @param dateTo - the ending date for the date range
* @return the list of {@link LaboratoryForPrint}s
* @throws OHServiceException
*/
Expand Down Expand Up @@ -307,89 +312,90 @@ public List<LaboratoryForPrint> getLaboratoryForPrint(String exam, LocalDateTime
*
* @param laboratory - the {@link Laboratory} to insert
* @param labRow - the list of results ({@link String}s)
* @return <code>true</code> if the exam has been inserted with all its results, <code>false</code> otherwise
* @return the newly persisted {@link Laboratory} object.
* @throws OHServiceException
*/
public boolean newLabSecondProcedure2(Laboratory laboratory, List<LaboratoryRow> labRow) throws OHServiceException {
boolean result = true;

int newCode = newLaboratory(laboratory);
public Laboratory newLabSecondProcedure2(Laboratory laboratory, List<LaboratoryRow> labRow) throws OHServiceException {
Laboratory newLaboratory = newLaboratory(laboratory);
int newCode = newLaboratory.getCode();
if (newCode > 0) {
laboratory = repository.findById(newCode).orElse(null);
if (laboratory == null) {
throw new OHServiceException(new OHExceptionMessage("Laboratory with code '" + newCode + "' not found"));
}
for (LaboratoryRow aLabRow : labRow) {
aLabRow.setLabId(laboratory);
LaboratoryRow savedLaboratoryRow = rowRepository.save(aLabRow);
result = result && (savedLaboratoryRow != null);
rowRepository.save(aLabRow);
}
}
return result;
return newLaboratory;
}

/**
* Update an already existing Laboratory exam {@link Laboratory}. No commit is performed.
* Update an already existing Laboratory exam {@link Laboratory}.
*
* @param laboratory - the {@link Laboratory} to update
* @return <code>true</code> if the exam has been updated with all its results, <code>false</code> otherwise
* @return the updated {@link Laboratory} object.
* @throws OHServiceException
*/
private boolean updateLaboratory(Laboratory laboratory) throws OHServiceException {
Laboratory savedLaboratory = repository.save(laboratory);
return savedLaboratory != null;
private Laboratory updateLaboratory(Laboratory laboratory) throws OHServiceException {
return repository.save(laboratory);
}

/**
* Update an already existing Laboratory exam {@link Laboratory} (Procedure One).
* If old exam was Procedure Two all its releated result are deleted.
* If the old exam was Procedure Two then all its related results are deleted.
*
* @param laboratory - the {@link Laboratory} to update
* @return <code>true</code> if the exam has been updated, <code>false</code> otherwise
* @return {@code true} if the exam has been updated, {@code false} otherwise
* @throws OHServiceException
*/
public boolean updateLabFirstProcedure(Laboratory laboratory) throws OHServiceException {
boolean result = updateLaboratory(laboratory);
rowRepository.deleteByLaboratory_Code(laboratory.getCode());
return result;
public Laboratory updateLabFirstProcedure(Laboratory laboratory) throws OHServiceException {
Laboratory updatedLaborator = updateLaboratory(laboratory);
rowRepository.deleteByLaboratory_Code(updatedLaborator.getCode());
return updatedLaborator;
}

/**
* Update an already existing Laboratory exam {@link Laboratory} (Procedure Two).
* Previous results are deleted and replaced with new ones.
* @param laboratory - the {@link Laboratory} to update
* @return <code>true</code> if the exam has been updated with all its results, <code>false</code> otherwise
* @return the updated {@link Laboratory} object.
* @throws OHServiceException
*/
public boolean updateLabSecondProcedure(Laboratory laboratory, List<String> labRow) throws OHServiceException {
boolean result = updateLabFirstProcedure(laboratory);
if (result) {
for (String aLabRow : labRow) {
LaboratoryRow laboratoryRow = new LaboratoryRow();
laboratoryRow.setLabId(laboratory);
laboratoryRow.setDescription(aLabRow);
rowRepository.save(laboratoryRow);
}
public Laboratory updateLabSecondProcedure(Laboratory laboratory, List<String> labRow) throws OHServiceException {
Laboratory updatedLaboratory = updateLabFirstProcedure(laboratory);
for (String aLabRow : labRow) {
LaboratoryRow laboratoryRow = new LaboratoryRow();
laboratoryRow.setLabId(laboratory);
laboratoryRow.setDescription(aLabRow);
rowRepository.save(laboratoryRow);
}
return result;
return updatedLaboratory;
}

/**
* Delete a Laboratory exam {@link Laboratory} (Procedure One or Two).
* Previous results, if any, are deleted as well.
* @param aLaboratory - the {@link Laboratory} to delete
* @return <code>true</code> if the exam has been deleted with all its results, if any. <code>false</code> otherwise
* @throws OHServiceException
*/
public boolean deleteLaboratory(Laboratory aLaboratory) throws OHServiceException {
public void deleteLaboratory(Laboratory aLaboratory) throws OHServiceException {
Laboratory objToRemove = repository.findById(aLaboratory.getCode()).orElse(null);
if (objToRemove == null) {
throw new OHServiceException(new OHExceptionMessage("Laboratory object not found to delete"));
}
if (objToRemove.getExam().getProcedure() == 2) {
rowRepository.deleteByLaboratory_Code(objToRemove.getCode());
}
repository.deleteById(objToRemove.getCode());
return true;
}

/**
* Checks if the code is already in use
*
* @param code - the laboratory 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class MalnutritionManager {
private MalnutritionIoOperation ioOperation;

/**
* Verify if the object is valid for CRUD and return a list of errors, if any
* Verify if the object is valid for CRUD and return a list of errors, if any.
*
* @param malnutrition
* @throws OHDataValidationException
Expand Down Expand Up @@ -74,11 +74,9 @@ protected void validateMalnutrition(Malnutrition malnutrition) throws OHDataVali

/**
* Retrieves all the {@link Malnutrition} associated to the given admission id.
* In case of wrong parameters an error message is shown and <code>null</code> value is returned.
* In case of error a message error is shown and an empty list is returned.
*
* @param admissionID the admission id to use as filter.
* @return all the retrieved malnutrition or <code>null</code> if the specified admission id is <code>null</code>.
* @return all the retrieved malnutrition or {@code null} if the specified admission id is {@code null}.
* @throws OHServiceException
*/
public List<Malnutrition> getMalnutrition(String admissionID) throws OHServiceException {
Expand All @@ -89,7 +87,7 @@ public List<Malnutrition> getMalnutrition(String admissionID) throws OHServiceEx
* Returns the last {@link Malnutrition} entry for specified patient ID
*
* @param patientID - the patient ID
* @return the last {@link Malnutrition} for specified patient ID. <code>null</code> if none.
* @return the last {@link Malnutrition} for specified patient ID. {@code null} if none.
* @throws OHServiceException
*/
public Malnutrition getLastMalnutrition(int patientID) throws OHServiceException {
Expand All @@ -100,7 +98,7 @@ public Malnutrition getLastMalnutrition(int patientID) throws OHServiceException
* Stores a new {@link Malnutrition}. The malnutrition object is updated with the generated id.
*
* @param malnutrition the malnutrition to store.
* @return <code>true</code> if the malnutrition has been stored
* @return the newly stored new {@link Malnutrition} object.
* @throws OHServiceException
*/
public Malnutrition newMalnutrition(Malnutrition malnutrition) throws OHServiceException {
Expand All @@ -109,10 +107,10 @@ public Malnutrition newMalnutrition(Malnutrition malnutrition) throws OHServiceE
}

/**
* Updates the specified {@link Malnutrition}.
* Update the specified {@link Malnutrition}.
*
* @param malnutrition the {@link Malnutrition} to update
* @return the updated {@link Malnutrition}
* @param malnutrition the {@link Malnutrition} to update.
* @return the updated {@link Malnutrition} object.
* @throws OHServiceException
*/
public Malnutrition updateMalnutrition(Malnutrition malnutrition) throws OHServiceException {
Expand All @@ -133,14 +131,11 @@ public Malnutrition getMalnutrition(int code) throws OHServiceException {

/**
* Deletes the specified {@link Malnutrition}.
* In case of wrong parameters an error message is shown and <code>false</code> value is returned.
* In case of error a message error is shown and a <code>false</code> value is returned.
*
* @param malnutrition the malnutrition to delete.
* @return <code>true</code> if the malnutrition has been deleted, <code>false</code> otherwise.
* @throws OHServiceException
*/
public boolean deleteMalnutrition(Malnutrition malnutrition) throws OHServiceException {
return ioOperation.deleteMalnutrition(malnutrition);
public void deleteMalnutrition(Malnutrition malnutrition) throws OHServiceException {
ioOperation.deleteMalnutrition(malnutrition);
}
}
Loading

0 comments on commit 4d1c9c0

Please sign in to comment.