Skip to content

Commit

Permalink
Merge pull request #95 from rcpch:eatyourpeas/issue86
Browse files Browse the repository at this point in the history
Eatyourpeas/issue86
  • Loading branch information
eatyourpeas authored Jun 6, 2024
2 parents 19b8dc8 + 38fa6df commit db76873
Show file tree
Hide file tree
Showing 12 changed files with 712 additions and 380 deletions.
28 changes: 26 additions & 2 deletions project/npda/general_functions/retrieve_pdu.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def retrieve_pdus():
"""
Returns all PDUs from the RCPCH NHS Organisations API
Returns all PDUs from the RCPCH NHS Organisations API with member organisations nested under each PDU
"""

url = settings.RCPCH_NHS_ORGANISATIONS_API_URL
Expand All @@ -27,6 +27,30 @@ def retrieve_pdus():
return response.json()


def retrieve_pdu_list():
"""
Returns all PDUs from the RCPCH NHS Organisations API as a list and returns them as a list of choices
"""

url = settings.RCPCH_NHS_ORGANISATIONS_API_URL
request_url = f"{url}/paediatric_diabetes_units/extended"

try:
response = requests.get(
url=request_url,
timeout=10, # times out after 10 seconds
)
response.raise_for_status()
except HTTPError as e:
print(e.response.text)
raise Exception("PDUs not found")

return sorted(
[("pz_code", pz_code["pz_code"]) for pz_code in response.json()],
key=lambda x: int(x[1][2:]),
)


def retrieve_pdu(pz_number):
"""
Returns GP practice as an object from NHS API against a postcode
Expand All @@ -45,7 +69,7 @@ def retrieve_pdu(pz_number):
print(e.response.text)
raise Exception(f"{pz_number} not found")

return response.json()
return response.json()[0]


def retrieve_pdu_from_organisation_ods_code(ods_code):
Expand Down
7 changes: 5 additions & 2 deletions project/npda/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
</style>
<script>
tailwind.config = {
darkMode: false,
darkMode: 'media',
theme: {
backgroundColor: theme => ({
...theme('colors'),
Expand All @@ -51,6 +51,9 @@
'montserrat':['Montserrat', 'regular'],
'arial':['Arial', 'sans-serif']
},
maxWidth: {
'custom': '33.7rem' // Replace '30rem' with the exact width you want
},
colors: {
rcpch_lightest_grey: "#f3f3f3",

Expand Down Expand Up @@ -138,7 +141,7 @@
extend: {
backgroundColor: ['active'],
},
},
}
}
</script>
</script>
Expand Down
170 changes: 10 additions & 160 deletions project/npda/templates/npda_users.html

Large diffs are not rendered by default.

155 changes: 155 additions & 0 deletions project/npda/templates/partials/npda_user_table.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{% load npda_tags %}
{% if npdauser_list %}
<table class="table-auto w-full text-sm text-left rtl:text-right text-gray-500 text-gray-400 mb-5 font-montserrat">
<thead class="text-xs text-gray-700 uppercase bg-gray-50 bg-rcpch_dark_blue text-white">
<tr>
<th scope="col" class="w-1/12">NPDA UserID</th>
<th scope="col" class="w-2/12">Name</th>
<th scope="col" class="px-0 w-3/12">Email</th>
<th scope="col" class="-mx-6 w-3/12 text-left">Memberships</th>
<th scope="col" class="w-2/12">Role</th>
<th class="w-1/12 text-center">Logs</th>
</tr>
</thead>
<tbody>
{% for npda_user in npdauser_list %}
<tr class="border-b bg-white text-rcpch_light_blue border-gray-100 hover:bg-r hover:bg-rcpch_light_blue hover:text-white">
<td class="text-left">
<div class='relative has-tooltip items-center'>
<span class='absolute tooltip rounded shadow-lg px-2 py-2 bg-gray-500 text-white -mt-10 text-left'>NPDA User Unique ID</span>
<a href="{% url 'npdauser-update' npda_user.pk %}" class="px-2 text-rcpch_pink hover:text-rcpch_dark_blue"><strong>{{ npda_user.pk }}</strong></a>
</div>
</td>
<td class="text-left">
{{npda_user.get_full_name}}
</td>
<td>
<div class='relative has-tooltip items-center'>
<span class="flex flex-nowrap items-center">
{{npda_user.email}}
<div class='relative has-tooltip items-center '>
{% if npda_user.email_confirmed %}
<span class='absolute tooltip rounded shadow-lg px-2 py-2 bg-gray-500 text-white'>Email confirmed</span>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="16" height="16" class="-mt-3 -mx-2">
<g id="_12-Mail" data-name="12-Mail">
<path fill="#e00087" d="M11,24H4a4,4,0,0,1-4-4V4A4,4,0,0,1,4,0H28a4,4,0,0,1,4,4v9a1,1,0,0,1-2,0V4a2,2,0,0,0-2-2H4A2,2,0,0,0,2,4V20a2,2,0,0,0,2,2h7a1,1,0,0,1,0,2Z"/>
<path fill="#e00087" d="M16,14a1,1,0,0,1-.618-.214l-14-11A1,1,0,0,1,2.618,1.214L16,11.728,29.382,1.214a1,1,0,1,1,1.236,1.572l-14,11A1,1,0,0,1,16,14Z"/>
<path fill="#e00087" d="M2,23a1,1,0,0,1-.707-1.707l11-11a1,1,0,0,1,1.414,1.414l-11,11A1,1,0,0,1,2,23Z"/>
<path fill="#e00087" d="M23,32a9,9,0,1,1,9-9A9.01,9.01,0,0,1,23,32Zm0-16a7,7,0,1,0,7,7A7.008,7.008,0,0,0,23,16Z"/>
<path fill="#e00087" d="M22,27a1,1,0,0,1-.707-.293l-2-2a1,1,0,0,1,1.414-1.414L22,24.586l4.293-4.293a1,1,0,0,1,1.414,1.414l-5,5A1,1,0,0,1,22,27Z"/>
</g>
</svg>
</div>
{% else %}
<div class='relative has-tooltip items-center'>
<span class='absolute tooltip rounded shadow-lg p-2 bg-gray-500 text-white -mt-8'>Pending confirmation</span>
<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 24 24" width="16" height="16" class="-mt-1 -mx-2">
<path fill="#e00087" d="M24,10v9c0,2.76-2.24,5-5,5H5c-2.76,0-5-2.24-5-5V8C0,5.24,2.24,3,5,3H13c.55,0,1,.45,1,1s-.45,1-1,1H5c-1.15,0-2.14,.65-2.65,1.59l7.53,7.53c1.17,1.17,3.07,1.17,4.24,0l3.82-3.82c.39-.39,1.02-.39,1.41,0s.39,1.02,0,1.41l-3.82,3.82c-.97,.97-2.26,1.46-3.54,1.46s-2.56-.49-3.54-1.46L2,9.07v9.93c0,1.65,1.35,3,3,3h14c1.65,0,3-1.35,3-3V10c0-.55,.45-1,1-1s1,.45,1,1Zm-8-6c0-2.21,1.79-4,4-4s4,1.79,4,4-1.79,4-4,4-4-1.79-4-4Zm2,0c0,1.1,.9,2,2,2s2-.9,2-2-.9-2-2-2-2,.9-2,2Z"/>
</svg>
</div>
{% endif %}
</span>
</td>
<td class="grid grid-cols-4 gap-1 px-5 place-content-evenly items-center mt-5">
<!-- <span> -->
{% if npda_user.is_staff %}
<div class='relative has-tooltip items-center'>
<span class='absolute tooltip rounded shadow-lg p-2 bg-gray-500 text-white -mt-6'>Has admin access</span>
<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 32 32" height="32" width="32">
<path fill="#e00087" d="m22.21.939c-.365-.588-.997-.939-1.689-.939h-3.009c-1.534,0-2.909.854-3.587,2.23l-1.861,3.773c-.021,0-.042-.003-.063-.003-.014,0-.027.002-.041.002l-1.861-3.772c-.679-1.376-2.053-2.23-3.587-2.23h-3.009c-.692,0-1.324.351-1.69.939-.365.588-.4,1.31-.094,1.931l3.232,6.553c-1.217,1.535-1.95,3.471-1.95,5.578,0,4.962,4.038,9,9,9s9-4.038,9-9c0-2.099-.728-4.027-1.937-5.56l3.241-6.57c.307-.621.271-1.343-.094-1.931Zm-15.699,1.061c.767,0,1.454.427,1.793,1.115l1.555,3.153c-1.264.31-2.424.884-3.416,1.666L3.502,2h3.009Zm5.489,20c-3.86,0-7-3.14-7-7,0-3.66,2.825-6.668,6.409-6.97.001,0,.002,0,.004,0,.194-.016.39-.03.588-.03,3.86,0,7,3.14,7,7s-3.14,7-7,7Zm5.57-14.055c-.99-.784-2.148-1.359-3.41-1.672l1.558-3.158c.339-.688,1.026-1.115,1.793-1.115l3-.015-2.94,5.96Zm-1.413,6.465c0,.361-.251.665-.539.825l-1.49.828.661,1.803c.128.349.012.741-.285.965h0c-.304.229-.723.226-1.023-.007l-1.482-1.146-1.482,1.146c-.301.232-.72.235-1.023.007h0c-.297-.224-.413-.615-.285-.965l.661-1.803-1.49-.828c-.288-.16-.539-.464-.539-.825,0-.306.266-.644.696-.644h2.14l.567-2.175c.09-.345.399-.585.755-.591.355.007.665.246.755.591l.567,2.175h2.14c.43,0,.696.337.696.644Z"/>
</svg>
</div>
{% endif %}
{% if npda_user.is_superuser %}
<div class='relative has-tooltip items-center'>
<span class='absolute tooltip rounded shadow-lg p-2 bg-gray-500 text-white -mt-6'>Superuser</span>
<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" data-name="Layer 1" viewBox="0 0 32 32" height="32" weight="32">
<path fill="#e00087" d="m14.5,7c1.93,0,3.5-1.57,3.5-3.5s-1.57-3.5-3.5-3.5-3.5,1.57-3.5,3.5,1.57,3.5,3.5,3.5Zm0-5c.827,0,1.5.673,1.5,1.5s-.673,1.5-1.5,1.5-1.5-.673-1.5-1.5.673-1.5,1.5-1.5ZM5.5,7c1.93,0,3.5-1.57,3.5-3.5S7.43,0,5.5,0s-3.5,1.57-3.5,3.5,1.57,3.5,3.5,3.5Zm0-5c.827,0,1.5.673,1.5,1.5s-.673,1.5-1.5,1.5-1.5-.673-1.5-1.5.673-1.5,1.5-1.5Zm-.39,8.021c-1.611.178-2.91,1.477-3.088,3.089-.057.512-.49.89-.993.89-.717,0-1.056-.562-.996-1.11.281-2.534,2.323-4.576,4.857-4.856.542-.054,1.043.336,1.104.885s-.335,1.043-.884,1.104Zm3.906,3.985c-.197.209-.462.314-.729.314-.246,0-.492-.09-.685-.271-.701-.659-1.103-1.589-1.103-2.55,0-1.93,1.57-3.5,3.5-3.5.765,0,1.492.242,2.101.701.441.332.53.959.198,1.4-.333.44-.959.53-1.4.197-.26-.195-.571-.299-.899-.299-.827,0-1.5.673-1.5,1.5,0,.418.168.806.473,1.093.402.379.422,1.012.043,1.414Zm-1.181,3.182c.304.462.177,1.082-.285,1.386-.875.576-1.442,1.501-1.556,2.536-.057.511-.49.89-.993.89-.707,0-1.056-.562-.996-1.11.18-1.628,1.071-3.08,2.444-3.985.461-.303,1.081-.176,1.385.284Zm9.165-7.188c-3.86,0-7,3.141-7,7s3.14,7,7,7,7-3.141,7-7-3.14-7-7-7Zm0,12c-2.757,0-5-2.243-5-5s2.243-5,5-5,5,2.243,5,5-2.243,5-5,5Zm3.221-6.212c.383.398.37,1.031-.029,1.414l-2.212,2.124c-.452.446-1.052.671-1.653.671s-1.204-.225-1.664-.674l-1.132-1.108c-.395-.387-.401-1.02-.015-1.414.387-.396,1.02-.401,1.414-.016l1.132,1.108c.144.141.379.142.522,0l2.223-2.134c.399-.382,1.031-.371,1.414.029Z"/>
</svg>
</div>
{% endif %}
{% if npda_user.is_rcpch_audit_team_member %}
<div class='relative has-tooltip items-center'>
<span class='absolute tooltip rounded shadow-lg p-2 bg-gray-500 text-white -mt-20'>RCPCH Audit Team Member</span>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" viewBox="0 0 340 340" xml:space="preserve" width="32" height="32">
<g id="XMLID_2186_">
<g id="XMLID_2187_">
<g id="XMLID_2188_">
<path id="XMLID_2189_" style="fill:#e00087;" d="M170,134.134c3.547,0,6.927,0.72,10,2.021V13.134h-20v123.021 C163.073,134.854,166.453,134.134,170,134.134z"/>
<path id="XMLID_2190_" style="fill:#e00087;" d="M170,185.467c-3.547,0-6.927-0.72-10-2.021v85.688h20v-85.688 C176.927,184.747,173.547,185.467,170,185.467z"/>
</g>
<path id="XMLID_2191_" style="fill:#e00087;" d="M170,195.467c-19.667,0-35.667-16-35.667-35.666 c0-19.667,16-35.667,35.667-35.667s35.667,16,35.667,35.667C205.667,179.467,189.667,195.467,170,195.467z M170,144.134 c-8.639,0-15.667,7.028-15.667,15.667s7.028,15.666,15.667,15.666s15.667-7.027,15.667-15.666S178.639,144.134,170,144.134z"/>
</g>
<g id="XMLID_2194_">
<g id="XMLID_2195_">
<path id="XMLID_2196_" style="fill:#e00087;" d="M65.5,134.134c3.547,0,6.927,0.72,10,2.021V13.134h-20v123.021 C58.573,134.854,61.953,134.134,65.5,134.134z"/>
<path id="XMLID_2197_" style="fill:#e00087;" d="M65.5,185.467c-3.547,0-6.927-0.72-10-2.021v85.688h20v-85.688 C72.427,184.747,69.047,185.467,65.5,185.467z"/>
</g>
<path id="XMLID_2198_" style="fill:#e00087;" d="M65.5,195.467c-19.667,0-35.667-16-35.667-35.666 c0-19.667,16-35.667,35.667-35.667s35.667,16,35.667,35.667C101.167,179.467,85.167,195.467,65.5,195.467z M65.5,144.134 c-8.639,0-15.667,7.028-15.667,15.667s7.028,15.666,15.667,15.666s15.667-7.027,15.667-15.666S74.139,144.134,65.5,144.134z"/>
</g>
<path id="XMLID_2201_" style="fill:#e00087;" d="M313.134,326.866H26.866C12.052,326.866,0,314.814,0,300v-18 c0-14.814,12.052-26.866,26.866-26.866h286.268C327.948,255.134,340,267.186,340,282v18 C340,314.814,327.948,326.866,313.134,326.866z M26.866,275.134c-3.786,0-6.866,3.08-6.866,6.866v18 c0,3.786,3.08,6.866,6.866,6.866h286.268c3.786,0,6.866-3.08,6.866-6.866v-18c0-3.786-3.08-6.866-6.866-6.866H26.866z"/>
<g id="XMLID_2204_">
<circle id="XMLID_2205_" style="fill:#e00087;" cx="65.5" cy="95.134" r="25.667"/>
<path id="XMLID_2206_" style="fill:#e00087;" d="M65.5,130.801c-19.667,0-35.667-16-35.667-35.667s16-35.667,35.667-35.667 s35.667,16,35.667,35.667S85.167,130.801,65.5,130.801z M65.5,79.467c-8.639,0-15.667,7.028-15.667,15.667 s7.028,15.667,15.667,15.667s15.667-7.028,15.667-15.667S74.139,79.467,65.5,79.467z"/>
</g>
<g id="XMLID_2209_">
<circle id="XMLID_2210_" style="fill:#e00087;" cx="65.5" cy="224.467" r="25.667"/>
<path id="XMLID_2211_" style="fill:#e00087;" d="M65.5,260.134c-19.667,0-35.667-16-35.667-35.667 c0-19.666,16-35.666,35.667-35.666s35.667,16,35.667,35.666C101.167,244.134,85.167,260.134,65.5,260.134z M65.5,208.801 c-8.639,0-15.667,7.027-15.667,15.666s7.028,15.667,15.667,15.667s15.667-7.028,15.667-15.667S74.139,208.801,65.5,208.801z"/>
</g>
<g id="XMLID_2214_">
<circle id="XMLID_2215_" style="fill:#e00087;" cx="170" cy="224.467" r="25.667"/>
<path id="XMLID_2216_" style="fill:#e00087;" d="M170,260.134c-19.667,0-35.667-16-35.667-35.667 c0-19.666,16-35.666,35.667-35.666s35.667,16,35.667,35.666C205.667,244.134,189.667,260.134,170,260.134z M170,208.801 c-8.639,0-15.667,7.027-15.667,15.666s7.028,15.667,15.667,15.667s15.667-7.028,15.667-15.667S178.639,208.801,170,208.801z"/>
</g>
<g id="XMLID_2219_">
<g id="XMLID_2220_">
<rect id="XMLID_2221_" x="264.5" y="13.134" style="fill:#e00087;" width="20" height="256"/>
</g>
<g id="XMLID_2222_">
<circle id="XMLID_2223_" style="fill:#e00087;" cx="274.5" cy="224.467" r="25.667"/>
<path id="XMLID_2224_" style="fill:#e00087;" d="M274.5,260.134c-19.667,0-35.667-16-35.667-35.667 c0-19.666,16-35.666,35.667-35.666s35.667,16,35.667,35.666C310.167,244.134,294.167,260.134,274.5,260.134z M274.5,208.801 c-8.639,0-15.667,7.027-15.667,15.666s7.028,15.667,15.667,15.667s15.667-7.028,15.667-15.667S283.139,208.801,274.5,208.801z"/>
</g>
</g>
</g>
<!-- </svg> -->
</div>
{% endif %}
{% if npda_user.is_rcpch_staff %}
<div class='has-tooltip items-center'>
<span class='tooltip rounded shadow-lg p-2 bg-gray-500 text-white -mt-6'>RCPCH Staff Member</span>
<svg xmlns="http://www.w3.org/2000/svg" id="Layer_1" height="16" viewBox="0 0 32 32" width="32" height="32" data-name="Layer 1">
<path fill="#e00087" d="m19 4h-4v-1a3 3 0 0 0 -6 0v1h-4a5.006 5.006 0 0 0 -5 5v10a5.006 5.006 0 0 0 5 5h14a5.006 5.006 0 0 0 5-5v-10a5.006 5.006 0 0 0 -5-5zm-8-1a1 1 0 0 1 2 0v2a1 1 0 0 1 -2 0zm11 16a3 3 0 0 1 -3 3h-14a3 3 0 0 1 -3-3v-10a3 3 0 0 1 3-3h4.184a2.982 2.982 0 0 0 5.632 0h4.184a3 3 0 0 1 3 3zm-12-9h-5a1 1 0 0 0 -1 1v8a1 1 0 0 0 1 1h5a1 1 0 0 0 1-1v-8a1 1 0 0 0 -1-1zm-1 8h-3v-6h3zm11-3a1 1 0 0 1 -1 1h-5a1 1 0 0 1 0-2h5a1 1 0 0 1 1 1zm0-4a1 1 0 0 1 -1 1h-5a1 1 0 0 1 0-2h5a1 1 0 0 1 1 1zm-2 8a1 1 0 0 1 -1 1h-3a1 1 0 0 1 0-2h3a1 1 0 0 1 1 1z"/>
</svg>
</div>
{% endif %}
</span>
</td>
<td class="px-6 text-left">{{npda_user.get_role_display}}</td>
<td class="px-2 text-right w-80">
<a href="{% url 'npdauser-logs' npda_user.pk %}" class="text-rcpch_pink px-2 flex justify-center items-center">
<svg class="h-8 w-8 text-rcpch_pink" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"> <path stroke="none" d="M0 0h24v24H0z"/> <polyline points="9 6 15 12 9 18" /></svg>
</a>
</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
{% if npdauser_list %}
<tr class="text-xs text-gray-700 uppercase bg-gray-50 bg-rcpch_dark_blue text-white py-5">
<th colspan="9" class="px-2">
<strong>
Total: {{ npdauser_list|length }} User{% if npdauser_list|length > 1 %}s{% endif %}
</strong>
</th>
</tr>
{% else %}
<tr class="text-xs text-gray-700 uppercase bg-gray-50 bg-rcpch_dark_blue text-white py-5">
<th>
<h5>No NPDA users yet!</h5>
</th>
</tr>
{% endif %}
</tfoot>
</table>
{% else %}
<h5 class="py-5">No NPDA users yet!</h5>
{% endif %}
Loading

0 comments on commit db76873

Please sign in to comment.