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

Fi 900 - generic ui fields - proof of concept #470

Merged
merged 18 commits into from
Aug 7, 2020

Conversation

ghost
Copy link

@ghost ghost commented Jul 16, 2020

This is adds a way for sequences to specify their own prerequisites without changing the the view erb files or changing the testinginstance data model. They would just "require" whatever prerequisites they need and the UI and database entry for it would be made by Inferno. I have it working with US Core tests. The patient id's field and device codes field are not in the default.erb file, but you can see them in the UI when running the tests. I also tested with my generated ukcore code, and confirmed it was working for the new fields there as well.

To require a new field, you'll first need to add it in the module yaml file. In the uscore_v3.1.0_module.yml file, you can see the sequence_requirements section. To add a new requirement, just add one with a label. Then in a sequence file, add that requirement.

Submitter:

  • This pull request describes why these changes were made
  • Internal ticket for this PR:
  • 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

@ghost ghost added the WIP Work in progress label Jul 16, 2020
@radamson
Copy link
Contributor

I think adding the labels and descriptions in the module.yml is a good way to start, but I'm worried about having to manage and update the prerequisites in multiple places. Right now we have a situation where they need to be edited in the ERBs, model and test code and its a bear to deal with.

I'm not sure if its the best way to do it, but it might be nice to be able to add the label and description when defining the prerequisite so that it all happens in the same place. Otherwise I could see the prerequisites getting out of sync where maybe we forget to add a label in the config or have a label in the config, but never use it.

I don't want perfect to get in the way of good, but I think longer term we might want to be able to centralize the management of prereqs.

lib/app/sequence_base.rb Outdated Show resolved Hide resolved
@arscan
Copy link
Contributor

arscan commented Jul 30, 2020

I think adding the labels and descriptions in the module.yml is a good way to start, but I'm worried about having to manage and update the prerequisites in multiple places. Right now we have a situation where they need to be edited in the ERBs, model and test code and its a bear to deal with.

Could take care of this using ruby. By default have these just be defined completely in the sequences. And if you use in multiple sequences place in a common ruby file / module and include the common file. And/or you could have it be smart enough that only 1 sequence has to include the label/description portions, and in the other just require the parameter name it is good enough.

But from a workflow perspective, maybe it does make sense to have a module file on the top where you define what global variables there are and what gets 'exported'?

lib/app/models/sequence_requirement.rb Outdated Show resolved Hide resolved
lib/app/models/testing_instance.rb Outdated Show resolved Hide resolved
lib/app/sequence_base.rb Outdated Show resolved Hide resolved
lib/app/models/testing_instance.rb Outdated Show resolved Hide resolved

instance_class.define_method requirement_setter_name do
requirement_found = sequence_requirements.find { |requirement| requirement.name == requirement_name.to_s }
return unless requirement_found.present?
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this create the requirement if it isn't found?

Copy link
Author

Choose a reason for hiding this comment

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

I added this so the rake tests pass, but it also works so if you don't have the requirement in the module file, you can still use the requirement. It just won't have a nice label or description.

@ghost ghost removed the WIP Work in progress label Aug 4, 2020
# Get the conditions that determine whether the record already exists
conditions = attributes.select { |key, _value| condition_attributes.include?(key) }

SequenceRequirement.first_or_create(conditions, attributes)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think lines 287-290 are overcomplicating things.

Suggested change
SequenceRequirement.first_or_create(conditions, attributes)
SequenceRequirement.first_or_create({ name: requirement[:name], testing_instance: self }, attributes)

def get_sequence_requirement(requirement)
return unless requirement&.dig(:name)

attributes = { name: requirement[:name],
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't need to set name: requirement[:name] if we're then merging in requirement.

@@ -37,6 +38,13 @@ def initialize(params)
test_sets[test_set_key] = TestSet.new(test_set_key, test_set)
end
end
if params[:sequence_requirements].present?
@sequence_requirements = {}.tap do |requirements|
params[:sequence_requirements].each do |requirement_key, texts|
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this value called texts? The same thing is done in TestingInstance.

Copy link
Author

Choose a reason for hiding this comment

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

changed name to req_description.


def set_requirement_value(requirement_name, value)
get_sequence_requirement(name: requirement_name.to_s, testing_instance: self).update(value: value)
self.patient_id = value if requirement_name == 'patient_id'
Copy link
Contributor

Choose a reason for hiding this comment

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

I hope we're not keeping this in the final version.

Copy link
Author

Choose a reason for hiding this comment

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

Took this out. Forgot we have the setters now so I'm back to using that in the test_set_endpoint

@arscan
Copy link
Contributor

arscan commented Aug 7, 2020

Not a blocking issue, but I was very specific about how we ordered the fields that come up in the form. At least now, the order is not quite right -- though that may be because this is a mix of the old and new methods... perhaps if we went to all the new method they will show up in the interface in the order that they are put in the module file?

Copy link
Contributor

@arscan arscan left a comment

Choose a reason for hiding this comment

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

This looks like an improvement for sure. We've got a ways to go, but this moves it in the right direction and any issues I have with it can be addressed later.

@radamson radamson merged commit 8fcfc49 into development Aug 7, 2020
@radamson radamson deleted the fi-900-generic-ui-fields branch August 7, 2020 18:14
@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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants