def METHOD_NAME(query, fields, dir_shapefile, shp_filename, TYPE):
    """ Convert and insert data into shapefile
    """
    from localities_osm.serializer.locality_osm import (
        LocalityOSMGeoSerializer
    )
    # Insert data into shapefile
    print('generating shape object for ' + shp_filename)
    shapefile_output = os.path.join(dir_shapefile, shp_filename)
    shp = shapefile.Writer(shapefile_output, TYPE)
    for field in fields:
        shp.field(str(field), 'C', 100)
    # insert data
    for healthsite_obj in query:
        values = []
        healthsite = LocalityOSMGeoSerializer(healthsite_obj).data
        properties = healthsite['properties']
        if not properties['centroid'] or not properties['centroid']['coordinates']:
            continue
        for field in fields:
            value = ''
            if field in properties['attributes']:
                value = properties['attributes'][field]
            elif field in properties:
                value = properties[field]
            try:
                value = value
            except AttributeError:
                pass
            values.append(value)
        if not values:
            continue
        if TYPE == shapefile.POINT:
            shp.point(
                properties['centroid']['coordinates'][0],
                properties['centroid']['coordinates'][1])
        elif TYPE == shapefile.POLYGON:
            coordinates = healthsite['geometry']['coordinates']
            if isinstance(healthsite_obj.geometry, Polygon):
                shp.poly(coordinates)
            else:
                shp.poly(coordinates[0])
        shp.record(*values)
    shp.close()
    # create .cpg
    cpg_file = os.path.join(dir_shapefile, shp_filename + '.cpg')
    file = open(cpg_file, 'w+')
    file.write('UTF-8')
    file.close()
    # create .prj
    prj_file = os.path.join(dir_shapefile, shp_filename + '.prj')
    prj = open(prj_file, 'w+')
    epsg = getWKT_PRJ('4326')
    prj.write(epsg)
    prj.close()