Exemple #1
0
def human_name(source):
    """
    Receive a dict with Name elements
    :param source: {}
    :return: hn {}

{
  "resourceType" : "HumanName",
  // from Element: extension
  "use" : "<code>", // usual | official | temp | nickname | anonymous | old | maiden
  "text" : "<string>", // Text representation of the full name
  "family" : ["<string>"], // Family name (often called 'Surname')
  "given" : ["<string>"], // Given names (not always 'first'). Includes middle names
  "prefix" : ["<string>"], // Parts that come before the name
  "suffix" : ["<string>"], // Parts that come after the name
  "period" : { Period } // Time period when name was/is in use
}

    """
    # Setup the dictionary
    hn = {}

    if settings.DEBUG:
        print("Source:", source)
    # Map values across to new dictionary
    hn['resourceType'] = "HumanName"
    hn['use'] = assign_str(source, 'use', "usual")
    hn['suffix'] = assign_str(
        source,
        'suffix',
    )
    hn['prefix'] = assign_str(
        source,
        'prefix',
    )
    hn['family'] = assign_str(source, 'family')
    hn['given'] = assign_str(source, 'given')
    hn['period'] = assign_str(source, 'period')

    # Build the Text section
    if 'text' in source:
        hn['text'] = source['text']
    else:
        hn['text'] = build_str("", 'prefix', source)
        hn['text'] = build_str(hn['text'], 'given', source)
        hn['text'] = build_str(hn['text'], 'family', source)
        hn['text'] = build_str(hn['text'], 'suffix', source)

    # Return the dictionary
    # if settings.DEBUG:
    # print("Human_Name element:", hn)

    return hn
def human_name(source):
    """
    Receive a dict with Name elements
    :param source: {}
    :return: hn {}

{
  "resourceType" : "HumanName",
  // from Element: extension
  "use" : "<code>", // usual | official | temp | nickname | anonymous | old | maiden
  "text" : "<string>", // Text representation of the full name
  "family" : ["<string>"], // Family name (often called 'Surname')
  "given" : ["<string>"], // Given names (not always 'first'). Includes middle names
  "prefix" : ["<string>"], // Parts that come before the name
  "suffix" : ["<string>"], // Parts that come after the name
  "period" : { Period } // Time period when name was/is in use
}

    """
    # Setup the dictionary
    hn = {}

    if settings.DEBUG:
        print("Source:", source)
    # Map values across to new dictionary
    hn['resourceType'] = "HumanName"
    hn['use'] = assign_str(source, 'use', "usual")
    hn['suffix'] = assign_str(source, 'suffix',)
    hn['prefix'] = assign_str(source, 'prefix',)
    hn['family'] = assign_str(source, 'family')
    hn['given']  = assign_str(source, 'given')
    hn['period'] = assign_str(source, 'period')

    # Build the Text section
    if 'text' in source:
        hn['text'] = source['text']
    else:
        hn['text'] = build_str("", 'prefix', source)
        hn['text'] = build_str(hn['text'], 'given', source)
        hn['text'] = build_str(hn['text'], 'family', source)
        hn['text'] = build_str(hn['text'], 'suffix', source)

    # Return the dictionary
    # if settings.DEBUG:
        # print("Human_Name element:", hn)

    return hn
def address(source):
    """
    Receive a dict with Address Elements
    :param source:
    :return: Ad {}

{
  "resourceType" : "Address",
  // from Element: extension
  "use" : "<code>", // home | work | temp | old - purpose of this address
  "type" : "<code>", // postal | physical | both
  "text" : "<string>", // Text representation of the address
  "line" : ["<string>"], // Street name, number, direction & P.O. Box etc
  "city" : "<string>", // Name of city, town etc.
  "district" : "<string>", // District name (aka county)
  "state" : "<string>", // Sub-unit of country (abbreviations ok)
  "postalCode" : "<string>", // Postal code for area
  "country" : "<string>", // Country (can be ISO 3166 3 letter code)
  "period" : { Period } // Time period when address was/is in use
}

    """
    # Setup dictionary
    ad = {}

    # Map values across to new dictionary
    ad['resourceType'] = "Address"
    ad['use']        = assign_str(source, 'use',)
    ad['type']       = assign_str(source, 'type',)
    ad['line']       = assign_str(source, 'line',)
    ad['city']       = assign_str(source, 'city',)
    ad['district']   = assign_str(source, 'district',)
    ad['state']      = assign_str(source, 'state',)
    ad['postalCode'] = assign_str(source, 'postalCode',)
    ad['country']    = assign_str(source, 'country',)
    ad['period']     = assign_str(source, 'period',)

    if 'text' in source:
        ad['text'] = source['text']
    else:
        ad['text'] = build_str("", 'line', source, delimiter=", ")
        ad['text'] = build_str(ad['text'], 'city', source, delimiter=", ")
        ad['text'] = build_str(ad['text'], 'state', source)
        ad['text'] = build_str(ad['text'], 'postalCode', source, delimiter=", ")
        ad['text'] = build_str(ad['text'], 'country', source, delimiter=".")

    return ad
Exemple #4
0
def address(source):
    """
    Receive a dict with Address Elements
    :param source:
    :return: Ad {}

{
  "resourceType" : "Address",
  // from Element: extension
  "use" : "<code>", // home | work | temp | old - purpose of this address
  "type" : "<code>", // postal | physical | both
  "text" : "<string>", // Text representation of the address
  "line" : ["<string>"], // Street name, number, direction & P.O. Box etc
  "city" : "<string>", // Name of city, town etc.
  "district" : "<string>", // District name (aka county)
  "state" : "<string>", // Sub-unit of country (abbreviations ok)
  "postalCode" : "<string>", // Postal code for area
  "country" : "<string>", // Country (can be ISO 3166 3 letter code)
  "period" : { Period } // Time period when address was/is in use
}

    """
    # Setup dictionary
    ad = {}

    # Map values across to new dictionary
    ad['resourceType'] = "Address"
    ad['use'] = assign_str(
        source,
        'use',
    )
    ad['type'] = assign_str(
        source,
        'type',
    )
    ad['line'] = assign_str(
        source,
        'line',
    )
    ad['city'] = assign_str(
        source,
        'city',
    )
    ad['district'] = assign_str(
        source,
        'district',
    )
    ad['state'] = assign_str(
        source,
        'state',
    )
    ad['postalCode'] = assign_str(
        source,
        'postalCode',
    )
    ad['country'] = assign_str(
        source,
        'country',
    )
    ad['period'] = assign_str(
        source,
        'period',
    )

    if 'text' in source:
        ad['text'] = source['text']
    else:
        ad['text'] = build_str("", 'line', source, delimiter=", ")
        ad['text'] = build_str(ad['text'], 'city', source, delimiter=", ")
        ad['text'] = build_str(ad['text'], 'state', source)
        ad['text'] = build_str(ad['text'],
                               'postalCode',
                               source,
                               delimiter=", ")
        ad['text'] = build_str(ad['text'], 'country', source, delimiter=".")

    return ad