Skip to content

Commit

Permalink
Merge pull request #39 from OHDSI/cohort-importer-route-fi
Browse files Browse the repository at this point in the history
Rename to match endpoint; follow webapi endpoint pattern
  • Loading branch information
charhart committed Apr 30, 2015
2 parents bd83f5f + 78db1e0 commit d73ab0c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ohdsi.webapi.cohortimportexport;
package org.ohdsi.webapi.cohort;

import java.io.Serializable;
import java.util.Date;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ohdsi.webapi.cohortimportexport;
package org.ohdsi.webapi.cohort;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ohdsi.webapi.cohortimportexport;
package org.ohdsi.webapi.service;

import java.util.List;

Expand All @@ -11,18 +11,20 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.ohdsi.webapi.cohort.CohortEntity;
import org.ohdsi.webapi.cohort.CohortRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

/**
* Imports exports cohorts using something like http://localhost:8080/WebAPI/import/cohort/7
*
* Service to read/write to the Cohort table
*/
@Path("/cohort/")
@Component
public class CohortImportExportService {
public class CohortService {

@Autowired
public CohortRepository cohortRepository;
Expand All @@ -33,19 +35,30 @@ public class CohortImportExportService {
@Autowired
private EntityManager em;

/**
* Retrieves all cohort entities for the given cohort definition id
* from the COHORT table
*
* @param id Cohort Definition id
* @return List of CohortEntity
*/
@GET
@Path("import/{id}")
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public List<CohortEntity> getCohortListById(@PathParam("id") final long id) {

List<CohortEntity> d = this.cohortRepository.getAllCohortsForId(id);


return d;
}

/**
* Imports a List of CohortEntity into the COHORT table
*
* @param cohort List of CohortEntity
* @return status
*/
@POST
@Path("export")
@Path("import")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String saveCohortListToCDM(final List<CohortEntity> cohort) {
Expand All @@ -66,9 +79,7 @@ public Void doInTransaction(TransactionStatus status) {
return null;
}
});

//System.out.println(cohort);


return "ok";
}

Expand Down

0 comments on commit d73ab0c

Please sign in to comment.