Skip to content
1 change: 1 addition & 0 deletions src/main/java/com/iemr/mmu/data/anc/ANCCareDetails.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public class ANCCareDetails {

public ANCCareDetails() {
super();
this.processed = "N";
// TODO Auto-generated constructor stub
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public class ANCWomenVaccineDetail {

public ANCWomenVaccineDetail() {
super();
this.processed = "N";
// TODO Auto-generated constructor stub
}

Expand Down
43 changes: 25 additions & 18 deletions src/test/java/com/iemr/mmu/service/anc/ANCServiceImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;

class ANCServiceImplTest {
Expand Down Expand Up @@ -696,11 +703,11 @@ void testUpdateANCDoctorData_allBranchesSuccess() throws Exception {
when(commonDoctorServiceImpl.callTmForSpecialistSlotBook(any(), any())).thenReturn(1);
when(teleConsultationServiceImpl.createTCRequest(any())).thenReturn(1);
when(commonDoctorServiceImpl.updateDocFindings(any())).thenReturn(1);
when(commonDoctorServiceImpl.updateBenFlowtableAfterDocDataUpdate(any(), anyBoolean(), anyBoolean(), any())).thenReturn(1);
when(commonDoctorServiceImpl.updateBenFlowtableAfterDocDataUpdate(any(), anyBoolean(), anyBoolean(), any(),null)).thenReturn(1);
when(commonNurseServiceImpl.updatePrescription(any())).thenReturn(1);
when(ancDoctorServiceImpl.updateBenANCDiagnosis(any())).thenReturn(1);
when(commonNurseServiceImpl.saveBenInvestigation(any())).thenReturn(1L);
when(commonNurseServiceImpl.saveBenPrescribedDrugsList(any())).thenReturn(1);
when(commonNurseServiceImpl.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(commonDoctorServiceImpl.updateBenReferDetails(any())).thenReturn(1L);

try {
Expand All @@ -726,11 +733,11 @@ void testUpdateANCDoctorData_failureBranches() throws Exception {
when(commonDoctorServiceImpl.callTmForSpecialistSlotBook(any(), any())).thenReturn(0);
when(teleConsultationServiceImpl.createTCRequest(any())).thenReturn(0);
when(commonDoctorServiceImpl.updateDocFindings(any())).thenReturn(0);
when(commonDoctorServiceImpl.updateBenFlowtableAfterDocDataUpdate(any(), anyBoolean(), anyBoolean(), any())).thenReturn(0);
when(commonDoctorServiceImpl.updateBenFlowtableAfterDocDataUpdate(any(), anyBoolean(), anyBoolean(), any(),null)).thenReturn(0);
when(commonNurseServiceImpl.updatePrescription(any())).thenReturn(0);
when(ancDoctorServiceImpl.updateBenANCDiagnosis(any())).thenReturn(0);
when(commonNurseServiceImpl.saveBenInvestigation(any())).thenReturn(0L);
when(commonNurseServiceImpl.saveBenPrescribedDrugsList(any())).thenReturn(0);
when(commonNurseServiceImpl.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(commonDoctorServiceImpl.updateBenReferDetails(any())).thenReturn(0L);

try {
Expand Down Expand Up @@ -759,13 +766,13 @@ void testSaveANCDoctorData_allBranchesSuccess() throws Exception {
when(commonDoctorServiceImpl.callTmForSpecialistSlotBook(any(), any())).thenReturn(1);
when(teleConsultationServiceImpl.createTCRequest(any())).thenReturn(1);
when(commonDoctorServiceImpl.saveDocFindings(any())).thenReturn(1);
when(commonDoctorServiceImpl.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any())).thenReturn(1);
when(commonDoctorServiceImpl.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any(),null)).thenReturn(1);
when(commonNurseServiceImpl.savePrescriptionDetailsAndGetPrescriptionID(
any(Long.class), any(Long.class), any(Integer.class), any(String.class), any(String.class),
any(Long.class), any(Integer.class), any(Integer.class), any(ArrayList.class)
)).thenReturn(1L);
when(commonNurseServiceImpl.saveBenInvestigation(any())).thenReturn(1L);
when(commonNurseServiceImpl.saveBenPrescribedDrugsList(any())).thenReturn(1);
when(commonNurseServiceImpl.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(ancDoctorServiceImpl.saveBenANCDiagnosis(any(), any())).thenReturn(1L);
when(commonDoctorServiceImpl.saveBenReferDetails(any())).thenReturn(1L);

Expand Down Expand Up @@ -793,13 +800,13 @@ void testSaveANCDoctorData_failureBranches() throws Exception {
when(commonDoctorServiceImpl.callTmForSpecialistSlotBook(any(), any())).thenReturn(0);
when(teleConsultationServiceImpl.createTCRequest(any())).thenReturn(0);
when(commonDoctorServiceImpl.saveDocFindings(any())).thenReturn(0);
when(commonDoctorServiceImpl.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any())).thenReturn(0);
when(commonDoctorServiceImpl.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any(),null)).thenReturn(0);
when(commonNurseServiceImpl.savePrescriptionDetailsAndGetPrescriptionID(
any(Long.class), any(Long.class), any(Integer.class), any(String.class), any(String.class),
any(Long.class), any(Integer.class), any(Integer.class), any(ArrayList.class)
)).thenReturn(0L);
when(commonNurseServiceImpl.saveBenInvestigation(any())).thenReturn(0L);
when(commonNurseServiceImpl.saveBenPrescribedDrugsList(any())).thenReturn(0);
when(commonNurseServiceImpl.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(ancDoctorServiceImpl.saveBenANCDiagnosis(any(), any())).thenReturn(0L);
when(commonDoctorServiceImpl.saveBenReferDetails(any())).thenReturn(0L);

Expand Down Expand Up @@ -1099,10 +1106,10 @@ void testUpdateANCDoctorData_allBranches() throws Exception {

// Mock all service calls to return success
when(doctorService.updateDocFindings(any())).thenReturn(1);
when(doctorService.updateBenFlowtableAfterDocDataUpdate(any(), anyBoolean(), anyBoolean(), any())).thenReturn(1);
when(doctorService.updateBenFlowtableAfterDocDataUpdate(any(), anyBoolean(), anyBoolean(), any(),null)).thenReturn(1);
when(nurseService.savePrescriptionDetailsAndGetPrescriptionID(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
when(nurseService.saveBenInvestigation(any())).thenReturn(1L);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(1);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(ancDoctorService.updateBenANCDiagnosis(any())).thenReturn(1);
when(doctorService.updateBenReferDetails(any())).thenReturn(1L);

Expand Down Expand Up @@ -1244,10 +1251,10 @@ void testSaveANCDoctorData_comprehensiveSuccess() throws Exception {
when(doctorService.callTmForSpecialistSlotBook(any(), any())).thenReturn(1);
when(teleService.createTCRequest(any())).thenReturn(1);
when(doctorService.saveDocFindings(any())).thenReturn(1);
when(doctorService.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any())).thenReturn(1);
when(doctorService.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any(),null)).thenReturn(1);
when(nurseService.savePrescriptionDetailsAndGetPrescriptionID(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(1L);
when(nurseService.saveBenInvestigation(any())).thenReturn(1L);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(1);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(ancDoctorService.saveBenANCDiagnosis(any(), any())).thenReturn(1L);
when(doctorService.saveBenReferDetails(any())).thenReturn(1L);

Expand Down Expand Up @@ -1338,9 +1345,9 @@ void testSaveANCDoctorData_prescriptionLogic() throws Exception {
when(doctorService.saveDocFindings(any())).thenReturn(1);
when(nurseService.savePrescriptionDetailsAndGetPrescriptionID(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(100L);
when(nurseService.saveBenInvestigation(any())).thenReturn(1L);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(1);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(ancDoctorService.saveBenANCDiagnosis(any(), any())).thenReturn(1L);
when(doctorService.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any())).thenReturn(1);
when(doctorService.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any(),null)).thenReturn(1);

Long result = service.saveANCDoctorData(obj, "auth");
assertNotNull(result);
Expand Down Expand Up @@ -1405,9 +1412,9 @@ void testSaveANCDoctorData_prescriptionDrugDetailProcessing() throws Exception {
when(doctorService.saveDocFindings(any())).thenReturn(1);
when(nurseService.savePrescriptionDetailsAndGetPrescriptionID(any(), any(), any(), any(), any(), any(), any(), any(), any())).thenReturn(999L);
when(nurseService.saveBenInvestigation(any())).thenReturn(1L);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(2); // Return > 0
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(ancDoctorService.saveBenANCDiagnosis(any(), any())).thenReturn(1L);
when(doctorService.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any())).thenReturn(1);
when(doctorService.updateBenFlowtableAfterDocDataSave(any(), anyBoolean(), anyBoolean(), any(),null)).thenReturn(1);

Long result = service.saveANCDoctorData(obj, "auth");
assertNotNull(result);
Expand Down Expand Up @@ -1476,9 +1483,9 @@ void testUpdateANCDoctorData_prescriptionCoverage() throws Exception {
when(nurseService.updatePrescription(any())).thenReturn(1);
when(ancDoctorService.updateBenANCDiagnosis(any())).thenReturn(1);
when(nurseService.saveBenInvestigation(any())).thenReturn(1L);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(1);
when(nurseService.saveBenPrescribedDrugsList(any())).thenReturn(new HashMap<String, Object>());
when(doctorService.updateBenReferDetails(any())).thenReturn(1L);
when(doctorService.updateBenFlowtableAfterDocDataUpdate(any(), anyBoolean(), anyBoolean(), any())).thenReturn(1);
when(doctorService.updateBenFlowtableAfterDocDataUpdate(any(), anyBoolean(), anyBoolean(), any(), null)).thenReturn(1);

// Call method - should cover prescription array processing
service.updateANCDoctorData(obj, "auth");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ void testUpdateBenFlowNurseAfterNurseUpdateNCD_Screening_Exception() {

@Test
@DisplayName("Test updateBenFlowAfterDocData - Success")
void testUpdateBenFlowAfterDocData_Success() {
void testUpdateBenFlowAfterDocData_Success() throws Exception {
// Arrange
Long benFlowID = 1L;
Long benRegID = 1L;
Expand All @@ -404,20 +404,20 @@ void testUpdateBenFlowAfterDocData_Success() {
Timestamp tcDate = new Timestamp(System.currentTimeMillis());

when(beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivity(
benFlowID, benRegID, benID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate))
benFlowID, benRegID, benID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null))
.thenReturn(1);

// Act
int result = commonBenStatusFlowService.updateBenFlowAfterDocData(
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate);
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null);

// Assert
assertEquals(1, result);
}

@Test
@DisplayName("Test updateBenFlowAfterDocData - Exception")
void testUpdateBenFlowAfterDocData_Exception() {
void testUpdateBenFlowAfterDocData_Exception() throws Exception {
// Arrange
Long benFlowID = 1L;
Long benRegID = 1L;
Expand All @@ -431,12 +431,12 @@ void testUpdateBenFlowAfterDocData_Exception() {
Timestamp tcDate = new Timestamp(System.currentTimeMillis());

when(beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivity(
benFlowID, benRegID, benID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate))
benFlowID, benRegID, benID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null))
.thenThrow(new RuntimeException("Database error"));

// Act
int result = commonBenStatusFlowService.updateBenFlowAfterDocData(
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate);
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null);

// Assert
assertEquals(0, result);
Expand All @@ -459,12 +459,12 @@ void testUpdateBenFlowAfterDocDataUpdate_SuccessWithExistingPharmaFlag() throws

when(beneficiaryFlowStatusRepo.getPharmaFlag(benFlowID)).thenReturn((short) 1);
when(beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivity(
benFlowID, benRegID, benID, docFlag, (short) 1, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate))
benFlowID, benRegID, benID, docFlag, (short) 1, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null))
.thenReturn(1);

// Act
int result = commonBenStatusFlowService.updateBenFlowAfterDocDataUpdate(
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate);
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null);

// Assert
assertEquals(1, result);
Expand All @@ -487,12 +487,12 @@ void testUpdateBenFlowAfterDocDataUpdate_SuccessWithNewPharmaFlag() throws Excep

when(beneficiaryFlowStatusRepo.getPharmaFlag(benFlowID)).thenReturn((short) 0);
when(beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivity(
benFlowID, benRegID, benID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate))
benFlowID, benRegID, benID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null))
.thenReturn(1);

// Act
int result = commonBenStatusFlowService.updateBenFlowAfterDocDataUpdate(
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate);
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null);

// Assert
assertEquals(1, result);
Expand All @@ -519,7 +519,7 @@ void testUpdateBenFlowAfterDocDataUpdate_Exception() {
// Act & Assert
Exception exception = assertThrows(Exception.class, () -> {
commonBenStatusFlowService.updateBenFlowAfterDocDataUpdate(
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate);
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null);
});

assertNotNull(exception);
Expand All @@ -541,12 +541,12 @@ void testUpdateBenFlowAfterDocDataUpdateWDF_Success() throws Exception {

when(beneficiaryFlowStatusRepo.getPharmaFlag(benFlowID)).thenReturn((short) 0);
when(beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivityWDF(
benFlowID, benRegID, benID, docFlag, pharmaFlag, oncologistFlag, tcUserID, tcDate))
benFlowID, benRegID, benID, docFlag, pharmaFlag, oncologistFlag, tcUserID, tcDate, null))
.thenReturn(1);

// Act
int result = commonBenStatusFlowService.updateBenFlowAfterDocDataUpdateWDF(
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcUserID, tcDate);
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcUserID, tcDate, null);

// Assert
assertEquals(1, result);
Expand All @@ -569,12 +569,12 @@ void testUpdateBenFlowAfterDocDataUpdateTCSpecialist_Success() throws Exception

when(beneficiaryFlowStatusRepo.getPharmaFlag(benFlowID)).thenReturn((short) 0);
when(beneficiaryFlowStatusRepo.updateBenFlowStatusAfterDoctorActivityTCSpecialist(
benFlowID, benRegID, benID, pharmaFlag, oncologistFlag, tcSpecialistFlag))
benFlowID, benRegID, benID, pharmaFlag, oncologistFlag, tcSpecialistFlag, null))
.thenReturn(1);

// Act
int result = commonBenStatusFlowService.updateBenFlowAfterDocDataUpdateTCSpecialist(
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate);
benFlowID, benRegID, benID, benVisitID, docFlag, pharmaFlag, oncologistFlag, tcSpecialistFlag, tcUserID, tcDate, null);

// Assert
assertEquals(1, result);
Expand Down
Loading
Loading