Skip to content

Commit

Permalink
Merge pull request #43 from zucisystems-dev/bugs/sor_grouping_001
Browse files Browse the repository at this point in the history
Bugs/sor grouping 001
  • Loading branch information
Manikandan-Thangaraj-ZS0321 authored Jun 2, 2023
2 parents dd3650e + 1250bf7 commit 81fb073
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 125 deletions.
3 changes: 2 additions & 1 deletion src/main/antlr/in.handyman.raven/gmr/Raven.g4
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,8 @@ episodeOfCoverage:
'patient-eoc-count' eocIdCount=STRING
'input-file-path' '{' filepath=STRING '}'
'qr-grouping' '{' qrInput=STRING '}'
'eoc-grouping' '{' value=STRING '}' ('on-condition' condition=expression)* ;
'eoc-grouping' '{' value=STRING '}'
'pnd-grouping' '{' pndValue=STRING '}' ('on-condition' condition=expression)* ;

userRegistration:
'userRegistration' 'as' name=STRING
Expand Down
130 changes: 7 additions & 123 deletions src/main/java/in/handyman/raven/lib/EpisodeOfCoverageAction.java
Original file line number Diff line number Diff line change
@@ -1,161 +1,45 @@
package in.handyman.raven.lib;

import in.handyman.raven.exception.HandymanException;
import in.handyman.raven.lambda.access.ResourceAccess;
import in.handyman.raven.lambda.action.ActionExecution;
import in.handyman.raven.lambda.action.IActionExecution;
import in.handyman.raven.lambda.doa.audit.ActionExecutionAudit;
import in.handyman.raven.lib.agadia.eocsplitting.EocIdCoverage;
import in.handyman.raven.lib.agadia.eocsplitting.OriginCoverage;
import in.handyman.raven.lib.agadia.eocsplitting.QrCodeCoverage;
import in.handyman.raven.lib.agadia.eocsplitting.SorItemCoverage;
import in.handyman.raven.lib.model.EpisodeOfCoverage;
import in.handyman.raven.util.ExceptionUtil;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jdbi.v3.core.Jdbi;
import java.lang.Exception;
import java.lang.Object;
import java.lang.Override;
import org.slf4j.Logger;
import org.slf4j.Marker;
import org.slf4j.MarkerFactory;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Auto Generated By Raven
*/
@ActionExecution(
actionName = "EpisodeOfCoverage"
actionName = "EpisodeOfCoverage"
)
public class EpisodeOfCoverageAction implements IActionExecution {
private final ActionExecutionAudit action;

private final Logger log;
public static Map<String, List<Integer>> qrObjectMap = new HashMap<>();
public static Boolean hasMember = false;

private final EpisodeOfCoverage episodeOfCoverage;

private final Marker aMarker;

public EpisodeOfCoverageAction(final ActionExecutionAudit action, final Logger log,
final Object episodeOfCoverage) {
final Object episodeOfCoverage) {
this.episodeOfCoverage = (EpisodeOfCoverage) episodeOfCoverage;
this.action = action;
this.log = log;
this.aMarker = MarkerFactory.getMarker(" EpisodeOfCoverage:" + this.episodeOfCoverage.getName());
this.aMarker = MarkerFactory.getMarker(" EpisodeOfCoverage:"+this.episodeOfCoverage.getName());
}

@Override
public void execute() throws Exception {

try {
log.info(aMarker, "Episode of coverage Action for {} with group by eoc-id has started" , episodeOfCoverage.getName());
final Jdbi jdbi = ResourceAccess.rdbmsJDBIConn(episodeOfCoverage.getResourceConn());
if (Integer.parseInt(episodeOfCoverage.getEocIdCount()) > 0) {
log.info("patient instance check for Eoc id in aggregation");
EocIdCoverage eocIdCoverage = new EocIdCoverage(log, episodeOfCoverage, aMarker, action);
Map<String, List<Integer>> sorIdPageNumbers = eocIdCoverage.SplitByEocId(jdbi, "patient_eoc");
OutputQueryExecutor(jdbi, "EID", sorIdPageNumbers);
log.info("patient instance checked for Eoc id in aggregation and the output result is {}", sorIdPageNumbers);

} else if (Integer.parseInt(episodeOfCoverage.getEocIdCount()) <= 0) {
log.info("patient instance extract QR code from source of truth table");
QrCodeCoverage qrCodeCoverage = new QrCodeCoverage(log, episodeOfCoverage, aMarker, action);
Map<String, List<Integer>> qrPagenumbers = qrCodeCoverage.splitByQrcode(jdbi, "qr_code");
OutputQueryExecutor(jdbi, "QID", qrPagenumbers);

log.info("patient instance checked for Qrcode from source of truth and the output result is {}", qrPagenumbers);

if (qrPagenumbers.isEmpty()) {
log.info("patient instance check for member_id from aggregation");
SorItemCoverage sorItemMemberIdCoverage = new SorItemCoverage(log, episodeOfCoverage, aMarker, action);
Map<String, List<Integer>> patientMemberPageNumbers = sorItemMemberIdCoverage.splitBySorItem(jdbi, "patient_member_id");
OutputQueryExecutor(jdbi, "PID", patientMemberPageNumbers);
log.info("patient instance check for member_id from aggregation and the output result is {}", patientMemberPageNumbers);

if (patientMemberPageNumbers.isEmpty()) {
log.info("patient instance check for patient_name and patient_dob from aggregation");
SorItemCoverage sorItemPatientNameCoverage = new SorItemCoverage(log, episodeOfCoverage, aMarker, action);
Map<String, List<Integer>> patientNamePageNumbers = sorItemPatientNameCoverage.splitBySorItem(jdbi, "patient_name");
OutputQueryExecutor(jdbi, "PND", patientNamePageNumbers);
log.info("patient instance checked for patient_name and patient_dob from aggregation and the output result is {}", patientNamePageNumbers);

if(patientNamePageNumbers.isEmpty()){
log.info("patient instance check for origin id from aggregation");
OriginCoverage originCoverage = new OriginCoverage(log, episodeOfCoverage, aMarker, action);
Map<String, List<Integer>> originIdPageNumbers = originCoverage.aggregateByOrigin(jdbi, episodeOfCoverage.getOriginId()) ;
OutputQueryExecutor(jdbi, "NID", originIdPageNumbers);
log.info("patient instance checked for no id from aggregation and the output result is {}", originIdPageNumbers);
}
}

}
}

} catch (Exception e) {
log.error(aMarker, "Episode of coverage Action for {} with group by eoc-id has failed for {}" , episodeOfCoverage.getName(), ExceptionUtil.toString(e));
throw new HandymanException("Error in sor grouping", e, action);
}

}

@Override
public boolean executeIf() throws Exception {
return episodeOfCoverage.getCondition();
}


public void OutputQueryExecutor(Jdbi jdbi, String sorItem, Map<String, List<Integer>> stringListMap) {

stringListMap.forEach((s, integers) -> {
for (Integer integer : integers) {
CoverageEntity coverageEntity = CoverageEntity.builder()
.paperNo(integer)
.pahubId(s)
.originId(episodeOfCoverage.getOriginId())
.groupId(Integer.valueOf(episodeOfCoverage.getGroupId()))
.createdOn(Timestamp.valueOf(LocalDateTime.now()))
.sourceOfPahub(sorItem)
.build();
try {
jdbi.useTransaction(handle -> {
handle.createUpdate("INSERT INTO " + episodeOfCoverage.getOutputTable() +
"(pahub_id, origin_id, source_of_pahub,group_id,created_on, paper_no,status,stage,message)" +
"VALUES (:pahubId , :originId, :sourceOfPahub ,:groupId,:createdOn, :paperNo, 'COMPLETED', 'SOR_GROUPING', 'sor grouping completed')")
.bindBean(coverageEntity).execute();
});
log.info(aMarker, "Completed insert for the patient instance {}", coverageEntity);

} catch (Exception e) {
log.error(aMarker, "Failed in executed formatted query {} for this sor item {}", e, sorItem);
throw new HandymanException("Failed in executed formatted query {} for this sor item {}", e, action);
}
}
});
}


@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public static class CoverageEntity {
private String pahubId;

private String originId;
private Integer groupId;
private String fileId;
private Timestamp createdOn;
private String sourceOfPahub;

private Integer paperNo;
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Map<String, List<Integer>> splitBySorItem(Jdbi jdbi, String sorItem){
if(Objects.equals("patient_name",sorItem)){
inputSorItem=" AND sor_item_name IN ('patient_name' , 'patient_dob') group by paper_no;";
}
String inputQuery=episodeOfCoverage.getValue().replace(";"," ").concat(inputSorItem);
String inputQuery=episodeOfCoverage.getPndValue().replace(";"," ").concat(inputSorItem);
List<Map<String, Object>> eocGroupingMemberItemRequestInfos = queryExecutor(jdbi,sorItem,inputQuery);

List<Integer> breakPointsList = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,7 @@ public class EpisodeOfCoverage implements IActionContext {

private String value;

private String pndValue;

private Boolean condition = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public void episodeOfCoverageTest() throws Exception {
.qrInput(" SELECT '${gen_group_id.group_id}' AS group_id,extracted_value AS answer, min(paper_no) AS start_no, max(paper_no) AS end_no,'${file_count.total_page}' AS total_pages\n" +
" FROM qr_extraction.qr_extraction_result_138971395735140128\n" +
" WHERE origin_id='INT-1' AND qr_format='DATAMATRIX' group by extracted_value")
.pndValue(" SELECT '${group_id}' AS group_id,string_agg(predicted_value,'-') AS answer,min(paper_no) AS start_no,max(paper_no) AS end_no ,'${file_count.total_page}' AS total_pages\n" +
" FROM score.aggregation_evaluator\n" +
" WHERE origin_id='${origin_id}' and predicted_value !='' and predicted_value is not null;")
.build();

final ActionExecutionAudit action = ActionExecutionAudit.builder()
Expand Down

0 comments on commit 81fb073

Please sign in to comment.