Beispiel #1
0
def mint_guid(name, birth_date=None, age=None, reference_date=None, sex="U"):

    mint = GUIDMint()
    sham = mint.get_sham_id(name=name,
                            dob=birth_date,
                            age=age,
                            reference_date=reference_date,
                            gender=sex)

    resp = {
        "name": dicom_name(sham['Name']),
        "birth_date": dicom_date(sham["BirthDate"]),
        "id": sham["ID"],
        "time_offset": sham["TimeOffset"]
    }

    return resp
Beispiel #2
0
def test_guids():

    M = GUIDMint()

    expected = {
        'ID': 'JGHVCZSDBOFIA2QZ4H6EI43K4HAPB3IM',
        'Name': ['JACKSITS', 'GENE', 'H'],
        'BirthDate': datetime.date(2007, 10, 8),
        'TimeOffset': datetime.timedelta(-86, 3040)
    }

    # expected = ('JGHVCZSDBOFIA2QZ4H6EI43K4HAPB3IM', 'JAMESON^GRAHAM^H', '20080209')

    s = "FOO^BAR^Z^^"
    age = 10
    reference_date = "2018-01-01"

    out = M.get_sham_id(name=s, age=age, reference_date=reference_date)
    logging.debug(out)

    assert (out == expected)

    s = "Foo, Bar Z"
    age = 10
    reference_date = "1/1/2018"

    out = M.get_sham_id(name=s, age=age, reference_date=reference_date)
    logging.debug(out)

    s = "Bar Z Foo"
    age = 10
    reference_date = "January 1, 2018"

    out = M.get_sham_id(name=s, age=age, reference_date=reference_date)
    logging.debug(out)

    assert (out == expected)
Beispiel #3
0
def guid(ctx, name, dob, gender, age, reference_date):
    """Generate a globally unique sham ID from NAME, DOB, and GENDER."""

    click.echo(click.style('Generating GUID', underline=True, bold=True))

    sham = GUIDMint.get_sham_id(name=name, dob=dob, gender=gender,
                                age=age, reference_date=reference_date)

    resp = {
        "name": dicom_name(sham['Name']),
        "birth_date": dicom_date(sham["BirthDate"]),
        "id": sham["ID"],
        "time_offset": sham["TimeOffset"].__str__()
    }

    click.echo(pformat(resp))
Beispiel #4
0
def test_guid_genders():

    M = GUIDMint()

    expected = {
        'ID': 'WHLOKMAGICLQGYKC3ZQLLMFKMOX3ZAP2',
        'Name': ['WAGENAAR', 'HERIBERTO', 'L'],
        'BirthDate': datetime.date(1999, 10, 8),
        'TimeOffset': datetime.timedelta(-86, 85464)
    }

    s = "Bar Z Foo"
    dob = "2000-01-01"

    out = M.get_sham_id(name=s, dob=dob)
    assert (out == expected)

    out = M.get_sham_id(name=s, dob=dob, gender="U")
    assert (out == expected)

    out = M.get_sham_id(name=s, dob=dob, gender="u")
    assert (out == expected)

    out = M.get_sham_id(name=s, dob=dob, gender="UNKNOWN")
    assert (out == expected)

    out = M.get_sham_id(name=s, dob=dob, gender="unknown")
    assert (out == expected)

    out = M.get_sham_id(name=s, dob=dob, gender="")
    assert (out == expected)

    out = M.get_sham_id(name=s, dob=dob, gender="ABCD")
    assert (out == expected)

    expected = {
        'BirthDate': datetime.date(2000, 2, 19),
        'ID': 'HNG54O6PWWEIVTTQCYCVIYBENW4RK64G',
        'Name': ['HOWDESHELL', 'NELSON', 'G'],
        'TimeOffset': datetime.timedelta(48, 84883)
    }

    out = M.get_sham_id(name=s, dob=dob, gender="M")
    assert (out == expected)

    out = M.get_sham_id(name=s, dob=dob, gender="male")
    assert (out == expected)

    expected = {
        'BirthDate': datetime.date(1999, 10, 19),
        'ID': 'SIDYPTGPM27TDCMQOPSXFOAXECXJGOZZ',
        'Name': ['SARSON', 'IRENA', 'D'],
        'TimeOffset': datetime.timedelta(-74, 1033)
    }

    out = M.get_sham_id(name=s, dob=dob, gender="F")
    assert (out == expected)

    out = M.get_sham_id(name=s, dob=dob, gender="female")
    assert (out == expected)
Beispiel #5
0
    def __attrs_post_init__(self):

        name_seed = _R.random()
        gender = _R.choice(["M", "F"])
        age = _R.randint(18, 85)
        # logging.debug(name_seed)
        # logging.debug(gender)
        # logging.debug(age)

        patient_info = GUIDMint.get_sham_id(name=name_seed,
                                            age=age,
                                            gender=gender,
                                            reference_date=self.study_datetime)
        hash_str = patient_info["ID"] + self.study_datetime.isoformat()
        accession_num = md5(hash_str.encode("UTF-8")).hexdigest()

        self.stuid = dcm_mint.uid(patient_info["ID"], accession_num)

        self.meta = {"StudyDateTime": self.study_datetime}
        self.tags = {
            "AccessionNumber": accession_num,
            "PatientName": dicom_name(patient_info["Name"]),
            "PatientID": patient_info["ID"],
            "PatientSex": gender,
            "PatientBirthDate": dicom_date(patient_info["BirthDate"]),
            "StudyInstanceUID": self.stuid,
            "StudyDescription": self.study_description,
            "StationName": self.station_name,
            "Manufacturer": "Device Manufacturer",
            "ManufacturerModelName": "Device Model Name",
            "Institution": self.site_name,
            "Modality": self.modality,
            "StudyDate": dicom_date(self.study_datetime),
            "StudyTime": dicom_time(self.study_datetime)
        }

        distribution = {
            # Mod  SeriesDesc    NSer  NInst  P of at least one
            "CT": [("Localizer", 2, 2, 1, 1), ("Volume", 1, 3, 30, 200),
                   ("Fluoro", 0, 1, 10, 50, 0.2),
                   ("Reformat", 0, 2, 100, 200, 0.2),
                   ("Dose Report", 1, 1, 1, 1)],
            "MR": [("Localizer", 1, 3, 1, 1), ("Sequence", 3, 6, 10, 50),
                   ("Diffusion Map", 0, 1, 1, 1, 0.2)],
            "CR": [("PA", 1, 1, 1, 1), ("Lateral", 1, 1, 1, 1),
                   ("Bx", 0, 1, 1, 2, 0.2)],
            "US": [("Transverse", 3, 6, 1, 1), ("Sagittal", 3, 6, 1, 1),
                   ("Cine", 1, 3, 30, 50), ("Doppler", 0, 3, 1, 3, 0.2),
                   ("Bx", 0, 2, 3, 5, 0.2)]
        }

        series_defs = distribution[self.modality]

        ser_num = 0
        for s in series_defs:

            if s[0] == 0:
                if _R.random() < s[5]:
                    num_series_this_type = 1
                else:
                    num_series_this_type = 0
            else:
                num_series_this_type = _R.randint(s[1], s[2])

            for i in range(1, num_series_this_type + 1):

                ser_num += 1

                if num_series_this_type > 1:
                    ser_desc = "{} {}".format(s[0], i)
                else:
                    ser_desc = s[0]

                n_instances = _R.randint(s[3], s[4])

                S = MockSeries(parent=self,
                               ser_num=ser_num,
                               ser_desc=ser_desc,
                               n_instances=n_instances)
                self.children.append(S)