From 0edfd6a5531d7d1c3a6b581d9d489f9af2a78642 Mon Sep 17 00:00:00 2001 From: David Randolph Phillips Date: Thu, 11 May 2023 13:53:02 -0400 Subject: [PATCH 01/11] [BI-1717] WIP --- src/breeding-insight/dao/ExperimentDAO.ts | 45 +++++ src/breeding-insight/model/Experiment.ts | 52 +++++ src/breeding-insight/model/Trial.ts | 8 +- .../service/ExperimentService.ts | 41 ++++ src/breeding-insight/utils/ExperimentUtils.ts | 63 ++++++ .../ExperimentsObservationsTable.vue | 4 + src/components/trait/TraitDetailPanel.vue | 2 +- src/router/index.ts | 13 +- .../ExperimentDetails.vue | 188 ++++++++++++++++++ 9 files changed, 412 insertions(+), 4 deletions(-) create mode 100644 src/breeding-insight/dao/ExperimentDAO.ts create mode 100644 src/breeding-insight/model/Experiment.ts create mode 100644 src/breeding-insight/service/ExperimentService.ts create mode 100644 src/breeding-insight/utils/ExperimentUtils.ts create mode 100644 src/views/experiments-and-observations/ExperimentDetails.vue diff --git a/src/breeding-insight/dao/ExperimentDAO.ts b/src/breeding-insight/dao/ExperimentDAO.ts new file mode 100644 index 000000000..98f61aae6 --- /dev/null +++ b/src/breeding-insight/dao/ExperimentDAO.ts @@ -0,0 +1,45 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {BiResponse, Response} from "@/breeding-insight/model/BiResponse"; +import * as api from "@/util/api"; +import {PaginationQuery} from "@/breeding-insight/model/PaginationQuery"; +import {Result, ResultGenerator} from "@/breeding-insight/model/Result"; +import {Germplasm} from "@/breeding-insight/brapi/model/germplasm"; + +export class ExperimentDAO { + + static async getSingleExperiment(programId: string, experimentId: string): Promise> { + experimentId = '26b98605-b7dc-40aa-a8b9-2e3dc6664a7f' + const config: any = {}; + config.url = `${process.env.VUE_APP_BI_API_V1_PATH}/programs/${programId}/brapi/v2/trials/${experimentId}`; + config.method = 'get'; + config.programId = programId; + config.experimentId = experimentId; + // TODO set boolean param for stats + config.params = {}; +console.log(config.url); + try { + const res = await api.call(config) as Response; + let { result } = res.data; + console.log(result); + return ResultGenerator.success(result); + } catch (error) { + return ResultGenerator.err(error); + } + } +} diff --git a/src/breeding-insight/model/Experiment.ts b/src/breeding-insight/model/Experiment.ts new file mode 100644 index 000000000..0fbfd1c5c --- /dev/null +++ b/src/breeding-insight/model/Experiment.ts @@ -0,0 +1,52 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { ExternalReferences } from '@/breeding-insight/brapi/model/externalReferences'; + +export class Experiment { + id?: string; + trialName?: string; + trialDescription?: string; + active?: boolean; + externalReferences?: ExternalReferences; + + constructor(id?: string, + trialName?: string, + active?: boolean, + externalReferences?: ExternalReferences, + trialDescription?: string) { + this.id = id; + this.trialName = trialName; + this.trialDescription = trialDescription; + if (active !== undefined) { + this.active = active; + } else { + this.active = true; + } + this.externalReferences = externalReferences; + } + + static assign(trial: Trial): Trial { + return new Trial(trial.id, trial.trialName, trial.active, trial.externalReferences); + } + + equals(trial?: Trial): boolean { + if (!trial) {return false;} + return (this.id === trial.id) && + (this.trialName === trial.trialName) + } +} diff --git a/src/breeding-insight/model/Trial.ts b/src/breeding-insight/model/Trial.ts index 85876363e..635683c43 100644 --- a/src/breeding-insight/model/Trial.ts +++ b/src/breeding-insight/model/Trial.ts @@ -20,15 +20,19 @@ import { ExternalReferences } from '@/breeding-insight/brapi/model/externalRefer export class Trial { id?: string; trialName?: string; + trialDescription?: string; active?: boolean; externalReferences?: ExternalReferences; constructor(id?: string, trialName?: string, active?: boolean, - externalReferences?: ExternalReferences) { + externalReferences?: ExternalReferences, + trialDescription?: string + ) { this.id = id; this.trialName = trialName; + this.trialDescription = trialDescription; if (active !== undefined) { this.active = active; } else { @@ -38,7 +42,7 @@ export class Trial { } static assign(trial: Trial): Trial { - return new Trial(trial.id, trial.trialName, trial.active, trial.externalReferences); + return new Trial(trial.id, trial.trialName, trial.active, trial.externalReferences, trial.trialDescription); } equals(trial?: Trial): boolean { diff --git a/src/breeding-insight/service/ExperimentService.ts b/src/breeding-insight/service/ExperimentService.ts new file mode 100644 index 000000000..aa380389f --- /dev/null +++ b/src/breeding-insight/service/ExperimentService.ts @@ -0,0 +1,41 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {GermplasmList} from "@/breeding-insight/model/GermplasmList"; +import {BiResponse, Metadata} from "@/breeding-insight/model/BiResponse"; +import {PaginationQuery} from "@/breeding-insight/model/PaginationQuery"; +import {PaginationUtilities} from "@/breeding-insight/model/view_models/PaginationUtilities"; +import {ExperimentDAO} from "@/breeding-insight/dao/ExperimentDAO"; +import {Germplasm} from "@/breeding-insight/brapi/model/germplasm"; +import {Result, ResultGenerator} from "@/breeding-insight/model/Result"; +import {SortOrder} from "@/breeding-insight/model/Sort"; +import * as api from "@/util/api"; +import {GermplasmFilter} from "@/breeding-insight/model/GermplasmFilter"; + +export class ExperimentService { + + static async getSingleExperiment(programId: string, experimentId: string): Promise> { + try { + if (!programId) throw new Error('Missing or invalid program id'); + let response: Result = await ExperimentDAO.getSingleExperiment(programId, experimentId); + return response; + } catch(error) { + return ResultGenerator.err(error); + } + } + +} diff --git a/src/breeding-insight/utils/ExperimentUtils.ts b/src/breeding-insight/utils/ExperimentUtils.ts new file mode 100644 index 000000000..d15895648 --- /dev/null +++ b/src/breeding-insight/utils/ExperimentUtils.ts @@ -0,0 +1,63 @@ +/* + * See the NOTICE file distributed with this work for additional information + * regarding copyright ownership. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import moment from "moment"; +import {Germplasm} from "@/breeding-insight/brapi/model/germplasm"; +import {ExternalReferences} from "@/breeding-insight/brapi/model/externalReferences"; +import {GermplasmService} from "@/breeding-insight/service/GermplasmService"; +import {MOMENT_BRAPI_DATE_FORMAT} from "@/breeding-insight/utils/BrAPIDateTime"; + +// The moment.js interpretable format for Date values sent and received via the BI API. +export const MOMENT_DATE_PERSISTED_FORMAT = 'DD/MM/YYYY h:mm:ss'; + +export class ExperimentUtils { + static getExternalUID(germplasm: Germplasm): string | undefined { + let val; + if (germplasm.externalReferences && germplasm.seedSource) { + val = germplasm.externalReferences!.filter(ref => ref.referenceSource == germplasm.seedSource!) + .map(ref => ref.referenceID); + return val ? val[0]: ""; + } + return ""; + } + + static getCreatedDate(germplasm: Germplasm): string | undefined { + if (germplasm.additionalInfo && germplasm.additionalInfo.createdDate) { + let dateTime = moment(germplasm.additionalInfo!.createdDate!, MOMENT_DATE_PERSISTED_FORMAT); + return dateTime.format(MOMENT_BRAPI_DATE_FORMAT); + } + return ""; + } + + static getBreedingInsightId(references: ExternalReferences, referenceSourcePath: string = ""): string | undefined { + let val = references.find(ref => ref.referenceSource === process.env.VUE_APP_BI_REFERENCE_SOURCE + referenceSourcePath); + return val ? val.referenceID : ""; + } + + static formatSynonyms(synonyms: any[]): string { + if (!synonyms) return ""; + return synonyms.map(synonym => synonym.synonym).join("; "); + } + + static getEntryNumber(germplasm: Germplasm, referenceId: string | undefined): string | undefined { + if (germplasm.additionalInfo) { + return referenceId ? germplasm.additionalInfo.listEntryNumbers[referenceId] : + germplasm.additionalInfo.importEntryMumber; + } + return ""; + } +} \ No newline at end of file diff --git a/src/components/experiments/ExperimentsObservationsTable.vue b/src/components/experiments/ExperimentsObservationsTable.vue index cf5f01ad8..4a34274fd 100644 --- a/src/components/experiments/ExperimentsObservationsTable.vue +++ b/src/components/experiments/ExperimentsObservationsTable.vue @@ -57,6 +57,10 @@ > Download + + + Show Details +