          'resourceType', 'Patient',
          'gender', sex,
          'birthDate', birth_date,
+         'active', TRUE,
          'name', ARRAY[
            json_build_object(
             'given', ARRAY[first_name],

  with first_names_source as (
    select CASE WHEN sex = 'M' THEN 'male' ELSE 'female' END as sex,
           first_name,
           row_number() over () from temp.first_names
    cross join generate_series(0, ceil(_total_count_::float
                                        / (select count(*) from temp.first_names)::float)::integer)
    order by random()
  ), last_names_source as (
    select last_name, row_number() over () from temp.last_names
    cross join generate_series(0, ceil(_total_count_::float
                                        / (select count(*) from temp.last_names)::float)::integer)
    order by random()
  ), street_names_source as (
    select street_name, row_number() over () from temp.street_names
    cross join generate_series(0, ceil(_total_count_::float
                                        / (select count(*) from temp.street_names)::float)::integer)
    order by random()
  ), cities_source as (
    select city, zip, state, row_number() over () from temp.cities
    cross join generate_series(0, ceil(_total_count_::float
                                        / (select count(*) from temp.cities)::float)::integer)
    order by random()
  ), languages_source as (
    select code as language_code,
           name as language_name,
           row_number() over () from temp.languages
    cross join generate_series(0, ceil(_total_count_::float
                                        / (select count(*) from temp.languages)::float)::integer)
    order by random()
  ), patient_data as (
    select

             'value', this.random(6000000, 100000000)::text,
             'label', 'MRN'
           )
         ],
         'managingOrganization', json_build_object(
           'reference', 'Organization/' || organization_id,
           'display', organization_name
         )
        )::jsonb as obj
        FROM patient_data
        LIMIT _total_count_
