function resultDataToStudies(resultData) {
  var studies = [];

  resultData.forEach(function(study) {
    studies.push({
      studyInstanceUid: remoteGetValue(study['0020,000d']),
      // 00080005 = SpecificCharacterSet
      studyDate: remoteGetValue(study['0008,0020']),
      studyTime: remoteGetValue(study['0008,0030']),
      accessionNumber: remoteGetValue(study['0008,0050']),
      referringPhysicianName: remoteGetValue(study['0008,0090']),
      // 00081190 = URL
      patientName: remoteGetValue(study['0010,0010']),
      patientId: remoteGetValue(study['0010,0020']),
      patientBirthdate: remoteGetValue(study['0010,0030']),
      patientSex: remoteGetValue(study['0010,0040']),
      studyId: remoteGetValue(study['0020,0010']),
      numberOfStudyRelatedSeries: parseFloat(remoteGetValue(study['0020,1206'])),
      numberOfStudyRelatedInstances: parseFloat(remoteGetValue(study['0020,1208'])),
      studyDescription: remoteGetValue(study['0008,1030']),
      modalities: remoteGetValue(study['0008,0061'])
    });
  });
  return studies;
}

Services.REMOTE.Studies = function(server, filter) {
    var parameters = {
        PatientName: filter.patientName ? filter.patientName : "",
        PatientID: filter.patientId,
        AccessionNumber: filter.accessionNumber ? filter.accessionNumber : "",
        StudyDescription: "",
        StudyDate : "",
        StudyTime : "",
        ReferringPhysicianName : "",
        PatientBirthDate : "",
        PatientSex : "",
        StudyID : "",
        NumberOfStudyRelatedSeries : "",
        NumberOfStudyRelatedInstances : "",
        ModalitiesInStudy : ""
    };
    var remote = new OrthancRemote(server.root, server.sourceAE);
    var data = remote.findStudies(server.modality, parameters);

    return resultDataToStudies(data.results);
};