use of gov.cms.ab2d.eventlogger.events.ContractSearchEvent in project ab2d by CMSgov.
the class JobProcessorIntegrationTest method when_beneHasNoEobs_notCounted.
@Test
@DisplayName("When bene has no eobs then do not count bene toward statistic")
void when_beneHasNoEobs_notCounted() {
reset(mockBfdClient);
OngoingStubbing<IBaseBundle> stubbing = when(mockBfdClient.requestEOBFromServer(eq(STU3), anyLong(), any()));
stubbing = andThenAnswerEobs(stubbing, 0, 95);
stubbing.thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle()).thenReturn(BundleUtils.createBundle());
var processedJob = cut.process(job.getJobUuid());
assertEquals(JobStatus.SUCCESSFUL, processedJob.getStatus());
assertEquals(COMPLETED_PERCENT, processedJob.getStatusMessage());
assertNotNull(processedJob.getExpiresAt());
assertNotNull(processedJob.getCompletedAt());
List<LoggableEvent> beneSearchEvents = loggerEventRepository.load(ContractSearchEvent.class);
assertEquals(1, beneSearchEvents.size());
ContractSearchEvent event = (ContractSearchEvent) beneSearchEvents.get(0);
assertEquals(JOB_UUID, event.getJobId());
assertEquals(100, event.getBenesExpected());
assertEquals(100, event.getBenesSearched());
assertEquals(CONTRACT_NAME, event.getContractNumber());
assertEquals(95, event.getBenesWithEobs());
final List<JobOutput> jobOutputs = processedJob.getJobOutputs();
assertFalse(jobOutputs.isEmpty());
}
use of gov.cms.ab2d.eventlogger.events.ContractSearchEvent in project ab2d by CMSgov.
the class LoggerEventSummary method getSummary.
public JobSummaryEvent getSummary(String jobId) {
try {
if (jobId == null || jobId.isEmpty()) {
log.error("Can't do a job summary for an empty job id");
return new JobSummaryEvent();
}
List<LoggableEvent> jobChangeEvents = loggerEventRepository.load(JobStatusChangeEvent.class, jobId);
List<LoggableEvent> fileEvents = loggerEventRepository.load(FileEvent.class, jobId);
List<LoggableEvent> downloadEvents = loggerEventRepository.load(ApiResponseEvent.class, jobId).stream().filter(e -> "File Download".equalsIgnoreCase(((ApiResponseEvent) e).getResponseString())).collect(Collectors.toList());
List<LoggableEvent> contractSearchData = loggerEventRepository.load(ContractSearchEvent.class, jobId);
List<LoggableEvent> allEvents = new ArrayList<>();
allEvents.addAll(jobChangeEvents);
allEvents.addAll(fileEvents);
allEvents.addAll(downloadEvents);
allEvents.addAll(contractSearchData);
String firstUserFound = allEvents.stream().map(LoggableEvent::getOrganization).filter(Objects::nonNull).findFirst().orElse(null);
JobSummaryEvent jobSummaryEvent = new JobSummaryEvent();
jobSummaryEvent.setJobId(jobId);
jobSummaryEvent.setOrganization(firstUserFound);
jobSummaryEvent.setSubmittedTime(getTime(jobChangeEvents, "SUBMITTED"));
jobSummaryEvent.setInProgressTime(getTime(jobChangeEvents, "IN_PROGRESS"));
jobSummaryEvent.setSuccessfulTime(getTime(jobChangeEvents, "SUCCESSFUL"));
jobSummaryEvent.setCancelledTime(getTime(jobChangeEvents, "CANCELLED"));
jobSummaryEvent.setFailedTime(getTime(jobChangeEvents, "FAILED"));
jobSummaryEvent.setNumFilesCreated(getUniqueNumFilesOfType(fileEvents, FileEvent.FileStatus.CLOSE));
jobSummaryEvent.setNumFilesDeleted(getUniqueNumFilesOfType(fileEvents, FileEvent.FileStatus.DELETE));
jobSummaryEvent.setNumFilesDownloaded(downloadEvents.size());
if (!contractSearchData.isEmpty()) {
List<ContractSearchEvent> searches = new ArrayList<>();
for (LoggableEvent event : contractSearchData) {
searches.add((ContractSearchEvent) event);
}
jobSummaryEvent.setSuccessfullySearched(searches.stream().map(ContractSearchEvent::getBenesSearched).reduce(0, Integer::sum));
jobSummaryEvent.setErrorSearched(searches.stream().map(ContractSearchEvent::getBenesErrored).reduce(0, Integer::sum));
jobSummaryEvent.setTotalNum(searches.stream().map(ContractSearchEvent::getBenesExpected).reduce(0, Integer::sum));
}
return jobSummaryEvent;
} catch (Exception ex) {
// Logging shouldn ever break anything
log.error("Error creating summary object", ex);
}
return null;
}
use of gov.cms.ab2d.eventlogger.events.ContractSearchEvent in project ab2d by CMSgov.
the class ContractSearchEventMapper method mapRow.
@Override
public ContractSearchEvent mapRow(ResultSet resultSet, int i) throws SQLException {
ContractSearchEvent event = new ContractSearchEvent();
extractSuperParams(resultSet, event);
event.setContractNumber(resultSet.getString("contract_number"));
event.setBenesExpected(resultSet.getInt("benes_expected"));
event.setBenesQueued(resultSet.getInt("benes_queued"));
event.setBenesSearched(resultSet.getInt("benes_searched"));
event.setBenesErrored(resultSet.getInt("benes_errored"));
event.setBenesWithEobs(resultSet.getInt("benes_with_eobs"));
event.setEobsFetched(resultSet.getInt("eobs_fetched"));
event.setEobsWritten(resultSet.getInt("eobs_written"));
event.setEobFiles(resultSet.getInt("eob_files"));
return event;
}
use of gov.cms.ab2d.eventlogger.events.ContractSearchEvent in project ab2d by CMSgov.
the class ContractSearchEventMapper method log.
@Override
public void log(LoggableEvent event) {
if (event.getClass() != ContractSearchEvent.class) {
throw new EventLoggingException("Used " + event.getClass().toString() + " instead of " + ContractSearchEvent.class.toString());
}
ContractSearchEvent be = (ContractSearchEvent) event;
KeyHolder keyHolder = new GeneratedKeyHolder();
String query = "insert into event_bene_search " + " (time_of_event, organization, job_id, contract_number, benes_expected, benes_queued, benes_searched, " + " benes_errored, benes_with_eobs, eobs_fetched, eobs_written, eob_files, aws_id, environment) " + " values (:time, :organization, :job, :contractNum, :benes_expected, :benes_queued, :benes_searched, " + " :benes_errored, :benes_with_eobs, :eobs_fetched, :eobs_written, :eob_files, :awsId, :environment)";
SqlParameterSource parameters = super.addSuperParams(event).addValue("contractNum", be.getContractNumber()).addValue("benes_expected", be.getBenesExpected()).addValue("benes_queued", be.getBenesQueued()).addValue("benes_searched", be.getBenesSearched()).addValue("benes_errored", be.getBenesErrored()).addValue("benes_with_eobs", be.getBenesWithEobs()).addValue("eobs_fetched", be.getEobsFetched()).addValue("eobs_written", be.getEobsWritten()).addValue("eob_files", be.getEobFiles());
template.update(query, parameters, keyHolder);
event.setId(SqlEventMapper.getIdValue(keyHolder));
}
use of gov.cms.ab2d.eventlogger.events.ContractSearchEvent in project ab2d by CMSgov.
the class JobProcessorImpl method persistTrackedJobProgress.
void persistTrackedJobProgress(Job job) {
ProgressTracker progressTracker = jobProgressService.getStatus(job.getJobUuid());
if (progressTracker == null) {
log.info("Job [{}] - contract [{}] does not have any progress information, skipping persisting tracker", job.getJobUuid(), job.getContractNumber());
return;
}
int eobFilesCreated = progressTracker.getPatientFailureCount() == 0 ? job.getJobOutputs().size() : job.getJobOutputs().size() - 1;
// Regardless of whether we pass or fail the basic
eventLogger.log(new ContractSearchEvent(job.getOrganization(), job.getJobUuid(), job.getContractNumber(), progressTracker.getPatientsExpected(), progressTracker.getPatientRequestQueuedCount(), progressTracker.getPatientRequestProcessedCount(), progressTracker.getPatientFailureCount(), progressTracker.getPatientsWithEobsCount(), progressTracker.getEobsFetchedCount(), progressTracker.getEobsProcessedCount(), eobFilesCreated));
}
Aggregations