Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Code System Mappings, compression, bug 681
Browse files Browse the repository at this point in the history
  • Loading branch information
kierk committed Oct 12, 2018
1 parent c475598 commit c676c9e
Show file tree
Hide file tree
Showing 27 changed files with 163 additions and 221 deletions.
8 changes: 2 additions & 6 deletions app/controllers/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,8 @@ def update
end

def update_tags
@question.add_tags(params)
if @question.save!
render :show, status: :ok, location: @question
else
render json: @question.errors, status: :unprocessable_entity
end
# This functionality is removed until single word tags changes
render json: @question.errors, status: :unprocessable_entity
end

def usage
Expand Down
8 changes: 2 additions & 6 deletions app/controllers/sections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,8 @@ def remove_from_group
end

def update_tags
@section.add_tags(params)
if @section.save!
render :show, status: :ok, location: @section
else
render json: @section.errors, status: :unprocessable_entity
end
# This functionality is removed until single word tags changes
render json: @sections.errors, status: :unprocessable_entity
end

def update_pdv
Expand Down
8 changes: 2 additions & 6 deletions app/controllers/surveys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,8 @@ def remove_from_group
end

def update_tags
@survey.add_tags(params)
if @survey.save!
render :show, status: :ok, location: @survey
else
render json: @survey.errors, status: :unprocessable_entity
end
# This functionality is removed until single word tags changes
render json: @survey.errors, status: :unprocessable_entity
end

# GET /surveys/1/duplicates
Expand Down
1 change: 1 addition & 0 deletions app/models/survey.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def potential_duplicates(current_user)
q_count = 0
rs_count = 0
sect_dupes = s.potential_duplicates(current_user)
sect_dupes[:questions] ||= []
sect_dupes[:response_sets] ||= []
q_count = sect_dupes[:questions].length if sect_dupes[:questions]
rs_count = sect_dupes[:response_sets].length if sect_dupes[:response_sets]
Expand Down
1 change: 1 addition & 0 deletions app/views/questions/_question.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ end
json.versions question.paper_trail_versions do |version|
json.extract! version, :created_at, :comment, :associations
json.tags JSON.parse(version.associations['tags'].gsub('=>', ':')) if version.associations['tags']
json.mappings JSON.parse(version.associations['mappings'].gsub('=>', ':')) if version.associations['mappings']
json.response_sets JSON.parse(version.associations['response sets'].gsub('=>', ':')) if version.associations['response sets']
json.author User.find(version.whodunnit).email if version.whodunnit
temp_hash = {}
Expand Down
1 change: 1 addition & 0 deletions app/views/sections/_section.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ end
json.versions section.paper_trail_versions do |version|
json.extract! version, :created_at, :comment
json.tags JSON.parse(version.associations['tags'].gsub('=>', ':')) if version.associations['tags']
json.mappings JSON.parse(version.associations['mappings'].gsub('=>', ':')) if version.associations['mappings']
json.nested_items JSON.parse(version.associations['nested items'].gsub('=>', ':')) if version.associations['nested items']
json.pdv JSON.parse(version.associations['pdv'].gsub('=>', ':')) if version.associations['pdv']
json.response_sets JSON.parse(version.associations['response sets'].gsub('=>', ':')) if version.associations['response sets']
Expand Down
1 change: 1 addition & 0 deletions app/views/surveys/show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ end
json.versions @survey.paper_trail_versions do |version|
json.extract! version, :created_at, :comment
json.tags JSON.parse(version.associations['tags'].gsub('=>', ':')) if version.associations['tags']
json.mappings JSON.parse(version.associations['mappings'].gsub('=>', ':')) if version.associations['mappings']
json.sections JSON.parse(version.associations['sections'].gsub('=>', ':')) if version.associations['sections']
json.author User.find(version.whodunnit).email if version.whodunnit
temp_hash = {}
Expand Down
1 change: 1 addition & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Application < Rails::Application
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.assets.enabled = false
config.middleware.use Rack::Deflater
config.middleware.use OliveBranch::Middleware
Rails.application.routes.default_url_options[:host] = Settings.default_url_helper_host || 'localhost:3000'
end
Expand Down
21 changes: 1 addition & 20 deletions features/manage_questions.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ Feature: Manage Questions
Then I should see "Group1"
And I should see "None"

Scenario: Manage Tags on a Question Show page
Given I have a published Question with the content "What is your gender?" and the description "This is a question" and the type "MC" and the concept "New Concept Name"
And I am logged in as test_author@gmail.com
When I go to the list of Questions
And I click on the menu link for the Question with the content "What is your gender?"
And I click on the option to Details the Question with the content "What is your gender?"
Then I should see "Name: What is your gender?"
And I should see "Update"
When I click on the "Update" link
And I click on the "Add Row" link
And I fill in the "value_1" field with "Test Concept 2"
And I click on the "remove_0" link
And I click on the "Add Row" link
And I fill in the "displayName_1" field with "New"
And I select tag "New Concept Name" in the tag dropdown
And I click on the "Save" button
Then I should see "New Concept Name"
And I should see "Test Concept 2"

Scenario: Send a Draft Question to a Publisher
Given I have a Question with the content "What is your gender?" and the description "This is a question" and the type "MC" and the concept "New Concept Name"
And I have a publisher "[email protected]" with the first name "Johnny" and last name "Test"
Expand All @@ -84,7 +65,7 @@ Feature: Manage Questions
And I click on the option to Details the Question with the content "What is your gender?"
Then I should see "Name: What is your gender?"
Then I should see "Description: This is a question"
Then I should see "No Tags Selected"
Then I should see "No Code System Mappings Selected"

Scenario: Comment on a Question in Detail
Given I have a Question with the content "What is your gender?" and the type "MC"
Expand Down
31 changes: 16 additions & 15 deletions test/controllers/questions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,28 @@ class QuestionsControllerTest < ActionDispatch::IntegrationTest
assert_response :unauthorized
end

test 'cannot edit tags on something you do not own' do
test 'cannot edit tags before single word tagging is implemented' do
post questions_url(format: :json), params: { question: { content: 'This is now a thread.', response_type_id: @question.response_type.id, category_id: @question.category.id } }
sign_in users(:not_admin)
put update_tags_question_path(Question.last, format: :json, params: { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] })
assert_response :forbidden
end

test 'can edit tags on something you do own' do
post questions_url(format: :json), params: { question: { content: 'This is now a thread.', response_type_id: @question.response_type.id, category_id: @question.category.id } }
put update_tags_question_path(Question.last, format: :json, params: { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] })
assert_response :success
end

test 'can edit tags on something you share a group with' do
post questions_url(format: :json), params: { question: { content: 'This is now a thread.', response_type_id: @question.response_type.id, category_id: @question.category.id } }
Question.last.add_to_group(@group.id)
sign_in @na_user
@group.add_user(@na_user)
put update_tags_question_path(Question.last, format: :json, params: { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] })
assert_response :success
end
# Reimplementing these when single word tagging is implemented
# test 'can edit tags on something you do own' do
# post questions_url(format: :json), params: { question: { content: 'This is now a thread.', response_type_id: @question.response_type.id, category_id: @question.category.id } }
# put update_tags_question_path(Question.last, format: :json, params: { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] })
# assert_response :success
# end
#
# test 'can edit tags on something you share a group with' do
# post questions_url(format: :json), params: { question: { content: 'This is now a thread.', response_type_id: @question.response_type.id, category_id: @question.category.id } }
# Question.last.add_to_group(@group.id)
# sign_in @na_user
# @group.add_user(@na_user)
# put update_tags_question_path(Question.last, format: :json, params: { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] })
# assert_response :success
# end

test 'can revise something you share a group with' do
post questions_url(format: :json), params: { question: { content: 'This is now a thread.', response_type_id: @question.response_type.id, category_id: @question.category.id } }
Expand Down
41 changes: 21 additions & 20 deletions test/controllers/sections_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,33 +47,34 @@ class SectionsControllerTest < ActionDispatch::IntegrationTest
assert_response :unauthorized
end

test 'cannot edit tags on something you do not own' do
# Reimplementing these when single word tagging is implemented
test 'cannot edit tags before single word tagging is implemented' do
section_json = { section: { name: @section.name, version_independent_id: 'SECT-1337' } }.to_json
post sections_url, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
sign_in users(:not_admin)
section_json = { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] }
put update_tags_section_path(Section.last, format: :json, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' })
assert_response :forbidden
end

test 'can edit tags on something you do own' do
section_json = { section: { name: @section.name, version_independent_id: 'SECT-1337' } }.to_json
post sections_url, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
section_json = { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] }
put update_tags_section_path(Section.last, format: :json, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' })
assert_response :success
end

test 'can edit tags on something you are in a group with' do
section_json = { section: { name: @section.name, version_independent_id: 'SECT-1337' } }.to_json
post sections_url, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
Section.last.add_to_group(@group.id)
sign_in @na_user
@group.add_user(@na_user)
section_json = { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] }
put update_tags_section_path(Section.last, format: :json, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' })
assert_response :success
end
#
# test 'can edit tags on something you do own' do
# section_json = { section: { name: @section.name, version_independent_id: 'SECT-1337' } }.to_json
# post sections_url, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
# section_json = { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] }
# put update_tags_section_path(Section.last, format: :json, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' })
# assert_response :success
# end
#
# test 'can edit tags on something you are in a group with' do
# section_json = { section: { name: @section.name, version_independent_id: 'SECT-1337' } }.to_json
# post sections_url, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' }
# Section.last.add_to_group(@group.id)
# sign_in @na_user
# @group.add_user(@na_user)
# section_json = { concepts_attributes: [{ value: 'Tag2', display_name: 'TagName2', code_system: 'SNOMED' }, { value: 'Tag1', display_name: 'TagName1', code_system: 'SNOMED' }] }
# put update_tags_section_path(Section.last, format: :json, params: section_json, headers: { 'ACCEPT' => 'application/json', 'CONTENT_TYPE' => 'application/json' })
# assert_response :success
# end

test 'cannot edit pdv on something you do not own' do
sign_in @na_user
Expand Down
6 changes: 3 additions & 3 deletions webpack/components/CodedSetTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export default class CodedSetTable extends Component {
<caption>Table of {this.props.itemName}s:</caption>
<thead>
<tr>
<th scope="col" id="display-name-column">{this.props.itemName === 'Response' ? 'Display Name' : `${this.props.itemName} Name`}</th>
<th scope="col" id="code-column">{this.props.itemName} Value</th>
<th scope="col" id="code-system-column">Code System Identifier (Optional)</th>
<th scope="col" id="display-name-column">{this.props.itemName === 'Response' ? 'Display Name' : 'Concept Name'}</th>
<th scope="col" id="code-column">Value</th>
<th scope="col" id="code-system-column">Code System Identifier {this.props.itemName === 'Response' && '(Optional)'}</th>
</tr>
</thead>
<tbody>
Expand Down
10 changes: 5 additions & 5 deletions webpack/components/questions/QuestionEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ class QuestionEdit extends Component {
{this.otherAllowedBox()}
<Row>
<Col md={12}>
<h2 className="tags-table-header"><strong>Tags</strong></h2>
<h2 className="code-system-mappings-table-header"><strong>Code System Mappings</strong></h2>
<CodedSetTableEditContainer itemWatcher={(r) => this.handleConceptsChange(r)}
initialItems={this.state.conceptsAttributes}
parentName={'question'}
childName={'tag'} />
childName={'Code System Mapping'} />
</Col>
</Row>
{ this.isChoiceType() ?
Expand Down Expand Up @@ -374,10 +374,10 @@ class QuestionEdit extends Component {
}

handleConceptsChange(newConcepts) {
if (this.associationChanges['tags']) {
this.associationChanges['tags']['updated'] = newConcepts;
if (this.associationChanges['mappings']) {
this.associationChanges['mappings']['updated'] = newConcepts;
} else {
this.associationChanges['tags'] = {original: this.state.conceptsAttributes, updated: newConcepts};
this.associationChanges['mappings'] = {original: this.state.conceptsAttributes, updated: newConcepts};
}
this.setState({conceptsAttributes: filterConcepts(newConcepts)});
this.unsavedState = true;
Expand Down
20 changes: 2 additions & 18 deletions webpack/components/questions/QuestionShow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import ProgramsAndSystems from "../shared_show/ProgramsAndSystems";
import PublisherLookUp from "../shared_show/PublisherLookUp";
import ChangeHistoryTab from "../shared_show/ChangeHistoryTab";
import GroupLookUp from "../shared_show/GroupLookUp";
import TagModal from "../TagModal";
import Breadcrumb from "../Breadcrumb";
import BasicAlert from '../../components/BasicAlert';
import LoadingSpinner from '../../components/LoadingSpinner';
Expand Down Expand Up @@ -313,27 +312,12 @@ export default class QuestionShow extends Component {
<div className="basic-c-box panel-default">
<div className="panel-heading">
<h2 className="panel-title">
Tags
{isSimpleEditable(question, this.props.currentUser) &&
<a className="pull-right tag-modal-link" href="#" onClick={(e) => {
e.preventDefault();
this.setState({ tagModalOpen: true });
}}>
<TagModal show={this.state.tagModalOpen || false}
cancelButtonAction={() => this.setState({ tagModalOpen: false })}
concepts={question.concepts}
saveButtonAction={(conceptsAttributes) => {
this.props.updateQuestionTags(question.id, conceptsAttributes);
this.setState({ tagModalOpen: false });
}} />
<i className="fa fa-pencil-square-o" aria-hidden="true"></i> Update
</a>
}
Code System Mappings
</h2>
</div>
<div className="box-content">
<div id="concepts-table">
<CodedSetTable items={question.concepts} itemName={'Tag'} />
<CodedSetTable items={question.concepts} itemName={'Code System Mapping'} />
</div>
</div>
</div>
Expand Down
10 changes: 5 additions & 5 deletions webpack/components/sections/SectionEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ class SectionEdit extends Component {
}

handleConceptsChange(newConcepts) {
if (this.associationChanges['tags']) {
this.associationChanges['tags']['updated'] = newConcepts;
if (this.associationChanges['mappings']) {
this.associationChanges['mappings']['updated'] = newConcepts;
} else {
this.associationChanges['tags'] = {original: this.state.conceptsAttributes, updated: newConcepts};
this.associationChanges['mappings'] = {original: this.state.conceptsAttributes, updated: newConcepts};
}
this.setState({conceptsAttributes: filterConcepts(newConcepts)});
this.unsavedState = true;
Expand Down Expand Up @@ -383,11 +383,11 @@ class SectionEdit extends Component {
<input tabIndex="3" className="input-format" placeholder="Enter a description here..." type="text" value={this.state.description || ''} name="section-description" id="section-description" onChange={this.handleChangeDescription}/>
</div>
<div className="section-group">
<h2 className="tags-table-header"><strong>Tags</strong></h2>
<h2 className="code-system-mappings-table-header"><strong>Code System Mappings</strong></h2>
<CodedSetTableEditContainer itemWatcher={(r) => this.handleConceptsChange(r)}
initialItems={this.state.conceptsAttributes}
parentName={'section'}
childName={'tag'} />
childName={'Code System Mapping'} />
</div>
{this.props.action === 'edit' && <div className="section-group">
<label htmlFor="save-with-comment">Notes / Comments About Changes Made (Optional)</label>
Expand Down
Loading

0 comments on commit c676c9e

Please sign in to comment.