Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
216 commits
Select commit Hold shift + click to select a range
a2341f1
Initial group changes & management
ieuans Nov 27, 2024
31cf884
initial organisation_checks
ZinnurovArtur Dec 3, 2024
efd4483
Merge remote-tracking branch 'origin/Development' into publish-organi…
ZinnurovArtur Jan 13, 2025
f85d4b5
organisisation permission utils
ZinnurovArtur Jan 20, 2025
5eb1789
migration merge
ZinnurovArtur Jan 20, 2025
022c397
some test of permission publish
ZinnurovArtur Jan 27, 2025
5baeb1c
adding organisation permissions
ZinnurovArtur Jan 27, 2025
775f7d9
getting the right role
ZinnurovArtur Jan 28, 2025
64ec184
adding the brand check
ZinnurovArtur Feb 20, 2025
b17e71c
adding brand checks and allowed to publish cheks
ZinnurovArtur Feb 20, 2025
67fe179
removed print
ZinnurovArtur Feb 28, 2025
ddb3fcf
adding the conjestion of two dictionaries of permissions
ZinnurovArtur Feb 28, 2025
bb82d15
using checks from publish utils
ZinnurovArtur Feb 28, 2025
4d8a6ae
some code refactor
ZinnurovArtur Feb 28, 2025
4dbb6ab
some condition changes
ZinnurovArtur Feb 28, 2025
1cc7e23
adding more checks
ZinnurovArtur Feb 28, 2025
8d2f447
adding organisation check alongside if user exists there
ZinnurovArtur Mar 3, 2025
298172d
fix the moderator issue
ZinnurovArtur Mar 3, 2025
a847e36
hide button
ZinnurovArtur Mar 3, 2025
f142e27
deleted print
ZinnurovArtur Mar 4, 2025
78e4b0f
fix conditions
ZinnurovArtur Mar 4, 2025
70b720f
using allowed to publish instead of user edi
ZinnurovArtur Mar 6, 2025
adb1209
adding publish for a moderator
ZinnurovArtur Mar 6, 2025
de9c3d8
adding the organisation user checks when brand is accessd
ZinnurovArtur Mar 7, 2025
6db8f4b
applied changes
ZinnurovArtur Mar 7, 2025
b49ac2e
fix!: data sources, breaking change as datasource_id now refers to in…
JackScanlon Mar 10, 2025
15de5f2
feat: collection/tag brand behaviour
JackScanlon Mar 11, 2025
5a52028
feat: administrator asset & relation interface;
JackScanlon Mar 12, 2025
a2ee22a
fix: use tags as asset cat
JackScanlon Mar 12, 2025
27f8a0e
feat: use tags instead of collections
JackScanlon Mar 12, 2025
8e992b8
changing publish file so it can work in org env
ZinnurovArtur Mar 13, 2025
9f92809
changing template tag button visibility
ZinnurovArtur Mar 13, 2025
b773710
reset everything if using org
ZinnurovArtur Mar 13, 2025
08dce38
adding check if false
ZinnurovArtur Mar 13, 2025
e5ef36a
using the normal flow of conditions instead of previos
ZinnurovArtur Mar 13, 2025
b17f91c
Merge branch 'Development' into feat/HDRN
ieuans Mar 14, 2025
1102159
feat: brand administration & cleanup
ieuans Mar 14, 2025
4968ab2
Merge branch 'feat/HDRN' into JS/HDRN
JackScanlon Mar 14, 2025
25a20cd
Js/hdrn (#1789)
JackScanlon Mar 14, 2025
8e20826
JS/hdrn (#1787)
JackScanlon Mar 14, 2025
7c794e5
feat: perms iter
ieuans Mar 16, 2025
73206ca
feat: perms iter (#1791)
ieuans Mar 16, 2025
8b656ca
feat: caching
ieuans Mar 16, 2025
086bb4b
feat: account management changes
JackScanlon Mar 16, 2025
fc464b7
feat: perms iter
ieuans Mar 16, 2025
eecae80
feat: perms iter
ieuans Mar 16, 2025
1458a07
add check if user is present in group
ZinnurovArtur Mar 17, 2025
5e67819
Merge remote-tracking branch 'origin/Development' into publish-organi…
ZinnurovArtur Mar 17, 2025
3b850c8
feat: iterate on API
JackScanlon Mar 17, 2025
44274b1
adding check if org user managed
ZinnurovArtur Mar 17, 2025
09cd5b0
renamed function
ZinnurovArtur Mar 17, 2025
2d36a70
fix: moderation test
JackScanlon Mar 17, 2025
3c5c19f
Merge branch 'Development' into feat/HDRN
JackScanlon Mar 17, 2025
d5008ff
fix: btn presence test
JackScanlon Mar 17, 2025
6637789
Merge branch 'Development' into publish-organisation-hdrn
ZinnurovArtur Mar 18, 2025
cfaa3f7
feat: iter
JackScanlon Mar 18, 2025
32284c1
feat: adding HDRN logos and scss elements
roshantoby Mar 18, 2025
333131a
feat: adding HDRN logos and scss elements
roshantoby Mar 18, 2025
679f360
email organization handling
ZinnurovArtur Mar 18, 2025
7bff486
feat: iter panel
JackScanlon Mar 18, 2025
1af55ce
Merge branch 'feat/HDRN' of https://github.com/SwanseaUniversityMedic…
JackScanlon Mar 18, 2025
f11e2b2
fix of brand accecebility
ZinnurovArtur Mar 19, 2025
4deb16d
test if user can look other brands phenotupe
ZinnurovArtur Mar 20, 2025
4e85636
Merge remote-tracking branch 'origin/publish-organisation-hdrn' into …
ZinnurovArtur Mar 20, 2025
28439a6
Merge remote-tracking branch 'origin/feat/HDRN' into publish-organisa…
ZinnurovArtur Mar 20, 2025
5eec4bc
feat: iter brand admin
JackScanlon Mar 22, 2025
3dde196
fix: nav tooltip
JackScanlon Mar 22, 2025
f3a583c
feat: iter. dashboard
JackScanlon Mar 23, 2025
774ddf4
Js/brand admin (#1796)
JackScanlon Mar 23, 2025
1203efa
deleted wrong migration
ZinnurovArtur Mar 24, 2025
354d8fc
Merge remote-tracking branch 'origin/feat/HDRN' into publish-organisa…
ZinnurovArtur Mar 24, 2025
a09dadf
Merge remote-tracking branch 'origin/publish-organisation-hdrn' into …
ZinnurovArtur Mar 24, 2025
e054bff
feat: iter brand behaviour & dashboard
JackScanlon Mar 24, 2025
0c7e9a0
feat: iter brand behaviour & dashboard (#1797)
JackScanlon Mar 24, 2025
7d32a04
using the entity organisation instead of request
ZinnurovArtur Mar 24, 2025
0ec271d
feat: iter
JackScanlon Mar 24, 2025
5260992
feat: iter (#1798)
JackScanlon Mar 25, 2025
27bc509
feat: dashboard form serialiser & formalise asset rules
JackScanlon Mar 25, 2025
50e38fa
using published entity insteadof entity
ZinnurovArtur Mar 25, 2025
eeee7fa
same for decline
ZinnurovArtur Mar 25, 2025
901577f
using different way of getting brands and entity
ZinnurovArtur Mar 25, 2025
4103306
adding this functions of brand id and
ZinnurovArtur Mar 25, 2025
8e40244
Merge branch 'Development' into publish-organisation-hdrn
ZinnurovArtur Mar 25, 2025
01bc3a9
iterate on brand asset rules
JackScanlon Mar 26, 2025
57618ad
Js/brand admin (#1800)
JackScanlon Mar 26, 2025
fcc0744
Merge branch 'Development' into publish-organisation-hdrn
ZinnurovArtur Mar 26, 2025
eaed3f6
has org authority change
ZinnurovArtur Mar 27, 2025
0baca8f
Added TagTarget
roshantoby Mar 27, 2025
a7495aa
Added TagTarget
roshantoby Mar 27, 2025
f570211
Added HDRNSiteTarget
roshantoby Mar 27, 2025
3503a09
removed wget key install
ZinnurovArtur Mar 28, 2025
5ec966e
Added BrandTarget.py
roshantoby Mar 28, 2025
032c882
Added HDRNSiteTarget
roshantoby Mar 28, 2025
4a33563
Added HDRNCategory Targets and site target
roshantoby Mar 28, 2025
d661db0
pre-merge admin backend
JackScanlon Mar 28, 2025
171fd53
cleanup erroneous files
JackScanlon Mar 28, 2025
295959a
Merge backend
JackScanlon Mar 28, 2025
8a8d0a9
pre-merge admin backend (#1802)
JackScanlon Mar 28, 2025
ebbd07d
Added PeopleTarget.py
roshantoby Mar 29, 2025
7bffb15
feat: org iter
ieuans Mar 31, 2025
9ba74ac
Merge branch 'feat/HDRN' into IS/HDRN-ORG
ieuans Mar 31, 2025
4635c2f
Remove err code
ieuans Mar 31, 2025
a3991e5
Merge branch 'IS/HDRN-ORG' of https://github.com/SwanseaUniversityMed…
ieuans Mar 31, 2025
ffb53f9
feat; org iter
ieuans Mar 31, 2025
0d94b43
Merge branch 'feat/HDRN' into publish-organisation-hdrn
ZinnurovArtur Mar 31, 2025
79f1738
org model/view fix
ieuans Mar 31, 2025
ed7117d
Revert "Adding workingset from upstream (#1778)"
ieuans Mar 31, 2025
1cd0517
Remove merge conflicts
ieuans Mar 31, 2025
2f67bee
Merge branch 'feat/HDRN' into temp/publsh-organisation-hdrn
ieuans Mar 31, 2025
20c4b36
feat: iter. brand UI
JackScanlon Mar 31, 2025
37a7ab9
Merge branch 'feat/HDRN' into JS/brand-admin
JackScanlon Mar 31, 2025
80a2f03
feat: iter. brand UI (#1806)
JackScanlon Mar 31, 2025
a3de06c
Merge branch 'feat/HDRN' into temp/publsh-organisation-hdrn
ieuans Mar 31, 2025
0d95e6d
subquery issue
ieuans Mar 31, 2025
099d90b
Temp/publsh organisation hdrn (#1805)
ieuans Apr 2, 2025
faabb64
iter brand administration
JackScanlon Apr 4, 2025
ae662e6
dev: rename inventory target
JackScanlon Apr 4, 2025
442f266
dev: upd inventory resolver
JackScanlon Apr 4, 2025
312f26a
dev: iter dashboard
JackScanlon Apr 4, 2025
5173095
update
ieuans Apr 4, 2025
50a8a0c
feat: brand administration finalised
JackScanlon Apr 4, 2025
618704f
feat: administration history popstate
JackScanlon Apr 4, 2025
e6f3f17
feat: impl. dashboard access & perms
JackScanlon Apr 4, 2025
2748559
feat: validation & password reset improvements
JackScanlon Apr 4, 2025
d1fb92a
email fix
ieuans Apr 4, 2025
1c17785
iter brand administration (#1809)
JackScanlon Apr 4, 2025
b5f1c28
fix: dash perms
JackScanlon Apr 4, 2025
c28b50b
Merge branch 'JS/brand-admin' of https://github.com/SwanseaUniversity…
JackScanlon Apr 4, 2025
e63fa5a
fix: dash perms (#1810)
JackScanlon Apr 4, 2025
8d10044
dev: dash logging
JackScanlon Apr 4, 2025
c00b80e
dev: dash logging
JackScanlon Apr 4, 2025
7684349
Js/brand admin (#1811)
JackScanlon Apr 4, 2025
d8112b2
fix: dashboard autocomplete & fk selection
JackScanlon Apr 5, 2025
28433dd
fix: request signals
JackScanlon Apr 6, 2025
e2eb2f2
dev: iter signals
JackScanlon Apr 6, 2025
041c275
feat: hide Dashboard from TRE
JackScanlon Apr 6, 2025
4c5d727
dev: fix brand ctx compute
JackScanlon Apr 6, 2025
c258862
dev: detail pg style changes
JackScanlon Apr 6, 2025
e0ee76d
HDRN iteration (#1812)
JackScanlon Apr 6, 2025
0d12529
update org
ieuans Apr 6, 2025
1234ed3
added related concepts and related references fields to HDRN template
Apr 7, 2025
0f966f5
dev: iter tmpl
JackScanlon Apr 7, 2025
eb032bd
deps: upgrade deps
JackScanlon Apr 7, 2025
6cd191d
feat: brand context mapping & component enhancements
JackScanlon Apr 8, 2025
c59390b
fix: org view issue
ieuans Apr 8, 2025
10af7e3
Merge branch 'JS/tmpl' of https://github.com/SwanseaUniversityMedical…
ieuans Apr 8, 2025
6524906
fix: Org issue
ieuans Apr 9, 2025
688c0d6
feat: templ fields
ieuans Apr 13, 2025
3d5dbdc
feat: templ fields (#1820)
ieuans Apr 13, 2025
9e27406
feat: tmpl field iter
JackScanlon Apr 13, 2025
ca7c7ed
Merge branch 'JS/tmpl' into JS/iter-tmpl
JackScanlon Apr 13, 2025
27efb4d
Js/iter tmpl (#1821)
JackScanlon Apr 13, 2025
94244d7
feat: templ
ieuans Apr 13, 2025
0f8379e
dev: upd hdrn tmpl
JackScanlon Apr 13, 2025
f071e99
feat: iter
ieuans Apr 14, 2025
1a5cdf6
fix: err
ieuans Apr 14, 2025
f4cb4f4
dev: iter
JackScanlon Apr 14, 2025
4532778
Merge branch 'JS/iter-tmpl' of https://github.com/SwanseaUniversityMe…
JackScanlon Apr 14, 2025
963248a
Js/iter tmpl (#1823)
JackScanlon Apr 14, 2025
2d5f0a3
dev: iter
JackScanlon Apr 14, 2025
f58c9c9
Merge branch 'feat/HDRN' into JS/tmpl
JackScanlon Apr 14, 2025
6a76cc2
HDRN Iteration (#1816)
JackScanlon Apr 14, 2025
30cf1c3
fix: err org issue
JackScanlon Apr 14, 2025
2f60e78
fix: group enum issue
JackScanlon Apr 14, 2025
5429172
dev: iter. vars & measurements
JackScanlon Apr 14, 2025
4252378
feat: variable/measure creation & async enhancements
JackScanlon Apr 15, 2025
cc65ab5
feat: detail iter
ieuans Apr 15, 2025
33ae26c
dev: iter. vars & measurements (#1824)
JackScanlon Apr 15, 2025
9c8be1a
feat: finalise components
JackScanlon Apr 16, 2025
8707d39
fix: Excel issue
ieuans Apr 16, 2025
0abb9c3
Merge branch 'feat/HDRN' of https://github.com/SwanseaUniversityMedic…
ieuans Apr 16, 2025
d7abe06
feat: iter publishing
ieuans Apr 16, 2025
02284cf
feat: iter publishing (#1826)
ieuans Apr 16, 2025
3aa394b
Merge branch 'feat/HDRN' into JS/vars-related
JackScanlon Apr 16, 2025
bee795d
dev: remove todo
JackScanlon Apr 16, 2025
84c34ef
Merge branch 'JS/vars-related' of https://github.com/SwanseaUniversit…
JackScanlon Apr 16, 2025
11703cd
feat: finalise components (#1825)
JackScanlon Apr 16, 2025
ec3a633
feat: create context
ieuans Apr 19, 2025
a5d9eea
feat: create context (#1827)
ieuans Apr 19, 2025
716473f
feat: iter
ieuans Apr 22, 2025
b65caab
feat: tagify component, form enhancements & aesthetic changes
JackScanlon Apr 22, 2025
b65c1a3
feat: tagify component, form enhancements & aesthetic changes (#1828)
JackScanlon Apr 22, 2025
836e2ac
feat: accessibility enhancements
JackScanlon Apr 22, 2025
42842a7
dev: minor fix
JackScanlon Apr 22, 2025
4e30899
dev: cleanup
JackScanlon Apr 22, 2025
be0adce
fix: publication changes
JackScanlon Apr 23, 2025
c2360a4
fix: unique assets
JackScanlon Apr 23, 2025
02ceebe
dev: fix caching & intersection
JackScanlon Apr 23, 2025
b7816fa
dev: iter tag
JackScanlon Apr 23, 2025
a0c3454
dev: finalise ds
JackScanlon Apr 24, 2025
0f3afc4
fix: nl insertion in md editor
JackScanlon Apr 25, 2025
b08786b
feat: enable entity redirect
JackScanlon Apr 25, 2025
904ffff
fix: whitespace md
JackScanlon Apr 25, 2025
1f6ec7a
fix: anon user issue
JackScanlon Apr 25, 2025
b0c56e2
dev: fix historical issue conc. branded API req
JackScanlon Apr 25, 2025
279d781
feat: iter HDRN reqs
ieuans Jun 10, 2025
3051b78
docs
ieuans Jun 10, 2025
4431bb0
fix: task queue behaviour changes
JackScanlon Jun 11, 2025
6ac9d77
dev: ignore hierarchical filter stats
JackScanlon Jun 11, 2025
1b89c44
fix: minor perm changes
JackScanlon Jun 11, 2025
c933f36
fix: default values for historical fields
JackScanlon Jun 16, 2025
665987d
fix: imports
JackScanlon Jun 16, 2025
d242a46
fix: navigation ctx map
JackScanlon Jun 24, 2025
8911cf3
dev: key issue
JackScanlon Jun 24, 2025
ee755b7
dev: key issue
JackScanlon Jun 24, 2025
96986f6
dev: disable audit signal in remote test env
JackScanlon Jun 24, 2025
be6432a
dev: rm easyaudit middleware in test env
JackScanlon Jun 24, 2025
d1fb1b8
dev: mod. tests
JackScanlon Jun 24, 2025
7b2c4dd
dev: mod. fixtures
JackScanlon Jun 24, 2025
7f2a16a
dev: mod. cases
JackScanlon Jun 24, 2025
06b857f
dev: mod. cases
JackScanlon Jun 24, 2025
6188821
dev: mod. dbg
JackScanlon Jun 24, 2025
56c21e8
dev: mod. dbg
JackScanlon Jun 24, 2025
17693da
dev: mod. legacy
JackScanlon Jun 24, 2025
eaea60d
fix: falsey brand
JackScanlon Jun 24, 2025
c403ff6
feat: misc. improvements
JackScanlon Jun 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 3 additions & 3 deletions .github/workflows/testing-pipline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- run: |
sudo apt-get update
sudo apt-get install -y libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libnss3-dev libxss-dev libasound2
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo apt-get update
sudo apt-get install -y libgconf-2-4 libatk1.0-0 libatk-bridge2.0-0 libgdk-pixbuf2.0-0 libgtk-3-0 libgbm-dev libnss3-dev libxss-dev libasound2
- uses: browser-actions/setup-chrome@v1
- uses: actions/cache@v3
with:
Expand All @@ -65,6 +64,7 @@ jobs:

- name: Install Dependencies
run: |
sudo apt-get install -y -q dirmngr
python -m pip install --upgrade pip
pip install --upgrade --upgrade-strategy eager --default-timeout 100 -r docker/requirements/test.txt

Expand Down
49 changes: 46 additions & 3 deletions CodeListLibrary_project/clinicalcode/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
from .models.GenericEntity import GenericEntity
from .models.Template import Template
from .models.OntologyTag import OntologyTag
from .models.Organisation import Organisation
from .models.DMD_CODES import DMD_CODES

from .forms.TemplateForm import TemplateAdminForm
from .forms.EntityClassForm import EntityAdminForm
from .forms.OrganisationForms import OrganisationAdminForm, OrganisationMembershipInline, OrganisationAuthorityInline

@admin.register(OntologyTag)
class OntologyTag(admin.ModelAdmin):
Expand Down Expand Up @@ -51,10 +54,9 @@ def save_model(self, request, obj, form, change):

@admin.register(Brand)
class BrandAdmin(admin.ModelAdmin):
list_display = ['name', 'id', 'logo_path', 'owner', 'description']
list_filter = ['name', 'description', 'created', 'modified', 'owner']
list_filter = ['name', 'description', 'created', 'modified']
list_display = ['name', 'id', 'logo_path', 'description']
search_fields = ['name', 'id', 'description']
exclude = ['created_by', 'updated_by']


@admin.register(DataSource)
Expand All @@ -72,6 +74,47 @@ class CodingSystemAdmin(admin.ModelAdmin):
search_fields = ['name', 'codingsystem_id', 'description']
exclude = []

@admin.register(Organisation)
class OrganisationAdmin(admin.ModelAdmin):
"""
Organisation admin representation
"""
form = OrganisationAdminForm
inlines = [OrganisationMembershipInline, OrganisationAuthorityInline]
#exclude = ['created', 'owner', 'members', 'brands']

list_filter = ['id', 'name']
search_fields = ['id', 'name']
list_display = ['id', 'name', 'slug']
prepopulated_fields = {'slug': ['name']}

def get_form(self, request, obj=None, **kwargs):
"""
Responsible for pre-populating form data & resolving the associated model form

Args:
request (RequestContext): the request context of the form
obj (dict|None): an Organisation model instance (optional; defaults to `None`)
**kwargs (**kwargs): arbitrary form key-value pair data

Returns:
(OrganisationModelForm) - the prepared ModelForm instance
"""
form = super(OrganisationAdmin, self).get_form(request, obj, **kwargs)

if obj is None:
form.base_fields['slug'].initial = ''
form.base_fields['created'].initial = timezone.now()
else:
form.base_fields['slug'].initial = obj.slug
form.base_fields['created'].initial = obj.created

form.base_fields['slug'].disabled = True
form.base_fields['slug'].help_text = 'This field is not editable'
form.base_fields['created'].disabled = True
form.base_fields['created'].help_text = 'This field is not editable'

return form

@admin.register(Template)
class TemplateAdmin(admin.ModelAdmin):
Expand Down
3 changes: 3 additions & 0 deletions CodeListLibrary_project/clinicalcode/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def get_schema(self, request=None, public=False):
url(r'^data-sources/$',
DataSource.get_datasources,
name='data_sources'),
url(r'^data-sources/(?P<datasource_id>[\d-]+)/export/$',
DataSource.get_datasource_internal_detail,
name='data_source_by_internal_id'),
url(r'^data-sources/(?P<datasource_id>[\w-]+)/detail/$',
DataSource.get_datasource_detail,
name='data_source_by_id'),
Expand Down
54 changes: 36 additions & 18 deletions CodeListLibrary_project/clinicalcode/api/views/Collection.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,46 @@
from rest_framework import status
from django.db.models import F, Q
from rest_framework.response import Response
from rest_framework.decorators import (api_view, permission_classes)
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.response import Response
from rest_framework import status
from django.db.models import F
from django.contrib.postgres.search import TrigramWordSimilarity

from ...models import Tag, GenericEntity
from ...entity_utils import api_utils
from ...entity_utils import constants
from ...entity_utils import constants, gen_utils, api_utils

@api_view(['GET'])
@permission_classes([IsAuthenticatedOrReadOnly])
def get_collections(request):
"""
Get all collections
Get all Collections

Available parameters:

| Param | Type | Default | Desc |
|---------------|-----------------|---------|---------------------------------------------------------------|
| search | `str` | `NULL` | Full-text search across _name_ field |
| id | `int/list[int]` | `NULL` | Match by a single `int` _id_ field, or match by array overlap |
"""
collections = Tag.objects.filter(
tag_type=constants.TAG_TYPE.COLLECTION.value
) \
.order_by('id')

result = collections.annotate(
name=F('description')
) \
.values('id', 'name')
search = request.query_params.get('search', '')

collections = Tag.get_brand_records_by_request(request, params={ 'tag_type': 2 })
if collections is not None:
if not gen_utils.is_empty_string(search) and len(search.strip()) > 1:
collections = collections.annotate(
similarity=TrigramWordSimilarity(search, 'description')
) \
.filter(Q(similarity__gte=0.7)) \
.order_by('-similarity')
else:
collections = collections.order_by('id')

collections = collections.annotate(
name=F('description')
) \
.values('id', 'name')

return Response(
data=list(result),
data=collections.values('id', 'name'),
status=status.HTTP_200_OK
)

Expand All @@ -36,8 +51,11 @@ def get_collection_detail(request, collection_id):
Get detail of specified collection by collection_id, including associated
published entities
"""
collection = Tag.objects.filter(id=collection_id)
if not collection.exists():
collection = Tag.get_brand_assoc_queryset(request.BRAND_OBJECT, 'collections')
if collection is not None:
collection = collection.filter(id=collection_id)

if not collection or not collection.exists():
return Response(
data={
'message': 'Collection with id does not exist'
Expand Down
4 changes: 2 additions & 2 deletions CodeListLibrary_project/clinicalcode/api/views/Concept.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def get_concepts(request):
query_clauses.append(psycopg2.sql.SQL('''(
setweight(to_tsvector('pg_catalog.english', coalesce(historical.name,'')), 'A') ||
setweight(to_tsvector('pg_catalog.english', coalesce(historical.description,'')), 'B')
) @@ to_tsquery('pg_catalog.english', replace(websearch_to_tsquery('pg_catalog.english', %(search_query)s)::text || ':*', '<->', '|'))
) @@ to_tsquery('pg_catalog.english', replace(to_tsquery('pg_catalog.english', concat(regexp_replace(trim(%(search_query)s), '\W+', ':* & ', 'gm'), ':*'))::text, '<->', '|'))
'''))

# Resolve pagination behaviour
Expand Down Expand Up @@ -422,7 +422,7 @@ def get_concept_detail(request, concept_id, version_id=None, export_codes=False,
if not user_can_access:
return Response(
data={
'message': 'Concept version must be published or you must have permission to access it'
'message': 'Entity version must be published or you must have permission to access it'
},
content_type='json',
status=status.HTTP_401_UNAUTHORIZED
Expand Down
148 changes: 134 additions & 14 deletions CodeListLibrary_project/clinicalcode/api/views/DataSource.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,159 @@
from rest_framework.decorators import (api_view, permission_classes)
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from rest_framework.response import Response
from rest_framework import status
from django.db.models import Subquery, OuterRef
from django.db.models import Q, Subquery, OuterRef
from rest_framework.response import Response
from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticatedOrReadOnly
from django.contrib.postgres.search import TrigramWordSimilarity

from ...models import DataSource, Template, GenericEntity
from ...entity_utils import api_utils
from ...entity_utils import gen_utils
from ...entity_utils import constants
from ...entity_utils import api_utils, gen_utils, constants

@api_view(['GET'])
@permission_classes([IsAuthenticatedOrReadOnly])
def get_datasources(request):
"""
Get all datasources
Get all DataSources

Available parameters:

| Param | Type | Default | Desc |
|---------------|-----------------|---------|---------------------------------------------------------------|
| search | `str` | `NULL` | Full-text search across _name_ and _description_ fields |
| id | `int/list[int]` | `NULL` | Match by a single `int` _id_ field, or match by array overlap |
| name | `str` | `NULL` | Case insensitive direct match of _name_ field |
| uid | `str/uuid` | `NULL` | Case insensitive direct match of _uid_ field |
| datasource_id | `int` | `NULL` | Match by exact _datasource_id_ |
| url | `str` | `NULL` | Case insensitive direct match of _url_ field |
| source | `str` | `NULL` | Case insensitive direct match of _source_ field |
"""
datasources = DataSource.objects.all().order_by('id')
datasources = list(datasources.values('id', 'name', 'url', 'uid', 'source'))
params = gen_utils.parse_model_field_query(DataSource, request, ignored_fields=['description'])
if params is not None:
datasources = DataSource.objects.filter(**params)
else:
datasources = DataSource.objects.all()

search = request.query_params.get('search')
if not gen_utils.is_empty_string(search) and len(search.strip()) > 3:
datasources = datasources.annotate(
similarity=(
TrigramWordSimilarity(search, 'name') + \
TrigramWordSimilarity(search, 'description')
)
) \
.filter(Q(similarity__gte=0.7)) \
.order_by('-similarity')
else:
datasources = datasources.order_by('id')

return Response(
data=datasources,
data=datasources.values('id', 'name', 'description', 'url', 'uid', 'datasource_id', 'source'),
status=status.HTTP_200_OK
)

@api_view(['GET'])
@permission_classes([IsAuthenticatedOrReadOnly])
def get_datasource_internal_detail(request, datasource_id):
"""
Get detail of specified datasource by by its internal Id
"""
query = None
if gen_utils.parse_int(datasource_id, default=None) is not None:
query = { 'id': int(datasource_id) }

if not query:
return Response(
data={
'message': 'Invalid id, expected int-like value'
},
content_type='json',
status=status.HTTP_400_BAD_REQUEST
)

datasource = DataSource.objects.filter(**query)
if not datasource.exists():
return Response(
data={
'message': 'Datasource with this internal Id does not exist'
},
content_type='json',
status=status.HTTP_404_NOT_FOUND
)

datasource = datasource.first()

# Get all templates and their versions where data_sources exist
templates = Template.history.filter(
definition__fields__has_key='data_sources'
) \
.annotate(
was_deleted=Subquery(
Template.history.filter(
id=OuterRef('id'),
history_date__gte=OuterRef('history_date'),
history_type='-'
)
.order_by('id', '-history_id')
.distinct('id')
.values('id')
)
) \
.exclude(was_deleted__isnull=False) \
.order_by('id', '-template_version', '-history_id') \
.distinct('id', 'template_version')

template_ids = list(templates.values_list('id', flat=True))
template_versions = list(templates.values_list('template_version', flat=True))

# Get all published entities with this datasource
entities = GenericEntity.history.filter(
template_id__in=template_ids,
template_version__in=template_versions,
publish_status=constants.APPROVAL_STATUS.APPROVED.value
) \
.extra(where=[f"""
exists(
select 1
from jsonb_array_elements(
case jsonb_typeof(template_data->'data_sources') when 'array'
then template_data->'data_sources'
else '[]'
end
) as val
where val in ('{datasource.id}')
)"""
]) \
.order_by('id', '-history_id') \
.distinct('id')

# Format results
entities = api_utils.annotate_linked_entities(entities)

result = {
'id': datasource.id,
'name': datasource.name,
'url': datasource.url,
'uid': datasource.uid,
'description': datasource.description,
'source': datasource.source,
'phenotypes': list(entities)
}

return Response(
data=result,
status=status.HTTP_200_OK
)

@api_view(['GET'])
@permission_classes([IsAuthenticatedOrReadOnly])
def get_datasource_detail(request, datasource_id):
"""
Get detail of specified datasource by datasource_id (id or HDRUK UUID for
linkage between applications), including associated published entities
Get detail of specified datasource by `datasource_id`, _i.e._ the HDRUK DataSource `pid` or its `UUID` for linkage between applications, including associated published entities.
"""
query = None
if gen_utils.is_valid_uuid(datasource_id):
query = { 'uid': datasource_id }
elif gen_utils.parse_int(datasource_id, default=None) is not None:
query = { 'id': int(datasource_id) }
query = { 'datasource_id': int(datasource_id) }

if not query:
return Response(
Expand Down
Loading
Loading