From 9808ccd309b8c2fb5157e1bce3c57856e99d8dc1 Mon Sep 17 00:00:00 2001 From: jamesagnew Date: Thu, 21 Jan 2016 06:41:04 -0500 Subject: [PATCH] Add some tests that can be enhanced for #286 - These don't yet validate anything useful but they have chains --- .../rest/server/PatientResourceProvider.java | 189 ++++++++++++++++++ .../ServerConformanceProviderDstu2Test.java | 45 ++++- 2 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/PatientResourceProvider.java diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/PatientResourceProvider.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/PatientResourceProvider.java new file mode 100644 index 00000000000..25693fcffd7 --- /dev/null +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/PatientResourceProvider.java @@ -0,0 +1,189 @@ + +package ca.uhn.fhir.rest.server; + +import java.util.Set; + +import ca.uhn.fhir.model.api.Include; +import ca.uhn.fhir.model.api.annotation.Description; +// +import ca.uhn.fhir.model.dstu2.resource.Organization; +import ca.uhn.fhir.model.dstu2.resource.Patient; +import ca.uhn.fhir.model.dstu2.resource.Practitioner; +import ca.uhn.fhir.rest.annotation.IncludeParam; +import ca.uhn.fhir.rest.annotation.OptionalParam; +import ca.uhn.fhir.rest.annotation.Search; +import ca.uhn.fhir.rest.annotation.Sort; +import ca.uhn.fhir.rest.api.SortSpec; +// import ca.uhn.fhir.model.dstu.resource.Binary; +// import ca.uhn.fhir.model.dstu2.resource.Bundle; +// import ca.uhn.fhir.model.api.Bundle; +import ca.uhn.fhir.rest.param.DateRangeParam; +import ca.uhn.fhir.rest.param.ReferenceAndListParam; +import ca.uhn.fhir.rest.param.StringAndListParam; +import ca.uhn.fhir.rest.param.TokenAndListParam; +import ca.uhn.fhir.rest.param.UriAndListParam; + +public class PatientResourceProvider implements IResourceProvider + { + + @Override + public Class getResourceType() { + return Patient.class; + } + + //@formatter:off + @Search() + public ca.uhn.fhir.rest.server.IBundleProvider search( + javax.servlet.http.HttpServletRequest theServletRequest, + + @Description(shortDefinition="The resource identity") + @OptionalParam(name="_id") + StringAndListParam theId, + + @Description(shortDefinition="The resource language") + @OptionalParam(name="_language") + StringAndListParam theResourceLanguage, + + @Description(shortDefinition="Search the contents of the resource's data using a fulltext search") + @OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_CONTENT) + StringAndListParam theFtContent, + + @Description(shortDefinition="Search the contents of the resource's narrative using a fulltext search") + @OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_TEXT) + StringAndListParam theFtText, + + @Description(shortDefinition="Search for resources which have the given tag") + @OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_TAG) + TokenAndListParam theSearchForTag, + + @Description(shortDefinition="Search for resources which have the given security labels") + @OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_SECURITY) + TokenAndListParam theSearchForSecurity, + + @Description(shortDefinition="Search for resources which have the given profile") + @OptionalParam(name=ca.uhn.fhir.rest.server.Constants.PARAM_PROFILE) + UriAndListParam theSearchForProfile, + + + @Description(shortDefinition="A patient identifier") + @OptionalParam(name="identifier") + TokenAndListParam theIdentifier, + + @Description(shortDefinition="A portion of either family or given name of the patient") + @OptionalParam(name="name") + StringAndListParam theName, + + @Description(shortDefinition="A portion of the family name of the patient") + @OptionalParam(name="family") + StringAndListParam theFamily, + + @Description(shortDefinition="A portion of the given name of the patient") + @OptionalParam(name="given") + StringAndListParam theGiven, + + @Description(shortDefinition="A portion of either family or given name using some kind of phonetic matching algorithm") + @OptionalParam(name="phonetic") + StringAndListParam thePhonetic, + + @Description(shortDefinition="The value in any kind of telecom details of the patient") + @OptionalParam(name="telecom") + TokenAndListParam theTelecom, + + @Description(shortDefinition="A value in a phone contact") + @OptionalParam(name="phone") + TokenAndListParam thePhone, + + @Description(shortDefinition="A value in an email contact") + @OptionalParam(name="email") + TokenAndListParam theEmail, + + @Description(shortDefinition="An address in any kind of address/part of the patient") + @OptionalParam(name="address") + StringAndListParam theAddress, + + @Description(shortDefinition="A city specified in an address") + @OptionalParam(name="address-city") + StringAndListParam theAddress_city, + + @Description(shortDefinition="A state specified in an address") + @OptionalParam(name="address-state") + StringAndListParam theAddress_state, + + @Description(shortDefinition="A postalCode specified in an address") + @OptionalParam(name="address-postalcode") + StringAndListParam theAddress_postalcode, + + @Description(shortDefinition="A country specified in an address") + @OptionalParam(name="address-country") + StringAndListParam theAddress_country, + + @Description(shortDefinition="A use code specified in an address") + @OptionalParam(name="address-use") + TokenAndListParam theAddress_use, + + @Description(shortDefinition="Gender of the patient") + @OptionalParam(name="gender") + TokenAndListParam theGender, + + @Description(shortDefinition="Language code (irrespective of use value)") + @OptionalParam(name="language") + TokenAndListParam theLanguage, + + @Description(shortDefinition="The patient's date of birth") + @OptionalParam(name="birthdate") + DateRangeParam theBirthdate, + + @Description(shortDefinition="The organization at which this person is a patient") + @OptionalParam(name="organization", targetTypes={ Organization.class } ) + ReferenceAndListParam theOrganization, + + @Description(shortDefinition="Patient's nominated care provider, could be a care manager, not the organization that manages the record") + @OptionalParam(name="careprovider", targetTypes={ Organization.class , Practitioner.class } ) + ReferenceAndListParam theCareprovider, + + @Description(shortDefinition="Whether the patient record is active") + @OptionalParam(name="active") + TokenAndListParam theActive, + + @Description(shortDefinition="The species for animal patients") + @OptionalParam(name="animal-species") + TokenAndListParam theAnimal_species, + + @Description(shortDefinition="The breed for animal patients") + @OptionalParam(name="animal-breed") + TokenAndListParam theAnimal_breed, + + @Description(shortDefinition="All patients linked to the given patient") + @OptionalParam(name="link", targetTypes={ Patient.class } ) + ReferenceAndListParam theLink, + + @Description(shortDefinition="This patient has been marked as deceased, or as a death date entered") + @OptionalParam(name="deceased") + TokenAndListParam theDeceased, + + @Description(shortDefinition="The date of death has been provided and satisfies this search value") + @OptionalParam(name="deathdate") + DateRangeParam theDeathdate, + + @IncludeParam(reverse=true) + Set theRevIncludes, + @Description(shortDefinition="Only return resources which were last updated as specified by the given range") + @OptionalParam(name="_lastUpdated") + DateRangeParam theLastUpdated, + + @IncludeParam(allow= { + "Patient:careprovider" , "Patient:link" , "Patient:organization" , "Patient:careprovider" , "Patient:link" , "Patient:organization" , "Patient:careprovider" , "Patient:link" , "Patient:organization" , "*" + }) + Set theIncludes, + + @Sort + SortSpec theSort, + + @ca.uhn.fhir.rest.annotation.Count + Integer theCount + ) { + return null; + } + //@formatter:on + +} diff --git a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderDstu2Test.java b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderDstu2Test.java index add3f9d601d..a8c5d8ba192 100644 --- a/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderDstu2Test.java +++ b/hapi-fhir-structures-dstu2/src/test/java/ca/uhn/fhir/rest/server/ServerConformanceProviderDstu2Test.java @@ -54,6 +54,7 @@ import ca.uhn.fhir.rest.method.BaseMethodBinding; import ca.uhn.fhir.rest.method.SearchMethodBinding; import ca.uhn.fhir.rest.method.SearchParameter; import ca.uhn.fhir.rest.param.DateRangeParam; +import ca.uhn.fhir.rest.param.ReferenceAndListParam; import ca.uhn.fhir.rest.param.TokenOrListParam; import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; import ca.uhn.fhir.validation.ValidationResult; @@ -392,6 +393,36 @@ public class ServerConformanceProviderDstu2Test { } + @Test + public void testSearchReferenceParameterDocumentation() throws Exception { + + RestfulServer rs = new RestfulServer(ourCtx); + rs.setProviders(new PatientResourceProvider()); + + ServerConformanceProvider sc = new ServerConformanceProvider(rs); + rs.setServerConformanceProvider(sc); + + rs.init(createServletConfig()); + + boolean found = false; + Collection resourceBindings = rs.getResourceBindings(); + for (ResourceBinding resourceBinding : resourceBindings) { + if (resourceBinding.getResourceName().equals("Patient")) { + List> methodBindings = resourceBinding.getMethodBindings(); + SearchMethodBinding binding = (SearchMethodBinding) methodBindings.get(0); + SearchParameter param = (SearchParameter) binding.getParameters().get(25); + assertEquals("The organization at which this person is a patient", param.getDescription()); + found = true; + } + } + assertTrue(found); + Conformance conformance = sc.getServerConformance(createHttpServletRequest()); + + String conf = ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance); + ourLog.info(conf); + + } + @Test public void testSystemHistorySupported() throws Exception { @@ -582,7 +613,19 @@ public class ServerConformanceProviderDstu2Test { public static class SearchProvider { @Search(type = Patient.class) - public Patient findPatient(@Description(shortDefinition = "The patient's identifier (MRN or other card number)") @RequiredParam(name = Patient.SP_IDENTIFIER) IdentifierDt theIdentifier) { + public Patient findPatient1( + @Description(shortDefinition = "The patient's identifier (MRN or other card number)") + @RequiredParam(name = Patient.SP_IDENTIFIER) + IdentifierDt theIdentifier) { + return null; + } + + @Search(type = Patient.class) + public Patient findPatient2( + @Description(shortDefinition="All patients linked to the given patient") + @OptionalParam(name="link", targetTypes={ Patient.class } ) + ReferenceAndListParam theLink + ) { return null; }