Grassroots Infrastructure
The Grassroots Infrastructure is a suite of computing tools to help users and developers use scientific data infrastructure that can easily be interconnected.
study.h
Go to the documentation of this file.
1 /*
2 ** Copyright 2014-2018 The Earlham Institute
3 **
4 ** Licensed under the Apache License, Version 2.0 (the "License");
5 ** you may not use this file except in compliance with the License.
6 ** You may obtain a copy of the License at
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
10 ** Unless required by applicable law or agreed to in writing, software
11 ** distributed under the License is distributed on an "AS IS" BASIS,
12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16 /*
17  * experimental_area.h
18  *
19  * Created on: 11 Sep 2018
20  * Author: billy
21  */
22 
23 #ifndef SERVICES_FIELD_TRIALS_INCLUDE_STUDY_H_
24 #define SERVICES_FIELD_TRIALS_INCLUDE_STUDY_H_
25 
26 
27 #include <time.h>
28 
31 #include "field_trial.h"
32 #include "location.h"
33 #include "jansson.h"
34 #include "key_value_pair.h"
35 #include "crop.h"
36 #include "person.h"
37 
38 #include "typedefs.h"
39 #include "address.h"
40 #include "json_processor.h"
41 #include "statistics.h"
42 
43 
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 
46 #ifdef ALLOCATE_STUDY_TAGS
47  #define STUDY_PREFIX DFW_FIELD_TRIAL_SERVICE_LOCAL
48  #define STUDY_VAL(x) = x
49  #define STUDY_CONCAT_VAL(x,y) = x y
50  #define STUDY_KEY_VALUE_PAIR_VAL(x,y) = {x, y}
51 #else
52  #define STUDY_PREFIX extern
53  #define STUDY_VAL(x)
54  #define STUDY_CONCAT_VAL(x,y)
55  #define STUDY_KEY_VALUE_PAIR_VAL(x,y)
56 #endif
57 
58 #endif /* #ifndef DOXYGEN_SHOULD_SKIP_THIS */
59 
60 STUDY_PREFIX const char *ST_NAME_S STUDY_CONCAT_VAL (CONTEXT_PREFIX_SCHEMA_ORG_S, "name");
61 
62 STUDY_PREFIX const char *ST_LOCATION_ID_S STUDY_VAL ("address_id");
63 
64 STUDY_PREFIX const char *ST_LOCATION_S STUDY_VAL ("address");
65 
66 
67 STUDY_PREFIX const char *ST_CONTACT_S STUDY_VAL ("contact");
68 
69 STUDY_PREFIX const char *ST_CURATOR_S STUDY_VAL ("curator");
70 
71 
72 STUDY_PREFIX const char *ST_CONTRIBUTORS_S STUDY_VAL ("contributors");
73 
74 
75 STUDY_PREFIX const char *ST_ASPECT_S STUDY_CONCAT_VAL (CONTEXT_PREFIX_NCI_THESAUSUS_ONTOLOGY_S, "C42677");
76 
77 STUDY_PREFIX const char *ST_SLOPE_S STUDY_CONCAT_VAL (CONTEXT_PREFIX_ENVIRONMENT_ONTOLOGY_S, "00002000");
78 
79 
80 STUDY_PREFIX const char *ST_PARENT_FIELD_TRIAL_S STUDY_VAL ("parent_field_trial");
81 
82 STUDY_PREFIX const char *ST_PLOTS_S STUDY_VAL ("plots");
83 
84 STUDY_PREFIX const char *ST_NUMBER_OF_PLOTS_S STUDY_VAL ("number_of_plots");
85 
86 
87 STUDY_PREFIX const char *ST_DATA_LINK_S STUDY_CONCAT_VAL (CONTEXT_PREFIX_SCHEMA_ORG_S, "url");
88 
89 STUDY_PREFIX const char *ST_FRICTIONLESS_DATA_LINK_S STUDY_CONCAT_VAL (CONTEXT_PREFIX_SCHEMA_ORG_S, "contentUrl");
90 
91 
92 STUDY_PREFIX const char *ST_HANDBOOK_DATA_LINK_S STUDY_VAL ("handbook");
93 
94 
95 STUDY_PREFIX const char *ST_CURRENT_CROP_S STUDY_VAL ("current_crop");
96 
97 STUDY_PREFIX const char *ST_PREVIOUS_CROP_S STUDY_VAL ("previous_crop");
98 
99 STUDY_PREFIX const char *ST_DESCRIPTION_S STUDY_CONCAT_VAL (CONTEXT_PREFIX_SCHEMA_ORG_S, "description");
100 
101 
102 STUDY_PREFIX const char *ST_DESIGN_S STUDY_VAL ("study_design");
103 
104 STUDY_PREFIX const char *ST_GROWING_CONDITIONS_S STUDY_VAL ("growing_conditions");
105 
106 STUDY_PREFIX const char *ST_PHENOTYPE_GATHERING_NOTES_S STUDY_VAL ("phenotype_gathering_notes");
107 
108 
109 STUDY_PREFIX const char *ST_NUMBER_OF_PLOT_ROWS_S STUDY_VAL ("num_rows");
110 
111 STUDY_PREFIX const char *ST_NUMBER_OF_PLOT_COLUMN_S STUDY_VAL ("num_columns");
112 
113 STUDY_PREFIX const char *ST_NUMBER_OF_REPLICATES_S STUDY_VAL ("num_replicates");
114 
115 
116 STUDY_PREFIX const char *ST_PLOT_LENGTH_S STUDY_VAL ("plot_length");
117 
118 STUDY_PREFIX const char *ST_PLOT_WIDTH_S STUDY_VAL ("plot_width");
119 
120 
121 STUDY_PREFIX const char *ST_WEATHER_S STUDY_VAL ("weather");
122 
123 STUDY_PREFIX const char *ST_SHAPE_S STUDY_VAL ("shape_data");
124 
125 STUDY_PREFIX const char *ST_HAS_SHAPE_S STUDY_VAL ("has_shape_data");
126 
127 STUDY_PREFIX const char *ST_SHAPE_NOTES_S STUDY_VAL ("shape_data_notes");
128 
129 
130 STUDY_PREFIX const char *ST_PLOT_H_GAP_S STUDY_VAL ("plot_horizontal_gap");
131 
132 STUDY_PREFIX const char *ST_PLOT_V_GAP_S STUDY_VAL ("plot_vertical_gap");
133 
134 STUDY_PREFIX const char *ST_PLOT_BLOCK_H_GAP_S STUDY_VAL ("plot_block_horizontal_gap");
135 
136 STUDY_PREFIX const char *ST_PLOT_BLOCK_V_GAP_S STUDY_VAL ("plot_block_vertical_gap");
137 
138 STUDY_PREFIX const char *ST_PLOT_ROWS_PER_BLOCK_S STUDY_VAL ("plot_block_rows");
139 
140 STUDY_PREFIX const char *ST_PLOT_COLS_PER_BLOCK_S STUDY_VAL ("plot_block_columns");
141 
142 
143 STUDY_PREFIX const char *ST_TREATMENTS_S STUDY_VAL ("treatment_factors");
144 
145 
146 STUDY_PREFIX const char *ST_PHENOTYPES_S STUDY_VAL ("phenotypes");
147 
148 STUDY_PREFIX const char *ST_ACCESSIONS_S STUDY_VAL ("accessions");
149 
150 
151 STUDY_PREFIX const char *ST_PHENOTYPE_STATISTICS_S STUDY_VAL ("statistics");
152 
153 STUDY_PREFIX const char *ST_PHENOTYPE_DEFINITION_S STUDY_VAL ("definition");
154 
155 
156 STUDY_PREFIX const char *ST_HARVEST_YEAR_S STUDY_VAL ("harvest_year");
157 
158 STUDY_PREFIX const char *ST_SOWING_YEAR_S STUDY_VAL ("sowing_year");
159 
160 
161 STUDY_PREFIX const char *ST_PLAN_CHANGES_S STUDY_VAL ("plan_changes");
162 
163 STUDY_PREFIX const char *ST_PHYSICAL_SAMPLES_COLLECTED_S STUDY_VAL ("physical_samples_collected");
164 
165 STUDY_PREFIX const char *ST_DATA_NOT_INCLUDED_S STUDY_VAL ("data_not_included");
166 
167 STUDY_PREFIX const char *ST_PHOTO_URL_S STUDY_CONCAT_VAL (CONTEXT_PREFIX_SCHEMA_ORG_S, "image");
168 
169 STUDY_PREFIX const char *ST_IMAGE_COLLECTION_NOTE_S STUDY_VAL ("image_collection_notes");
170 
171 STUDY_PREFIX int32 ST_UNSET_PH STUDY_VAL (-1);
172 
173 
177 #define ST_UNKNOWN_DIRECTION_S "Unknown"
178 
179 
180 
181 
182 typedef struct Study
183 {
184  bson_oid_t *st_id_p;
185 
187 
189 
191 
193 
194  char *st_name_s;
195 
197 
198  char *st_aspect_s;
199 
200  char *st_slope_s;
201 
208 
210 
212 
214 
215  char *st_design_s;
216 
221 
226 
231 
233 
235 
237 
239 
240  uint32 *st_num_rows_p;
241 
243 
245 
247 
251  json_t *st_shape_p;
252 
257 
259 
261 
262 
264 
266 
268 
270 
272 
274 
276 
278 
280 
282 
284 
286 
292 
293 } Study;
294 
295 
296 
297 typedef struct StudyNode
298 {
300 
302 
303 } StudyNode;
304 
305 
306 
307 /* forward declarations */
308 struct Plot;
309 
310 #ifdef __cplusplus
311 extern "C"
312 {
313 #endif
314 
315 
316 
317 
318 DFW_FIELD_TRIAL_SERVICE_LOCAL Study *AllocateStudy (bson_oid_t *id_p, const char *name_s, const char *data_url_s, const char *aspect_s, const char *slope_s,
319  struct Location *location_p, FieldTrial *parent_field_trial_p,
320  MEM_FLAG parent_field_trial_mem, Crop *current_crop_p, Crop *previous_crop_p, const char *description_s,
321  const char *design_s, const char *growing_conditions_s, const char *phenotype_gathering_notes_s,
322  const uint32 *num_rows_p, const uint32 *num_cols_p, const uint32 *num_replicates_p, const double64 *plot_width_p, const double64 *plot_length_p,
323  const char *weather_s, const json_t *shape_p, const double64 *plot_horizontal_gap_p, const double64 *plot_vertical_gap_p,
324  const uint32 *plot_rows_per_block_p, const uint32 *plot_columns_per_block_p, const double64 *plot_block_horizontal_gap_p,
325  const double64 *plot_block_vertical_gap_p,
326  Person *curator_p, Person *contact_p,
327  const uint32 *sowing_year_p, const uint32 *harvest_year_p,
328  const char *plan_changes_s, const char *physical_samples_collected_s, const char *data_not_included_s,
329  const char *photo_url_s, const char *image_collection_notes_s,
330  const char *gps_notes_s,
331  const FieldTrialServiceData *data_p);
332 
333 
335 
337 
339 
340 DFW_FIELD_TRIAL_SERVICE_LOCAL json_t *GetStudyAsJSON (Study *study_p, const ViewFormat format, JSONProcessor *processor_p, FieldTrialServiceData *data_p);
341 
342 DFW_FIELD_TRIAL_SERVICE_LOCAL Study *GetStudyFromJSON (const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p);
343 
344 DFW_FIELD_TRIAL_SERVICE_LOCAL Study *GetStudyWithParentTrialFromJSON (const json_t *json_p, FieldTrial *parent_trial_p, const ViewFormat format, const FieldTrialServiceData *data_p);
345 
347 
348 DFW_FIELD_TRIAL_SERVICE_LOCAL OperationStatus SaveStudy (Study *study_p, ServiceJob *job_p, FieldTrialServiceData *data_p, const char *url_key_s);
349 
350 DFW_FIELD_TRIAL_SERVICE_LOCAL Study *GetStudyByIdString (const char *study_id_s, const ViewFormat format, const FieldTrialServiceData *data_p);
351 
352 DFW_FIELD_TRIAL_SERVICE_LOCAL Study *GetStudyById (bson_oid_t *st_id_p, const ViewFormat format, const FieldTrialServiceData *data_p);
353 
355 
356 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AddPhenotypesToJSON (const Study *study_p, json_t *study_json_p, const ViewFormat format, const FieldTrialServiceData *data_p);
357 
358 
359 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AddPlotToStudy (Study *study_p, struct Plot *plot_p);
360 
361 
363 
364 DFW_FIELD_TRIAL_SERVICE_LOCAL OperationStatus IndexStudy (Study *study_p, ServiceJob *job_p, const char *job_name_s, FieldTrialServiceData *data_p);
365 
366 
368 
369 
370 DFW_FIELD_TRIAL_SERVICE_LOCAL bool IsMeasuredVariableOnStudy (const Study * const study_p, const char *mv_s);
371 
372 
373 DFW_FIELD_TRIAL_SERVICE_LOCAL bool AddPhenotypeStatisticsToStudy (Study * const study_p, const char *mv_s, const Statistics *stats_p);
374 
375 #ifdef __cplusplus
376 }
377 #endif
378 
379 
380 #endif /* SERVICES_FIELD_TRIALS_INCLUDE_STUDY_H_ */
Plot
Definition: plot.h:84
Study::st_num_columns_p
uint32 * st_num_columns_p
Definition: study.h:242
Study::st_plots_rows_per_block_p
uint32 * st_plots_rows_per_block_p
Definition: study.h:263
Study::st_plots_columns_per_block_p
uint32 * st_plots_columns_per_block_p
Definition: study.h:265
Statistics
Definition: statistics.h:21
Study::st_phenotype_gathering_notes_s
char * st_phenotype_gathering_notes_s
Definition: study.h:234
MEM_FLAG
MEM_FLAG
An enum specifying the particular status of a piece of dynamically allocated memory for a particular ...
Definition: memory_allocations.h:38
Study::st_contributors_p
LinkedList * st_contributors_p
A LinkedList of PersonNodes of people who have contributed to this Study.
Definition: study.h:291
Study::st_photo_url_s
char * st_photo_url_s
Definition: study.h:281
Crop
Definition: crop.h:34
ServiceJob
A datatype to represent a running task.
Definition: service_job.h:72
Study::st_predicted_sowing_year_p
uint32 * st_predicted_sowing_year_p
Definition: study.h:277
Study::st_treatments_p
LinkedList * st_treatments_p
Definition: study.h:271
Study::st_default_plot_length_p
double64 * st_default_plot_length_p
Definition: study.h:238
Study::st_curator_p
Person * st_curator_p
Definition: study.h:273
SaveStudy
OperationStatus SaveStudy(Study *study_p, ServiceJob *job_p, FieldTrialServiceData *data_p, const char *url_key_s)
JSONProcessor
Definition: json_processor.h:21
IndexStudy
OperationStatus IndexStudy(Study *study_p, ServiceJob *job_p, const char *job_name_s, FieldTrialServiceData *data_p)
StudyNode
Definition: study.h:297
FreeStudy
void FreeStudy(Study *study_p)
Study::st_description_s
char * st_description_s
Definition: study.h:213
Study::st_design_s
char * st_design_s
Definition: study.h:215
STUDY_VAL
const STUDY_PREFIX char *ST_LOCATION_ID_S STUDY_VAL("address_id")
statistics.h
Study::st_slope_s
char * st_slope_s
Definition: study.h:200
Study::st_shape_p
json_t * st_shape_p
The GeoJSON data for the shape of the plots.
Definition: study.h:251
Study::st_data_not_included_s
char * st_data_not_included_s
Data collected but not currently stored within Grassroots.
Definition: study.h:230
dfw_field_trial_service_library.h
Study::st_default_plot_width_p
double64 * st_default_plot_width_p
Definition: study.h:236
StudyNode::stn_study_p
Study * stn_study_p
Definition: study.h:301
GetStudyByIdString
Study * GetStudyByIdString(const char *study_id_s, const ViewFormat format, const FieldTrialServiceData *data_p)
Study::st_previous_crop_p
Crop * st_previous_crop_p
Definition: study.h:211
AddStudyContributor
bool AddStudyContributor(Study *study_p, Person *person_p, MEM_FLAG mf)
Study::st_plot_horizontal_gap_p
double64 * st_plot_horizontal_gap_p
Definition: study.h:258
Study::st_timestamp_s
char * st_timestamp_s
Definition: study.h:186
address.h
DFW_FIELD_TRIAL_SERVICE_LOCAL
#define DFW_FIELD_TRIAL_SERVICE_LOCAL
Definition: dfw_field_trial_service_library.h:43
CONTEXT_PREFIX_SCHEMA_ORG_S
#define CONTEXT_PREFIX_SCHEMA_ORG_S
Definition: schema_keys.h:103
Study::st_plot_block_horizontal_gap_p
double64 * st_plot_block_horizontal_gap_p
Definition: study.h:267
FieldTrial
A datatype that represents a Field Trial that can contain one or more Studies.
Definition: field_trial.h:50
StudyNode::stn_node
ListItem stn_node
Definition: study.h:299
Study::st_num_rows_p
uint32 * st_num_rows_p
Definition: study.h:240
typedefs.h
Study::st_growing_conditions_s
char * st_growing_conditions_s
Definition: study.h:232
CONTEXT_PREFIX_ENVIRONMENT_ONTOLOGY_S
#define CONTEXT_PREFIX_ENVIRONMENT_ONTOLOGY_S
Definition: schema_keys.h:118
field_trial.h
GetStudyAsJSON
json_t * GetStudyAsJSON(Study *study_p, const ViewFormat format, JSONProcessor *processor_p, FieldTrialServiceData *data_p)
Study::st_aspect_s
char * st_aspect_s
Definition: study.h:198
Study::st_image_collection_notes_s
char * st_image_collection_notes_s
Definition: study.h:283
Study::st_contact_p
Person * st_contact_p
Definition: study.h:275
LinkedList
A doubly-linked list that can be traversed in either direction.
Definition: linked_list.h:56
GetStudyFromJSON
Study * GetStudyFromJSON(const json_t *json_p, const ViewFormat format, const FieldTrialServiceData *data_p)
Study::st_data_url_s
char * st_data_url_s
Definition: study.h:196
key_value_pair.h
OperationStatus
OperationStatus
The current status of an Operation.
Definition: operation.h:96
CONTEXT_PREFIX_NCI_THESAUSUS_ONTOLOGY_S
#define CONTEXT_PREFIX_NCI_THESAUSUS_ONTOLOGY_S
Definition: schema_keys.h:124
FreeStudyNode
void FreeStudyNode(ListItem *node_p)
GetStudyById
Study * GetStudyById(bson_oid_t *st_id_p, const ViewFormat format, const FieldTrialServiceData *data_p)
GetStudyWithParentTrialFromJSON
Study * GetStudyWithParentTrialFromJSON(const json_t *json_p, FieldTrial *parent_trial_p, const ViewFormat format, const FieldTrialServiceData *data_p)
location.h
Study::st_id_p
bson_oid_t * st_id_p
Definition: study.h:184
Person
Definition: person.h:51
AllocateStudyNode
StudyNode * AllocateStudyNode(Study *study_p)
Study::st_predicted_harvest_year_p
uint32 * st_predicted_harvest_year_p
Definition: study.h:279
dfw_field_trial_service_data.h
AddPlotToStudy
bool AddPlotToStudy(Study *study_p, struct Plot *plot_p)
AddPhenotypesToJSON
bool AddPhenotypesToJSON(const Study *study_p, json_t *study_json_p, const ViewFormat format, const FieldTrialServiceData *data_p)
Study::st_num_replicates_p
uint32 * st_num_replicates_p
Definition: study.h:244
Study::st_location_p
struct Location * st_location_p
Definition: study.h:192
Study::st_weather_link_s
char * st_weather_link_s
Definition: study.h:246
Study::st_plots_p
LinkedList * st_plots_p
A LinkedList of PlotNodes for all of the Plots in this Study.
Definition: study.h:207
Study::st_name_s
char * st_name_s
Definition: study.h:194
Study::st_physical_samples_collected_s
char * st_physical_samples_collected_s
Details about plant, soil or other samples collected.
Definition: study.h:225
crop.h
Study::st_phenotypes_p
LinkedList * st_phenotypes_p
Definition: study.h:285
Study::st_shape_notes_s
char * st_shape_notes_s
Any notes about the GeoJSON data.
Definition: study.h:256
Study::st_parent_field_trial_mem
MEM_FLAG st_parent_field_trial_mem
Definition: study.h:190
FieldTrialServiceData
The configuration data used by the DFW Field Trial Service.
Definition: dfw_field_trial_service_data.h:118
Study::st_plot_vertical_gap_p
double64 * st_plot_vertical_gap_p
Definition: study.h:260
ViewFormat
ViewFormat
An indicator of what the output destination is for the JSON data values.
Definition: view_format.h:19
GetNumberOfPlotsInStudy
int64 GetNumberOfPlotsInStudy(const Study *study_p, const FieldTrialServiceData *data_p)
json_processor.h
Study::st_parent_p
FieldTrial * st_parent_p
Definition: study.h:188
AllocateStudy
Study * AllocateStudy(bson_oid_t *id_p, const char *name_s, const char *data_url_s, const char *aspect_s, const char *slope_s, struct Location *location_p, FieldTrial *parent_field_trial_p, MEM_FLAG parent_field_trial_mem, Crop *current_crop_p, Crop *previous_crop_p, const char *description_s, const char *design_s, const char *growing_conditions_s, const char *phenotype_gathering_notes_s, const uint32 *num_rows_p, const uint32 *num_cols_p, const uint32 *num_replicates_p, const double64 *plot_width_p, const double64 *plot_length_p, const char *weather_s, const json_t *shape_p, const double64 *plot_horizontal_gap_p, const double64 *plot_vertical_gap_p, const uint32 *plot_rows_per_block_p, const uint32 *plot_columns_per_block_p, const double64 *plot_block_horizontal_gap_p, const double64 *plot_block_vertical_gap_p, Person *curator_p, Person *contact_p, const uint32 *sowing_year_p, const uint32 *harvest_year_p, const char *plan_changes_s, const char *physical_samples_collected_s, const char *data_not_included_s, const char *photo_url_s, const char *image_collection_notes_s, const char *gps_notes_s, const FieldTrialServiceData *data_p)
HasStudyGotPlotLayoutDetails
bool HasStudyGotPlotLayoutDetails(const Study *study_p)
Study::st_plan_changes_s
char * st_plan_changes_s
Changes to the Study field experiment plan.
Definition: study.h:220
STUDY_CONCAT_VAL
const STUDY_PREFIX char *ST_NAME_S STUDY_CONCAT_VAL(CONTEXT_PREFIX_SCHEMA_ORG_S, "name")
Location
Definition: location.h:45
Study
Definition: study.h:182
IsMeasuredVariableOnStudy
bool IsMeasuredVariableOnStudy(const Study *const study_p, const char *mv_s)
person.h
Study::st_current_crop_p
Crop * st_current_crop_p
Definition: study.h:209
Study::st_plot_block_vertical_gap_p
double64 * st_plot_block_vertical_gap_p
Definition: study.h:269
GetStudyPlots
bool GetStudyPlots(Study *study_p, const ViewFormat format, FieldTrialServiceData *data_p)
AddPhenotypeStatisticsToStudy
bool AddPhenotypeStatisticsToStudy(Study *const study_p, const char *mv_s, const Statistics *stats_p)
ListItem
A doubly-linked node that points to its predecessor and successor.
Definition: linked_list.h:43