-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #19 Support creating and editing groups of observations.
- Loading branch information
Showing
34 changed files
with
1,375 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
class Interleave.Observation | ||
constructor: () -> | ||
render: (link) -> | ||
$(link).on 'click', (e) -> | ||
$modal = $('#observation_modal') | ||
$observation = $('#observation_modal .observation') | ||
$.ajax(this.href).done (response) -> | ||
$observation.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') | ||
$('.observation_form').enableClientSideValidations() | ||
if $('.observation_concept_id_select').length | ||
$('#observation_observation_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 | ||
|
||
$('#observation_condition_concept_id').on 'select2:select', (e) -> | ||
$(this).blur() | ||
return | ||
|
||
$('.observation_form').on('ajax:success', (e, data, status, xhr) -> | ||
$modal.foundation 'close' | ||
Turbolinks.visit(location.toString()) | ||
$('.observations_list').fadeOut() | ||
).on 'ajax:error', (e, xhr, status, error) -> | ||
|
||
$('.observation_form .cancel-link').on 'click', (e) -> | ||
$modal.foundation 'close' | ||
e.preventDefault() | ||
|
||
return | ||
e.preventDefault() | ||
return | ||
return | ||
|
||
$(document).on 'page:load ready', -> | ||
return unless $('.observations.index').length > 0 | ||
ui = new Interleave.Observation | ||
ui.render('.observation_link') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#observations { | ||
@include grid-row(); | ||
|
||
.interleave_datapoint { | ||
@include grid-column( | ||
$columns: 20 | ||
); | ||
} | ||
|
||
.observations_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 | ||
); | ||
} | ||
} | ||
} | ||
|
||
#observation_modal { | ||
position: fixed; | ||
bottom: 0; | ||
top: 30% !important; | ||
right: 0; | ||
left: 0; | ||
width: 100%; | ||
} | ||
|
||
#observation { | ||
@include grid-row(); | ||
|
||
.ui-autocomplete-input { | ||
width: 90%; | ||
height: 2.5rem; | ||
} | ||
.ui-button { | ||
width: 5%; | ||
height: 2.5rem; | ||
} | ||
|
||
.observation_date { | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
input { | ||
margin-bottom: 0; | ||
} | ||
} | ||
|
||
.observation_type_concept_id { | ||
label { | ||
display: block; | ||
} | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
select { | ||
margin-bottom: 0; | ||
} | ||
|
||
.select2 { | ||
width: 100% !important; | ||
} | ||
} | ||
|
||
.observation_value { | ||
label { | ||
display: block; | ||
} | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
input { | ||
margin-bottom: 0; | ||
} | ||
} | ||
|
||
.interleave_sub_datapoint { | ||
label { | ||
display: block; | ||
} | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
input { | ||
margin-bottom: 0; | ||
} | ||
} | ||
|
||
.interleave_sub_datapoints { | ||
.left { | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
|
||
} | ||
|
||
.right { | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
} | ||
} | ||
|
||
.navigation { | ||
padding: 1rem; | ||
@include grid-column-offset(12); | ||
@include grid-column( | ||
$columns: 12 | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
class ObservationsController < 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_observation, only: [:edit, :update] | ||
before_filter :load_interleave_datapoint, only: [:new, :edit] | ||
|
||
def index | ||
@datapoint = @registry.interleave_datapoints.find(params[:datapoint_id]) | ||
params[:page]||= 1 | ||
options = {} | ||
options[:sort_column] = sort_column | ||
options[:sort_direction] = sort_direction | ||
add_breadcrumbs(registry: @registry, interleave_person: @interleave_person, datapoint: @datapoint) | ||
@observations = Observation.by_person(@interleave_person.person.person_id).by_interleave_data_point(@datapoint.id, options).paginate(per_page: 10, page: params[:page]) | ||
end | ||
|
||
def new | ||
@observation = Observation.new() | ||
@observation.interleave_datapoint = @datapoint | ||
@datapoint.initialize_defaults(@observation) | ||
@concepts = [] | ||
@type_concepts = load_concepts('observation_type_concept_id') | ||
@sub_datapoints = @datapoint.initialize_sub_datapoint_entities | ||
respond_to do |format| | ||
format.html { render :layout => false } | ||
end | ||
end | ||
|
||
def create | ||
@observation = Observation.new(observation_params) | ||
interleave_registry_cdm_source = @registry.interleave_registry_cdm_sources.where(cdm_source_name: InterleaveRegistryCdmSource::CDM_SOURCE_EX_NIHILO).first | ||
@observation.person = @interleave_person.person | ||
|
||
respond_to do |format| | ||
if @observation.create_with_sub_datapoints!(interleave_registry_cdm_source, observations: params[:observations]) | ||
format.js { } | ||
else | ||
format.js { render json: { errors: @observation.errors.full_messages }, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
def edit | ||
@observation.interleave_datapoint = @datapoint | ||
@concepts = [[@observation.observation_concept.concept_name, @observation.observation_concept_id]] | ||
@type_concepts = load_concepts('observation_type_concept_id') | ||
@sub_datapoints = @datapoint.initialize_sub_datapoint_entities(@observation.interleave_entity) | ||
respond_to do |format| | ||
format.html { render :layout => false } | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @observation.update_with_sub_datapoints!(observation_params, observations: params[:observations]) | ||
format.js { } | ||
else | ||
format.js { render json: { errors: @observation.errors.full_messages }, status: :unprocessable_entity } | ||
end | ||
end | ||
end | ||
|
||
private | ||
def observation_params | ||
params.require(:observation).permit(:interleave_datapoint_id, :observation_concept_id, :observation_date, :observation_time, :observation_type_concept_id, :value_as_number, :value_as_string, :value_as_concept_id, :qualifier_concept_id, :unit_concept_id) | ||
end | ||
|
||
def load_observation | ||
@observation = Observation.find(params[:id]) | ||
end | ||
|
||
def sort_column | ||
['observation_date'].concat(@datapoint.interleave_sub_datapoints.map { |interleave_sub_datapoint| interleave_sub_datapoint.id.to_s }).include?(params[:sort]) ? params[:sort] : "#{@datapoint.id}" | ||
end | ||
|
||
def sort_direction | ||
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ConceptRelationship < ActiveRecord::Base | ||
self.table_name = 'concept_relationship' | ||
end |
Oops, something went wrong.