@Read() public Patient readPatient(@IdParam IdType theId) { Patient retVal = new Patient(); // ..populate demographics, contact, or anything else you usually would.. // Populate some tags retVal.getMeta().addTag("http://animals", "Dog", "Canine Patient"); // TODO: more realistic example retVal.getMeta().addTag("http://personality", "Friendly", "Friendly"); // TODO: more realistic example return retVal; } //END SNIPPET: readTags
@Create public MethodOutcome createPatientResource(@ResourceParam Patient thePatient) { // ..save the resouce.. IdType id = new IdType("123"); // the new databse primary key for this resource // Get the tag list List<Coding> tags = thePatient.getMeta().getTag(); for (Coding tag : tags) { // process/save each tag somehow } return new MethodOutcome(id); } //END SNIPPET: createTags
public void clientRead() { //START SNIPPET: clientReadTags IPatientClient client = FhirContext.forDstu2().newRestfulClient(IPatientClient.class, "http://foo/fhir"); Patient patient = client.readPatient(new IdType("1234")); // Access the tag list List<Coding> tagList = patient.getMeta().getTag(); for (Coding next : tagList) { // ..process the tags somehow.. } //END SNIPPET: clientReadTags //START SNIPPET: clientCreateTags Patient newPatient = new Patient(); // Populate the resource object newPatient.addIdentifier().setUse(IdentifierUse.OFFICIAL).setValue("123"); newPatient.addName().setFamily("Jones").addGiven("Frank"); // Populate some tags newPatient.getMeta().addTag("http://animals", "Dog", "Canine Patient"); // TODO: more realistic example newPatient.getMeta().addTag("http://personality", "Friendly", "Friendly"); // TODO: more realistic example // ...invoke the create method on the client... //END SNIPPET: clientCreateTags }
@Update public MethodOutcome updatePatientPrefer( @ResourceParam Patient thePatient, @IdParam IdType theId) { // Save the patient to the database // Update the version and last updated time on the resource IdType updatedId = theId.withVersion("123"); thePatient.setId(updatedId); InstantType lastUpdated = InstantType.withCurrentTime(); thePatient.getMeta().setLastUpdatedElement(lastUpdated); // Add the resource to the outcome, so that it can be returned by the server // if the client requests it MethodOutcome outcome = new MethodOutcome(); outcome.setId(updatedId); outcome.setResource(thePatient); return outcome; } //END SNIPPET: updatePrefer