コード例 #1
0
ファイル: dicom_str_test.py プロジェクト: yxiao009/diana2
def test_dcm_dt_strings():

    for _t in testv:

        assert dicom_time(_t["dt"]) == _t["dcm_tm"].split(".")[0]
        assert dicom_date(_t["dt"]) == _t["dcm_dt"]
        assert dicom_datetime(_t["dt"]) == (_t["dcm_dt"],
                                            _t["dcm_tm"].split(".")[0])
コード例 #2
0
    def __attrs_post_init__(self):

        self.meta = {
            **self.parent.meta, "InstanceDateTime": self.inst_datetime
        }
        self.tags = {
            **self.parent.tags, "InstanceNumber": self.inst_num,
            "SOPInstanceUID": self.instuid,
            "InstanceCreationDate": dicom_date(self.inst_datetime),
            "InstanceCreationTime": dicom_time(self.inst_datetime)
        }
コード例 #3
0
    def __attrs_post_init__(self):

        self.meta = {
            **self.parent.meta, "SeriesDateTime": self.series_datetime
        }
        self.tags = {
            **self.parent.tags, "SeriesDescription": self.ser_desc,
            "SeriesNumber": self.ser_num,
            "SeriesInstanceUID": self.seruid,
            "SeriesDate": dicom_date(self.series_datetime),
            "SeriesTime": dicom_time(self.series_datetime)
        }

        for i in range(1, self.n_instances + 1):
            self.children.append(MockInstance(parent=self, inst_num=i))
コード例 #4
0
ファイル: guid.py プロジェクト: yxiao009/diana2
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))
コード例 #5
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
コード例 #6
0
ファイル: ofind.py プロジェクト: devhliu/diana2
def ofind(ctx,
          source,
          accession_number,
          today,
          query, level,
          domain, retrieve):
    """Find studies matching yaml/json QUERY in SOURCE Orthanc or ProxiedDicom service.
     The optional proxy DOMAIN issues a remote-find to a manually proxied DICOM endpoint."""
    services = ctx.obj.get('services')

    click.echo(click.style('Orthanc Find', underline=True, bold=True))

    level = DicomLevel.from_label(level)
    S = Serializable.Factory.create(**services.get(source))

    # S = Orthanc(**services.get(source))
    if isinstance(query, str):
        query = yaml.safe_load(query)

    if accession_number:
        query["AccessionNumber"] = accession_number

    if today:
        dt = datetime.today()
        query['StudyDate'] = dicom_date(dt)

    # # For simple local Orthanc find, we don't need placeholder query attribs
    # if not isinstance(S, Orthanc) and not domain:
    #     if level==DicomLevel.STUDIES and not query.get("NumberOfStudyRelatedInstances"):
    #         query["NumberOfStudyRelatedInstances"] = ""
    #     if level==DicomLevel.STUDIES and not query.get("ModalitiesInStudy"):
    #         query["ModalitiesInStudy"] = ""
    #     if not query.get("StudyDate") and not query.get("StudyTime"):
    #         query["StudyDate"] = ""
    #         query["StudyTime"] = ""

    if domain and hasattr(S, "rfind"):
        result = S.rfind(query, domain, level, retrieve=retrieve)
    else:
        result = S.find(query, level, retrieve=retrieve)

    click.echo(pformat(result))
コード例 #7
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)