Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

FI-545 FHIR Terminology Endpoint #420

Merged
merged 10 commits into from
Jan 24, 2020
Merged

FI-545 FHIR Terminology Endpoint #420

merged 10 commits into from
Jan 24, 2020

Conversation

okeefm
Copy link

@okeefm okeefm commented Jan 22, 2020

This Pull Request adds a terminology endpoint to Inferno, to provide the CodeSystem/$validate-code and ValueSet/$validate-code operations to fhir-validator-wrapper. The endpoint also defines a metadata url, to provide CapabilityStatement and TerminologyCapabilities resources for the validator as well.

The Terminology Endpoint is part of Inferno, which means it runs on the same base URL and port as Inferno. It is served up at <inferno_host>:<inferno_port>/fhir, which must be added to fhir-validator-wrapper for the time being.

This PR also adds some additional valuesets and codesystems to the resources directory, but this is not an exhaustive list. Missing valuesets and codesystems are logged to terminology_misses.log.

NOTE: Needs work to fix one test suite for CodeSystem/$validate-code.
Submitter:

  • This pull request describes why these changes were made
  • Internal ticket for this PR: https://oncprojectracking.healthit.gov/support/browse/FI-545
  • Internal ticket links to this PR
  • Internal ticket is properly labeled (Community/Program)
  • Internal ticket has a justification for its Community/Program label
  • Code diff has been reviewed for extraneous/missing code
  • Tests are included and test edge cases
  • Tests/code quality metrics have been run locally and pass

Reviewer 1:

Name:

  • Code is maintainable and reusable, reuses existing code and infrastructure
    where appropriate, and accomplishes the task's purpose
  • The tests appropriately test the new code, including edge cases
  • You have tried to break the code

Reviewer 2:

Name:

  • Code is maintainable and reusable, reuses existing code and infrastructure
    where appropriate, and accomplishes the task's purpose
  • The tests appropriately test the new code, including edge cases
  • You have tried to break the code

@okeefm okeefm changed the base branch from master to development January 22, 2020 20:38
@okeefm okeefm added the WIP Work in progress label Jan 22, 2020
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
when %r{application\/.*xml}
return [status, { 'Content-Type' => 'application/fhir+xml' }, resource.to_xml]
else
return [status, { 'Content-Type' => 'application/fhir+json' }, resource.to_json]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can be combined with when %r{application/.*json}

lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
"title" : "Provenance participant type",
"status" : "draft",
"experimental" : false,
"date" : "2023-05-12T00:00:00+10:00",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

really?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hah; didn't notice this. This file is straight from HL7-- https://www.hl7.org/fhir/codesystem-provenance-agent-type.json.html

set :prefix, '/fhir'
Inferno::Terminology.register_umls_db('umls.db')
Inferno::Terminology.load_valuesets_from_directory('resources', true)
set :logger, Logger.new('terminology_misses.log')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use Inferno.logger?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that, yeah. I wanted this to log to a separate log file to keep them separated, and because I expect this logger to go away once we've been able to add more code systems and valuesets.

set :logger, Logger.new('terminology_misses.log')

get '/metadata', provides: ['application/fhir+json', 'application/fhir+xml'] do
if params[:mode] == 'terminology'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be really nice if our business logic didn't live in our endpoints.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair. I'll see how much of this I can get into another class as possible.

lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
lib/app/endpoint/terminology.rb Outdated Show resolved Hide resolved
end

def respond_with_type(resource, accept, status = 200)
accept.each do |type|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block looks like it always returns, so the iteration doesn't seem necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. It's complicated because accept is an array, but we could just take the first item in the array (or search the array for either of the return types we care about before returning the default type).

return respond_with_type(FHIR::OperationOutcome.new(issue: issue), request.accept, 400)
end

def valueset_validates_code(parameters, id_param = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These non-endpoint methods also seem like something that could potentially be useful outside of the context of an http request, so it would be nice if they lived somewhere else.

unless @valueset_ids
@valueset_ids = {}
@known_valuesets.each_pair do |k, v|
@valueset_ids[v&.valueset_model&.id] = k
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do k and v actually represent? This makes @valueset_ids look like a hash whose keys are ids, but what are its values?

@arscan
Copy link
Contributor

arscan commented Jan 24, 2020

All but stylistic comments incorporated, incorporating into the next update.

@arscan arscan merged commit 33e63e3 into development Jan 24, 2020
@arscan arscan deleted the validate_code_endpoint branch January 24, 2020 20:35
@radamson radamson mentioned this pull request Aug 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
WIP Work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants