Skip to content

Commit

Permalink
Merge pull request #2069 from bcgov/gwells-2007-attachments-search
Browse files Browse the repository at this point in the history
[GWELLS-2007] FEATURE** Search wells that contain [document type]
  • Loading branch information
LocalNewsTV authored Nov 28, 2023
2 parents 5bc4b28 + 3a2552e commit b918c1e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 9 deletions.
12 changes: 11 additions & 1 deletion app/backend/wells/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
WellOrientationCode,
WaterQualityCharacteristic,
Well,
WellAttachment,
PumpingTestDescriptionCode,
BoundaryEffectCode,
AnalysisMethodCode
Expand Down Expand Up @@ -215,7 +216,9 @@ class WellListFilter(AnyOrAllFilterSet):
filter_pack_range = filters.RangeFilter(method='filter_filter_pack_range',
label='Filter pack from/to range')
liner_range = filters.RangeFilter(method='filter_liner_range', label='Liner range')

well_document_type = filters.CharFilter(method='filter_by_document_type',
label='Contains document type')

# Don't require a choice (i.e. select box) for aquifer
aquifer = filters.NumberFilter()

Expand Down Expand Up @@ -462,6 +465,7 @@ class Meta:
'well_class',
'well_depth',
'well_disinfected_status',
'well_document_type',
'well_identification_plate_attached',
'well_location_description',
'well_orientation_status',
Expand Down Expand Up @@ -505,6 +509,12 @@ def filter_street_address_or_city(self, queryset, name, value):
return queryset.filter(Q(street_address__icontains=value) |
Q(city__icontains=value))

def filter_by_document_type(self, queryset, name, value):
filter_condition = {f"{value.lower().replace(' ', '_')}__gt": 0}
attachments = WellAttachment.objects.filter(**filter_condition).values_list('well_tag_number', flat=True)
attachments = list(map(int, attachments))
return queryset.filter(well_tag_number__in=attachments)

def filter_combined_legal(self, queryset, name, value):
lookups = (
Q(legal_lot__iexact=value) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def process_well_tag(self, well_tag_number):
split_file = doc["name"].split("_")
if len(split_file) <= 3:
value = split_file[1].replace(" ", "_").lower()
if "." in value:
value = value.split(".")[0]
else:
value = split_file[1].lower() + "_" + split_file[2].lower()
hash_map[value] = (hash_map[value] or 0) + 1
Expand All @@ -109,7 +111,7 @@ def process_well_tag(self, well_tag_number):
try:
well_attachment_entry = self.get_or_create_entry(well_tag_number)
for key, value in hash_map.items():
if key == "well_record":
if "well_record" in key:
setattr(well_attachment_entry, 'well_construction', value)
elif key in self.formatted_well_tags:
setattr(well_attachment_entry, key, value)
Expand Down
4 changes: 2 additions & 2 deletions app/backend/wells/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2630,9 +2630,9 @@ def __str__(self):
return_string += template.format('Well Decommission',self.well_decommission)
return_string += template.format('Well Photos',self.photo)
return_string += template.format('Well Pump Installations',self.well_pump_installation)
return_string += template.format('Pumping Test',self.pumping_test)
return_string += template.format('Pumping Test',self.pumping_test_data)
return_string += template.format('Map',self.map)
return_string += template.format('Additional Detail',self.additional_well_details)
return_string += template.format('Additional Detail',self.additional_details)
return_string += template.format('Well Inspections',self.well_inspection)
return_string += template.format('Alternative Specs',self.alternative_specs)
return_string += template.format('Water Quality',self.water_quality)
Expand Down
2 changes: 1 addition & 1 deletion app/backend/wells/views_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
GeometryFilterBackend,
RadiusFilterBackend
)
from wells.models import Well
from wells.models import Well, WellAttachment
from wells.serializers_v2 import (
WellLocationSerializerV2,
WellVerticalAquiferExtentSerializerV2,
Expand Down
8 changes: 6 additions & 2 deletions app/frontend/src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export const WELL_TAGS_PUBLIC = [
{ text: "Well Decommission Report", value: "Well Decommission" },
{ text: "Well Pump Installation Report", value: "Well Pump Installation" },
{ text: "Other", value: "Additional Details" },
]
].sort((a,b) => {
if(a.text === 'Other') return 1;
if(b.text === 'Other') return -1;
return a.text.toLowerCase().localeCompare(b.text.toLowerCase())
})

export const WELL_TAGS_PRIVATE = [
{ text: "Alternative Specifications", value: "Alternative Specs" },
Expand All @@ -26,7 +30,7 @@ export const WELL_TAGS_PRIVATE = [
{ text: "Signed Sharing Agreement", value: "Sharing Agreement" },
{ text: "Water Quality Report", value: "Water Quality" },
{ text: "Well Inspection Report", value: "Well Inspection" },
]
].sort((a,b) => a.text.toLowerCase().localeCompare(b.text.toLowerCase()))

export const WELL_TAGS = [
{
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/wells/components/AdvancedSearchForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export default {
defaultFilterSections: [
{ header: 'Search By', fields: ['matchAny', 'well', 'streetOrCity', 'ownerName', 'publicationStatus'] },
{ header: 'Location', fields: ['legal', 'landDistrict'] },
{ header: 'Well Details', fields: ['wellStatus', 'licencedStatus', 'personResponsibleGuid', 'orgResponsibleGuid', 'dateOfWork', 'wellDepth'] },
{ header: 'Well Details', fields: ['wellStatus', 'licencedStatus', 'personResponsibleGuid', 'orgResponsibleGuid', 'dateOfWork', 'wellDepth', 'wellDocumentType'] },
{ header: 'Aquifer', fields: ['aquiferNr'] }
],
additionalFilterSections: ADDITIONAL_FILTER_SECTIONS
Expand Down
12 changes: 11 additions & 1 deletion app/frontend/src/wells/components/mixins/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
/* Shared logic for handling search filters. */
import { mapGetters } from 'vuex'

import { WELL_TAGS_PRIVATE, WELL_TAGS_PUBLIC, } from '../../../common/constants'
const SEARCH_FIELDS = {
matchAny: {
param: 'match_any',
Expand All @@ -24,6 +24,16 @@ const SEARCH_FIELDS = {
]
},
well: { param: 'well', label: 'Well tag or ID plate number', type: 'text' },
wellDocumentType: {
param: "well_document_type",
label: "Contains document type",
type: "select",
options: [...WELL_TAGS_PUBLIC, ...WELL_TAGS_PRIVATE].sort((a,b) => {
if(a.text === 'Other') return 1;
if(b.text === 'Other') return -1;
return a.text.toLowerCase().localeCompare(b.text.toLowerCase())
})
},
streetOrCity: {
param: 'street_address_or_city',
label: 'Street address or city',
Expand Down

0 comments on commit b918c1e

Please sign in to comment.