<commit_before>import {TitleCasePipe} from '@angular/common';
import {
  CriteriaSubType,
  CriteriaType,
  DomainType,
  SearchGroup,
  SearchGroupItem,
  SearchParameter,
  SearchRequest,
  TemporalMention,
  TemporalTime
} from 'generated/fetch';
import {idsInUse} from './search-state.service';

export function typeDisplay(parameter): string {
  if ([DomainType.CONDITION, DomainType.PROCEDURE, DomainType.MEASUREMENT].includes(parameter.domainId)) {
    return parameter.code;
  }
}

export function nameDisplay(parameter): string {
  if (parameter.type === CriteriaType.AGE || parameter.type === CriteriaType.DECEASED) {
    return '';
  } else {
    let name = stripHtml(parameter.name);
    if (parameter.type === CriteriaType.ETHNICITY || parameter.type === CriteriaType.RACE) {
      name = new TitleCasePipe().transform(name);
    }
    return name;
  }
}

export function attributeDisplay(parameter): string {
  if (parameter.type === CriteriaType.AGE) {
    const attrs = parameter.attributes;
    const display = [];
    attrs.forEach(attr => {
      const op = {
        'BETWEEN': 'In Range',
        'EQUAL': 'Equal To',
        'GREATER_THAN': 'Greater Than',
        'LESS_THAN': 'Less Than',
        'GREATER_THAN_OR_EQUAL_TO': 'Greater Than or Equal To',
        'LESS_THAN_OR_EQUAL_TO': 'Less Than or Equal To',
      }[attr.operator];
      const args = attr.operands.join(', ');
      display.push(`${op} ${args}`);
    });
    return display.join(' ');
  } else {
    return '';
  }
}

export function domainToTitle(domain: any): string {
  switch (domain) {
    case DomainType.PERSON:
      domain = 'Demographics';
      break;
    case DomainType.MEASUREMENT:
      domain = 'Measurements';
      break;
    case DomainType.PHYSICALMEASUREMENT:
      domain = 'Physical Measurements';
      break;
    case DomainType.VISIT:
      domain = 'Visits';
      break;
    case DomainType.DRUG:
      domain = 'Drugs';
      break;
    case DomainType.CONDITION:
      domain = 'Conditions';
      break;
    case DomainType.PROCEDURE:
      domain = 'Procedures';
      break;
    case DomainType.OBSERVATION:
      domain = 'Observations';
      break;
    case DomainType.LAB:
      domain = 'Labs';
      break;
    case DomainType.VITAL:
      domain = 'Vitals';
      break;
    case DomainType.SURVEY:
      domain = 'Surveys';
      break;
    case DomainType.ALLEVENTS:
      domain = 'All Events';
      break;
  }
  return domain;
}

export function typeToTitle(_type: string): string {
  switch (_type) {
    case CriteriaType[CriteriaType.AGE]:
      _type = 'Current Age/Deceased';
      break;
    case CriteriaType[CriteriaType.ETHNICITY]:
      _type = 'Ethnicity';
      break;
    case CriteriaType[CriteriaType.GENDER]:<commit_msg>[risk=no] Fix title for deceased search items (#2809)<commit_after>import {TitleCasePipe} from '@angular/common';
import {
  CriteriaSubType,
  CriteriaType,
  DomainType,
  SearchGroup,
  SearchGroupItem,
  SearchParameter,
  SearchRequest,
  TemporalMention,
  TemporalTime
} from 'generated/fetch';
import {idsInUse} from './search-state.service';

export function typeDisplay(parameter): string {
  if ([DomainType.CONDITION, DomainType.PROCEDURE, DomainType.MEASUREMENT].includes(parameter.domainId)) {
    return parameter.code;
  }
}

export function nameDisplay(parameter): string {
  if (parameter.type === CriteriaType.AGE || parameter.type === CriteriaType.DECEASED) {
    return '';
  } else {
    let name = stripHtml(parameter.name);
    if (parameter.type === CriteriaType.ETHNICITY || parameter.type === CriteriaType.RACE) {
      name = new TitleCasePipe().transform(name);
    }
    return name;
  }
}

export function attributeDisplay(parameter): string {
  if (parameter.type === CriteriaType.AGE) {
    const attrs = parameter.attributes;
    const display = [];
    attrs.forEach(attr => {
      const op = {
        'BETWEEN': 'In Range',
        'EQUAL': 'Equal To',
        'GREATER_THAN': 'Greater Than',
        'LESS_THAN': 'Less Than',
        'GREATER_THAN_OR_EQUAL_TO': 'Greater Than or Equal To',
        'LESS_THAN_OR_EQUAL_TO': 'Less Than or Equal To',
      }[attr.operator];
      const args = attr.operands.join(', ');
      display.push(`${op} ${args}`);
    });
    return display.join(' ');
  } else {
    return '';
  }
}

export function domainToTitle(domain: any): string {
  switch (domain) {
    case DomainType.PERSON:
      domain = 'Demographics';
      break;
    case DomainType.MEASUREMENT:
      domain = 'Measurements';
      break;
    case DomainType.PHYSICALMEASUREMENT:
      domain = 'Physical Measurements';
      break;
    case DomainType.VISIT:
      domain = 'Visits';
      break;
    case DomainType.DRUG:
      domain = 'Drugs';
      break;
    case DomainType.CONDITION:
      domain = 'Conditions';
      break;
    case DomainType.PROCEDURE:
      domain = 'Procedures';
      break;
    case DomainType.OBSERVATION:
      domain = 'Observations';
      break;
    case DomainType.LAB:
      domain = 'Labs';
      break;
    case DomainType.VITAL:
      domain = 'Vitals';
      break;
    case DomainType.SURVEY:
      domain = 'Surveys';
      break;
    case DomainType.ALLEVENTS:
      domain = 'All Events';
      break;
  }
  return domain;
}

export function typeToTitle(_type: string): string {
  switch (_type) {
    case CriteriaType[CriteriaType.AGE]:
      _type = 'Current Age/Deceased';
      break;
    case CriteriaType[CriteriaType.DECEASED]:
      _type = 'Current Age/Deceased';
      break;
    case CriteriaType[CriteriaType.ETHNICITY]:
      _type = 'Ethnicity';
      break;
    case CriteriaType[CriteriaType.GENDER]:
{'fraction_non_alphanumeric': 0.12238438544047828, 'fraction_numerical': 0.000703358537014243, 'mean_word_length': 2.9527449617790134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6699148', 'n_tokens_mistral': 1847, 'n_tokens_neox': 1767, 'n_words': 400}