 svcs = angular.module 'qiprofile.services', ['ngResource']
 
 svcs.factory 'Subject', ['$q', '$resource', ($q, $resource) ->
-  $resource '/api/subjects/:number/', null,
+  # The Subject resource recognizes a 'get' query method on the
+  # subject id, but qiprofile does not call this in practice.
+  # Fetching a Subject is done by a query on the subject project,
+  # collection and number, which returns a singleton or empty
+  # array.
+  $resource '/api/subjects/:id', null,
+    query:
+      method: 'GET'
+      isArray: true
+      transformResponse: (data) -> angular.fromJson(data)._items
     detail:
       method: 'GET'
       url: '/api/subject-detail/:id/'

  # cached object image content data is not loaded until the image
  # object load() function is called.
  #
  # @param parent the ImageContainer scan or registration object
  # @returns the image objects
  imagesFor: (parent) ->
    cache(parent) or cache(parent, parent.files...)

    if typeof date == 'string' or date instanceof String
      # Reset the attribute to a date.
      obj[attr] = moment(date)
  
  
svcs.factory 'Chart', ->
  # Builds the nvd3 chart format for the given input resource
