Skip to content

Commit

Permalink
Merge pull request #1314 from mskcc/fix/patient_record
Browse files Browse the repository at this point in the history
Fix updating samples in Patient record and migration
  • Loading branch information
sivkovic authored Jan 10, 2024
2 parents 492b91d + 4becac7 commit 6c71158
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions file_system/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def create_or_update_patient(self, patient_id, sex, sample):
patient = Patient.objects.create(patient_id=patient_id, sex=sex)
if sample not in patient.samples:
patient.samples.append(sample)
patient.save(do_not_version=True)
return patient

def save(self, *args, **kwargs):
Expand Down
11 changes: 11 additions & 0 deletions populate_patients_samples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.conf import settings
from file_system.models import Patient
from file_system.repository import FileRepository


def populate_patient_samples():
from_lims = FileRepository.filter(file_group=settings.IMPORT_FILE_GROUP, values_metadata="cmoPatientId").all()
for p in Patient.objects.filter(patient_id__in=from_lims).all():
samples = FileRepository.filter(metadata={"cmoPatientId": p.patient_id}, values_metadata="primaryId").all()
p.samples = list(samples)
p.save()

0 comments on commit 6c71158

Please sign in to comment.