<commit_before>package models

import models.meta.Profile._
import models.meta.Schema._
import models.meta.Profile.driver.simple._
import com.rockymadden.stringmetric.similarity._

case class MedicationProductID(value: Long) extends MappedTo[Long]

case class MedicationProduct(
    id: Option[MedicationProductID],
    name: String)(implicit includes: Includes[MedicationProduct])
  extends Entity[MedicationProduct, MedicationProductID]
{
  val genericTypes = many(MedicationProduct.genericTypes)
}

object MedicationProduct extends EntityCompanion[MedicationProducts, MedicationProduct, MedicationProductID] {
  val query = TableQuery[MedicationProducts]

  val genericTypes = toManyThrough[GenericTypes, GenericTypesMedicationProducts, GenericType](
    TableQuery[GenericTypesMedicationProducts] leftJoin TableQuery[GenericTypes] on(_.genericTypeId === _.id),
    _.id === _._1.medicationProductId)

  def findByName(name: String)(implicit s: Session): Option[MedicationProduct] =
    TableQuery[MedicationProducts].filter(_.name.toLowerCase === name.toLowerCase).firstOption

  def findByUserInput(userInput: String)(implicit s: Session): Option[MedicationProduct] = {
    val normalizedInput = userInput.trim().replaceAll("""\s+""", " ")
    query.filter(_.name.toLowerCase === normalizedInput).firstOption
  }

  def findAlternatives(userInput: String, similarityThreshold: Double, maxNum: Int)(implicit s: Session): Seq[MedicationProduct] =
    list.map(x => (JaroWinklerMetric.compare(userInput.toLowerCase, x.name.toLowerCase), x))
      .filter(_._1.get > similarityThreshold)
      .sortBy(_._1)(Ordering[Option[Double]].reverse)
      .take(maxNum)
      .map(_._2)
}<commit_msg>[Bugfix] Finding medication by user input was case sensitive<commit_after>package models

import models.meta.Profile._
import models.meta.Schema._
import models.meta.Profile.driver.simple._
import com.rockymadden.stringmetric.similarity._

case class MedicationProductID(value: Long) extends MappedTo[Long]

case class MedicationProduct(
    id: Option[MedicationProductID],
    name: String)(implicit includes: Includes[MedicationProduct])
  extends Entity[MedicationProduct, MedicationProductID]
{
  val genericTypes = many(MedicationProduct.genericTypes)
}

object MedicationProduct extends EntityCompanion[MedicationProducts, MedicationProduct, MedicationProductID] {
  val query = TableQuery[MedicationProducts]

  val genericTypes = toManyThrough[GenericTypes, GenericTypesMedicationProducts, GenericType](
    TableQuery[GenericTypesMedicationProducts] leftJoin TableQuery[GenericTypes] on(_.genericTypeId === _.id),
    _.id === _._1.medicationProductId)

  def findByName(name: String)(implicit s: Session): Option[MedicationProduct] =
    TableQuery[MedicationProducts].filter(_.name.toLowerCase === name.toLowerCase).firstOption

  def findByUserInput(userInput: String)(implicit s: Session): Option[MedicationProduct] = {
    val normalizedInput = userInput.trim().replaceAll("""\s+""", " ")
    query.filter(_.name.toLowerCase === normalizedInput.toLowerCase).firstOption
  }

  def findAlternatives(userInput: String, similarityThreshold: Double, maxNum: Int)(implicit s: Session): Seq[MedicationProduct] =
    list.map(x => (JaroWinklerMetric.compare(userInput.toLowerCase, x.name.toLowerCase), x))
      .filter(_._1.get > similarityThreshold)
      .sortBy(_._1)(Ordering[Option[Double]].reverse)
      .take(maxNum)
      .map(_._2)
}
{'fraction_non_alphanumeric': 0.1123367198838897, 'fraction_numerical': 0.0023222060957910013, 'mean_word_length': 6.119834710743802, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '1765747', 'n_tokens_mistral': 996, 'n_tokens_neox': 987, 'n_words': 188}