<commit_before>
import { throwError as observableThrowError,  Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { AppSettingsService } from '../app-settings/app-settings.service';
import { DataCacheService } from '../shared/services/data-cache.service';
import { HttpClient, HttpParams } from '@angular/common/http';
@Injectable()
export class DataEntryStatisticsService {
  constructor(protected http: HttpClient,
              protected appSettingsService: AppSettingsService,
              private cacheService: DataCacheService) {
  }

  public getBaseUrl(): string {
    return this.appSettingsService.getEtlRestbaseurl().trim();
  }

  public  getDataEntryStatisticsTypes(): Observable<any> {
      let dataStatisticsTypes = [{
          id: 'view1',
          subType: 'Encounter Types Per Day'
      }, {
          id: 'view2',
          subType: 'Encounters Types Per Month'
      }, {
          id: 'view3',
          subType: 'Encounters Types Per Provider'
      }, {
          id: 'view4',
          subType: 'Encounters Types Per Creator'
      }];

      return of(dataStatisticsTypes);
   }

  public getDataEntryStatistics(payload): Observable<any> {

    if (payload && payload.subType && payload.startDate && payload.endDate && payload.groupBy) {

      

      let baseUrl = this.getBaseUrl();
      let params: any = this.getDataEntryStatisticsQueryParam(payload);

      let dataEntryStatsUrl = 'data-entry-statistics/' + params.subType;
      let url = baseUrl + dataEntryStatsUrl;
      let urlParams: HttpParams = new HttpParams()
      .set('startDate', params.startDate)
      .set('endDate', params.endDate)
      .set('groupBy', params.groupBy);
      if (params.locationUuids) {
          urlParams.set('locationUuids', params.locationUuids);
      }
      if (params.encounterTypeUuids) {
         urlParams.set('encounterTypeUuids', params.encounterTypeUuids);
      }
      if (params.providerUuid) {
         urlParams.set('providerUuid', params.providerUuid);
      }
      if (params.creatorUuid) {
         urlParams.set('creatorUuid', params.creatorUuid);
      }

      let request = this.http.get(url, {params : urlParams}).pipe(
        map((response: any) => {
           return response.result;
        }));

      return this.cacheService.cacheRequest(url, urlParams, request);

    } else {

      console.log('Error getting params');

      return observableThrowError({ error:
        'Request must contain subtype,startDate,endDate and groupBy' });

    }

  }

    public getDataEntryStatisticsQueryParam(payload) {

      let subType = '';
      let startDate = '';
      let endDate = '';
      let groupBy = '';

      if (payload.subType) {
         subType = payload.subType;
      }
      if (payload.startDate) {
         startDate = payload.startDate;
      }
      if (payload.endDate) {
         endDate = payload.endDate;
      }
      if (payload.groupBy) {
          groupBy = payload.groupBy;
      }

      let param: any = {
        subType: subType, // mandatory params
        startDate: startDate,
        endDate: endDate,
        groupBy: groupBy
      };

        // set-up the param object
      if (payload.locationUuids && payload.locationUuids.length > 0) {
          param.locationUuids = payload.locationUuids;
      }
      if (payload.encounterTypeUuids && payload.encounterTypeUuids.length > 0) {
          param.encounterTypeUuids = payload.encounterTypeUuids;
      }
      if (payload.formUuids && payload.formUuids.length > 0) {
          param.formUuids = payload.formUuids;
      }
      if (payload.providerUuid && payload.providerUuid.length > 0) {
          param.providerUuid = payload.providerUuid;
      }
      if (payload.creatorUuid && payload.creatorUuid.length > 0) {
          param.creatorUuid = payload.creatorUuid;
      }

      return param;
    }

    public getDataEntrySatisticsPatientList(params) {

      let baseUrl = this.getBaseUrl();
      let dataEntryStatsPatientListUrl = 'data-entry-statistics/patientList' ;
      let url = baseUrl + dataEntryStatsPatientListUrl;
      let urlParams: HttpParams = new HttpParams()
      .set('startDate', params.startDate)
      .set('endDate', params.endDate)
      .set('groupBy', 'groupByLocationId,groupByPatientId');

      if (params.encounterTypeUuids && params.encounterTypeUuids.length > 0) {
          urlParams.set('encounterTypeUuids', params.encounterTypeUuids);
      }
      if (params.providerUuid && params.providerUuid.length > 0) {
          urlParams.set('providerUuid', params.providerUuid);
      }
      if (params.creatorUuid && params.creatorUuid.length > 0) {
          urlParams.set('creatorUuid', params.creatorUuid);
      }
      if (params.locationUuids && params.locationUuids.length > 0) {
           urlParams.set('locationUuids', params.locationUuids);
      }

      let request = this.http.get(url, {params : urlParams}).pipe(
        map((response: any) => {
           return response.result;
        }));

      return this.cacheService.cacheRequest(url, urlParams, request);

    }

}
<commit_msg>POCAMRS-102: Fix data entry stats bug<commit_after>
import { throwError as observableThrowError,  Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { AppSettingsService } from '../app-settings/app-settings.service';
import { DataCacheService } from '../shared/services/data-cache.service';
import { HttpClient, HttpParams } from '@angular/common/http';
@Injectable()
export class DataEntryStatisticsService {
  constructor(protected http: HttpClient,
              protected appSettingsService: AppSettingsService,
              private cacheService: DataCacheService) {
  }

  public getBaseUrl(): string {
    return this.appSettingsService.getEtlRestbaseurl().trim();
  }

  public  getDataEntryStatisticsTypes(): Observable<any> {
      let dataStatisticsTypes = [{
          id: 'view1',
          subType: 'Encounter Types Per Day'
      }, {
          id: 'view2',
          subType: 'Encounters Types Per Month'
      }, {
          id: 'view3',
          subType: 'Encounters Types Per Provider'
      }, {
          id: 'view4',
          subType: 'Encounters Types Per Creator'
      }];

      return of(dataStatisticsTypes);
   }

  public getDataEntryStatistics(payload): Observable<any> {

    if (payload && payload.subType && payload.startDate && payload.endDate && payload.groupBy) {

      let baseUrl = this.getBaseUrl();
      let params: any = this.getDataEntryStatisticsQueryParam(payload);

      let dataEntryStatsUrl = 'data-entry-statistics/' + params.subType;
      let url = baseUrl + dataEntryStatsUrl;
      let urlParams: HttpParams = new HttpParams()
      .set('startDate', params.startDate)
      .set('endDate', params.endDate)
      .set('groupBy', params.groupBy);
      if (params.locationUuids) {
         urlParams = urlParams.set('locationUuids', params.locationUuids);
      }
      if (params.encounterTypeUuids) {
         urlParams = urlParams.set('encounterTypeUuids', params.encounterTypeUuids);
      }
      if (params.providerUuid) {
         urlParams = urlParams.set('providerUuid', params.providerUuid);
      }
      if (params.creatorUuid) {
         urlParams = urlParams.set('creatorUuid', params.creatorUuid);
      }

      let request = this.http.get(url, {params : urlParams}).pipe(
        map((response: any) => {
           return response.result;
        }));

      return this.cacheService.cacheRequest(url, urlParams, request);

    } else {

      console.log('Error getting params');

      return observableThrowError({ error:
        'Request must contain subtype,startDate,endDate and groupBy' });

    }

  }

    public getDataEntryStatisticsQueryParam(payload) {

      let subType = '';
      let startDate = '';
      let endDate = '';
      let groupBy = '';

      if (payload.subType) {
         subType = payload.subType;
      }
      if (payload.startDate) {
         startDate = payload.startDate;
      }
      if (payload.endDate) {
         endDate = payload.endDate;
      }
      if (payload.groupBy) {
          groupBy = payload.groupBy;
      }

      let param: any = {
        subType: subType, // mandatory params
        startDate: startDate,
        endDate: endDate,
        groupBy: groupBy
      };

        // set-up the param object
      if (payload.locationUuids && payload.locationUuids.length > 0) {
          param.locationUuids = payload.locationUuids;
      }
      if (payload.encounterTypeUuids && payload.encounterTypeUuids.length > 0) {
          param.encounterTypeUuids = payload.encounterTypeUuids;
      }
      if (payload.formUuids && payload.formUuids.length > 0) {
          param.formUuids = payload.formUuids;
      }
      if (payload.providerUuid && payload.providerUuid.length > 0) {
          param.providerUuid = payload.providerUuid;
      }
      if (payload.creatorUuid && payload.creatorUuid.length > 0) {
          param.creatorUuid = payload.creatorUuid;
      }

      return param;
    }

    public getDataEntrySatisticsPatientList(params) {

      let baseUrl = this.getBaseUrl();
      let dataEntryStatsPatientListUrl = 'data-entry-statistics/patientList' ;
      let url = baseUrl + dataEntryStatsPatientListUrl;
      let urlParams: HttpParams = new HttpParams()
      .set('startDate', params.startDate)
      .set('endDate', params.endDate)
      .set('groupBy', 'groupByLocationId,groupByPatientId');

      if (params.encounterTypeUuids && params.encounterTypeUuids.length > 0) {
          urlParams = urlParams.set('encounterTypeUuids', params.encounterTypeUuids);
      }
      if (params.providerUuid && params.providerUuid.length > 0) {
          urlParams = urlParams.set('providerUuid', params.providerUuid);
      }
      if (params.creatorUuid && params.creatorUuid.length > 0) {
          urlParams = urlParams.set('creatorUuid', params.creatorUuid);
      }
      if (params.locationUuids && params.locationUuids.length > 0) {
           urlParams = urlParams.set('locationUuids', params.locationUuids);
      }

      let request = this.http.get(url, {params : urlParams}).pipe(
        map((response: any) => {
           return response.result;
        }));

      return this.cacheService.cacheRequest(url, urlParams, request);

    }

}

{'fraction_non_alphanumeric': 0.11585307375083917, 'fraction_numerical': 0.002781241008919152, 'mean_word_length': 2.618320610687023, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6957932', 'n_tokens_mistral': 3134, 'n_tokens_neox': 3057, 'n_words': 603}