Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.iemr.tm</groupId>
<artifactId>tm-api</artifactId>
<version>3.1.0</version>
<version>3.4.0</version>
<packaging>war</packaging>

<name>TM-API</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public BeneficiaryFlowStatus() {
public BeneficiaryFlowStatus(Long benFlowID, Long benRegID, Timestamp visitDate, String benName, String age,
Integer ageVal, Short genderID, String genderName, String villageName, String districtName,
Long beneficiaryID, String servicePoint, String VisitReason, String VisitCategory, Long benVisitID,
Timestamp regDate, Timestamp benVisitDate, Long visitCode, Timestamp consultationDate) {
Timestamp regDate, Timestamp benVisitDate, Long visitCode, Timestamp consultationDate, String fatherName, String preferredPhoneNum) {
this.benFlowID = benFlowID;
this.beneficiaryRegID = benRegID;
this.serviceDate = benVisitDate;
Expand All @@ -349,7 +349,8 @@ public BeneficiaryFlowStatus(Long benFlowID, Long benRegID, Timestamp visitDate,
this.visitCode = visitCode;
this.consultationDate = consultationDate;
this.bloodGroup = null;

this.fatherName = fatherName;
this.preferredPhoneNum = preferredPhoneNum;
}

public BeneficiaryFlowStatus(Long benFlowID, Long benRegID, Long visitCode, Timestamp visitDate, Short benVisitNo,
Expand All @@ -371,7 +372,8 @@ public static BeneficiaryFlowStatus getBeneficiaryFlowStatusForLeftPanel(ArrayLi
(String) objArr[3], (String) objArr[4], (Integer) objArr[5], (Short) objArr[6],
(String) objArr[7], (String) objArr[8], (String) objArr[9], (Long) objArr[10],
(String) objArr[11], (String) objArr[12], (String) objArr[13], (Long) objArr[14],
(Timestamp) objArr[15], (Timestamp) objArr[16], (Long) objArr[17], (Timestamp) objArr[18]);
(Timestamp) objArr[15], (Timestamp) objArr[16], (Long) objArr[17], (Timestamp) objArr[18],
(String) objArr[19], (String) objArr[20]);
}
Comment on lines +375 to 377
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Brittle index-based mapping — prefer JPQL constructor projection

The indices align with the SELECT list today (fatherName at 19, preferredPhoneNum at 20). To eliminate future off-by-one risks, switch the repository query to a constructor projection and return BeneficiaryFlowStatus directly (no Object[] casts).

In the repo file, change the query to:

-@Query("SELECT  t.benFlowID, t.beneficiaryRegID, t.visitDate, t.benName, t.age, t.ben_age_val, t.genderID, t.genderName, "
-     + " t.villageName, t.districtName, t.beneficiaryID, t.servicePointName, t.VisitReason, t.VisitCategory, t.benVisitID,  "
-     + " t.registrationDate, t.benVisitDate, t.visitCode, t.consultationDate, t.fatherName, t.preferredPhoneNum FROM BeneficiaryFlowStatus t "
-     + " Where t.beneficiaryRegID = :benRegID AND t.benFlowID = :benFlowID ")
-public ArrayList<Object[]> getBenDetailsForLeftSidePanel(...)
+@Query("SELECT new com.iemr.tm.data.benFlowStatus.BeneficiaryFlowStatus("
+     + " t.benFlowID, t.beneficiaryRegID, t.visitDate, t.benName, t.age, t.ben_age_val, t.genderID, t.genderName, "
+     + " t.villageName, t.districtName, t.beneficiaryID, t.servicePointName, t.VisitReason, t.VisitCategory, t.benVisitID, "
+     + " t.registrationDate, t.benVisitDate, t.visitCode, t.consultationDate, t.fatherName, t.preferredPhoneNum) "
+     + " FROM BeneficiaryFlowStatus t WHERE t.beneficiaryRegID = :benRegID AND t.benFlowID = :benFlowID ")
+public ArrayList<BeneficiaryFlowStatus> getBenDetailsForLeftSidePanel(...)

Then this method can simply return the first element (or Optional).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
(Timestamp) objArr[15], (Timestamp) objArr[16], (Long) objArr[17], (Timestamp) objArr[18],
(String) objArr[19], (String) objArr[20]);
}
// Before
- @Query("SELECT t.benFlowID, t.beneficiaryRegID, t.visitDate, t.benName, t.age, t.ben_age_val, t.genderID, t.genderName, "
- + " t.villageName, t.districtName, t.beneficiaryID, t.servicePointName, t.VisitReason, t.VisitCategory, t.benVisitID, "
- + " t.registrationDate, t.benVisitDate, t.visitCode, t.consultationDate, t.fatherName, t.preferredPhoneNum FROM BeneficiaryFlowStatus t "
- + " Where t.beneficiaryRegID = :benRegID AND t.benFlowID = :benFlowID ")
- public ArrayList<Object[]> getBenDetailsForLeftSidePanel(...);
// After
@Query("SELECT new com.iemr.tm.data.benFlowStatus.BeneficiaryFlowStatus("
+ " t.benFlowID, t.beneficiaryRegID, t.visitDate, t.benName, t.age, t.ben_age_val, t.genderID, t.genderName, "
+ " t.villageName, t.districtName, t.beneficiaryID, t.servicePointName, t.VisitReason, t.VisitCategory, t.benVisitID, "
+ " t.registrationDate, t.benVisitDate, t.visitCode, t.consultationDate, t.fatherName, t.preferredPhoneNum) "
+ " FROM BeneficiaryFlowStatus t "
+ "WHERE t.beneficiaryRegID = :benRegID AND t.benFlowID = :benFlowID ")
public ArrayList<BeneficiaryFlowStatus> getBenDetailsForLeftSidePanel(...);
🤖 Prompt for AI Agents
In src/main/java/com/iemr/tm/data/benFlowStatus/BeneficiaryFlowStatus.java
around lines 375 to 377, the code relies on fragile Object[] index-based mapping
from a native/JPQL select; replace that by changing the repository query to use
a JPQL constructor projection (SELECT new
com.iemr.tm.data.benFlowStatus.BeneficiaryFlowStatus(...matching fields... )
...) so the repository returns BeneficiaryFlowStatus instances instead of
Object[], then update this method to accept the repository result and simply
return the first element or Optional<BeneficiaryFlowStatus> (no casts or index
extraction). Ensure the constructor parameter order matches the select list and
update the repository method signature to the concrete type.

}
return obj;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public int updateBenFlowStatusAfterNurseActivityANC(@Param("benFlowID") Long ben

@Query("SELECT t.benFlowID, t.beneficiaryRegID, t.visitDate, t.benName, t.age, t.ben_age_val, t.genderID, t.genderName, "
+ " t.villageName, t.districtName, t.beneficiaryID, t.servicePointName, t.VisitReason, t.VisitCategory, t.benVisitID, "
+ " t.registrationDate, t.benVisitDate, t.visitCode, t.consultationDate FROM BeneficiaryFlowStatus t "
+ " t.registrationDate, t.benVisitDate, t.visitCode, t.consultationDate, t.fatherName, t.preferredPhoneNum FROM BeneficiaryFlowStatus t "
+ " Where t.beneficiaryRegID = :benRegID AND t.benFlowID = :benFlowID ")
Comment on lines 119 to 122
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Reduce mapping fragility with JPQL constructor projection

To avoid Object[] casting and index coupling, consider returning BeneficiaryFlowStatus directly with a constructor expression.

Apply:

-    @Query("SELECT  t.benFlowID, t.beneficiaryRegID, t.visitDate, t.benName, t.age, t.ben_age_val, t.genderID, t.genderName, "
-            + " t.villageName, t.districtName, t.beneficiaryID, t.servicePointName, t.VisitReason, t.VisitCategory, t.benVisitID,  "
-            + " t.registrationDate, t.benVisitDate, t.visitCode, t.consultationDate, t.fatherName, t.preferredPhoneNum FROM BeneficiaryFlowStatus t "
-            + " Where t.beneficiaryRegID = :benRegID AND t.benFlowID = :benFlowID ")
-    public ArrayList<Object[]> getBenDetailsForLeftSidePanel(@Param("benRegID") Long benRegID,
-            @Param("benFlowID") Long benFlowID);
+    @Query("SELECT new com.iemr.tm.data.benFlowStatus.BeneficiaryFlowStatus("
+            + " t.benFlowID, t.beneficiaryRegID, t.visitDate, t.benName, t.age, t.ben_age_val, t.genderID, t.genderName, "
+            + " t.villageName, t.districtName, t.beneficiaryID, t.servicePointName, t.VisitReason, t.VisitCategory, t.benVisitID, "
+            + " t.registrationDate, t.benVisitDate, t.visitCode, t.consultationDate, t.fatherName, t.preferredPhoneNum) "
+            + " FROM BeneficiaryFlowStatus t WHERE t.beneficiaryRegID = :benRegID AND t.benFlowID = :benFlowID ")
+    public ArrayList<BeneficiaryFlowStatus> getBenDetailsForLeftSidePanel(@Param("benRegID") Long benRegID,
+            @Param("benFlowID") Long benFlowID);
🤖 Prompt for AI Agents
In src/main/java/com/iemr/tm/repo/benFlowStatus/BeneficiaryFlowStatusRepo.java
around lines 119 to 122, the JPQL currently selects individual fields which
forces consumers to handle Object[] and fragile index-based mapping; change the
query to use a JPQL constructor expression (SELECT new
com.iemr.tm.model.benFlowStatus.BeneficiaryFlowStatus(...)) listing the same
fields in the same order, ensure the BeneficiaryFlowStatus class has a matching
public constructor accepting those types in that order, and update the
repository method signature to return BeneficiaryFlowStatus (or
List<BeneficiaryFlowStatus>) instead of Object[] so callers receive typed
instances directly.

public ArrayList<Object[]> getBenDetailsForLeftSidePanel(@Param("benRegID") Long benRegID,
@Param("benFlowID") Long benFlowID);
Expand Down
Loading