More tutorial work

This commit is contained in:
James Agnew 2014-11-21 11:18:04 -05:00
parent ae3e030c3e
commit b416944f89
3 changed files with 105 additions and 0 deletions

View File

@ -0,0 +1,46 @@
package ca.uhn.fhir.example.ex1;
import java.util.List;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.Create;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.OptionalParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.param.StringParam;
import ca.uhn.fhir.rest.server.IResourceProvider;
/**
* Note, this is an incomplete example of a resource provider. It does not
* do anything but is used as examples of methods that can be used.
*/
public class Example01_ResourceProviders implements IResourceProvider {
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;
}
@Read()
public Patient read(@IdParam IdDt theId) {
return null; // populate this
}
@Create
void create(@ResourceParam Patient thePatient) {
// save the resource
}
@Search
List<Patient> search(
@OptionalParam(name="family") StringParam theFamily,
@OptionalParam(name="given") StringParam theGiven
) {
return null; // populate this
}
}

View File

@ -0,0 +1,20 @@
package ca.uhn.fhir.example.ex1;
import javax.servlet.ServletException;
import ca.uhn.fhir.rest.server.RestfulServer;
public class Example01_SimpleRestfulServer extends RestfulServer {
private static final long serialVersionUID = 1L;
@Override
protected void initialize() throws ServletException {
}
}

View File

@ -0,0 +1,39 @@
package ca.uhn.fhir.example.ex1;
import java.util.HashMap;
import java.util.Map;
import ca.uhn.fhir.model.api.IResource;
import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.annotation.IdParam;
import ca.uhn.fhir.rest.annotation.Read;
import ca.uhn.fhir.rest.server.IResourceProvider;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
/**
* Note, this is an incomplete example of a resource provider. It shows a
* read method which reads from a HashMap, but does not have any way
* of putting things in that HashMap.
*/
public class Example02_PatientResourceProvider implements IResourceProvider {
private Map<IdDt, Patient> myPatients = new HashMap<IdDt, Patient>();
/** All Resource Providers must implement this method */
@Override
public Class<? extends IResource> getResourceType() {
return Patient.class;
}
/** Simple implementation of the "read" method */
@Read()
public Patient read(@IdParam IdDt theId) {
Patient retVal = myPatients.get(theId);
if (retVal == null) {
throw new ResourceNotFoundException(theId);
}
return retVal;
}
}