Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GWELLS-2048] BUG FIX** Display Licences in Well Summary #2073

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/backend/wells/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
FilterPackMaterialSizeCode,
FilterPackMaterialCode,
Well,
WellAttachment
WellAttachment,
WellLicence
)
from gwells.models.lithology import (
LithologyColourCode, LithologyHardnessCode,
Expand All @@ -41,3 +42,4 @@
admin.site.register(FilterPackMaterialCode)
admin.site.register(Well)
admin.site.register(WellAttachment)
admin.site.register(WellLicence)
10 changes: 10 additions & 0 deletions app/backend/wells/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2640,3 +2640,13 @@ def __str__(self):
return_string += "{} File count: {}".format('Consultants Report',self.consultants_report)

return return_string

class WellLicence(models.Model):
id = models.IntegerField(primary_key=True)
well_id = models.IntegerField()
waterrightslicence_id = models.IntegerField()
class Meta:
db_table = "well_licences"
managed = False
def __str__(self):
return "Well Number: " + str(self.well_id) + ", License #: " + str(self.waterrightslicence_id)
65 changes: 28 additions & 37 deletions app/backend/wells/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
WellClassCode,
WellYieldUnitCode,
WellStatusCode,
AquiferParameters,
)

from wells.change_history import get_well_history
from wells.renderers import WellListCSVRenderer, WellListExcelRenderer
from wells.serializers import (
Expand Down Expand Up @@ -783,42 +783,33 @@ def lithology_geojson(request, **kwargs):
@api_view(['GET'])
def well_licensing(request, **kwargs):
tag = request.GET.get('well_tag_number')
e_licensing_url = get_env_variable('E_LICENSING_URL')
api_success = False

headers = {
'content_type': 'application/json',
'AuthUsername': get_env_variable('E_LICENSING_AUTH_USERNAME'),
'AuthPass': get_env_variable('E_LICENSING_AUTH_PASSWORD')
}

if e_licensing_url:
try:
response = requests.get(e_licensing_url + '{}'.format(tag), headers=headers)
if response.ok:
try:
licence = response.json()[-1] # Use the latest licensing value, fails purposely if empty array
licence_status = 'Licensed' if licence.get('authorization_status') == 'ACTIVE' else 'Unlicensed'
data = {
'status': licence_status,
'number': licence.get('authorization_number'),
'date': licence.get('authorization_status_date')
}
api_success = True
except:
pass
except:
pass

if not api_success:
well = Well.objects.get(well_tag_number=tag)
data = {
'status': well.licenced_status.description,
'number': '',
'date': ''
}

return HttpResponse(json.dumps(data), content_type="application/json")
try:
if tag and tag.isnumeric():
well = Well.objects.get(well_tag_number=tag)
raw_query = """
SELECT DISTINCT
aw.licence_number
FROM well_licences wl
LEFT JOIN aquifers_waterrightslicence aw
ON aw.wrl_sysid = wl.waterrightslicence_id
WHERE well_id = %s
"""

with connection.cursor() as cursor:
cursor.execute(raw_query, [tag])
result = cursor.fetchall()
flattened_result = [value for row in result for value in row]
data = {
'status': well.licenced_status.description,
'number': flattened_result,
'date': ''
}
return JsonResponse(data)
except Exception:
return HttpResponse(status=500)
return HttpResponse(status=400)




# Deprecated. Use WellSubsurface instead
Expand Down
6 changes: 3 additions & 3 deletions app/frontend/src/wells/views/WellDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ Licensed under the Apache License, Version 2.0 (the "License");
<legend>Licensing Information</legend>
<b-row>
<b-col cols="12" md="4"><span class="font-weight-bold">Licensed Status:</span> {{ wellLicence.status }}</b-col>
<b-col cols="12" md="4"><span class="font-weight-bold">Licence Number:</span>&nbsp;
<a :href="`https://j200.gov.bc.ca/pub/ams/Default.aspx?PossePresentation=AMSPublic&amp;PosseObjectDef=o_ATIS_DocumentSearch&amp;PosseMenuName=WS_Main&Criteria_LicenceNumber=${wellLicence.number}`" target="_blank">
{{ wellLicence.number }}
<b-col cols="12" md="4"><span class="font-weight-bold">Licence Number{{ wellLicence.number.length > 1 ? "s" : "" }}:</span>&nbsp;
<a v-for="(licence, index) in wellLicence.number" :href="`https://j200.gov.bc.ca/pub/ams/Default.aspx?PossePresentation=AMSPublic&amp;PosseObjectDef=o_ATIS_DocumentSearch&amp;PosseMenuName=WS_Main&Criteria_LicenceNumber=${licence}`" target="_blank">
{{ licence}}{{ index + 1 < wellLicence.number.length ? ", " : ""}}
</a>
</b-col>
<b-col cols="12" md="4"></b-col>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,14 +505,6 @@ exports[`WellDetail.vue should match snapshot 1`] = `
</span>


<a
href="https://j200.gov.bc.ca/pub/ams/Default.aspx?PossePresentation=AMSPublic&PosseObjectDef=o_ATIS_DocumentSearch&PosseMenuName=WS_Main&Criteria_LicenceNumber="
target="_blank"
>



</a>
</b-col-stub>

<b-col-stub
Expand Down