uwrit / leaf

Leaf Clinical Data Explorer
https://www.youtube.com/watch?v=ZuKKC7B8mHI
Other
86 stars 47 forks source link

Exception when using "My Saved Cohorts" #551

Closed am202 closed 1 year ago

am202 commented 1 year ago

I tried using "My Saved Cohorts" to combine one query with other conditions, and I got this:

Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "." POSITION: 72

I checked the line above the error, and it contained these two queries:

SELECT _S000.person_id FROM leaf_drug_exposure AS _S000 WHERE EXISTS (SELECT 1 FROM drug_ancestor AS _S000CA WHERE _S000CA.descendant_concept_id = _S000.drug_concept_id AND _S000CA.ancestor_concept_id = 21601387) GROUP BY _S000.person_id

SELECT _S100.person_id FROM (SELECT _S100C.PersonId AS person_id FROM .app.Cohort AS _S100C WHERE _S100C.QueryId = 'be3a70ce-3f17-ed11-9924-005056a9d94c') AS_S100

Position 72 of the second query is the first dot in "FROM .app.Cohort", so I think that's the issue.

Here's the full error and stack trace:

{"Timestamp":"2022-08-08T13:31:28.1310209-04:00","Level":"Error","MessageTemplate":"Failed to execute query. Error:{Error}","Properties":{"Error":"Npgsql.PostgresException (0x80004005): 42601: syntax error at or near \".\" POSITION: 72 at Npgsql.Internal.NpgsqlConnector.gReadMessageLong|213_0(NpgsqlConnector connector, Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage) at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken) at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) at Npgsql.NpgsqlCommand.ExecuteReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) at Services.Compiler.PostgreSqlQueryExecutor.ExecuteReaderAsync(String connStr, String query, Int32 timeout, CancellationToken token, IEnumerable`1 parameters) in C:\Git\leaf-multi-rdbms\leaf\src\server\Services\Compiler\SqlProviderQueryExecutor.cs:line 185 at Services.Cohort.ParallelPatientCohortService.GetPartialContext(LeafQuery query, CancellationToken token) in C:\Git\leaf-multi-rdbms\leaf\src\server\Services\Cohort\ParallelPatientCohortService.cs:line 80 at Services.Cohort.ParallelPatientCohortService.<>c__DisplayClass4_1.<b0>d.MoveNext() in C:\Git\leaf-multi-rdbms\leaf\src\server\Services\Cohort\ParallelPatientCohortService.cs:line 64 --- End of stack trace from previous location where exception was thrown --- at Services.Cohort.ParallelPatientCohortService.GetPatientSetAsync(IReadOnlyCollection`1 queries, CancellationToken token) in C:\Git\leaf-multi-rdbms\leaf\src\server\Services\Cohort\ParallelPatientCohortService.cs:line 67 at Services.Cohort.ParallelPatientCohortService.GetCohortAsync(PatientCountQuery query, CancellationToken token) in C:\Git\leaf-multi-rdbms\leaf\src\server\Services\Cohort\ParallelPatientCohortService.cs:line 47 at Model.Cohort.PatientCohortService.GetPatientCohortAsync(PatientCountQuery query, CancellationToken token) in C:\Git\leaf-multi-rdbms\leaf\src\server\Model\Cohort\PatientCohortService.cs:line 41 at Model.Cohort.CohortCounter.FullCount(IPatientCountQueryDTO queryDTO, CancellationToken token) in C:\Git\leaf-multi-rdbms\leaf\src\server\Model\Cohort\CohortCounter.cs:line 204 at Model.Cohort.CohortCounter.Count(IPatientCountQueryDTO queryDTO, CancellationToken token) in C:\Git\leaf-multi-rdbms\leaf\src\server\Model\Cohort\CohortCounter.cs:line 91 at API.Controllers.CohortCountController.Count(PatientCountQueryDTO patientCountQuery, CohortCounter counter, CancellationToken cancelToken) in C:\Git\leaf-multi-rdbms\leaf\src\server\API\Controllers\CohortCountController.cs:line 73 Exception data: Severity: ERROR SqlState: 42601 MessageText: syntax error at or near \".\" Position: 72 File: scan.l Line: 1127 Routine: scanner_yyerror","SourceContext":"API.Controllers.CohortCountController","ActionId":"6a1ae148-511b-476a-b582-02a60daa08b5","ActionName":"API.Controllers.CohortCountController.Count (API)","RequestId":"0HMJ05R6TE1E2:00000004","RequestPath":"/api/cohort/count","SpanId":"|894f10f4-4fb1c58d5b7bccf3.","TraceId":"894f10f4-4fb1c58d5b7bccf3","ParentId":"","ConnectionId":"0HMJ05R6TE1E2","SessionId":"3f2d7b19-5e48-482e-918c-9bbda1c47606","User":"am202@iu.edu@urn:leaf:issuer:leaf.regenstrief.org"}}

ndobb commented 1 year ago

Got it, thanks @am202 . This issue should be fixed in https://github.com/uwrit/leaf/commit/db2b6660d2d77fc52169a378dd080d6396f91df6.