Project

tnql

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
Domain Specific Language for querying PHE NCRAS datastores
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

~> 0.3
>= 3.0, < 6
>= 1.4.10
>= 7.0, < 8.1
 Project Readme

TNQL Build Status Gem Version

Tumour Natural Query Language (TNQL) is a Treetop driven Domain Specific Language (DSL) used by the NHS Digital (NHS-D) National Cancer Registration and Analysis Service (NCRAS) to identify cohorts of tumours.

Used for analysis, research and day-to-day operations, it was first created in March 2011 to empower non-technical users to write sophisticated human readable queries without the need to know or understand the underlying datastore and/or schema.

In moving it into a gem, TNQL is being further decoupled from the specifics of the NCRAS systems by producing an intermediate representation, known as Disease Intermediate Representation (DIR). This allows us to:

  1. implement separate DIR adapters for different datastores (e.g. SQL and NoSQL datastores);
  2. utilize the same DIR adapters for different but over-lapping DSLs, starting with the Congenital Anomaly Natural Query Language (CANQL); and
  3. pass DIR queries to non-ruby backend systems using any simple format like JSON.

Installation

Add this line to your application's Gemfile:

gem 'tnql'

And then execute:

$ bundle

Or install it yourself as:

$ gem install tnql

Usage

Here is a simple example showing a TNQL query of all Colon tumours diagnosed at "Hello World" Hospital:

require 'tnql'
require 'json'

query = 'All C18 Tumours Diagnosed at Hello World Hospital'
parser = Tnql::Parser.new(query)

if parser.valid?
	puts JSON.dump(parser.meta_data)
end

would output:

{"tumour.primarycode":{"begins":["C18"]},"diagnosis.providername":{"begins":"HELLO WORLD","interval":"29...49"}}

The parser is case insensitive. An example of an almost fully involved TNQL query is:

First 27 Final Y0401 Non-invasive Stage 4 Head and Neck Tumours Diagnosed Between August 2010 and Oct 2010 at Hospital RGT01 Treated at Hospital RGN42 With Wait Action and Unprocessed PAS or Somerset Records for Dead Male Patients Who Were Born in 1999, Died Between May 2001 and Aug 2003, and Have no Death Certificate

Please see the tests for many more examples.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

PLEASE NOTE: A side-effect of decoupling TNQL from the NCRAS SQL adapter is that more of the grammar logic can be DRYed up, esp. in relation to providers. We plan to fix this and some internal namespacing in forthcoming releases.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/NHSDigital/tnql.

This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.