Skip to content

Commit

Permalink
closes #16 Support creating and editing drug exposures.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgurley committed Aug 15, 2016
1 parent f7ec254 commit ca4ada9
Show file tree
Hide file tree
Showing 30 changed files with 773 additions and 134 deletions.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@
//= require turbolinks
//= require init
//= require interleave.condition_occurrence
//= require interleave.drug_exposure
//= require interleave.measurement
//= require interleave.procedure_occurrence
67 changes: 67 additions & 0 deletions app/assets/javascripts/interleave.drug_exposure.js.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
class Interleave.DrugExposure
constructor: () ->
render: (link) ->
$(link).on 'click', (e) ->
$modal = $('#drug_exposure_modal')
$drug_exposure = $('#drug_exposure_modal .drug_exposure')
$.ajax(this.href).done (response) ->
$drug_exposure.html(response)
$modal.foundation 'open'
$('.datepicker').datepicker
onClose: (dateText, inst) ->
$(inst.input).focusout()
return
changeMonth: true
changeYear: true
interleaveDatapointConceptsUrl = $('#concepts_interleave_datapoint_url').attr('href')
$('.drug_exposure_form').enableClientSideValidations()
$('#drug_exposure_drug_concept_id').select2
ajax:
url: interleaveDatapointConceptsUrl
dataType: 'json'
delay: 250
data: (params) ->
{
q: params.term
page: params.page
}
processResults: (data, params) ->
params.page = params.page or 1
results = $.map(data.concepts, (obj) ->
obj.id = obj.concept_id
obj.text = obj.text
obj
)

{
results: results
pagination: more: params.page * 10 < data.total
}
cache: true
escapeMarkup: (markup) ->
markup
minimumInputLength: 2

$('#drug_exposure_condition_concept_id').on 'select2:select', (e) ->
$(this).blur()
return

$('.drug_exposure_form').on('ajax:success', (e, data, status, xhr) ->
$modal.foundation 'close'
Turbolinks.visit(location.toString())
$('.drug_exposures_list').fadeOut()
).on 'ajax:error', (e, xhr, status, error) ->

$('.drug_exposure_form .cancel-link').on 'click', (e) ->
$modal.foundation 'close'
e.preventDefault()

return
e.preventDefault()
return
return

$(document).on 'page:load ready', ->
return unless $('.drug_exposures.index').length > 0
ui = new Interleave.DrugExposure
ui.render('.drug_exposure_link')
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
@import "registries";
@import "people";
@import "condition_occurrences";
@import "drug_exposures";
@import "measurements";
@import "procedure_occurrences";
@import "jquery.ui.override";
Expand Down
108 changes: 108 additions & 0 deletions app/assets/stylesheets/drug_exposures.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#drug_exposures {
@include grid-row();

.interleave_datapoint {
@include grid-column(
$columns: 20
);
}

.drug_exposures_list {
@include grid-column(
$columns: 24
);

th .current {
padding-right: 2em;
background-repeat: no-repeat;
background-position: right center;
}

th .asc {
background-image: asset_url("drop25.png");
}

th .desc {
background-image: asset_url("drop27.png");
}

table {
@include grid-column(
$columns: 24
);
}
}
}

#drug_exposure_modal {
position: fixed;
bottom: 0;
top: 30% !important;
right: 0;
left: 0;
width: 100%;
}

#drug_exposure {
@include grid-row();

.ui-autocomplete-input {
width: 90%;
height: 2.5rem;
}
.ui-button {
width: 5%;
height: 2.5rem;
}

.drug_exposure_start_date {
@include grid-column(
$columns: 12
);
input {
margin-bottom: 0;
}
}
.drug_exposure_end_date {
@include grid-column(
$columns: 12
);
input {
margin-bottom: 0;
}
}
.drug_concept_id {
label {
display: block;
}
@include grid-column(
$columns: 12
);
select {
margin-bottom: 0;
}

.select2 {
width: 100% !important;
}
}

.drug_type_concept_id {
label {
display: block;
}
@include grid-column(
$columns: 12
);
select {
margin-bottom: 0;
}
}
.navigation {
padding: 1rem;
@include grid-column-offset(12);
@include grid-column(
$columns: 12
);
}
}
20 changes: 19 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,29 @@ def add_breadcrumbs(options = {})
case options[:datapoint].domain_id
when 'Condition'
@breadcrumbs << { name: "#{options[:datapoint].domain_id}:#{options[:datapoint].name}", url: interleave_registry_interleave_person_condition_occurrences_url(@registry, @interleave_person, datapoint_id: @datapoint.id), class: 'datapoint_link' }
when 'Drug'
@breadcrumbs << { name: "#{options[:datapoint].domain_id}:#{options[:datapoint].name}", url: interleave_registry_interleave_person_drug_exposures_url(@registry, @interleave_person, datapoint_id: @datapoint.id), class: 'datapoint_link' }
when 'Measurement'
@breadcrumbs << { name: "#{options[:datapoint].domain_id}:#{options[:datapoint].name}", url: interleave_registry_interleave_person_measurements_url(@registry, @interleave_person, datapoint_id: @datapoint.id), class: 'datapoint_link' }
when 'Procedure'
@breadcrumbs << { name: "#{options[:datapoint].domain_id}:#{options[:datapoint].name}", url: interleave_registry_interleave_person_procedure_occurrences_url(@registry, @interleave_person, datapoint_id: @datapoint.id), class: 'datapoint_link' }
end
end
end
end

def load_concepts(column)
@datapoint.concept_values(column).map { |concept| [concept.concept_name, concept.concept_id] }
end

def load_interleave_registry
@registry = InterleaveRegistry.find(params[:interleave_registry_id])
end

def load_interleave_person
@interleave_person = InterleavePerson.find(params[:interleave_person_id])
end

def load_interleave_datapoint
@datapoint = InterleaveDatapoint.find(params[:datapoint_id])
end
end
20 changes: 2 additions & 18 deletions app/controllers/condition_occurrences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def new
@condition_occurrence.interleave_datapoint = @datapoint
@datapoint.initialize_defaults(@condition_occurrence)
@concepts = []
@type_concepts = load_type_concepts
@type_concepts = load_concepts('condition_type_concept_id')
respond_to do |format|
format.html { render :layout => false }
end
Expand All @@ -42,7 +42,7 @@ def create
def edit
@condition_occurrence.interleave_datapoint = @datapoint
@concepts = [[@condition_occurrence.condition_concept.concept_name, @condition_occurrence.condition_concept_id]]
@type_concepts = load_type_concepts
@type_concepts = load_concepts('condition_type_concept_id')
respond_to do |format|
format.html { render :layout => false }
end
Expand All @@ -63,26 +63,10 @@ def condition_occurrence_params
params.require(:condition_occurrence).permit(:interleave_datapoint_id, :condition_concept_id, :condition_start_date, :condition_end_date, :condition_type_concept_id)
end

def load_interleave_registry
@registry = InterleaveRegistry.find(params[:interleave_registry_id])
end

def load_interleave_person
@interleave_person = InterleavePerson.find(params[:interleave_person_id])
end

def load_condition_occurrence
@condition_occurrence = ConditionOccurrence.find(params[:id])
end

def load_interleave_datapoint
@datapoint = InterleaveDatapoint.find(params[:datapoint_id])
end

def load_type_concepts
@datapoint.concept_values('condition_type_concept_id').map { |condition_type| [condition_type.concept_name, condition_type.concept_id] }
end

def sort_column
['condition_start_date', 'condition_end_date', 'condition_concept.concept_name', 'condition_type_concept.concept_name'].include?(params[:sort]) ? params[:sort] : 'condition_start_date'
end
Expand Down
82 changes: 82 additions & 0 deletions app/controllers/drug_exposures_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
class DrugExposuresController < ApplicationController
helper_method :sort_column, :sort_direction
before_filter :load_interleave_registry, only: [:index, :new, :create, :edit]
before_filter :load_interleave_person, only: [:index, :new, :create, :edit]
before_filter :load_drug_exposure, only: [:edit, :update]
before_filter :load_interleave_datapoint, only: [:new, :edit]

def index
params[:page]||= 1
options = {}
options[:sort_column] = sort_column
options[:sort_direction] = sort_direction
@datapoint = @registry.interleave_datapoints.find(params[:datapoint_id])
add_breadcrumbs(registry: @registry, interleave_person: @interleave_person, datapoint: @datapoint)
@drug_exposures = DrugExposure.by_person(@interleave_person.person.person_id).by_interleave_data_point(@datapoint.id, options).paginate(per_page: 10, page: params[:page])
end

def new
@drug_exposure = DrugExposure.new()
@drug_exposure.interleave_datapoint = @datapoint
@datapoint.initialize_defaults(@drug_exposure)
@concepts = []
@type_concepts = load_concepts('drug_type_concept_id')
@route_concepts = load_concepts('route_concept_id')
# @dose_unit_concepts = []
respond_to do |format|
format.html { render :layout => false }
end
end

def create
@drug_exposure = DrugExposure.new(drug_exposure_params)
interleave_registry_cdm_source = @registry.interleave_registry_cdm_sources.where(cdm_source_name: InterleaveRegistryCdmSource::CDM_SOURCE_EX_NIHILO).first
@drug_exposure.person = @interleave_person.person
respond_to do |format|
if @drug_exposure.create_with_sub_datapoints!(interleave_registry_cdm_source)
format.js { }
else
format.js { render json: { errors: @drug_exposure.errors.full_messages }, status: :unprocessable_entity }
end
end
end

def edit
@drug_exposure.interleave_datapoint = @datapoint
@concepts = [[@drug_exposure.drug_concept.concept_name, @drug_exposure.drug_concept_id]]
@type_concepts = load_concepts('drug_type_concept_id')
@route_concepts = load_concepts('route_concept_id')
# @dose_unit_concepts = [[@drug_exposure.dose_unit_concept.concept_name, @drug_exposure.dose_unit_concept_id]]

respond_to do |format|
format.html { render :layout => false }
end
end

def update
respond_to do |format|
if @drug_exposure.update_attributes(drug_exposure_params)
format.js { }
else
format.js { render json: { errors: @drug_exposure.errors.full_messages }, status: :unprocessable_entity }
end
end
end

private
def drug_exposure_params
params.require(:drug_exposure).permit(:interleave_datapoint_id, :drug_concept_id, :drug_exposure_start_date, :drug_exposure_end_date, :drug_type_concept_id, :route_concept_id, :dose_unit_concept_id)
end

def load_drug_exposure
@drug_exposure = DrugExposure.find(params[:id])
end

def sort_column
['drug_exposure_start_date', 'drug_exposure_end_date', 'drug_concept.concept_name', 'drug_type_concept.concept_name'].include?(params[:sort]) ? params[:sort] : 'drug_exposure_start_date'
end

def sort_direction
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
end
end
Loading

0 comments on commit ca4ada9

Please sign in to comment.