defmodule ApiWeb.StudiesJSON do
  def index(%{results: results}) do
    %{data: for(result <- results.data, do: data(result)), last_page: results.last_page}
  end

  defp data(result) do
    %{
      idstudy: Map.get(result, "idstudy"),
      accessionnumber: Map.get(result, "accessionnumber"),
      proceduredescription: Map.get(result, "proceduredescription"),
      insurer: Map.get(result, "insurer"),
      sitename: Map.get(result, "sitename"),
      modality: Map.get(result, "modality"),
      nrodocumento: Map.get(result, "nrodocumento"),
      patientname: Map.get(result, "patientname"),
      region: Map.get(result, "region"),
      studydate: Map.get(result, "studydate"),
      studytime: Map.get(result, "studytime"),
      hasaudio: Map.get(result, "hasaudio")
    }
  end
end
