示例#1
0
    def __init__(self, text=None, coding=None, block=None):
        self.text = text
        self.coding = None

        if coding:
            self.coding = Coding(block=coding)

        if block:
            if "coding" in block:
                self.coding = Coding(block=block.get('coding'))

            self.text = block.get('text')
示例#2
0
    def __init__(self,
                 value=None,
                 unit=None,
                 system=None,
                 code=None,
                 block=None):
        self.value = value
        self.unit = unit
        self.system = system
        self.code = code

        if block is not None:
            self.value = block.get('value')
            self.unit = block.get('unit')
            self.system = block.get('system')

            if 'code' in block:
                self.code = Coding(block.get('code'))
示例#3
0
def test_coding_block_init_multi():
    c1 = Coding(block=[{
        'code': 'A1',
        'system': 'sys1',
        'display': 'A1 Something'
    }, {
        'code': 'B10',
        'system': 'sysL',
        'display': 'Burritos'
    }])
    c2 = Coding(code='A1', system='sys1', display='A1 Some Other')
    c3 = Coding(code='A2', system='sys1', display='A2 something')
    c4 = Coding(code='A1', system='sys2', display='A1 something')

    assert (c1 == 'A1')
    assert (c1 == 'B10')
    assert (c1 != 'A2')
    assert (c1 == c2)
    assert (c1 != c3)
    assert (c1 != c4)

    obj = c1.as_obj()
    assert (len(obj) == 2)
    assert (obj[0]['code'] == 'A1')
    assert (obj[0]['system'] == 'sys1')
    assert (obj[1]['code'] == 'B10')
    assert (obj[1]['system'] == 'sysL')
示例#4
0
    def __init__(self, block):
        assert block['name'] == "match"
        self.equivalence = None
        self.concept = None
        self.source = ""

        for part in block['part']:
            if part['name'] == "equivalence":
                self.equivalence = part['valueCode']
            elif part['name'] == "concept":
                self.concept = Coding(block=part['valueCoding'])
            elif part['name'] == "source":
                self.source = part['valueUri']
示例#5
0
class SimpleQuantity(FhirBase):
    def __init__(self,
                 value=None,
                 unit=None,
                 system=None,
                 code=None,
                 block=None):
        self.value = value
        self.unit = unit
        self.system = system
        self.code = code

        if block is not None:
            self.value = block.get('value')
            self.unit = block.get('unit')
            self.system = block.get('system')

            if 'code' in block:
                self.code = Coding(block.get('code'))

    def __eq__(self, value):
        "Check to see if this matches the string or another text object"

        if value is None:
            return False
        # This is a bit more complicated. Let's assume that a real range
        # can be separated by a "-"
        if type(value) is str:
            return self.value == float(value)

        if type(value) in [int, float]:
            return self.value == value

        return self.value == value.value

    def as_obj(self):
        "Convert to generic object"

        repr = {"value": self.value}

        self.add_kv(repr, 'unit')
        self.add_kv(repr, 'system')

        if self.code:
            repr['code'] = self.code.as_obj()

        return repr
示例#6
0
def test_coding_param_init():
    c1 = Coding(code='A1', system='sys1', display='A1 Something')
    c2 = Coding(code='A1', system='sys1', display='A1 Some Other')
    c3 = Coding(code='A2', system='sys1', display='A2 something')
    c4 = Coding(code='A1', system='sys2', display='A1 something')

    assert (c1 == 'A1')
    assert (c1 != 'A2')
    assert (c1 == c2)
    assert (c1 != c3)
    assert (c1 != c4)

    obj = c1.as_obj()
    assert (obj['code'] == 'A1')
    assert (obj['system'] == 'sys1')
示例#7
0
def test_coding_param_init_as_array():
    c1 = Coding(code='A1', system='sys1', display='A1 Something', is_list=True)
    c2 = Coding(code='A1', system='sys1', display='A1 Some Other')
    c3 = Coding(code='A2', system='sys1', display='A2 something')
    c4 = Coding(code='A1', system='sys2', display='A1 something')

    assert (c1 == 'A1')
    assert (c1 != 'A2')
    assert (c1 == c2)
    assert (c1 != c3)
    assert (c1 != c4)

    obj = c1.as_obj()
    assert (obj[0]['code'] == 'A1')
    assert (obj[0]['system'] == 'sys1')
    assert (len(obj) == 1)
示例#8
0
class CodeableConcept(FhirBase):
    def __init__(self, text=None, coding=None, block=None):
        self.text = text
        self.coding = None

        if coding:
            self.coding = Coding(block=coding)

        if block:
            if "coding" in block:
                self.coding = Coding(block=block.get('coding'))

            self.text = block.get('text')

    def to_str(self):
        if self.text:
            return self.text
        return self.coding.display

    def __eq__(self, cc):
        if self.coding:
            if type(cc) is str:
                return self.coding == cc
            if cc.coding:
                return cc.coding == self.coding

        if type(cc) is str:
            return self.text == cc
        return self.text == cc.text

    def as_obj(self):
        obj = {}

        self.add_kv(obj, 'text')
        if self.coding:
            obj['coding'] = self.coding.as_obj()

        return obj
示例#9
0
    def build_entity(cls, record, get_target_id_from_record):
        key = cls.get_key_components(record,
                                     get_target_id_from_record)['identifier']
        study_id = record[CONCEPT.STUDY.NAME]
        biospecimen_id = get_target_id_from_record(Specimen, record)
        subject_id = record[CONCEPT.PARTICIPANT.ID]
        variant_id = record[CONCEPT.DISCOVERY.VARIANT.ID]
        inheritance = record[CONCEPT.DISCOVERY.VARIANT.INHERITANCE]

        signif = record[CONCEPT.DISCOVERY.VARIANT.SIGNIFICANCE]

        entity = {
            "resourceType":
            DiscoveryImplication.resource_type,
            "id":
            get_target_id_from_record(DiscoveryImplication, record),
            "meta": {
                "profile": [
                    f"http://hl7.org/fhir/StructureDefinition/{DiscoveryImplication.resource_type}"
                ]
            },
            "identifier":
            Identifier(system=cls.identifier_system, value=key,
                       is_list=True).as_obj(),
            "status":
            "final",
            "category": [{
                "coding":
                Coding(
                    system=
                    "http://terminology.hl7.org/CodeSystem/observation-category",
                    code="laboratory",
                    is_list=True).as_obj()
            }],
            "code": {
                "coding":
                Coding(
                    system=
                    "http://hl7.org/fhir/uv/genomics-reporting/CodeSystem/tbd-codes",
                    code="diagnostic-implication",
                    display="Diagnostic Implication",
                    is_list=True).as_obj()
            },
            "specimen":
            Reference(ref=f"{Specimen.resource_type}/{biospecimen_id}",
                      display="Specimen").as_obj(),
            "derivedFrom": [
                Reference(
                    ref=
                    f"{DiscoveryVariant.resource_type}/{get_target_id_from_record(DiscoveryVariant, record)}"
                ).as_obj()
            ],
            "component": []
        }

        if inheritance:
            entity['component'].append({
                "code": {
                    "coding":
                    Coding(
                        system=
                        "http://hl7.org/fhir/uv/genomics-reporting/CodeSystem/tbd-codes",
                        code="mode-of-inheritance",
                        display="mode-of-inheritance",
                        is_list=True).as_obj()
                },
                "valueCodeableConcept": {
                    "coding":
                    Coding(
                        system=
                        "http://ghr.nlm.nih.gov/primer/inheritance/inheritancepatterns",
                        code=inheritance,
                        display=inheritance,
                        is_list=True).as_obj()
                }
            })

        if signif:
            entity['component'].append({
                "code": {
                    "coding":
                    Coding(
                        system="http://loinc.org",
                        code="53037-8",
                        display="Genetic variation clinical significance [Imp]",
                        is_list=True).as_obj()
                },
                "valueCodeableConcept":
                add_loinc_coding(signif)
            })

        # If we end up wanting to apply the clinvar url as an extension, it would be like this:
        # https://www.ncbi.nlm.nih.gov/clinvar/variation/{cvid}/#clinical-assertions
        # cvid is what we get when we probed the NIH for the hgsvc match

        return entity