Skip to content

Commit

Permalink
add batch aquatic chemical and mechanical treatment templates
Browse files Browse the repository at this point in the history
  • Loading branch information
brennanwebster authored and micheal-w-wells committed Dec 21, 2023
1 parent f9a0eb8 commit dd3499b
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 45 deletions.
8 changes: 3 additions & 5 deletions api/src/utils/batch/execution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ interface _MappedForDB {
shortId: string;
payload: object;
geog: any;

}

export function _mapToDBObject(row, status, type, subtype, userInfo): _MappedForDB {
Expand All @@ -44,7 +43,7 @@ export function _mapToDBObject(row, status, type, subtype, userInfo): _MappedFor
mapped.form_data.activity_data.invasive_species_agency_code = mapped.form_data.activity_data.invasive_species_agency_code.join();
}

if (['Activity_Treatment_ChemicalPlantTerrestrial'].includes(subtype)) {
if (['Activity_Treatment_ChemicalPlantTerrestrial', 'Activity_Treatment_ChemicalPlantAquatic'].includes(subtype)) {
const chemicalMethodSprayCodes = row.data[
'Chemical Treatment (If Tank Mix) - Application Method'
]?.templateColumn.codes.map((codeObj) => {
Expand All @@ -66,8 +65,8 @@ export function _mapToDBObject(row, status, type, subtype, userInfo): _MappedFor

const geog = mapped.geog;
delete mapped.geog;
mapped.short_id = shortId
mapped.activity_id = uuidToCreate
mapped.short_id = shortId;
mapped.activity_id = uuidToCreate;

return {
id: uuidToCreate,
Expand Down Expand Up @@ -186,7 +185,6 @@ export const BatchExecutionService = {
}
await dbConnection.query('COMMIT;');


await dbConnection.query({
text: `UPDATE batch_uploads
set status = 'SUCCESS'
Expand Down
8 changes: 8 additions & 0 deletions api/src/utils/batch/shared-columns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,14 @@ export const ShorelineInformation = [
.build()
];

export const AuthorizationInformation = [
new TemplateColumnBuilder(
'Authorization Information',
'text',
'form_data.activity_subtype_data.authorization_infotmation.additional_auth_information'
).build()
];

export const ShorelineSumValidator = SummingValidator(
['Shoreline - Shoreline 1 Percentage', 'Shoreline - Shoreline 2 Percentage'],
100,
Expand Down
12 changes: 8 additions & 4 deletions api/src/utils/batch/template-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,28 @@ import { ObservationTerrestrialPlantTemp } from './templates/observation_terrest
import { TreatmentChemicalTerrestrialPlantTemp } from './templates/treatment_chemical_terrestrial_plant_temp';
import { TreatmentMechanicalTerrestrialPlantTemp } from './templates/treatment_mechanical_terrestrial_plant_temp';
import { ObservationAquaticPlantTemp } from './templates/observation_aquatic_plant_temp';
import { TreatmentChemicalAquaticPlantTemp } from './templates/treatment_chemical_aquatic_plant_temp';
import { TreatmentMechanicalAquaticPlantTemp } from './templates/treatment_mechanical_aquatic_plant_temp';

const templateList: Template[] = [
ObservationTerrestrialPlant,
ObservationTerrestrialPlantTemp,
ObservationAquaticPlant,
ObservationAquaticPlantTemp,
BiocontrolCollection,
BiocontrolRelease,
MonitoringBiocontrolDispersalTerrestrialPlant,
MonitoringBiocontrolReleaseTerrestrialPlant,
MonitoringChemical,
MonitoringMechanical,
TreatmentChemicalAquaticPlant,
TreatmentChemicalTerrestrialPlant,
TreatmentChemicalTerrestrialPlantTemp,
TreatmentMechanicalAquaticPlant,
TreatmentChemicalAquaticPlant,
TreatmentChemicalAquaticPlantTemp,
TreatmentMechanicalTerrestrialPlant,
TreatmentMechanicalTerrestrialPlantTemp,
ObservationAquaticPlant,
ObservationAquaticPlantTemp
TreatmentMechanicalAquaticPlant,
TreatmentMechanicalAquaticPlantTemp
];

export const TemplateService = {
Expand Down
28 changes: 19 additions & 9 deletions api/src/utils/batch/templates/treatment_chemical_aquatic_plant.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
import { Template, TemplateColumnBuilder } from '../definitions';
import {
ActivityPersonsWithApplicatorLicense,
ApplicationMethodValidator,
BasicInformation,
BasicInformationRowValidators,
ChemicalPlantTreatmentInformation,
GranularHerbicideRate,
HerbicidesInformation,
PositiveObservationPlantValidator,
ProjectInformation
PmpValidator,
ProjectInformation,
WindDirectionValidator
} from '../shared-columns';
import { ChemTreatmentValidators } from '../validation/chemical-treatment';

const TreatmentChemicalAquaticPlant = new Template(
'treatment_chemical_aquatic_plant',
'Treatment - Chemical - Aquatic Plant',
null
);

TreatmentChemicalAquaticPlant.type = 'Treatment';
TreatmentChemicalAquaticPlant.subtype = 'Activity_Treatment_ChemicalPlantAquatic';

TreatmentChemicalAquaticPlant.columns = [
...BasicInformation,
...ProjectInformation,
Expand Down Expand Up @@ -46,9 +53,7 @@ TreatmentChemicalAquaticPlant.columns = [
'Chemical Treatment - Invasive Species 2 %',
'numeric',
'form_data.activity_subtype_data.chemical_treatment_details.invasive_plants[1].percent_area_covered'
)
.isRequired()
.build(),
).build(),
new TemplateColumnBuilder(
'Chemical Treatment - Invasive Species 3',
'codeReference',
Expand All @@ -60,10 +65,15 @@ TreatmentChemicalAquaticPlant.columns = [
'Chemical Treatment - Invasive Species 3 %',
'numeric',
'form_data.activity_subtype_data.chemical_treatment_details.invasive_plants[2].percent_area_covered'
)
.isRequired()
.build(),
).build(),
...HerbicidesInformation
];
TreatmentChemicalAquaticPlant.rowValidators = [...BasicInformationRowValidators, PositiveObservationPlantValidator];
TreatmentChemicalAquaticPlant.rowValidators = [
...BasicInformationRowValidators,
...ChemTreatmentValidators,
PmpValidator,
WindDirectionValidator,
ApplicationMethodValidator,
GranularHerbicideRate
];
export { TreatmentChemicalAquaticPlant };
Original file line number Diff line number Diff line change
@@ -1,25 +1,33 @@
import { Template, TemplateColumnBuilder } from '../definitions';
import {
ActivityPersonsWithApplicatorLicense,
ApplicationMethodValidator,
BasicInformation,
BasicInformationRowValidators,
ChemicalPlantTreatmentInformation,
GranularHerbicideRate,
HerbicidesInformation,
PositiveObservationPlantValidator,
ProjectInformation
PmpValidator,
ProjectInformation,
WindDirectionValidator
} from '../shared-columns';
import { ChemTreatmentValidators } from '../validation/chemical-treatment';

const TreatmentChemicalAquaticPlant = new Template(
'treatment_chemical_aquatic_plant',
'Treatment - Chemical - Aquatic Plant',
const TreatmentChemicalAquaticPlantTemp = new Template(
'treatment_chemical_aquatic_plant_temp',
'Treatment - Chemical - Aquatic Plant TEMP POINT',
null
);

TreatmentChemicalAquaticPlant.columns = [
TreatmentChemicalAquaticPlantTemp.type = 'Treatment';
TreatmentChemicalAquaticPlantTemp.subtype = 'Activity_Treatment_ChemicalPlantAquatic';

TreatmentChemicalAquaticPlantTemp.columns = [
...BasicInformation,
...ProjectInformation,
...ActivityPersonsWithApplicatorLicense,
...ChemicalPlantTreatmentInformation,
new TemplateColumnBuilder('Area', 'numeric').isRequired().build(),
new TemplateColumnBuilder(
'Chemical Treatment - Invasive Species 1',
'codeReference',
Expand All @@ -46,9 +54,7 @@ TreatmentChemicalAquaticPlant.columns = [
'Chemical Treatment - Invasive Species 2 %',
'numeric',
'form_data.activity_subtype_data.chemical_treatment_details.invasive_plants[1].percent_area_covered'
)
.isRequired()
.build(),
).build(),
new TemplateColumnBuilder(
'Chemical Treatment - Invasive Species 3',
'codeReference',
Expand All @@ -60,10 +66,15 @@ TreatmentChemicalAquaticPlant.columns = [
'Chemical Treatment - Invasive Species 3 %',
'numeric',
'form_data.activity_subtype_data.chemical_treatment_details.invasive_plants[2].percent_area_covered'
)
.isRequired()
.build(),
).build(),
...HerbicidesInformation
];
TreatmentChemicalAquaticPlant.rowValidators = [...BasicInformationRowValidators, PositiveObservationPlantValidator];
export { TreatmentChemicalAquaticPlant };
TreatmentChemicalAquaticPlantTemp.rowValidators = [
...BasicInformationRowValidators,
...ChemTreatmentValidators,
PmpValidator,
WindDirectionValidator,
ApplicationMethodValidator,
GranularHerbicideRate
];
export { TreatmentChemicalAquaticPlantTemp };
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Template, TemplateColumnBuilder } from '../definitions';
import { DISPOSED_MATERIAL_FORMAT_CODES } from '../hard-coded-codes';
import {
ActivityPersons,
AuthorizationInformation,
BasicInformation,
BasicInformationRowValidators,
ProjectInformation,
Expand All @@ -15,12 +16,15 @@ const TreatmentMechanicalAquaticPlant = new Template(
null
);

TreatmentMechanicalAquaticPlant.type = 'Treatment';
TreatmentMechanicalAquaticPlant.subtype = 'Activity_Treatment_MechanicalPlantAquatic';

TreatmentMechanicalAquaticPlant.columns = [
...BasicInformation,
...ProjectInformation,
...ActivityPersons,
...AuthorizationInformation,
...ShorelineInformation,
new TemplateColumnBuilder('Treatment - Authorization Information', 'text').build(),
new TemplateColumnBuilder(
'Treatment - Treated Area',
'numeric',
Expand All @@ -30,7 +34,7 @@ TreatmentMechanicalAquaticPlant.columns = [
.isRequired()
.build(),
new TemplateColumnBuilder(
'Treatment - Disposal Code',
'Treatment - Disposal Method Code',
'codeReference',
'form_data.activity_subtype_data.Treatment_MechanicalPlant_Information[0].mechanical_disposal_code'
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,30 @@ import { Template, TemplateColumnBuilder } from '../definitions';
import { DISPOSED_MATERIAL_FORMAT_CODES } from '../hard-coded-codes';
import {
ActivityPersons,
AuthorizationInformation,
BasicInformation,
BasicInformationRowValidators,
ProjectInformation,
ShorelineInformation,
ShorelineSumValidator
} from '../shared-columns';

const TreatmentMechanicalAquaticPlant = new Template(
'treatment_mechanical_aquatic_plant',
'Treatment - Mechanical - Aquatic Plant',
const TreatmentMechanicalAquaticPlantTemp = new Template(
'treatment_mechanical_aquatic_plant_temp',
'Treatment - Mechanical - Aquatic Plant TEMP POINT',
null
);

TreatmentMechanicalAquaticPlant.columns = [
TreatmentMechanicalAquaticPlantTemp.type = 'Treatment';
TreatmentMechanicalAquaticPlantTemp.subtype = 'Activity_Treatment_MechanicalPlantAquatic';

TreatmentMechanicalAquaticPlantTemp.columns = [
...BasicInformation,
...ProjectInformation,
...ActivityPersons,
...AuthorizationInformation,
...ShorelineInformation,
new TemplateColumnBuilder('Treatment - Authorization Information', 'text').build(),
new TemplateColumnBuilder('Area', 'numeric').isRequired().build(),
new TemplateColumnBuilder(
'Treatment - Treated Area',
'numeric',
Expand All @@ -30,7 +35,7 @@ TreatmentMechanicalAquaticPlant.columns = [
.isRequired()
.build(),
new TemplateColumnBuilder(
'Treatment - Disposal Code',
'Treatment - Disposal Method Code',
'codeReference',
'form_data.activity_subtype_data.Treatment_MechanicalPlant_Information[0].mechanical_disposal_code'
)
Expand Down Expand Up @@ -69,6 +74,6 @@ TreatmentMechanicalAquaticPlant.columns = [
.build()
];

TreatmentMechanicalAquaticPlant.rowValidators = [...BasicInformationRowValidators, ShorelineSumValidator];
TreatmentMechanicalAquaticPlantTemp.rowValidators = [...BasicInformationRowValidators, ShorelineSumValidator];

export { TreatmentMechanicalAquaticPlant };
export { TreatmentMechanicalAquaticPlantTemp };
2 changes: 1 addition & 1 deletion app/src/features/home/activity/ActivityPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ const ActivityPage: React.FC<IActivityPageProps> = (props) => {
}
//if geometry is withing british columbia boundries, save it
setTimeout(() => {
if (booleanContains(bcArea.features[0] as any, geometry[0] as any)) {
if (booleanContains(bcArea.features[0] as any, activityInStore.activity.geometry[0] as any)) {
//saveGeometry(geometry);
}
//if geometry is NOT withing british columbia boundries, display err
Expand Down
6 changes: 5 additions & 1 deletion app/src/state/reducers/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ function createBatchReducer() {
'observation_terrestrial_plant_temp',
'treatment_mechanical_terrestrial_plant',
'treatment_mechanical_terrestrial_plant_temp',
'treatment_mechanical_aquatic_plant',
'treatment_mechanical_aquatic_plant_temp',
'treatment_chemical_terrestrial_plant',
'treatment_chemical_terrestrial_plant_temp'
'treatment_chemical_terrestrial_plant_temp',
'treatment_chemical_aquatic_plant',
'treatment_chemical_aquatic_plant_temp'
].includes(template.key)
)
};
Expand Down
6 changes: 5 additions & 1 deletion appv2/src/state/reducers/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,12 @@ function createBatchReducer() {
'observation_terrestrial_plant_temp',
'treatment_mechanical_terrestrial_plant',
'treatment_mechanical_terrestrial_plant_temp',
'treatment_mechanical_aquatic_plant',
'treatment_mechanical_aquatic_plant_temp',
'treatment_chemical_terrestrial_plant',
'treatment_chemical_terrestrial_plant_temp'
'treatment_chemical_terrestrial_plant_temp',
'treatment_chemical_aquatic_plant',
'treatment_chemical_aquatic_plant_temp'
].includes(template.key)
)
};
Expand Down

0 comments on commit dd3499b

Please sign in to comment.