def generate_archive_patient_study_image_set():
    patient11 = PatientFactory()
    patient12 = PatientFactory()
    study111 = StudyFactory(patient=patient11)
    study112 = StudyFactory(patient=patient11)
    study113 = StudyFactory(patient=patient11)
    study121 = StudyFactory(patient=patient12)
    study122 = StudyFactory(patient=patient12)
    images111 = ImageFactoryWithoutImageFile.create_batch(4, study=study111)
    images112 = ImageFactoryWithoutImageFile.create_batch(5, study=study112)
    images113 = ImageFactoryWithoutImageFile.create_batch(6, study=study113)
    images121 = ImageFactoryWithoutImageFile.create_batch(2, study=study121)
    images122 = ImageFactoryWithoutImageFile.create_batch(3, study=study122)
    images211 = ImageFactoryWithoutImageFile.create_batch(4, study=None)
    archive1 = ArchiveFactory.create(
        images=[*images111, *images112, *images113, *images121, *images122])
    archive2 = ArchiveFactory.create(images=images211)
    return ArchivePatientStudyImageSet(
        archive1=archive1,
        patient11=patient11,
        patient12=patient12,
        study111=study111,
        study112=study112,
        study113=study113,
        study121=study121,
        study122=study122,
        images111=images111,
        images112=images112,
        images113=images113,
        images121=images121,
        images122=images122,
        archive2=archive2,
        images211=images211,
    )
def create_some_datastructure_data(archive_pars=None, ):
    patient_pars = {}
    study_pars = {}
    image_cf_pars = {}
    oct_study_pars = {}
    image_obs_pars = {}
    image_oct_pars = {}

    if archive_pars is None:
        archive_pars = {}

    # Create datastructures
    patient = PatientFactory(**patient_pars)
    study = StudyFactory(patient=patient, **study_pars)
    image_cf = ImageFactoryWithImageFile(
        study=study, modality__modality=settings.MODALITY_CF, **image_cf_pars)
    study_oct = StudyFactory(patient=patient, **oct_study_pars)
    # oct/obs image name has to end with OCT.fds for obs image recognition
    oct_obs_fake_name = "OBS_OCT.fds"
    image_obs = ImageFactoryWithImageFile(
        study=study_oct,
        modality__modality=settings.MODALITY_CF,
        name=oct_obs_fake_name,
        **image_obs_pars,
    )
    image_oct = ImageFactoryWithImageFile(
        study=study_oct,
        modality__modality=settings.MODALITY_OCT,
        name=
        oct_obs_fake_name,  # OCT image name has to be equal to OBS image name
        **image_oct_pars,
    )
    archive = ArchiveFactory.create(images=(image_oct, image_cf, image_obs),
                                    **archive_pars)
    return {
        "archive": archive,
        "patient": patient,
        "study": study,
        "image_cf": image_cf,
        "study_oct": study_oct,
        "image_obs": image_obs,
        "image_oct": image_oct,
    }
def get_response_status(client,
                        reverse_name,
                        data,
                        user="******",
                        annotation_data=None):
    auth_header = get_auth_token_header(user)
    url = reverse(reverse_name)

    if annotation_data:
        # create objects that need to exist in database before request is made
        patient = PatientFactory(name=data.get("patient_identifier"))
        existing_models = {"studies": [], "series": [], "images": []}
        images = []
        for data_row in data.get("data"):
            if (data_row.get("study_identifier")
                    not in existing_models["studies"]):
                study = StudyFactory(name=data_row.get("study_identifier"),
                                     patient=patient)
                existing_models["studies"].append(study.name)
            else:
                study = Study.objects.get(
                    name=data_row.get("study_identifier"))

            if (data_row.get("image_identifier")
                    not in existing_models["images"]):
                image = ImageFactory(name=data_row.get("image_identifier"),
                                     study=study)
                existing_models["images"].append(image.name)
                images.append(image)
        archive = ArchiveFactory(name=data.get("archive_identifier"),
                                 images=images)

        response = client.post(
            url,
            data=json.dumps(data),
            content_type="application/json",
            **auth_header,
        )
    else:
        response = client.post(url, data=data, **auth_header)
    return response.status_code
Beispiel #4
0
 def test_study_str(self):
     model = StudyFactory()
     assert str(model) == "{} <{} {}>".format(model.patient,
                                              model.__class__.__name__,
                                              model.name)