add function for retrieving treatment info by observation unit ids
[sgn.git] / lib / CXGN / AerialImagingEventProject.pm
blobf0690cad4cc45c0fd94347856b490ed94e374751
2 package CXGN::AerialImagingEventProject;
4 use Moose;
6 extends 'CXGN::Project';
8 use SGN::Model::Cvterm;
9 use CXGN::Calendar;
11 =head2 function get_associated_image_band_projects()
13 Usage:
14 Desc: returns the associated image band projects for this imaging event project
15 Ret: returns an arrayref [ id, name ] of arrayrefs
16 Args:
17 Side Effects:
18 Example:
20 =cut
22 sub get_associated_image_band_projects {
23 my $self = shift;
24 my $drone_run_on_drone_run_band_type_id = SGN::Model::Cvterm->get_cvterm_row($self->bcs_schema, 'drone_run_band_on_drone_run', 'project_relationship')->cvterm_id();
25 my $q = "SELECT drone_run_band.project_id, drone_run_band.name
26 FROM project AS drone_run
27 JOIN project_relationship on (drone_run.project_id = project_relationship.object_project_id AND project_relationship.type_id = $drone_run_on_drone_run_band_type_id)
28 JOIN project AS drone_run_band ON (drone_run_band.project_id = project_relationship.subject_project_id)
29 WHERE drone_run.project_id = ?;";
30 my $h = $self->bcs_schema->storage->dbh()->prepare($q);
31 $h->execute($self->get_trial_id);
32 my @image_band_projects;
33 while (my ($drone_run_band_project_id, $drone_run_band_name) = $h->fetchrow_array()) {
34 push @image_band_projects, [$drone_run_band_project_id, $drone_run_band_name];
36 return \@image_band_projects;
39 =head2 accessors get_drone_run_date(), set_drone_run_date()
41 Usage:
42 Desc:
43 Ret:
44 Args:
45 Side Effects:
46 Example:
48 =cut
50 sub get_drone_run_date {
51 my $self = shift;
53 my $date_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($self->bcs_schema, 'project_start_date', 'project_property')->cvterm_id();
54 my $row = $self->bcs_schema->resultset('Project::Projectprop')->find({
55 project_id => $self->get_trial_id(),
56 type_id => $date_cvterm_id,
57 });
59 my $calendar_funcs = CXGN::Calendar->new({});
61 if ($row) {
62 my $date = $calendar_funcs->display_start_date($row->value());
63 return $date;
64 } else {
65 return;
69 sub set_drone_run_date {
70 my $self = shift;
71 my $date = shift;
73 my $calendar_funcs = CXGN::Calendar->new({});
75 if (my $event = $calendar_funcs->check_value_format($date) ) {
77 my $date_cvterm_id = SGN::Model::Cvterm->get_cvterm_row($self->bcs_schema, 'project_start_date', 'project_property')->cvterm_id();
79 my $row = $self->bcs_schema->resultset('Project::Projectprop')->find_or_create({
80 project_id => $self->get_trial_id(),
81 type_id => $date_cvterm_id,
82 });
84 $row->value($event);
85 $row->update();
86 } else {
87 print STDERR "date format did not pass check: $date \n";