Skip to content
Open
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
17 changes: 11 additions & 6 deletions medcat-trainer/webapp/api/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ def __str__(self):
return str(self.label)


def update_project_last_modified(project: 'ProjectAnnotateEntities', last_modified):
# so that the local project last_modified is updated
project.last_modified = last_modified
# so that the project last_modified is updated in the database
ProjectAnnotateEntities.objects.filter(pk=project.id).update(
last_modified=last_modified
)

class EntityRelation(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
project = models.ForeignKey('Project', on_delete=models.CASCADE)
Expand All @@ -370,8 +378,7 @@ class Meta:

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
self.project.last_modified = self.last_modified
self.project.save()
update_project_last_modified(self.project, self.last_modified)

def __str__(self):
return f'{self.start_entity} - {self.relation} - {self.end_entity}'
Expand Down Expand Up @@ -402,8 +409,7 @@ class Meta:

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
self.project.last_modified = self.last_modified
self.project.save()
update_project_last_modified(self.project, self.last_modified)

def __str__(self):
return str(self.entity)
Expand Down Expand Up @@ -551,8 +557,7 @@ class MetaAnnotation(models.Model):

def save(self, *args, **kwargs):
super().save(*args, **kwargs)
self.annotated_entity.last_modified = self.last_modified
self.annotated_entity.save()
update_project_last_modified(self.annotated_entity.project, self.last_modified)

def __str__(self):
return str(self.annotated_entity)
Expand Down
17 changes: 12 additions & 5 deletions medcat-trainer/webapp/api/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
from typing import List
import dill
from functools import lru_cache

import requests
from background_task import background
Expand Down Expand Up @@ -482,15 +483,21 @@ def prep_docs(project_id: List[int], doc_ids: List[int], user_id: int):
project.id, project.prepared_documents)


@lru_cache(maxsize=8)
def _load_cuis_from_file(path):
with open(path) as f:
return json.load(f)


@receiver(post_save, sender=ProjectAnnotateEntities)
def save_project_anno(sender, instance, **kwargs):
if instance.cuis_file:
post_save.disconnect(save_project_anno, sender=ProjectAnnotateEntities)
cuis_from_file = json.load(open(instance.cuis_file.path))
cuis_from_file = _load_cuis_from_file(instance.cuis_file.path)
cui_list = [c.strip() for c in instance.cuis.split(',')]
instance.cuis = ','.join(set(cui_list) - set(cuis_from_file))
instance.save()
post_save.connect(save_project_anno, sender=ProjectAnnotateEntities)
new_cuis = ','.join(set(cui_list) - set(cuis_from_file))
if new_cuis != instance.cuis:
instance.cuis = new_cuis
ProjectAnnotateEntities.objects.filter(pk=instance.pk).update(cuis=new_cuis)


def env_str_to_bool(var: str, default: bool):
Expand Down
Loading