From ab5aaed3eaf1e41e9e87bccfa779d5df233de781 Mon Sep 17 00:00:00 2001 From: dbaluku Date: Wed, 10 Jul 2024 17:06:49 +0300 Subject: [PATCH 1/2] adjusted logging of failed fields in the vl program data --- ...ralLoadProgramDataToCentralServerTask.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadProgramDataToCentralServerTask.java b/api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadProgramDataToCentralServerTask.java index 35fc87d2..39c020c2 100644 --- a/api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadProgramDataToCentralServerTask.java +++ b/api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadProgramDataToCentralServerTask.java @@ -72,12 +72,13 @@ public void execute() { List firstSyncTaskToRun = allSyncTasks.stream().filter(p -> firstMessageSyncTaskType.getId().equals(p.getSyncTaskType().getId())).collect(Collectors.toList()); if (successfullVLProgramSyncTasks.size()<1 && firstSyncTaskToRun.size()>0) { - Map dataOutput = generateVLProgramDataFHIRBody((TestOrder) order, VL_SEND_PROGRAM_DATA_FHIR_JSON_STRING); - String json = dataOutput.get("json"); - String empty_fields = dataOutput.get("empty_fields"); - String patientARTno = dataOutput.get("patient"); + try { + Map dataOutput = generateVLProgramDataFHIRBody((TestOrder) order, VL_SEND_PROGRAM_DATA_FHIR_JSON_STRING); + String json = dataOutput.get("json"); + String empty_fields = dataOutput.get("empty_fields"); + String patientARTno = dataOutput.get("patient"); Map map = ugandaEMRHttpURLConnection.sendPostBy(syncTaskType.getUrl(), syncTaskType.getUrlUserName(), syncTaskType.getUrlPassword(), "", json, false); if (map != null) { SyncTask newSyncTask = new SyncTask(); @@ -89,7 +90,7 @@ public void execute() { newSyncTask.setSyncTask(order.getAccessionNumber()); newSyncTask.setStatusCode((Integer) map.get("responseCode")); if(empty_fields!="") { - newSyncTask.setStatus((String) map.get("responseMessage") + "Patient "+ patientARTno+" empty fields: " + empty_fields); + newSyncTask.setStatus((String) map.get("responseMessage") + " Patient "+ patientARTno+" empty fields: " + empty_fields); }else{ newSyncTask.setStatus((String) map.get("responseMessage")); } @@ -166,6 +167,8 @@ else if(dsdm_code==165141){ dsdm_hie_code = "734163000_05"; } } + if(dsdm_hie_code.isEmpty()) + empty_fields += empty_fields+", dsdm"; List obs_adherenceList = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_coded", patientId,90221,date_activated),true); String adherence=""; @@ -185,6 +188,8 @@ else if(dsdm_code==165141){ adherence_hie_code = "1156699004_03"; } } + if(adherence_hie_code.isEmpty()) + empty_fields += empty_fields+", adherence"; List current_regimen_start_date = administrationService.executeSQL(String.format("SELECT TIMESTAMPDIFF(MONTH, obs_datetime,'%s') from obs where person_id=%s and concept_id=90315 and voided=0 and value_coded = %s ORDER BY obs_datetime ASC LIMIT 1",date_activated.toString(),patientId,regimen_code),true); @@ -251,13 +256,16 @@ else if( duration < 6) { } } - List artStartList = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_datetime", patientId,99161,date_activated),true); + List artStartList = administrationService.executeSQL(String.format(Latest_obs_of_Person,"DATE(value_datetime)", patientId,99161,date_activated),true); Date artStartDate = null; if(artStartList.size()>0){ ArrayList myList = (ArrayList) artStartList.get(0); - artStartDate = Context.getService(UgandaEMRSyncService.class).convertStringToDate(myList.get(0).toString(),"","yyyy-MM-dd'T'HH:mm"); + artStartDate = Context.getService(UgandaEMRSyncService.class).convertStringToDate(myList.get(0).toString(),"","yyyy-MM-dd"); } + if(artStartDate==null) + empty_fields += empty_fields+", ART Start Date"; + List obs_indication_for_VL = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_coded", patientId,168689,date_activated),true); String vl_indication_hie_code =""; From 160a9937689209a3699770b9b4e89555d75f82c5 Mon Sep 17 00:00:00 2001 From: dbaluku Date: Tue, 15 Oct 2024 11:07:50 +0300 Subject: [PATCH 2/2] improvised on vl indicators that lead to failure of syncing to cphl ensure we have one sync task of failure for a sync task. --- .../api/UgandaEMRSyncService.java | 2 + .../api/dao/UgandaEMRSyncDao.java | 7 + .../api/impl/UgandaEMRSyncServiceImpl.java | 5 + .../ugandaemrsync/server/SyncConstant.java | 5 + ...ralLoadProgramDataToCentralServerTask.java | 196 +++++++++++++----- 5 files changed, 163 insertions(+), 52 deletions(-) diff --git a/api/src/main/java/org/openmrs/module/ugandaemrsync/api/UgandaEMRSyncService.java b/api/src/main/java/org/openmrs/module/ugandaemrsync/api/UgandaEMRSyncService.java index 3ad2e236..f6399b2a 100644 --- a/api/src/main/java/org/openmrs/module/ugandaemrsync/api/UgandaEMRSyncService.java +++ b/api/src/main/java/org/openmrs/module/ugandaemrsync/api/UgandaEMRSyncService.java @@ -483,5 +483,7 @@ public Encounter addVLToEncounter(String vlQualitative, String vlQuantitative, S public List getSyncFHIRResourceBySyncFhirProfile(SyncFhirProfile syncFhirProfile, String synceDateFrom, String synceDateTo); public List searchSyncTask(SyncTaskType syncTaskType,Integer statusCode,Date fromDate, Date toDate); + + public void deleteSyncTask(String syncTask, SyncTaskType syncTaskType); } diff --git a/api/src/main/java/org/openmrs/module/ugandaemrsync/api/dao/UgandaEMRSyncDao.java b/api/src/main/java/org/openmrs/module/ugandaemrsync/api/dao/UgandaEMRSyncDao.java index f643d2d3..9fba8827 100644 --- a/api/src/main/java/org/openmrs/module/ugandaemrsync/api/dao/UgandaEMRSyncDao.java +++ b/api/src/main/java/org/openmrs/module/ugandaemrsync/api/dao/UgandaEMRSyncDao.java @@ -10,11 +10,14 @@ package org.openmrs.module.ugandaemrsync.api.dao; import org.hibernate.Criteria; +import org.hibernate.Query; import org.hibernate.SQLQuery; +import org.hibernate.Transaction; import org.hibernate.criterion.Order; import org.hibernate.criterion.Restrictions; import org.hibernate.type.StringType; import org.openmrs.Patient; +import org.openmrs.api.context.Context; import org.openmrs.api.db.hibernate.DbSession; import org.openmrs.api.db.hibernate.DbSessionFactory; import org.openmrs.module.ugandaemrsync.model.SyncTask; @@ -471,4 +474,8 @@ public List searchSyncTask(SyncTaskType syncTaskType, Integer statusCo } return criteria.list(); } + + public void deleteUnSuccessfulSyncTasks(String syncTask, SyncTaskType syncTaskType) { + Context.getAdministrationService().executeSQL(String.format("delete from sync_task where status_code != %s and sync_task = '%s' and sync_task_type= %s",200,syncTask,syncTaskType.getSyncTaskTypeId()),false); + } } diff --git a/api/src/main/java/org/openmrs/module/ugandaemrsync/api/impl/UgandaEMRSyncServiceImpl.java b/api/src/main/java/org/openmrs/module/ugandaemrsync/api/impl/UgandaEMRSyncServiceImpl.java index 7a6e536d..a47958f6 100644 --- a/api/src/main/java/org/openmrs/module/ugandaemrsync/api/impl/UgandaEMRSyncServiceImpl.java +++ b/api/src/main/java/org/openmrs/module/ugandaemrsync/api/impl/UgandaEMRSyncServiceImpl.java @@ -1172,5 +1172,10 @@ public List getSyncTasksByType(SyncTaskType syncTaskType) { public List searchSyncTask(SyncTaskType syncTaskType,Integer statusCode,Date fromDate, Date toDate) { return dao.searchSyncTask( syncTaskType, statusCode, fromDate, toDate); } + + @Override + public void deleteSyncTask(String syncTask, SyncTaskType syncTaskType) { + dao.deleteUnSuccessfulSyncTasks(syncTask,syncTaskType); + } } diff --git a/api/src/main/java/org/openmrs/module/ugandaemrsync/server/SyncConstant.java b/api/src/main/java/org/openmrs/module/ugandaemrsync/server/SyncConstant.java index 6c84144e..a88f76fa 100644 --- a/api/src/main/java/org/openmrs/module/ugandaemrsync/server/SyncConstant.java +++ b/api/src/main/java/org/openmrs/module/ugandaemrsync/server/SyncConstant.java @@ -503,5 +503,10 @@ public class SyncConstant { public static List VL_SYNC_TASK_COLUMNS = Arrays.asList("sync_task_id", "sync_task_type", "sync_task", "status", "status_code", "sent_to_url", "require_action", "action_completed", "date_sent", "creator", "date_created", "changed_by", "date_changed", "voided", "date_voided", "voided_by ", "void_reason", "uuid"); public static final String Latest_obs_of_Person = "SELECT %s from obs where person_id=%s and concept_id=%s and obs_datetime <= '%s' and voided= 0 ORDER BY obs_datetime DESC LIMIT 1"; + public static final String Latest_drug_order_of_person = "SELECT o.concept_id FROM orders o\n" + + " INNER JOIN order_type ot ON o.order_type_id = ot.order_type_id\n" + + " INNER JOIN drug_order d_o ON o.order_id = d_o.order_id\n" + + "where ot.uuid='131168f4-15f5-102d-96e4-000c29c2a5d7' and o.voided=0 and patient_id=%s and DATE(date_activated) <='%s'" + + " and o.concept_id in (SELECT answer_concept from concept_answer where concept_id=90315) ORDER BY date_activated DESC LIMIT 1\n"; public static final String ALIS_SYNC_TASK_TYPE_UUID = "d4a3ebbb-e793-4e56-867c-0cf998e51f56"; } \ No newline at end of file diff --git a/api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadProgramDataToCentralServerTask.java b/api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadProgramDataToCentralServerTask.java index 39c020c2..2998d721 100644 --- a/api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadProgramDataToCentralServerTask.java +++ b/api/src/main/java/org/openmrs/module/ugandaemrsync/tasks/SendViralLoadProgramDataToCentralServerTask.java @@ -19,23 +19,12 @@ import java.io.IOException; import java.text.ParseException; +import java.time.LocalDate; +import java.time.ZoneId; import java.util.*; import java.util.stream.Collectors; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.VIRAL_LOAD_SYNC_TYPE_UUID; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.VL_PROGRAM_DATA_SYNC_TYPE_UUID; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.VL_SEND_PROGRAM_DATA_FHIR_JSON_STRING; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.PATIENT_IDENTIFIER_TYPE; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.OPENMRS_IDENTIFIER_TYPE_UUID; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.ANC_IDENTIFIER_TYPE_UUID; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.NATIONAL_ID_IDENTIFIER_TYPE_UUID; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.PNC_IDENTIFIER_TYPE_UUID; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.Latest_obs_of_Person; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.firstLineBody; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.secondLineBody; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.thirdLineBody; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.VIRAL_LOAD_ORDERS_QUERY; -import static org.openmrs.module.ugandaemrsync.server.SyncConstant.REGIMEN_LINE_QUERY; +import static org.openmrs.module.ugandaemrsync.server.SyncConstant.*; /** * Posts Viral load PROGRAM data to the central server @@ -79,6 +68,7 @@ public void execute() { String json = dataOutput.get("json"); String empty_fields = dataOutput.get("empty_fields"); String patientARTno = dataOutput.get("patient"); + ugandaEMRSyncService.deleteSyncTask(order.getAccessionNumber(),syncTaskType); Map map = ugandaEMRHttpURLConnection.sendPostBy(syncTaskType.getUrl(), syncTaskType.getUrlUserName(), syncTaskType.getUrlPassword(), "", json, false); if (map != null) { SyncTask newSyncTask = new SyncTask(); @@ -109,6 +99,7 @@ public Map generateVLProgramDataFHIRBody(TestOrder testOrder, St Map jsonMap = new HashMap<>(); UgandaEMRSyncService ugandaEMRSyncService = new UgandaEMRSyncServiceImpl(); String filledJsonFile = ""; + String empty_fields=""; if (testOrder != null) { AdministrationService administrationService = Context.getAdministrationService(); @@ -125,17 +116,22 @@ public Map generateVLProgramDataFHIRBody(TestOrder testOrder, St String sampleID = testOrder.getAccessionNumber(); String gender = patient.getGender(); List current_regimenList = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_coded", patientId,90315,date_activated),true); + List current_regimen_orders_List = administrationService.executeSQL(String.format(Latest_drug_order_of_person, patientId,date_activated),true); - String empty_fields=""; String current_regimen=""; int regimen_code=0; if(current_regimenList.size() > 0) { ArrayList regimenList = (ArrayList) current_regimenList.get(0); regimen_code = Integer.parseInt(regimenList.get(0).toString()); current_regimen = Context.getConceptService().getConcept(regimen_code).getName().getName(); + }else if (current_regimen_orders_List.size()>0){ + ArrayList regimenList = (ArrayList) current_regimen_orders_List.get(0); + regimen_code = Integer.parseInt(regimenList.get(0).toString()); + + current_regimen = Context.getConceptService().getConcept(regimen_code).getName().getName(); } if(current_regimen.isEmpty()) - empty_fields += empty_fields+", current regimen"; + empty_fields += ", current regimen"; List obs_dsdmList = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_coded", patientId,165143,date_activated),true); @@ -146,29 +142,29 @@ public Map generateVLProgramDataFHIRBody(TestOrder testOrder, St int dsdm_code = Integer.parseInt(myList.get(0).toString()); - if(dsdm_code==165138){ + if(dsdm_code==165138){ dsdm = "FBIM"; dsdm_hie_code = "734163000_01"; - } - else if (dsdm_code==165140) { + } + else if (dsdm_code==165140) { dsdm = "FBG"; dsdm_hie_code = "734163000_02"; } - else if(dsdm_code==165139){ + else if(dsdm_code==165139){ dsdm = "FTDR"; dsdm_hie_code = "734163000_03"; } - else if (dsdm_code==165142) { + else if (dsdm_code==165142) { dsdm = "CDDP"; dsdm_hie_code = "734163000_04"; } - else if(dsdm_code==165141){ + else if(dsdm_code==165141){ dsdm = "CCLAD"; dsdm_hie_code = "734163000_05"; } } if(dsdm_hie_code.isEmpty()) - empty_fields += empty_fields+", dsdm"; + dsdm_hie_code="734163000_01"; List obs_adherenceList = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_coded", patientId,90221,date_activated),true); String adherence=""; @@ -189,9 +185,12 @@ else if(dsdm_code==165141){ } } if(adherence_hie_code.isEmpty()) - empty_fields += empty_fields+", adherence"; + empty_fields += ", adherence"; List current_regimen_start_date = administrationService.executeSQL(String.format("SELECT TIMESTAMPDIFF(MONTH, obs_datetime,'%s') from obs where person_id=%s and concept_id=90315 and voided=0 and value_coded = %s ORDER BY obs_datetime ASC LIMIT 1",date_activated.toString(),patientId,regimen_code),true); + List current_regimen_start_date_by_orders = administrationService.executeSQL(String.format("SELECT TIMESTAMPDIFF(MONTH, date_activated,'%s') from orders o INNER JOIN order_type ot ON o.order_type_id = ot.order_type_id\n" + + "\t INNER JOIN drug_order d_o ON o.order_id = d_o.order_id\n" + + "\t where ot.uuid='131168f4-15f5-102d-96e4-000c29c2a5d7' and patient_id= %s and o.voided=0 and o.concept_id = %s ORDER BY date_activated ASC LIMIT 1",date_activated.toString(),patientId,regimen_code),true); String duration_string=""; String duration_string_hie_code=""; @@ -218,9 +217,32 @@ else if( duration < 6) { duration_string="< 6months"; duration_string_hie_code = "261773006_01"; } + } else if (current_regimen_start_date_by_orders.size()>0) { + ArrayList myList = (ArrayList) current_regimen_start_date_by_orders.get(0); + int duration= Integer.parseInt(myList.get(0).toString()); + if(duration >=60) { + duration_string=">5yrs"; + duration_string_hie_code = "261773006_05"; + } + else if(duration >=24 && duration < 60 ) { + duration_string="2 -< 5yrs"; + duration_string_hie_code = "261773006_04"; + } + else if(duration >=12 && duration < 24 ) { + duration_string="1 - 2yrs"; + duration_string_hie_code = "261773006_03"; + } + else if(duration >=6 && duration < 12) { + duration_string="6 months - < 1yr"; + duration_string_hie_code = "261773006_02"; + } + else if( duration < 6) { + duration_string="< 6months"; + duration_string_hie_code = "261773006_01"; + } } - if(duration_string_hie_code.isEmpty()) - empty_fields += empty_fields+", duration on art"; + if (duration_string_hie_code.isEmpty()) + empty_fields += ", duration on art"; List obs_pregnantList = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_coded", patientId,90041,date_activated),true); @@ -264,39 +286,46 @@ else if( duration < 6) { } if(artStartDate==null) - empty_fields += empty_fields+", ART Start Date"; + empty_fields += ", ART Start Date"; List obs_indication_for_VL = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_coded", patientId,168689,date_activated),true); String vl_indication_hie_code =""; + int vl_indicator_code=0; if(obs_indication_for_VL.size()>0) { ArrayList myList = (ArrayList) obs_indication_for_VL.get(0); - int vl_indicator_code = Integer.parseInt(myList.get(0).toString()); - - if(vl_indicator_code==168683){ // 6 months after ART initiation - vl_indication_hie_code = "315124004_01"; - } - else if (vl_indicator_code==168684) { //12 months after ART initiation - vl_indication_hie_code = "315124004_02"; - } - else if(vl_indicator_code==168688){ //Routine - vl_indication_hie_code = "315124004_03"; - } - else if (vl_indicator_code==168687) { //Repeat (after IAC) - vl_indication_hie_code = "315124004_04"; - } - else if(vl_indicator_code==168685){ //Suspected treatment failure - vl_indication_hie_code = "315124004_05"; - } - else if (vl_indicator_code==166508) { //1st ANC visit - vl_indication_hie_code = "315124004_06"; + vl_indicator_code = Integer.parseInt(myList.get(0).toString()); + + vl_indication_hie_code = getVl_indication_hie_code(vl_indicator_code); + } + if(vl_indication_hie_code.isEmpty()){ +// do manual fill of vl indication warning : this is a hack + List last_vl = administrationService.executeSQL(String.format(Latest_obs_of_Person,"DATE(value_datetime)", patientId,163023,date_activated),true); + if(pregnant){ + vl_indicator_code= 166508; + }else if(artStartDate!=null && isSixToSevenMonthsAgo(artStartDate,date_activated)){ + vl_indicator_code=168683; + }else if( artStartDate!=null &&isTwelveToThirteenMonthsAgo(artStartDate,date_activated)){ + vl_indicator_code = 168684; + }else if(last_vl.size()>0){ + ArrayList myList = (ArrayList) last_vl.get(0); + Date last_vl_date = Context.getService(UgandaEMRSyncService.class).convertStringToDate(myList.get(0).toString(),"","yyyy-MM-dd"); + + if(patient.getAge() <= 15 && last_vl_date!=null && isSixToSevenMonthsAgo(last_vl_date,date_activated)){ + vl_indicator_code=168688 ; + }else if(patient.getAge() >15 && last_vl_date!=null && isTwelveToThirteenMonthsAgo(last_vl_date,date_activated)){ + vl_indicator_code=168688 ; + }else{ + vl_indicator_code=168688 ; + } + }else{ + vl_indicator_code=168688 ; } - else if(vl_indicator_code==168686){ //Special Considerations - vl_indication_hie_code = "315124004_07"; + vl_indication_hie_code = getVl_indication_hie_code(vl_indicator_code); + if(vl_indication_hie_code.isEmpty()){ + empty_fields += " Indication for viral load"; } } - if(vl_indication_hie_code.isEmpty()) - empty_fields += empty_fields+", indication for vl"; List obs_WHOList = administrationService.executeSQL(String.format(Latest_obs_of_Person,"value_coded", patientId,90203,date_activated),true); @@ -354,7 +383,7 @@ else if(vl_indicator_code==168686){ //Special Considerations } } if(who_hie_code.isEmpty()) - empty_fields += empty_fields+", who code"; + empty_fields += ", who code"; String regimenline = getRegimenLineOfPatient(patient); String coded_regimen_line =""; @@ -366,7 +395,7 @@ else if(vl_indicator_code==168686){ //Special Considerations coded_regimen_line=thirdLineBody; } if(coded_regimen_line.isEmpty()) - empty_fields += empty_fields+", regimen_line"; + coded_regimen_line= firstLineBody; jsonMap.put("empty_fields",empty_fields); jsonMap.put("patient",patientARTNO); @@ -377,6 +406,34 @@ else if(vl_indicator_code==168686){ //Special Considerations return jsonMap; } + private static String getVl_indication_hie_code(int vl_indicator_code) { + + String vl_indication_hie_code =""; + + if(vl_indicator_code ==168683){ // 6 months after ART initiation + vl_indication_hie_code = "315124004_01"; + } + else if (vl_indicator_code ==168684) { //12 months after ART initiation + vl_indication_hie_code = "315124004_02"; + } + else if(vl_indicator_code ==168688){ //Routine + vl_indication_hie_code = "315124004_03"; + } + else if (vl_indicator_code ==168687) { //Repeat (after IAC) + vl_indication_hie_code = "315124004_04"; + } + else if(vl_indicator_code ==168685){ //Suspected treatment failure + vl_indication_hie_code = "315124004_05"; + } + else if (vl_indicator_code ==166508) { //1st ANC visit + vl_indication_hie_code = "315124004_06"; + } + else if(vl_indicator_code ==168686){ //Special Considerations + vl_indication_hie_code = "315124004_07"; + } + return vl_indication_hie_code; + } + public List getOrders() throws IOException, ParseException { OrderService orderService = Context.getOrderService(); @@ -419,4 +476,39 @@ private String getRegimenLineOfPatient(Patient patient){ } + public boolean isSixToSevenMonthsAgo(Date date,Date dateActivated) { + // Convert Date to LocalDate + LocalDate inputDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + + // Get current date + LocalDate activeDate = dateActivated.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + + // Calculate the date 6 and 7 months ago + LocalDate sixMonthsAgo = activeDate.minusMonths(6); + LocalDate sevenMonthsAgo = activeDate.minusMonths(7); + + // Check if the input date is between 6 and 7 months ago + return (inputDate.isBefore(sevenMonthsAgo) || inputDate.isEqual(sevenMonthsAgo)) && + (inputDate.isAfter(sixMonthsAgo) || inputDate.isEqual(sixMonthsAgo)); + } + + public boolean isTwelveToThirteenMonthsAgo(Date date,Date dateActivated) { + LocalDate inputDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + LocalDate activeDate = dateActivated.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + + LocalDate twelveMonthsAgo = activeDate.minusMonths(11); + LocalDate thirteenMonthsAgo = activeDate.minusMonths(13); + + return (inputDate.isBefore(thirteenMonthsAgo) || inputDate.isEqual(thirteenMonthsAgo)) && + (inputDate.isAfter(twelveMonthsAgo) || inputDate.isEqual(twelveMonthsAgo)); + } + + public boolean is12MonthsAfter(Date date,Date dateActivated) { + LocalDate inputDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + LocalDate activeDate = dateActivated.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); + + LocalDate thirteenMonthsAgo = activeDate.minusMonths(13); + + return (inputDate.isAfter(thirteenMonthsAgo) ); + } }