Search in sources :

Example 1 with ContractSearchEvent

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());
}
Also used : LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) JobOutput(gov.cms.ab2d.common.model.JobOutput) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringIntegrationTest(org.springframework.integration.test.context.SpringIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with ContractSearchEvent

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;
}
Also used : JobSummaryEvent(gov.cms.ab2d.eventlogger.events.JobSummaryEvent) FileEvent(gov.cms.ab2d.eventlogger.events.FileEvent) ApiResponseEvent(gov.cms.ab2d.eventlogger.events.ApiResponseEvent) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) OffsetDateTime(java.time.OffsetDateTime) Service(org.springframework.stereotype.Service) JobStatusChangeEvent(gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent) LoggableEvent(gov.cms.ab2d.eventlogger.LoggableEvent) ArrayList(java.util.ArrayList) Objects(java.util.Objects) JobSummaryEvent(gov.cms.ab2d.eventlogger.events.JobSummaryEvent) ApiResponseEvent(gov.cms.ab2d.eventlogger.events.ApiResponseEvent) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent)

Example 3 with ContractSearchEvent

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;
}
Also used : ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent)

Example 4 with ContractSearchEvent

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));
}
Also used : GeneratedKeyHolder(org.springframework.jdbc.support.GeneratedKeyHolder) EventLoggingException(gov.cms.ab2d.eventlogger.EventLoggingException) SqlParameterSource(org.springframework.jdbc.core.namedparam.SqlParameterSource) GeneratedKeyHolder(org.springframework.jdbc.support.GeneratedKeyHolder) KeyHolder(org.springframework.jdbc.support.KeyHolder) ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent)

Example 5 with ContractSearchEvent

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));
}
Also used : ContractSearchEvent(gov.cms.ab2d.eventlogger.events.ContractSearchEvent)

Aggregations

ContractSearchEvent (gov.cms.ab2d.eventlogger.events.ContractSearchEvent)6 LoggableEvent (gov.cms.ab2d.eventlogger.LoggableEvent)3 JobOutput (gov.cms.ab2d.common.model.JobOutput)2 IBaseBundle (org.hl7.fhir.instance.model.api.IBaseBundle)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 SpringIntegrationTest (org.springframework.integration.test.context.SpringIntegrationTest)2 EventLoggingException (gov.cms.ab2d.eventlogger.EventLoggingException)1 ApiResponseEvent (gov.cms.ab2d.eventlogger.events.ApiResponseEvent)1 FileEvent (gov.cms.ab2d.eventlogger.events.FileEvent)1 JobStatusChangeEvent (gov.cms.ab2d.eventlogger.events.JobStatusChangeEvent)1 JobSummaryEvent (gov.cms.ab2d.eventlogger.events.JobSummaryEvent)1 OffsetDateTime (java.time.OffsetDateTime)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 SqlParameterSource (org.springframework.jdbc.core.namedparam.SqlParameterSource)1