mirror of
https://github.com/hapifhir/hapi-fhir.git
synced 2025-03-25 01:18:37 +00:00
Workingon conformance operation for client
This commit is contained in:
parent
df2675867a
commit
8b6f00bb58
@ -1,8 +1,59 @@
|
||||
package ca.uhn.fhir.model.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.client.ClientInvocationHandler;
|
||||
import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
||||
|
||||
|
||||
|
||||
public abstract class BaseResourceReference extends BaseElement {
|
||||
|
||||
private IResource myResource;
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(BaseResourceReference.class);
|
||||
|
||||
/**
|
||||
* Gets the value(s) for <b>reference</b> (Relative, internal or absolute URL reference).
|
||||
* creating it if it does
|
||||
* not exist. Will not return <code>null</code>.
|
||||
*
|
||||
* <p>
|
||||
* <b>Definition:</b>
|
||||
* A reference to a location at which the other resource is found. The reference may a relative reference, in which case it is relative to the service base URL, or an absolute URL that resolves to the location where the resource is found. The reference may be version specific or not. If the reference is not to a FHIR RESTful server, then it should be assumed to be version specific. Internal fragment references (start with '#') refer to contained resources
|
||||
* </p>
|
||||
*/
|
||||
public abstract StringDt getReference();
|
||||
|
||||
public IResource loadResource(IRestfulClient theClient) throws IOException {
|
||||
if (myResource != null) {
|
||||
return myResource;
|
||||
}
|
||||
|
||||
ourLog.debug("Loading resource at URL: {}", getReference().getValue());
|
||||
|
||||
HttpClient httpClient = theClient.getHttpClient();
|
||||
FhirContext context = theClient.getFhirContext();
|
||||
|
||||
HttpGet get = new HttpGet(getReference().getValue());
|
||||
HttpResponse response = httpClient.execute(get);
|
||||
|
||||
// TODO: choose appropriate parser based on response CT
|
||||
IParser parser = context.newXmlParser();
|
||||
|
||||
Reader responseReader = ClientInvocationHandler.createReaderFromResponse(response);
|
||||
myResource = parser.parseResource(responseReader);
|
||||
|
||||
return myResource;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,116 @@
|
||||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ConformanceEventModeEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b>sender</b>
|
||||
*
|
||||
* The application sends requests and receives responses.
|
||||
*/
|
||||
SENDER("sender", "http://hl7.org/fhir/message-conformance-event-mode"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>receiver</b>
|
||||
*
|
||||
* The application receives requests and sends responses.
|
||||
*/
|
||||
RECEIVER("receiver", "http://hl7.org/fhir/message-conformance-event-mode"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/message-conformance-event-mode
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/message-conformance-event-mode";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* ConformanceEventMode
|
||||
*/
|
||||
public static final String VALUESET_NAME = "ConformanceEventMode";
|
||||
|
||||
private static Map<String, ConformanceEventModeEnum> CODE_TO_ENUM = new HashMap<String, ConformanceEventModeEnum>();
|
||||
private static Map<String, Map<String, ConformanceEventModeEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, ConformanceEventModeEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (ConformanceEventModeEnum next : ConformanceEventModeEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, ConformanceEventModeEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public ConformanceEventModeEnum forCode(String theCode) {
|
||||
ConformanceEventModeEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
public static final IValueSetEnumBinder<ConformanceEventModeEnum> VALUESET_BINDER = new IValueSetEnumBinder<ConformanceEventModeEnum>() {
|
||||
@Override
|
||||
public String toCodeString(ConformanceEventModeEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(ConformanceEventModeEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConformanceEventModeEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConformanceEventModeEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, ConformanceEventModeEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
ConformanceEventModeEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum ConformanceStatementStatusEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b>draft</b>
|
||||
*
|
||||
* This conformance statement is still under development.
|
||||
*/
|
||||
DRAFT("draft", "http://hl7.org/fhir/conformance-statement-status"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>active</b>
|
||||
*
|
||||
* This conformance statement is ready for use in production systems.
|
||||
*/
|
||||
ACTIVE("active", "http://hl7.org/fhir/conformance-statement-status"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>retired</b>
|
||||
*
|
||||
* This conformance statement has been withdrawn or superceded and should no longer be used.
|
||||
*/
|
||||
RETIRED("retired", "http://hl7.org/fhir/conformance-statement-status"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/conformance-statement-status
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/conformance-statement-status";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* ConformanceStatementStatus
|
||||
*/
|
||||
public static final String VALUESET_NAME = "ConformanceStatementStatus";
|
||||
|
||||
private static Map<String, ConformanceStatementStatusEnum> CODE_TO_ENUM = new HashMap<String, ConformanceStatementStatusEnum>();
|
||||
private static Map<String, Map<String, ConformanceStatementStatusEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, ConformanceStatementStatusEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (ConformanceStatementStatusEnum next : ConformanceStatementStatusEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, ConformanceStatementStatusEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public ConformanceStatementStatusEnum forCode(String theCode) {
|
||||
ConformanceStatementStatusEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
public static final IValueSetEnumBinder<ConformanceStatementStatusEnum> VALUESET_BINDER = new IValueSetEnumBinder<ConformanceStatementStatusEnum>() {
|
||||
@Override
|
||||
public String toCodeString(ConformanceStatementStatusEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(ConformanceStatementStatusEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConformanceStatementStatusEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConformanceStatementStatusEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, ConformanceStatementStatusEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
ConformanceStatementStatusEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum DocumentModeEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b>producer</b>
|
||||
*
|
||||
* The application produces documents of the specified type.
|
||||
*/
|
||||
PRODUCER("producer", "http://hl7.org/fhir/document-mode"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>consumer</b>
|
||||
*
|
||||
* The application consumes documents of the specified type.
|
||||
*/
|
||||
CONSUMER("consumer", "http://hl7.org/fhir/document-mode"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/document-mode
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/document-mode";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* DocumentMode
|
||||
*/
|
||||
public static final String VALUESET_NAME = "DocumentMode";
|
||||
|
||||
private static Map<String, DocumentModeEnum> CODE_TO_ENUM = new HashMap<String, DocumentModeEnum>();
|
||||
private static Map<String, Map<String, DocumentModeEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, DocumentModeEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (DocumentModeEnum next : DocumentModeEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, DocumentModeEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public DocumentModeEnum forCode(String theCode) {
|
||||
DocumentModeEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
public static final IValueSetEnumBinder<DocumentModeEnum> VALUESET_BINDER = new IValueSetEnumBinder<DocumentModeEnum>() {
|
||||
@Override
|
||||
public String toCodeString(DocumentModeEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(DocumentModeEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentModeEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DocumentModeEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, DocumentModeEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
DocumentModeEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum MessageSignificanceCategoryEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b>Consequence</b>
|
||||
*
|
||||
* The message represents/requests a change that should not be processed more than once. E.g. Making a booking for an appointment.
|
||||
*/
|
||||
CONSEQUENCE("Consequence", "http://hl7.org/fhir/message-significance-category"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>Currency</b>
|
||||
*
|
||||
* The message represents a response to query for current information. Retrospective processing is wrong and/or wasteful.
|
||||
*/
|
||||
CURRENCY("Currency", "http://hl7.org/fhir/message-significance-category"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>Notification</b>
|
||||
*
|
||||
* The content is not necessarily intended to be current, and it can be reprocessed, though there may be version issues created by processing old notifications.
|
||||
*/
|
||||
NOTIFICATION("Notification", "http://hl7.org/fhir/message-significance-category"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/message-significance-category
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/message-significance-category";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* MessageSignificanceCategory
|
||||
*/
|
||||
public static final String VALUESET_NAME = "MessageSignificanceCategory";
|
||||
|
||||
private static Map<String, MessageSignificanceCategoryEnum> CODE_TO_ENUM = new HashMap<String, MessageSignificanceCategoryEnum>();
|
||||
private static Map<String, Map<String, MessageSignificanceCategoryEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, MessageSignificanceCategoryEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (MessageSignificanceCategoryEnum next : MessageSignificanceCategoryEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, MessageSignificanceCategoryEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public MessageSignificanceCategoryEnum forCode(String theCode) {
|
||||
MessageSignificanceCategoryEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
public static final IValueSetEnumBinder<MessageSignificanceCategoryEnum> VALUESET_BINDER = new IValueSetEnumBinder<MessageSignificanceCategoryEnum>() {
|
||||
@Override
|
||||
public String toCodeString(MessageSignificanceCategoryEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(MessageSignificanceCategoryEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageSignificanceCategoryEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageSignificanceCategoryEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, MessageSignificanceCategoryEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
MessageSignificanceCategoryEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum RestfulConformanceModeEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b>client</b>
|
||||
*
|
||||
* The application acts as a server for this resource.
|
||||
*/
|
||||
CLIENT("client", "http://hl7.org/fhir/restful-conformance-mode"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>server</b>
|
||||
*
|
||||
* The application acts as a client for this resource.
|
||||
*/
|
||||
SERVER("server", "http://hl7.org/fhir/restful-conformance-mode"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/restful-conformance-mode
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/restful-conformance-mode";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* RestfulConformanceMode
|
||||
*/
|
||||
public static final String VALUESET_NAME = "RestfulConformanceMode";
|
||||
|
||||
private static Map<String, RestfulConformanceModeEnum> CODE_TO_ENUM = new HashMap<String, RestfulConformanceModeEnum>();
|
||||
private static Map<String, Map<String, RestfulConformanceModeEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, RestfulConformanceModeEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (RestfulConformanceModeEnum next : RestfulConformanceModeEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, RestfulConformanceModeEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public RestfulConformanceModeEnum forCode(String theCode) {
|
||||
RestfulConformanceModeEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
public static final IValueSetEnumBinder<RestfulConformanceModeEnum> VALUESET_BINDER = new IValueSetEnumBinder<RestfulConformanceModeEnum>() {
|
||||
@Override
|
||||
public String toCodeString(RestfulConformanceModeEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(RestfulConformanceModeEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestfulConformanceModeEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestfulConformanceModeEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, RestfulConformanceModeEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
RestfulConformanceModeEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,117 @@
|
||||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum RestfulOperationSystemEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b>transaction</b>
|
||||
*/
|
||||
TRANSACTION("transaction", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>search-system</b>
|
||||
*/
|
||||
SEARCH_SYSTEM("search-system", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>history-system</b>
|
||||
*/
|
||||
HISTORY_SYSTEM("history-system", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/system-restful-operation
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/system-restful-operation";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* RestfulOperationSystem
|
||||
*/
|
||||
public static final String VALUESET_NAME = "RestfulOperationSystem";
|
||||
|
||||
private static Map<String, RestfulOperationSystemEnum> CODE_TO_ENUM = new HashMap<String, RestfulOperationSystemEnum>();
|
||||
private static Map<String, Map<String, RestfulOperationSystemEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, RestfulOperationSystemEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (RestfulOperationSystemEnum next : RestfulOperationSystemEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, RestfulOperationSystemEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public RestfulOperationSystemEnum forCode(String theCode) {
|
||||
RestfulOperationSystemEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
public static final IValueSetEnumBinder<RestfulOperationSystemEnum> VALUESET_BINDER = new IValueSetEnumBinder<RestfulOperationSystemEnum>() {
|
||||
@Override
|
||||
public String toCodeString(RestfulOperationSystemEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(RestfulOperationSystemEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestfulOperationSystemEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestfulOperationSystemEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, RestfulOperationSystemEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
RestfulOperationSystemEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,147 @@
|
||||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum RestfulOperationTypeEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b>read</b>
|
||||
*/
|
||||
READ("read", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>vread</b>
|
||||
*/
|
||||
VREAD("vread", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>update</b>
|
||||
*/
|
||||
UPDATE("update", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>delete</b>
|
||||
*/
|
||||
DELETE("delete", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>history-instance</b>
|
||||
*/
|
||||
HISTORY_INSTANCE("history-instance", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>validate</b>
|
||||
*/
|
||||
VALIDATE("validate", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>history-type</b>
|
||||
*/
|
||||
HISTORY_TYPE("history-type", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>create</b>
|
||||
*/
|
||||
CREATE("create", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>search-type</b>
|
||||
*/
|
||||
SEARCH_TYPE("search-type", "http://hl7.org/fhir/restful-operation"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/type-restful-operation
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/type-restful-operation";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* RestfulOperationType
|
||||
*/
|
||||
public static final String VALUESET_NAME = "RestfulOperationType";
|
||||
|
||||
private static Map<String, RestfulOperationTypeEnum> CODE_TO_ENUM = new HashMap<String, RestfulOperationTypeEnum>();
|
||||
private static Map<String, Map<String, RestfulOperationTypeEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, RestfulOperationTypeEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (RestfulOperationTypeEnum next : RestfulOperationTypeEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, RestfulOperationTypeEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public RestfulOperationTypeEnum forCode(String theCode) {
|
||||
RestfulOperationTypeEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
public static final IValueSetEnumBinder<RestfulOperationTypeEnum> VALUESET_BINDER = new IValueSetEnumBinder<RestfulOperationTypeEnum>() {
|
||||
@Override
|
||||
public String toCodeString(RestfulOperationTypeEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(RestfulOperationTypeEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestfulOperationTypeEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestfulOperationTypeEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, RestfulOperationTypeEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
RestfulOperationTypeEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
|
||||
package ca.uhn.fhir.model.dstu.valueset;
|
||||
|
||||
import ca.uhn.fhir.model.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum RestfulSecurityServiceEnum {
|
||||
|
||||
/**
|
||||
* Code Value: <b>OAuth</b>
|
||||
*
|
||||
* OAuth (see oauth.net).
|
||||
*/
|
||||
OAUTH("OAuth", "http://hl7.org/fhir/restful-security-service"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>OAuth2</b>
|
||||
*
|
||||
* OAuth version 2 (see oauth.net).
|
||||
*/
|
||||
OAUTH2("OAuth2", "http://hl7.org/fhir/restful-security-service"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>NTLM</b>
|
||||
*
|
||||
* Microsoft NTLM Authentication.
|
||||
*/
|
||||
NTLM("NTLM", "http://hl7.org/fhir/restful-security-service"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>Basic</b>
|
||||
*
|
||||
* Basic authentication defined in HTTP specification.
|
||||
*/
|
||||
BASIC("Basic", "http://hl7.org/fhir/restful-security-service"),
|
||||
|
||||
/**
|
||||
* Code Value: <b>Kerberos</b>
|
||||
*
|
||||
* see http://www.ietf.org/rfc/rfc4120.txt.
|
||||
*/
|
||||
KERBEROS("Kerberos", "http://hl7.org/fhir/restful-security-service"),
|
||||
|
||||
;
|
||||
|
||||
/**
|
||||
* Identifier for this Value Set:
|
||||
* http://hl7.org/fhir/vs/restful-security-service
|
||||
*/
|
||||
public static final String VALUESET_IDENTIFIER = "http://hl7.org/fhir/vs/restful-security-service";
|
||||
|
||||
/**
|
||||
* Name for this Value Set:
|
||||
* RestfulSecurityService
|
||||
*/
|
||||
public static final String VALUESET_NAME = "RestfulSecurityService";
|
||||
|
||||
private static Map<String, RestfulSecurityServiceEnum> CODE_TO_ENUM = new HashMap<String, RestfulSecurityServiceEnum>();
|
||||
private static Map<String, Map<String, RestfulSecurityServiceEnum>> SYSTEM_TO_CODE_TO_ENUM = new HashMap<String, Map<String, RestfulSecurityServiceEnum>>();
|
||||
|
||||
private final String myCode;
|
||||
private final String mySystem;
|
||||
|
||||
static {
|
||||
for (RestfulSecurityServiceEnum next : RestfulSecurityServiceEnum.values()) {
|
||||
CODE_TO_ENUM.put(next.getCode(), next);
|
||||
|
||||
if (!SYSTEM_TO_CODE_TO_ENUM.containsKey(next.getSystem())) {
|
||||
SYSTEM_TO_CODE_TO_ENUM.put(next.getSystem(), new HashMap<String, RestfulSecurityServiceEnum>());
|
||||
}
|
||||
SYSTEM_TO_CODE_TO_ENUM.get(next.getSystem()).put(next.getCode(), next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code associated with this enumerated value
|
||||
*/
|
||||
public String getCode() {
|
||||
return myCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the code system associated with this enumerated value
|
||||
*/
|
||||
public String getSystem() {
|
||||
return mySystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the enumerated value associated with this code
|
||||
*/
|
||||
public RestfulSecurityServiceEnum forCode(String theCode) {
|
||||
RestfulSecurityServiceEnum retVal = CODE_TO_ENUM.get(theCode);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts codes to their respective enumerated values
|
||||
*/
|
||||
public static final IValueSetEnumBinder<RestfulSecurityServiceEnum> VALUESET_BINDER = new IValueSetEnumBinder<RestfulSecurityServiceEnum>() {
|
||||
@Override
|
||||
public String toCodeString(RestfulSecurityServiceEnum theEnum) {
|
||||
return theEnum.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toSystemString(RestfulSecurityServiceEnum theEnum) {
|
||||
return theEnum.getSystem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestfulSecurityServiceEnum fromCodeString(String theCodeString) {
|
||||
return CODE_TO_ENUM.get(theCodeString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public RestfulSecurityServiceEnum fromCodeString(String theCodeString, String theSystemString) {
|
||||
Map<String, RestfulSecurityServiceEnum> map = SYSTEM_TO_CODE_TO_ENUM.get(theSystemString);
|
||||
if (map == null) {
|
||||
return null;
|
||||
}
|
||||
return map.get(theCodeString);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
RestfulSecurityServiceEnum(String theCode, String theSystem) {
|
||||
myCode = theCode;
|
||||
mySystem = theSystem;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package ca.uhn.fhir.rest.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringReader;
|
||||
@ -17,10 +17,12 @@ import org.apache.http.client.HttpClient;
|
||||
import org.apache.http.client.methods.HttpRequestBase;
|
||||
import org.apache.http.entity.ContentType;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.parser.IParser;
|
||||
import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
||||
import ca.uhn.fhir.rest.client.exceptions.InvalidResponseException;
|
||||
import ca.uhn.fhir.rest.client.exceptions.NonFhirResponseException;
|
||||
import ca.uhn.fhir.rest.common.BaseMethodBinding;
|
||||
@ -33,11 +35,22 @@ public class ClientInvocationHandler implements InvocationHandler {
|
||||
private final HttpClient myClient;
|
||||
private final FhirContext myContext;
|
||||
private final String myUrlBase;
|
||||
private final Map<Method, Object> myMethodToReturnValue=new HashMap<Method, Object>();
|
||||
|
||||
public ClientInvocationHandler(HttpClient theClient, FhirContext theContext, String theUrlBase) {
|
||||
public ClientInvocationHandler(HttpClient theClient, FhirContext theContext, String theUrlBase, Class<? extends IRestfulClient> theClientType) {
|
||||
myClient = theClient;
|
||||
myContext = theContext;
|
||||
myUrlBase = theUrlBase;
|
||||
|
||||
try {
|
||||
myMethodToReturnValue.put(theClientType.getMethod("getFhirContext"), theContext);
|
||||
myMethodToReturnValue.put(theClientType.getMethod("getHttpClient"), theClient);
|
||||
myMethodToReturnValue.put(theClientType.getMethod("getServerBase"), theUrlBase);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new ConfigurationException("Failed to find methods on client. This is a HAPI bug!",e);
|
||||
} catch (SecurityException e) {
|
||||
throw new ConfigurationException("Failed to find methods on client. This is a HAPI bug!",e);
|
||||
}
|
||||
}
|
||||
|
||||
public void addBinding(Method theMethod, BaseMethodBinding theBinding) {
|
||||
@ -46,27 +59,26 @@ public class ClientInvocationHandler implements InvocationHandler {
|
||||
|
||||
@Override
|
||||
public Object invoke(Object theProxy, Method theMethod, Object[] theArgs) throws Throwable {
|
||||
Object directRetVal = myMethodToReturnValue.get(theMethod);
|
||||
if (directRetVal!=null) {
|
||||
return directRetVal;
|
||||
}
|
||||
|
||||
BaseMethodBinding binding = myBindings.get(theMethod);
|
||||
GetClientInvocation clientInvocation = binding.invokeClient(theArgs);
|
||||
HttpRequestBase httpRequest = clientInvocation.asHttpRequest(myUrlBase);
|
||||
HttpResponse response = myClient.execute(httpRequest);
|
||||
|
||||
ContentType ct = ContentType.get(response.getEntity());
|
||||
Charset charset = ct.getCharset();
|
||||
|
||||
if (charset == null) {
|
||||
ourLog.warn("Response did not specify a charset.");
|
||||
charset = Charset.forName("UTF-8");
|
||||
}
|
||||
|
||||
Reader reader = new InputStreamReader(response.getEntity().getContent(), charset);
|
||||
|
||||
Reader reader = createReaderFromResponse(response);
|
||||
|
||||
if (ourLog.isTraceEnabled()) {
|
||||
String responseString = IOUtils.toString(reader);
|
||||
ourLog.trace("FHIR response:\n{}\n{}", response, responseString);
|
||||
reader = new StringReader(responseString);
|
||||
}
|
||||
|
||||
ContentType ct = ContentType.get(response.getEntity());
|
||||
|
||||
IParser parser;
|
||||
String mimeType = ct.getMimeType();
|
||||
if (Constants.CT_ATOM_XML.equals(mimeType)) {
|
||||
@ -114,4 +126,17 @@ public class ClientInvocationHandler implements InvocationHandler {
|
||||
throw new IllegalStateException("Should not get here!");
|
||||
}
|
||||
|
||||
public static Reader createReaderFromResponse(HttpResponse theResponse) throws IllegalStateException, IOException {
|
||||
ContentType ct = ContentType.get(theResponse.getEntity());
|
||||
Charset charset = ct.getCharset();
|
||||
|
||||
if (charset == null) {
|
||||
ourLog.warn("Response did not specify a charset.");
|
||||
charset = Charset.forName("UTF-8");
|
||||
}
|
||||
|
||||
Reader reader = new InputStreamReader(theResponse.getEntity().getContent(), charset);
|
||||
return reader;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -46,6 +46,9 @@ public class GetClientInvocation extends BaseClientInvocation {
|
||||
|
||||
boolean first = true;
|
||||
for (Entry<String, String> next : myParameters.entrySet()) {
|
||||
if (next.getValue()==null) {
|
||||
continue;
|
||||
}
|
||||
if (first) {
|
||||
b.append('?');
|
||||
first = false;
|
||||
|
@ -47,8 +47,9 @@ public class RestfulClientFactory implements IRestfulClientFactory {
|
||||
* @throws ConfigurationException
|
||||
* If the interface type is not an interface
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T extends IRestfulClient> T newClient(Class<T> theClientType, String theServerBase){
|
||||
public <T extends IRestfulClient> T newClient(Class<T> theClientType, String theServerBase) {
|
||||
if (!theClientType.isInterface()) {
|
||||
throw new ConfigurationException(theClientType.getCanonicalName() + " is not an interface");
|
||||
}
|
||||
@ -56,37 +57,42 @@ public class RestfulClientFactory implements IRestfulClientFactory {
|
||||
HttpClient client;
|
||||
if (myHttpClient != null) {
|
||||
client = myHttpClient;
|
||||
}else {
|
||||
} else {
|
||||
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||
HttpClientBuilder builder = HttpClientBuilder.create();
|
||||
builder.setConnectionManager(connectionManager);
|
||||
client = builder.build();
|
||||
}
|
||||
|
||||
|
||||
String serverBase = theServerBase;
|
||||
if (!serverBase.endsWith("/")) {
|
||||
serverBase = serverBase + "/";
|
||||
}
|
||||
|
||||
ClientInvocationHandler theInvocationHandler = new ClientInvocationHandler(client, myContext, serverBase);
|
||||
|
||||
for (Method nextMethod : theClientType.getMethods()) {
|
||||
BaseMethodBinding binding = BaseMethodBinding.bindMethod(null, nextMethod);
|
||||
theInvocationHandler.addBinding(nextMethod, binding);
|
||||
ClientInvocationHandler invocationHandler = new ClientInvocationHandler(client, myContext, serverBase, theClientType);
|
||||
|
||||
for (Method nextMethod : theClientType.getMethods()) {
|
||||
Class<? extends IResource> resReturnType = null;
|
||||
Class<?> returnType = nextMethod.getReturnType();
|
||||
if (IResource.class.isAssignableFrom(returnType)) {
|
||||
resReturnType = (Class<? extends IResource>) returnType;
|
||||
}
|
||||
BaseMethodBinding binding = BaseMethodBinding.bindMethod(resReturnType, nextMethod);
|
||||
invocationHandler.addBinding(nextMethod, binding);
|
||||
}
|
||||
|
||||
T proxy = instantiateProxy(theClientType, theInvocationHandler);
|
||||
T proxy = instantiateProxy(theClientType, invocationHandler);
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the Apache HTTP client instance to be used by any new restful clients created by
|
||||
* this factory. If set to <code>null</code>, which is the default, a new HTTP client with
|
||||
* default settings will be created.
|
||||
*
|
||||
* @param theHttpClient An HTTP client instance to use, or <code>null</code>
|
||||
* Sets the Apache HTTP client instance to be used by any new restful
|
||||
* clients created by this factory. If set to <code>null</code>, which is
|
||||
* the default, a new HTTP client with default settings will be created.
|
||||
*
|
||||
* @param theHttpClient
|
||||
* An HTTP client instance to use, or <code>null</code>
|
||||
*/
|
||||
@Override
|
||||
public void setHttpClient(HttpClient theHttpClient) {
|
||||
|
@ -0,0 +1,20 @@
|
||||
package ca.uhn.fhir.rest.client.api;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.rest.server.operations.Metadata;
|
||||
|
||||
/**
|
||||
* Base interface for a client supporting the mandatory operations as defined by
|
||||
* the FHIR specification.
|
||||
*/
|
||||
public interface IMetadataClient extends IRestfulClient {
|
||||
|
||||
/**
|
||||
* Returns the server conformance statement
|
||||
*
|
||||
* @see See the <a href="http://hl7.org/implement/standards/fhir/http.html#conformance">FHIR HTTP Conformance</a> definition
|
||||
*/
|
||||
@Metadata
|
||||
Conformance getServerConformanceStatement();
|
||||
|
||||
}
|
@ -1,5 +1,16 @@
|
||||
package ca.uhn.fhir.rest.client.api;
|
||||
|
||||
|
||||
import org.apache.http.client.HttpClient;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
|
||||
public interface IRestfulClient {
|
||||
|
||||
FhirContext getFhirContext();
|
||||
|
||||
HttpClient getHttpClient();
|
||||
|
||||
String getServerBase();
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import ca.uhn.fhir.context.ConfigurationException;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
@ -16,9 +15,9 @@ import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.client.GetClientInvocation;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.Resource;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
import ca.uhn.fhir.rest.server.operations.Metadata;
|
||||
import ca.uhn.fhir.rest.server.operations.Search;
|
||||
|
||||
public abstract class BaseMethodBinding {
|
||||
@ -50,7 +49,8 @@ public abstract class BaseMethodBinding {
|
||||
public static BaseMethodBinding bindMethod(Class<? extends IResource> theReturnType, Method theMethod) {
|
||||
Read read = theMethod.getAnnotation(Read.class);
|
||||
Search search = theMethod.getAnnotation(Search.class);
|
||||
if (!verifyMethodHasZeroOrOneOperationAnnotation(theMethod, read, search)) {
|
||||
Metadata conformance = theMethod.getAnnotation(Metadata.class);
|
||||
if (!verifyMethodHasZeroOrOneOperationAnnotation(theMethod, read, search, conformance)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ public abstract class BaseMethodBinding {
|
||||
} else if (IResource.class.isAssignableFrom(methodReturnType)) {
|
||||
methodReturnTypeEnum = MethodReturnTypeEnum.RESOURCE;
|
||||
} else if (Bundle.class.isAssignableFrom(methodReturnType)) {
|
||||
methodReturnTypeEnum = MethodReturnTypeEnum.LIST_OF_RESOURCES;
|
||||
methodReturnTypeEnum = MethodReturnTypeEnum.BUNDLE;
|
||||
} else {
|
||||
throw new ConfigurationException("Invalid return type '" + methodReturnType.getCanonicalName() + "' on method '" + theMethod.getName() + "' on type: " + theMethod.getDeclaringClass().getCanonicalName());
|
||||
}
|
||||
@ -83,6 +83,8 @@ public abstract class BaseMethodBinding {
|
||||
return new ReadMethodBinding(methodReturnTypeEnum, returnType, theMethod);
|
||||
} else if (search != null) {
|
||||
return new SearchMethodBinding(methodReturnTypeEnum, returnType, theMethod);
|
||||
} else if (conformance != null) {
|
||||
return new ConformanceMethodBinding(methodReturnTypeEnum);
|
||||
} else {
|
||||
throw new ConfigurationException("Did not detect any FHIR annotations on method '" + theMethod.getName() + "' on type: " + theMethod.getDeclaringClass().getCanonicalName());
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package ca.uhn.fhir.rest.common;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.rest.client.GetClientInvocation;
|
||||
import ca.uhn.fhir.rest.common.SearchMethodBinding.RequestType;
|
||||
import ca.uhn.fhir.rest.server.IResourceProvider;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
|
||||
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
|
||||
|
||||
public class ConformanceMethodBinding extends BaseMethodBinding {
|
||||
|
||||
public ConformanceMethodBinding(MethodReturnTypeEnum theMethodReturnType) {
|
||||
super(theMethodReturnType, Conformance.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReturnTypeEnum getReturnType() {
|
||||
return ReturnTypeEnum.RESOURCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
|
||||
return new GetClientInvocation("metadata");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IResource> invokeServer(IResourceProvider theResourceProvider, IdDt theId, IdDt theVersionId, Map<String, String[]> theParameterValues) throws InvalidRequestException, InternalErrorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Request theRequest) {
|
||||
if (theRequest.getRequestType() == RequestType.OPTIONS) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (theRequest.getRequestType() == RequestType.GET && "metadata".equals(theRequest.getOperation())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@ -4,6 +4,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@ -59,12 +60,23 @@ public class SearchMethodBinding extends BaseMethodBinding {
|
||||
public GetClientInvocation invokeClient(Object[] theArgs) throws InternalErrorException {
|
||||
assert theArgs.length == myParameters.size() : "Wrong number of arguments: " + theArgs.length;
|
||||
|
||||
Map<String, String> args = new HashMap<String, String>();
|
||||
Map<String, String> args = new LinkedHashMap<String, String>();
|
||||
|
||||
for (int idx = 0; idx < theArgs.length; idx++) {
|
||||
Object object = theArgs[idx];
|
||||
Parameter nextParam = myParameters.get(idx);
|
||||
String value = nextParam.encode(object);
|
||||
String value;
|
||||
|
||||
if (object == null) {
|
||||
if (nextParam.isRequired()) {
|
||||
throw new NullPointerException("Parameter '" + nextParam.getName() + "' is required and may not be null");
|
||||
}else {
|
||||
value=null;
|
||||
}
|
||||
}else {
|
||||
value = nextParam.encode(object);
|
||||
}
|
||||
|
||||
args.put(nextParam.getName(), value);
|
||||
}
|
||||
|
||||
@ -152,7 +164,7 @@ public class SearchMethodBinding extends BaseMethodBinding {
|
||||
}
|
||||
|
||||
public static enum RequestType {
|
||||
DELETE, GET, POST, PUT
|
||||
DELETE, GET, POST, PUT, OPTIONS
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -42,6 +42,11 @@ public abstract class RestfulServer extends HttpServlet {
|
||||
|
||||
private Map<Class<? extends IResource>, IResourceProvider> myTypeToProvider = new HashMap<Class<? extends IResource>, IResourceProvider>();
|
||||
|
||||
@Override
|
||||
protected void doOptions(HttpServletRequest theReq, HttpServletResponse theResp) throws ServletException, IOException {
|
||||
handleRequest(SearchMethodBinding.RequestType.OPTIONS, theReq, theResp);
|
||||
}
|
||||
|
||||
// map of request handler resources keyed by resource name
|
||||
private Map<String, Resource> resources = new HashMap<String, Resource>();
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
package ca.uhn.fhir.rest.server.operations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* RESTful method annotation used for a method which provides
|
||||
* the FHIR "conformance" method.
|
||||
*
|
||||
* @see See the <a href="http://hl7.org/implement/standards/fhir/http.html#conformance">FHIR HTTP Conformance</a> definition
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value=ElementType.METHOD)
|
||||
public @interface Metadata {
|
||||
// nothing for now
|
||||
}
|
@ -1,12 +1,21 @@
|
||||
package ca.uhn.fhir.rest.server.operations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
||||
/**
|
||||
* RESTful method annotation used for a method which provides
|
||||
* the FHIR "search" method.
|
||||
*
|
||||
* @see See the <a href="http://hl7.org/implement/standards/fhir/http.html#search">FHIR Search</a> definition
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(value=ElementType.METHOD)
|
||||
public @interface Search {
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,26 @@
|
||||
package example;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.rest.client.IRestfulClientFactory;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class ExampleRestfulClient {
|
||||
|
||||
//START SNIPPET: client
|
||||
public static void main(String[] args) {
|
||||
FhirContext ctx = new FhirContext(Patient.class);
|
||||
IRestfulClientFactory clientFactory = ctx.newRestfulClientFactory();
|
||||
String serverBase = "http://foo.com/fhirServerBase";
|
||||
RestfulClientImpl client = clientFactory.newClient(RestfulClientImpl.class, serverBase);
|
||||
|
||||
// The client is now ready for use!
|
||||
List<Patient> patients = client.getPatient(new StringDt("SMITH"));
|
||||
|
||||
}
|
||||
//END SNIPPET: client
|
||||
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
package example;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
||||
import ca.uhn.fhir.rest.server.operations.Search;
|
||||
import ca.uhn.fhir.rest.server.parameters.Required;
|
||||
|
||||
//START SNIPPET: provider
|
||||
/**
|
||||
* All RESTful clients must be an interface which extends IRestfulClient
|
||||
*/
|
||||
public interface RestfulClientImpl extends IRestfulClient {
|
||||
|
||||
/**
|
||||
* The "@Read" annotation indicates that this method supports the
|
||||
* read operation. Read operations should return a single resource
|
||||
* instance.
|
||||
*
|
||||
* @param theId
|
||||
* The read operation takes one parameter, which must be of type
|
||||
* IdDt and must be annotated with the "@Read.IdParam" annotation.
|
||||
* @return
|
||||
* Returns a resource matching this identifier, or null if none exists.
|
||||
*/
|
||||
@Read()
|
||||
public Patient getResourceById(@Read.IdParam IdDt theId);
|
||||
|
||||
/**
|
||||
* The "@Search" annotation indicates that this method supports the
|
||||
* search operation. You may have many different method annotated with
|
||||
* this annotation, to support many different search criteria. This
|
||||
* example searches by family name.
|
||||
*
|
||||
* @param theIdentifier
|
||||
* This operation takes one parameter which is the search criteria. It is
|
||||
* annotated with the "@Required" annotation. This annotation takes one argument,
|
||||
* a string containing the name of the search criteria. The datatype here
|
||||
* is StringDt, but there are other possible parameter types depending on the
|
||||
* specific search criteria.
|
||||
* @return
|
||||
* This method returns a list of Patients. This list may contain multiple
|
||||
* matching resources, or it may also be empty.
|
||||
*/
|
||||
@Search()
|
||||
public List<Patient> getPatient(@Required(name = Patient.SP_FAMILY) StringDt theFamilyName);
|
||||
|
||||
}
|
||||
//END SNIPPET: provider
|
||||
|
||||
|
@ -30,6 +30,7 @@
|
||||
<item name="Introduction" href="./doc_intro.html"/>
|
||||
<item name="The Data Model" href="./doc_fhirobjects.html"/>
|
||||
<item name="RESTful Server" href="./doc_rest_server.html"/>
|
||||
<item name="RESTful Client" href="./doc_rest_client.html"/>
|
||||
<item name="RESTful Operations" href="./doc_rest_operations.html"/>
|
||||
<item name="JavaDocs" href="./apidocs/index.html"/>
|
||||
</menu>
|
||||
|
92
hapi-fhir-base/src/site/xdoc/doc_rest_client.xml
Normal file
92
hapi-fhir-base/src/site/xdoc/doc_rest_client.xml
Normal file
@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document xmlns="http://maven.apache.org/XDOC/2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
|
||||
|
||||
<properties>
|
||||
<title>RESTful Client - HAPI FHIR</title>
|
||||
<author email="jamesagnew@users.sourceforge.net">James Agnew</author>
|
||||
</properties>
|
||||
|
||||
<body>
|
||||
|
||||
<!-- The body of the document contains a number of sections -->
|
||||
<section name="Creating a RESTful Client">
|
||||
|
||||
<macro name="toc">
|
||||
</macro>
|
||||
|
||||
<p>
|
||||
HAPI provides a built-in mechanism for connecting to FHIR RESTful servers.
|
||||
The HAPI RESTful client is designed to be easy to set up and to allow strong
|
||||
compile-time type checking wherever possible.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
Setup is mostly done using simple annotations, which means that it should
|
||||
be possible to create a FHIR compliant server quickly and easily. Once again,
|
||||
this design is intended to be similar to that of JAX-WS, so users of that
|
||||
specification should be comfortable with this one.
|
||||
</p>
|
||||
|
||||
<subsection name="Defining A Restful Client Interface">
|
||||
|
||||
<p>
|
||||
The first step in creating a FHIR RESTful Client is to define a
|
||||
restful client interface.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
A restful client interface class must extend the
|
||||
<a href="./apidocs/ca/uhn/fhir/rest/client/api/IRestfulClient.html">IRestfulClient</a> interface,
|
||||
and will contain one or more methods which have been
|
||||
annotated with special annotations indicating which RESTful operation
|
||||
that method supports. Below is a simple example of a resource provider
|
||||
which supports the
|
||||
<a href="http://hl7.org/implement/standards/fhir/http.html#read">read</a>
|
||||
operation (i.e. retrieve a single resource by ID) as well as the
|
||||
<a href="http://hl7.org/implement/standards/fhir/http.html#search">search</a>
|
||||
operation (i.e. find any resources matching a given criteria) for a specific
|
||||
search criteria.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
You may notice that this interface looks a lot like the Resource Provider
|
||||
which is defined for use by the RESTful server. In fact, it supports all
|
||||
of the same annotations and is essentially identical, other than the
|
||||
fact that for a client you must use an interface but for a server you
|
||||
must use a concrete class with method implementations.
|
||||
</p>
|
||||
|
||||
<macro name="snippet">
|
||||
<param name="id" value="provider" />
|
||||
<param name="file" value="src/site/example/java/example/RestfulClientImpl.java" />
|
||||
</macro>
|
||||
|
||||
<p>
|
||||
You will probable wish to add more methods
|
||||
to your client interface. See
|
||||
<a href="./doc_rest_operations.html">RESTful Operations</a> for
|
||||
lots more examples of how to add methods for various operations.
|
||||
</p>
|
||||
|
||||
</subsection>
|
||||
|
||||
<subsection name="Instantiate the Client">
|
||||
|
||||
<p>
|
||||
Once your client interface is created, all that is left is to
|
||||
create a FhirContext and instantiate the client and you are
|
||||
ready to start using it.
|
||||
</p>
|
||||
|
||||
<macro name="snippet">
|
||||
<param name="id" value="client" />
|
||||
<param name="file" value="src/site/example/java/example/ExampleRestfulClient.java" />
|
||||
</macro>
|
||||
|
||||
</subsection>
|
||||
|
||||
</section>
|
||||
|
||||
</body>
|
||||
|
||||
</document>
|
@ -7,6 +7,7 @@ import static org.mockito.Mockito.when;
|
||||
import java.io.StringReader;
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.commons.io.input.ReaderInputStream;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.ProtocolVersion;
|
||||
@ -20,9 +21,13 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.api.IResource;
|
||||
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.rest.server.Constants;
|
||||
|
||||
public class ClientTest {
|
||||
@ -36,7 +41,7 @@ public class ClientTest {
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
ctx = new FhirContext(Patient.class);
|
||||
ctx = new FhirContext(Patient.class, Conformance.class);
|
||||
clientFactory = ctx.newRestfulClientFactory();
|
||||
|
||||
httpClient = mock(HttpClient.class, new ReturnsDeepStubs());
|
||||
@ -107,8 +112,75 @@ public class ClientTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearch() throws Exception {
|
||||
public void testSearchByToken() throws Exception {
|
||||
|
||||
String msg = getPatientFeedWithOneResult();
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP",1,1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
|
||||
ITestClient client = clientFactory.newClient(ITestClient.class, "http://foo");
|
||||
Patient response = client.findPatientByMrn(new IdentifierDt("urn:foo", "123"));
|
||||
|
||||
assertEquals("http://foo/Patient?identifier=urn%3Afoo%7C123", capt.getValue().getURI().toString());
|
||||
assertEquals("PRP1660", response.getIdentifier().get(0).getValue().getValue());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetConformance() throws Exception {
|
||||
|
||||
String msg = IOUtils.toString(ClientTest.class.getResourceAsStream("/example-metadata.xml"));
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP",1,1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
|
||||
ITestClient client = clientFactory.newClient(ITestClient.class, "http://foo");
|
||||
Conformance response = client.getServerConformanceStatement();
|
||||
|
||||
assertEquals("http://foo/metadata", capt.getValue().getURI().toString());
|
||||
assertEquals("Health Intersections", response.getPublisher().getValue());
|
||||
|
||||
}
|
||||
@Test
|
||||
public void testSearchWithOptionalParam() throws Exception {
|
||||
|
||||
String msg = getPatientFeedWithOneResult();
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP",1,1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
|
||||
ITestClient client = clientFactory.newClient(ITestClient.class, "http://foo");
|
||||
Bundle response = client.findPatientByName(new StringDt("AAA"), null);
|
||||
|
||||
assertEquals("http://foo/Patient?family=AAA", capt.getValue().getURI().toString());
|
||||
Patient resource = (Patient) response.getEntries().get(0).getResource();
|
||||
assertEquals("PRP1660", resource.getIdentifier().get(0).getValue().getValue());
|
||||
|
||||
/*
|
||||
* Now with a first name
|
||||
*/
|
||||
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
client = clientFactory.newClient(ITestClient.class, "http://foo");
|
||||
response = client.findPatientByName(new StringDt("AAA"), new StringDt("BBB"));
|
||||
|
||||
assertEquals("http://foo/Patient?family=AAA&given=BBB", capt.getValue().getURI().toString());
|
||||
resource = (Patient) response.getEntries().get(0).getResource();
|
||||
assertEquals("PRP1660", resource.getIdentifier().get(0).getValue().getValue());
|
||||
|
||||
}
|
||||
|
||||
private String getPatientFeedWithOneResult() {
|
||||
//@formatter:off
|
||||
String msg = "<feed xmlns=\"http://www.w3.org/2005/Atom\">\n" +
|
||||
"<title/>\n" +
|
||||
@ -133,18 +205,6 @@ public class ClientTest {
|
||||
+ " </entry>\n"
|
||||
+ "</feed>";
|
||||
//@formatter:on
|
||||
|
||||
ArgumentCaptor<HttpUriRequest> capt = ArgumentCaptor.forClass(HttpUriRequest.class);
|
||||
when(httpClient.execute(capt.capture())).thenReturn(httpResponse);
|
||||
when(httpResponse.getStatusLine()).thenReturn(new BasicStatusLine(new ProtocolVersion("HTTP",1,1), 200, "OK"));
|
||||
when(httpResponse.getEntity().getContentType()).thenReturn(new BasicHeader("content-type", Constants.CT_FHIR_XML + "; charset=UTF-8"));
|
||||
when(httpResponse.getEntity().getContent()).thenReturn(new ReaderInputStream(new StringReader(msg), Charset.forName("UTF-8")));
|
||||
|
||||
ITestClient client = clientFactory.newClient(ITestClient.class, "http://foo");
|
||||
Patient response = client.findPatientByMrn(new IdentifierDt("urn:foo", "123"));
|
||||
|
||||
assertEquals("http://foo/Patient?identifier=urn%3Afoo%7C123", capt.getValue().getURI().toString());
|
||||
assertEquals("PRP1660", response.getIdentifier().get(0).getValue().getValue());
|
||||
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
@ -4,12 +4,14 @@ import ca.uhn.fhir.model.api.Bundle;
|
||||
import ca.uhn.fhir.model.dstu.composite.IdentifierDt;
|
||||
import ca.uhn.fhir.model.dstu.resource.Patient;
|
||||
import ca.uhn.fhir.model.primitive.IdDt;
|
||||
import ca.uhn.fhir.model.primitive.StringDt;
|
||||
import ca.uhn.fhir.rest.annotation.Read;
|
||||
import ca.uhn.fhir.rest.client.api.IRestfulClient;
|
||||
import ca.uhn.fhir.rest.client.api.IMetadataClient;
|
||||
import ca.uhn.fhir.rest.server.operations.Search;
|
||||
import ca.uhn.fhir.rest.server.parameters.Optional;
|
||||
import ca.uhn.fhir.rest.server.parameters.Required;
|
||||
|
||||
public interface ITestClient extends IRestfulClient {
|
||||
public interface ITestClient extends IMetadataClient {
|
||||
|
||||
@Read(type=Patient.class)
|
||||
Patient getPatientById(@Read.IdParam IdDt theId);
|
||||
@ -21,7 +23,7 @@ public interface ITestClient extends IRestfulClient {
|
||||
Patient findPatientByMrn(@Required(name = Patient.SP_IDENTIFIER) IdentifierDt theId);
|
||||
|
||||
@Search(type=Patient.class)
|
||||
Bundle findPatientByLastName(@Required(name = Patient.SP_FAMILY) IdentifierDt theId);
|
||||
Bundle findPatientByName(@Required(name = Patient.SP_FAMILY) StringDt theId, @Optional(name=Patient.SP_GIVEN) StringDt theGiven);
|
||||
|
||||
|
||||
}
|
||||
|
85
hapi-fhir-base/src/test/resources/example-metadata.xml
Normal file
85
hapi-fhir-base/src/test/resources/example-metadata.xml
Normal file
@ -0,0 +1,85 @@
|
||||
<Conformance xmlns="http://hl7.org/fhir">
|
||||
<extension url="http://hl7.org/fhir/Profile/tools-extensions#supported-system">
|
||||
<valueUri value="http://snomed.info/sct"/>
|
||||
</extension>
|
||||
<text>
|
||||
<status value="generated"/>
|
||||
<div xmlns="http://www.w3.org/1999/xhtml">
|
||||
</div>
|
||||
</text>
|
||||
<publisher value="Health Intersections"/>
|
||||
<date value="2014-03-12T01:00:56Z"/>
|
||||
<software>
|
||||
<name value="Reference Server"/>
|
||||
<version value="0.80-2286"/>
|
||||
<releaseDate value="2013-11-03"/>
|
||||
</software>
|
||||
<fhirVersion value="0.80-2286"/>
|
||||
<format value="application/xml+fhir"/>
|
||||
<format value="application/json+fhir"/>
|
||||
<rest>
|
||||
<mode value="server"/>
|
||||
<resource>
|
||||
<type value="AdverseReaction"/>
|
||||
<profile>
|
||||
<reference value="http://fhir.healthintersections.com.au/open/Profile/adversereaction"/>
|
||||
</profile>
|
||||
<operation>
|
||||
<code value="read"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="vread"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="search-type"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="update"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="history-type"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="create"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="delete"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="history-instance"/>
|
||||
</operation>
|
||||
<readHistory value="true"/>
|
||||
</resource>
|
||||
<resource>
|
||||
<type value="Alert"/>
|
||||
<profile>
|
||||
<reference value="http://fhir.healthintersections.com.au/open/Profile/alert"/>
|
||||
</profile>
|
||||
<operation>
|
||||
<code value="read"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="vread"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="search-type"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="update"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="history-type"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="create"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="delete"/>
|
||||
</operation>
|
||||
<operation>
|
||||
<code value="history-instance"/>
|
||||
</operation>
|
||||
<readHistory value="true"/>
|
||||
</resource>
|
||||
</rest>
|
||||
</Conformance>
|
@ -32,13 +32,14 @@
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
<goal>generate-structures</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<package>ca.uhn.fhir.model.dstu</package>
|
||||
<baseResourceNames>
|
||||
<baseResourceName>conformance</baseResourceName>
|
||||
<baseResourceName>device</baseResourceName>
|
||||
<baseResourceName>group</baseResourceName>
|
||||
<baseResourceName>location</baseResourceName>
|
||||
|
@ -0,0 +1,60 @@
|
||||
package ca.uhn.fhir.tinder;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.http.ParseException;
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
import org.apache.maven.plugins.annotations.LifecyclePhase;
|
||||
import org.apache.maven.plugins.annotations.Mojo;
|
||||
|
||||
import ca.uhn.fhir.context.FhirContext;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance;
|
||||
import ca.uhn.fhir.model.dstu.resource.Conformance.Rest;
|
||||
import ca.uhn.fhir.model.dstu.valueset.RestfulConformanceModeEnum;
|
||||
|
||||
@Mojo(name = "generate-client", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||
public class TinderClientMojo extends AbstractMojo {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TinderClientMojo.class);
|
||||
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws ParseException, IOException, MojoFailureException {
|
||||
|
||||
// PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
|
||||
// HttpClientBuilder builder = HttpClientBuilder.create();
|
||||
// builder.setConnectionManager(connectionManager);
|
||||
// CloseableHttpClient client = builder.build();
|
||||
//
|
||||
// HttpGet get = new HttpGet("http://fhir.healthintersections.com.au/open/metadata");
|
||||
// CloseableHttpResponse response = client.execute(get);
|
||||
//
|
||||
// String metadataString = EntityUtils.toString(response.getEntity());
|
||||
//
|
||||
// ourLog.info("Metadata String: {}", metadataString);
|
||||
|
||||
String metadataString = IOUtils.toString(new FileInputStream("src/test/resources/healthintersections-metadata.xml"));
|
||||
Conformance conformance = new FhirContext(Conformance.class).newXmlParser().parseResource(Conformance.class, metadataString);
|
||||
|
||||
if (conformance.getRest().size() != 1) {
|
||||
throw new MojoFailureException("Found "+conformance.getRest().size()+" rest definitions in Conformance resource. Need exactly 1.");
|
||||
}
|
||||
|
||||
Rest rest = conformance.getRest().get(0);
|
||||
if (rest.getMode().getValueAsEnum() != RestfulConformanceModeEnum.SERVER) {
|
||||
throw new MojoFailureException("Conformance mode is not server, found: " + rest.getMode().getValue());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -13,10 +13,10 @@ import org.apache.maven.plugins.annotations.Mojo;
|
||||
import org.apache.maven.plugins.annotations.Parameter;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
@Mojo(name = "generate", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||
public class TinderMojo extends AbstractMojo {
|
||||
@Mojo(name = "generate-structures", defaultPhase = LifecyclePhase.GENERATE_SOURCES)
|
||||
public class TinderStructuresMojo extends AbstractMojo {
|
||||
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TinderMojo.class);
|
||||
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TinderStructuresMojo.class);
|
||||
|
||||
@Parameter(alias = "package", required = true)
|
||||
private String myPackage;
|
@ -6,7 +6,6 @@ import java.util.List;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import ca.uhn.fhir.model.api.IDatatype;
|
||||
import ca.uhn.fhir.model.api.ResourceReference;
|
||||
import edu.emory.mathcs.backport.java.util.Collections;
|
||||
|
||||
public class Child extends BaseElement {
|
||||
|
@ -0,0 +1,5 @@
|
||||
package ca.uhn.fhir.tinder.model;
|
||||
|
||||
public class RestResource {
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user