Sign inSign up

sdcplatform/ras-collection-instrument

By sdcplatform

•Updated over 5 years ago

Collection instrument microservice for RAS

Image
0

10K+

sdcplatform/ras-collection-instrument repository overview

⁠RAS Collection Instrument

This is the RAS Collection Instrument micro-service, responsible for the uploading of collection exercises and instruments. It can also be used to download collection instruments as .xlsx files, and allows for the searching of collection instruments via search filters. This service has the ability to link and unlink collection exercises with collection instruments. The relationship between exercises and instruments is one-to-many, so one collection exercise can have multiple collection instruments. Each collection instrument in the JSON schema has a sample unit reference, type, and summary ID, as well as additional attributes. This service commmunicates primarily with the collection exercise service, as well as the party, case, and survey services. Logging information about the collection instruments is sent to rabbitmq.

Collection instruments are stored in an instrument table with the following fields:

type = the type of the collection exercise (i.e. SEFT, EQ, etc.) instrument_id = the UUID for the instrument stamp = the timestamp showing when the collection instrument was created survey_id = the UUID of the associated survey classifiers = the survey classifiers survey = the survey itself seft_file = the instrument's seft file

Three different endpoint views exist: /collectioninstrument, which is used for the majority of the endpoints, as well as /survey_responses and /info.

When a collection instrument is uploaded for a collection exercise it writes a message onto the Seft.Instruments queue for the rm-collection-exercise service When a SEFT survey response is uploaded, it writes a message onto the Seft.Responses queue for sdx-seft-consumer service

⁠Environment

This requires pipenv to be installed:

pip install pipenv

⁠Tests

To run the tests a rabbitmq and database server is required. The tox script creates and runs these dependencies inside Docker containers, which are destroyed after the unit tests are run.

pipenv install --dev
pipenv run tox

To run the service with the required dependencies:

docker-compose up -d db rabbitmq
pipenv run python run.py

To test the service is up:

curl http://localhost:8082/info

The database will automatically be created when starting the application.

⁠Docker

To run the service in a Docker container a Compose script is included:

docker-compose up -d

⁠Configuration

Environment variables available for configuration are listed below:

Environment VariableDescriptionDefault
MAX_UPLOAD_FILE_NAME_LENGTHMaximum length of file names50
LOGGING_LEVELLevel of the loggerINFO
JSON_SECRET_KEYSJson representation of keysNone
ONS_CRYPTOKEYA key used by the CryptographerNone
SECURITY_USER_NAMEUsername the client uses to authenticate with other apisadmin
SECURITY_USER_PASSWORDPassword the client uses to authenticate with other apissecret
COLLECTION_EXERCISE_SCHEMALocation of the collection instrument schemaapplication/schemas/collection_instrument_schema.json
CASE_URLURL for the case service'http://localhost:8171⁠'
COLLECTION_EXERCISE_URLURL for the collection exercise service'http://localhost:8145⁠'
SURVEY_SERVICE_URLURL for the survey service'http://localhost:8080⁠'
PARTY_URLURL for the party service'http://localhost:8081⁠'
RABBITMQ_AMQP_COLLECTION_INSTRUMENTURI for rabbitmqNone
RABBITMQ_AMQP_SURVEY_RESPONSEURI for rabbitmqNone

These are set in config.py⁠

⁠Upload test collection instruments

Navigate to /developer_scripts and run import.py, answer the prompts on the command line

⁠Suggestions for improvements

  • The collection_instrument_schema has two seemingly identical attribute fields: formType and formtype.
  • Apropos the previous point, many of the attributes in the schema have unclear names and purposes, like entname1/2/3 and runame1/2/3, among others. The schema should be redesigned, or have more specific documentation.
  • A couple of the endpoints have fairly useless functionality. For example, all the /collectioninstrument/count endpoint does is return the number of collection instruments. Why is this something the service needs to do? Could this not be accomplished by a database query?
  • Given the service's heavy reliance on collection exercises, could this service not be combined with the collection exercise service during the ras-rm redesign?

Tag summary

Content type

Image

Digest

Size

211.8 MB

Last updated

over 5 years ago

docker pull sdcplatform/ras-collection-instrument