Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions app/models/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -664,14 +664,10 @@ class Backend @Inject() (implicit
}

def getDrugs(ids: Seq[String]): Future[IndexedSeq[Drug]] = {
val drugIndexName = getIndexOrDefault("drug")

logger.debug(s"querying drugs", keyValue("drug_ids", ids), keyValue("index", drugIndexName))

val queryTerm = Map("id.keyword" -> ids)
esRetriever
.getByIndexedQueryShould(drugIndexName, queryTerm, Pagination(0, ids.size), fromJsValue[Drug])
.map(_.mappedHits)
val tableName = getTableWithPrefixOrDefault(defaultOTSettings.clickhouse.drug.name)
logger.debug(s"querying drugs", keyValue("ids", ids), keyValue("table", tableName))
val query = IdsQuery(ids, "id", tableName, 0, Pagination.sizeMax)
dbRetriever.executeQuery[Drug, Query](query.query)
}

def getMechanismsOfAction(ids: Seq[String]): Future[IndexedSeq[MechanismsOfAction]] = {
Expand Down
23 changes: 0 additions & 23 deletions app/models/ElasticRetriever.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,29 +160,6 @@ class ElasticRetriever @Inject() (
}
throw new Exception(err.error.reason)

/** This fn represents a query where each kv from the map is used in a bool must. Based on the
* query asked by `getByIndexedQuery` and aggregation is applied
*/
def getByIndexedQueryMust[A, V](
esIndex: String,
kv: Map[String, V],
pagination: Pagination,
buildF: JsValue => Option[A],
aggs: Iterable[AbstractAggregation] = Iterable.empty,
sortByField: Option[sort.FieldSort] = None,
excludedFields: Seq[String] = Seq.empty
): Future[Results[A]] = {
// just log and execute the query
val indexQuery: IndexQuery[V] = IndexQuery(esIndex = esIndex,
kv = kv,
pagination = pagination,
aggs = aggs,
excludedFields = excludedFields
)
val searchRequest: SearchRequest = IndexQueryMust(indexQuery)
getByIndexedQuery(searchRequest, sortByField, buildF)
}

/** This fn represents a query where each kv from the map is used in a bool 'should'. Based on the
* query asked by `getByIndexedQuery` and aggregation is applied
*/
Expand Down
26 changes: 0 additions & 26 deletions app/models/ElasticRetrieverQueryBuilders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,8 @@ case class IndexQuery[V](
excludedFields: Seq[String] = Seq.empty
)

case class IndexBoolQuery(
esIndex: String,
boolQuery: BoolQuery,
pagination: Pagination,
aggs: Iterable[AbstractAggregation] = Iterable.empty,
excludedFields: Seq[String] = Seq.empty
)

trait ElasticRetrieverQueryBuilders extends OTLogging with QueryApi {

def IndexQueryMust[V](indexQuery: IndexQuery[V]): SearchRequest =
getByIndexQueryBuilder(indexQuery, must)

def IndexQueryShould[V](
indexQuery: IndexQuery[V]
): SearchRequest =
Expand Down Expand Up @@ -99,19 +88,4 @@ trait ElasticRetrieverQueryBuilders extends OTLogging with QueryApi {
.trackTotalHits(true)
.sourceExclude(indexQuery.excludedFields)
}

def BoolQueryBuilder(
indexQuery: IndexBoolQuery
): SearchRequest = {
val limitClause = indexQuery.pagination.toES
val searchRequest: SearchRequest = search(indexQuery.esIndex)
.bool(indexQuery.boolQuery)
.start(limitClause._1)
.limit(limitClause._2)
.aggs(indexQuery.aggs)
.trackTotalHits(true)
.sourceExclude(indexQuery.excludedFields)

searchRequest
}
}
1 change: 1 addition & 0 deletions app/models/entities/Configuration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ object Configuration {
credibleSet: CredibleSetSettings,
disease: DiseaseSettings,
diseaseHPO: DbTableSettings,
drug: DbTableSettings,
drugWarnings: DbTableSettings,
evidence: EvidenceSettings,
expression: DbTableSettings,
Expand Down
2 changes: 2 additions & 0 deletions app/models/entities/Drug.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models.entities

import play.api.libs.functional.syntax.toFunctionalBuilderOps
import play.api.libs.json._
import slick.jdbc.GetResult

case class IndicationReference(ids: Option[Seq[String]], source: String)

Expand Down Expand Up @@ -42,6 +43,7 @@ case class Drug(
)

object Drug {
implicit val getResult: GetResult[Drug] = GetResult(r => Json.parse(r.<<[String]).as[Drug])
implicit val linkedIdsImpW: OFormat[LinkedIds] = Json.format[models.entities.LinkedIds]
implicit val indicationReferenceImpW: OFormat[IndicationReference] =
Json.format[models.entities.IndicationReference]
Expand Down
4 changes: 4 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ ot {
label = "Disease phenotype table"
name = "disease_hpo"
}
drug {
label = "Drug table"
name = "drug"
}
drugWarnings {
label = "Drug warnings table"
name = "drug_warnings"
Expand Down