diff --git a/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRConstants.java b/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRConstants.java index 008535c7..3bbad05b 100644 --- a/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRConstants.java +++ b/api/src/main/java/org/openmrs/module/fhir/api/util/FHIRConstants.java @@ -246,5 +246,8 @@ public final class FHIRConstants { //Global Property Names public static final String CONCEPTS_CONVERTABLE_TO_CONDITIONS_STORED_AS_OBS = "fhir.concepts.conditions"; + //module id or name + public static final String MODULE_ID = "fhir"; + public static final String URI_PREFIX_GLOBAL_PROPERTY_NAME = MODULE_ID + ".uriPrefix"; } diff --git a/omod/pom.xml b/omod/pom.xml index 8043b7a6..00c3db2a 100644 --- a/omod/pom.xml +++ b/omod/pom.xml @@ -101,7 +101,11 @@ 0.1 provided - + + + com.fasterxml.jackson.core + jackson-databind + diff --git a/omod/src/main/java/org/openmrs/module/fhir/filter/SwaggerForwardingFilter.java b/omod/src/main/java/org/openmrs/module/fhir/filter/SwaggerForwardingFilter.java new file mode 100644 index 00000000..92af5712 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/filter/SwaggerForwardingFilter.java @@ -0,0 +1,53 @@ +/* + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.filter; + +import org.openmrs.module.fhir.util.FHIROmodConstants; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +public class SwaggerForwardingFilter implements Filter { + + private String openmrsPath; + + @Override + public void init(FilterConfig fc) throws ServletException { + openmrsPath = fc.getServletContext().getContextPath(); + } + + @Override + public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { + HttpServletRequest request = (HttpServletRequest) req; + String requestURI = request.getRequestURI(); + + if (requestURI.startsWith(openmrsPath + FHIROmodConstants.OPENMRS_FHIR_SWAGGER_SHORT_PATH)) { + String newURI = requestURI.replace(FHIROmodConstants.OPENMRS_FHIR_SWAGGER_LONG_PATH, FHIROmodConstants.OPENMRS_FHIR_SWAGGER_ORG_PATH); + req.getRequestDispatcher(newURI).forward(req, res); + } else { + chain.doFilter(req, res); + } + } + + @Override + public void destroy() { + } + +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/providers/RestfulEncounterResourceProvider.java b/omod/src/main/java/org/openmrs/module/fhir/providers/RestfulEncounterResourceProvider.java index 11c6d017..7a21f05c 100644 --- a/omod/src/main/java/org/openmrs/module/fhir/providers/RestfulEncounterResourceProvider.java +++ b/omod/src/main/java/org/openmrs/module/fhir/providers/RestfulEncounterResourceProvider.java @@ -56,7 +56,7 @@ public Class getResourceType() { * * @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. + * @return Returns a resource matching this identifier, or nu ll if none exists. */ @Read() public Encounter getResourceById(@IdParam IdDt theId) { @@ -115,7 +115,7 @@ public List searchEncountersByIdAndPartOf(@RequiredParam(name = Encou * @param encounterId if of the encounter * @return bundle */ - @Operation(name = "$everything") + @Operation(name = "$everything", type = Encounter.class) public Bundle encounterInstanceOperation(@IdParam IdDt encounterId) { return encounterResource.getEncounterOperationsById(encounterId); } diff --git a/omod/src/main/java/org/openmrs/module/fhir/providers/RestfulPatientResourceProvider.java b/omod/src/main/java/org/openmrs/module/fhir/providers/RestfulPatientResourceProvider.java index e4d0bed3..c6c126ce 100644 --- a/omod/src/main/java/org/openmrs/module/fhir/providers/RestfulPatientResourceProvider.java +++ b/omod/src/main/java/org/openmrs/module/fhir/providers/RestfulPatientResourceProvider.java @@ -158,7 +158,7 @@ public List searchPatientsByProvider(@RequiredParam(name = Patient.SP_C * @param patientId if of the patient * @return bundle */ - @Operation(name = "$everything") + @Operation(name = "$everything", type = Patient.class) public Bundle patientInstanceOperation(@IdParam IdDt patientId) { return patientResource.getPatientOperationsById(patientId); } diff --git a/omod/src/main/java/org/openmrs/module/fhir/resources/FHIRPatientResource.java b/omod/src/main/java/org/openmrs/module/fhir/resources/FHIRPatientResource.java index bc80421e..9befff54 100644 --- a/omod/src/main/java/org/openmrs/module/fhir/resources/FHIRPatientResource.java +++ b/omod/src/main/java/org/openmrs/module/fhir/resources/FHIRPatientResource.java @@ -43,7 +43,7 @@ public List searchByUniqueId(TokenParam id) { return patientService.searchPatientsById(id.getValue()); } - //search by patient identifier. ex: GET [base-url]/Patient?identifier=http://acme.org/patient|2345 + //search by patient identifier. ex: GET_DESCRIPTION [base-url]/Patient?identifier=http://acme.org/patient|2345 //returns a bundle of patients public List searchByIdentifier(TokenParam identifier) { org.openmrs.module.fhir.api.PatientService patientService = Context.getService( diff --git a/omod/src/main/java/org/openmrs/module/fhir/resources/FHIRPractitionerResource.java b/omod/src/main/java/org/openmrs/module/fhir/resources/FHIRPractitionerResource.java index 90c44d67..14efe160 100644 --- a/omod/src/main/java/org/openmrs/module/fhir/resources/FHIRPractitionerResource.java +++ b/omod/src/main/java/org/openmrs/module/fhir/resources/FHIRPractitionerResource.java @@ -41,7 +41,7 @@ public List searchByUniqueId(TokenParam id) { return patientService.searchPractitionersById(id.getValue()); } - //search by patient identifier. ex: GET [base-url]/Practitioner?identifier=12345 + //search by patient identifier. ex: GET_DESCRIPTION [base-url]/Practitioner?identifier=12345 //returns a bundle of practitioners public List searchByIdentifier(TokenParam identifier) { org.openmrs.module.fhir.api.PractitionerService patientService = Context diff --git a/omod/src/main/java/org/openmrs/module/fhir/server/ConformanceProvider.java b/omod/src/main/java/org/openmrs/module/fhir/server/ConformanceProvider.java new file mode 100644 index 00000000..90be9822 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/server/ConformanceProvider.java @@ -0,0 +1,46 @@ +/* + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.server; + +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.rest.server.RestfulServer; +import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; + +public class ConformanceProvider { + + private static Conformance conformance = null; + private static RestfulServer restfulServer; + + public static void setConformance(Conformance conformanceStatement) { + conformance = conformanceStatement; + } + + public static Conformance getConformance() { + if(conformance == null) { + ServerConformanceProvider confProvider = (ServerConformanceProvider) restfulServer.getServerConformanceProvider(); + conformance = confProvider.getServerConformance(null); + return conformance; + } else { + return conformance; + } + } + + public static RestfulServer getRestfulServer() { + return restfulServer; + } + + public void setRestfulServer(RestfulServer restfulServer) { + this.restfulServer = restfulServer; + } +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/server/FHIRRESTServer.java b/omod/src/main/java/org/openmrs/module/fhir/server/FHIRRESTServer.java index a3526073..01f86861 100644 --- a/omod/src/main/java/org/openmrs/module/fhir/server/FHIRRESTServer.java +++ b/omod/src/main/java/org/openmrs/module/fhir/server/FHIRRESTServer.java @@ -18,6 +18,8 @@ import javax.servlet.ServletException; +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.rest.server.provider.dstu2.ServerConformanceProvider; import org.openmrs.module.fhir.addressstrategy.OpenMRSFHIRRequestAddressStrategy; import org.openmrs.module.fhir.api.util.FHIRUtils; import org.openmrs.module.fhir.providers.RestfulAllergyIntoleranceResourceProvider; @@ -85,6 +87,10 @@ protected void initialize() throws ServletException { loggingInterceptor.setLoggerName("test.accesslog"); loggingInterceptor .setMessageFormat("Source[${remoteAddr}] Operation[${operationType} ${idOrResourceName}] UA[${requestHeader.user-agent}] Params[${requestParameters}]"); + ServerConformanceProvider sc = new ServerConformanceProvider(this); + this.setServerConformanceProvider(sc); + ConformanceProvider provider = new ConformanceProvider(); + provider.setRestfulServer(this); } protected String getRequestPath(String requestFullPath, String servletContextPath, String servletPath) { diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerDocConstants.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerDocConstants.java new file mode 100644 index 00000000..ef9c5b89 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerDocConstants.java @@ -0,0 +1,409 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + *

+ * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + *

+ * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger; + +public class SwaggerDocConstants { + + public static final String VERSION = "1.0.0"; + public static final String UTF_8 = "UTF-8"; + public static final String SHORT_FHIR_REST_PREFIX = "/openmrs/ws/fhir"; + public static final String HTTP = "http"; + public static final String HTTPS = "https"; + public static final String STR_EMPTY = ""; + public static final String HTTP_WITH_SLASHES = "http://"; + public static final String HTTPS_WITH_SLASHES = "https://"; + public static final String SLASHES = "://"; + public static final String OPENMRS_PREFIX = "/openmrs"; + public static final String COLON = ":"; + public static final String OPERATION_OUTCOME = "OperationOutcome"; + public static final String TITLE = "OpenMRS FHIR REST Services"; + public static final String DESCRIPTION = "Auto-generated documentation for OpenMRS FHIR Rest services"; + public static final String CONTACT_NAME = "OpenMRS FHIR Module Team"; + public static final String CONTACT_URL = "https://talk.openmrs.org/c/dev"; + public static final String CONTACT_EMAIL = "community@openmrs.org"; + public static final String LICENSE_NAME = "Mozilla Public License, v. 2.0"; + public static final String LICENSE_URL = "http://openmrs.org/license/"; + public static final String PRODUCES_XML = "application/xml"; + public static final String PRODUCES_JSON = "application/json"; + public static final String CONSUMES_XML = "application/xml"; + public static final String CONSUMES_JSON = "application/json"; + public static final String TERMS_AND_CONDITIONS = "https://www.mozilla.org/en-US/MPL/2.0/"; + public static final String BODY = "body"; + public static final String BUNDLE = "Bundle"; + public static final String FHIR_RESOURCE_CREATE = "create"; + public static final String FHIR_RESOURCE_update = "update"; + public static final String FHIR_RESOURCE_DELETE = "delete"; + public static final String FHIR_RESOURCE_READ= "read"; + public static final String FHIR_RESOURCE_SEARCH = "search"; + public static final String API_RESOURCE_ID = "{id}"; + public static final String SCHEMA_HTTP = "http"; + public static final String SCHEMA_HTTPS = "https"; + public static final String MORE_INFO = "Find more info here"; + public static final String DOCS_URL = "https://wiki.openmrs.org/display/projects/OpenMRS+FHIR+Module"; + public static final String READ = "read"; + public static final String CREATE = "create"; + public static final String UPDATE = "update"; + public static final String SEARCH_TYPE = "search-type"; + public static final String DELETE = "delete"; + public static final String GET = "get"; + public static final String PUT = "put"; + public static final String POST = "post"; + public static final String GET_DESCRIPTION = "Get"; + public static final String DELETE_DESCRIPTION = "Delete"; + public static final String BUNDLE_DESCRIPTION = "Bundle of"; + public static final String RESOURCES = "resources"; + public static final String CREATE_RESOURCE = "Create"; + public static final String UPDATR_RESOURCE = "Update"; + public static final String RESOURCE_BY_ID = "resource by id"; + public static final String READ_RESOURCE_PATH = "{id}"; + public static final String POST_RESOURCE_PATH = "{id}"; + public static final String UPDATE_RESOURCE_PATH = "{id}"; + public static final String DELETE_RESOURCE_PATH = "{id}"; + public static final String DETAILS_OF_GIVEN_ID = "details of given id"; + public static final String EVERYTHING_OF_GIVEN_ID = "everything of given id"; + public static final String CONTENT_OF_THE_REQUEST = "from the content of the request"; + public static final String RETURNS = "Returns"; + public static final String ID_DESCRIPTION = "Id of the "; + public static final String RESOURCE = "resource"; + public static final String BODY_SAMPLE_VALUE = "constant body parameter"; + public static final String ID = "id"; + public static final String _ID = "_id"; + public static final String IN_PATH = "path"; + public static final String IN_QUERY = "query"; + public static final String IN_BODY = "body"; + public static final String SUCCESS_RESPONSE = "successResponse"; + public static final String SUCCESS_RESPONSE_CODE = "200"; + public static final String ERROR_RESPONSE = "errorResponse"; + public static final String OBJECT = "object"; + public static final String ARRAY = "array"; + public static final String ERROR_RESPONSE_CODE = "404"; + public static final String FORMAT_PARAM = "_format"; + public static final String GENERAL_ERROR = "GeneralError"; + public static final String EVERYTHING = "$everything"; + public static final String ERROR_OCCURRED = "When error occurred"; + public static final String FORMAT_PARAM_NAME = "formatParam"; + public static final String NAME_PATIENT = "patient"; + public static final String SEARCH_RESOURCE = "Search"; + public static final String SEARCH_RESOURCE_BY_PARAMETERS = "by parameters"; + public static final String STRUCTURE_DEFINITION= "StructureDefinition"; + public static final String RETURNS_MATCHING_RESTULS = "matching results"; + public static final String RETURNS_SUCCESS_OPERATION_OUTCOME = "Returns success operation outcome"; + public static final String FORMAT_PARAM_DESC = "Format parameter can use to get response by setting _fromat param value " + + " from xml by _format=xml and response from json by _format=json"; + public static final String PATIENT_RESOURCE = "Patient"; + public static final String PERSON_RESOURCE = "Person"; + public static final String ENCOUNTER_RESOURCE = "Encounter"; + public static final String ALLERGY_RESOURCE = "AllergyIntolerance"; + public static final String OBSERVATION_RESOURCE = "Observation"; + public static final String LOCATION_RESOURCE = "Location"; + public static final String FAMILY_HISTORY_RESOURCE = "FamilyMemberHistory"; + public static final String PRACTITIONER_RESOURCE = "Practitioner"; + public static final String EMPTY = "{\n" + + " \"message\": \"Please refer docs\"\n" + + "}"; + public static final String ERROR_PAYLOAD = "{\"resourceType\":\"OperationOutcome\",\"issue\":[{\"severity\":\"error\",\"details\":\"Details of error\"}]}"; + public static final String SUCCESS_PAYLOAD = "{\"resourceType\":\"OperationOutcome\",\"issue\":[{\"severity\":\"information\",\"details\":\"Details of operation\"}]}"; + public static final String PATIENT_PAYLOAD = "{\n" + + " \"resourceType\": \"Patient\",\n" + + " \"id\": \"example\",\n" + + " \"identifier\": [\n" + + " {\n" + + " \"use\": \"usual\",\n" + + " \"label\": \"MRN\",\n" + + " \"system\": \"urn:oid:1.2.36.146.595.217.0.1\",\n" + + " \"value\": \"12345\",\n" + + " \"period\": {\n" + + " \"start\": \"2001-05-06\"\n" + + " },\n" + + " \"assigner\": {\n" + + " \"display\": \"Acme Healthcare\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"name\": [\n" + + " {\n" + + " \"use\": \"official\",\n" + + " \"family\": [\n" + + " \"Chalmers\"\n" + + " ],\n" + + " \"given\": [\n" + + " \"Peter\",\n" + + " \"James\"\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"use\": \"usual\",\n" + + " \"given\": [\n" + + " \"Jim\"\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"telecom\": [\n" + + " {\n" + + " \"use\": \"home\"\n" + + " },\n" + + " {\n" + + " \"system\": \"phone\",\n" + + " \"value\": \"(03) 5555 6473\",\n" + + " \"use\": \"work\"\n" + + " }\n" + + " ],\n" + + " \"gender\": \"male\",\n" + + " \"birthDate\": \"1974-12-25\",\n" + + " \"deceasedBoolean\": false,\n" + + " \"address\": [\n" + + " {\n" + + " \"use\": \"home\",\n" + + " \"line\": [\n" + + " \"534 Erewhon St\"\n" + + " ],\n" + + " \"city\": \"PleasantVille\",\n" + + " \"state\": \"Vic\",\n" + + " \"postalCode\": \"3999\"\n" + + " }\n" + + " ],\n" + + " \"active\": true\n" + + "}"; + + public static final String OBSERVATION_PAYLOAD = "{\n" + + " \"resourceType\": \"Observation\",\n" + + " \"name\": [\n" + + " {\n" + + " \"coding\": {\n" + + " \"system\": \"UNSPECIFIED\",\n" + + " \"code\": \"39156-5\",\n" + + " \"display\": \"Body Mass Index\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"valueQuantity\": {\n" + + " \"value\": 18.14,\n" + + " \"units\": \"kg/m2\",\n" + + " \"system\": \"http://unitsofmeasure.org\",\n" + + " \"code\": \"kg/m2\"\n" + + " },\n" + + " \"appliesDateTime\": \"2011-05-17T00:00:00\",\n" + + " \"issued\": \"2014-09-13T22:02:34.000\",\n" + + " \"status\": \"final\",\n" + + " \"reliability\": \"ok\",\n" + + " \"subject\": {\n" + + " \"reference\": \"Patient/dda12af7-1691-11df-97a5-7038c432aabf\",\n" + + " \"display\": \"Valentine Ekero(Identifier:8079AM-6)\"\n" + + " },\n" + + " \"referenceRange\": [\n" + + " {\n" + + " \"low\": {\n" + + " \"value\": 0\n" + + " },\n" + + " \"high\": {\n" + + " \"value\": 100\n" + + " }\n" + + " }\n" + + " ]\n" + + "}"; + + public static final String LOCATION_PAYLOAD = "{\n" + + " \"resourceType\": \"Location\",\n" + + " \"id\": \"a846f32f-5401-4d53-871a-68354c22c3f9\",\n" + + " \"name\": \"South Wing, second floor\",\n" + + " \"description\": \"Second floor of the Old South Wing, formerly in use by Psychiatry\",\n" + + " \"address\": {\n" + + " \"use\": \"work\",\n" + + " \"line\": [\n" + + " \"Galapagosweg 91, Building A\",\n" + + " \"line 3\",\n" + + " \"line 4\",\n" + + " \"line 5\"\n" + + " ],\n" + + " \"city\": \"Den Burg\",\n" + + " \"postalCode\": \"9105 PZ\",\n" + + " \"country\": \"NLD\",\n" + + " \"state\": \"southern\"\n" + + " },\n" + + " \"position\": {\n" + + " \"longitude\": -83.6945691,\n" + + " \"latitude\": 42.25475478\n" + + " },\n" + + " \"partOf\": {\n" + + " \"reference\": \"Location/c0937d4f-1691-11df-97a5-7038c432aabf\",\n" + + " \"display\": \"Mosoriot Hospital\"\n" + + " },\n" + + " \"status\": \"active\"\n" + + "}"; + + public static final String ENCOUNTER_PAYLOAD = "{\n" + + " \"resourceType\": \"Encounter\",\n" + + " \"status\": \"finished\",\n" + + " \"class\": \"inpatient\",\n" + + " \"subject\": {\n" + + " \"reference\": \"Patient/dd738d54-1691-11df-97a5-7038c432aabf\",\n" + + " \"display\": \"Daisylene Ekeno(Identifier:1865TU-8)\"\n" + + " },\n" + + " \"participant\": [\n" + + " {\n" + + " \"individual\": {\n" + + " \"reference\": \"Practitioner/bf218490-1691-11df-97a5-7038c432aabf\",\n" + + " \"display\": \"Super User(Identifier:admin)\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"period\": {\n" + + " \"start\": \"2006-02-07T00:00:00\",\n" + + " \"end\": \"2006-02-07T00:00:00\"\n" + + " },\n" + + " \"location\": [\n" + + " {\n" + + " \"location\": {\n" + + " \"reference\": \"Location/8d6c993e-c2cc-11de-8d13-0010c6dffd0f\",\n" + + " \"display\": \"Inpatient Ward\"\n" + + " },\n" + + " \"period\": {\n" + + " \"start\": \"2006-02-07T00:00:00\",\n" + + " \"end\": \"2006-02-07T00:00:00\"\n" + + " }\n" + + " }\n" + + " ]\n" + + "}"; + + public static final String PRACTITIONER_PAYLOAD = "{\n" + + " \"resourceType\": \"Practitioner\",\n" + + " \"id\": \"a846f32f-5401-4d53-871a-68354c22c3f9\",\n" + + " \"identifier\": [\n" + + " {\n" + + " \"system\": \"http://www.acme.org/practitioners\",\n" + + " \"value\": \"clerk\"\n" + + " }\n" + + " ],\n" + + " \"name\": {\n" + + " \"family\": [\n" + + " \"Careful\"\n" + + " ],\n" + + " \"given\": [\n" + + " \"Adam\"\n" + + " ]\n" + + " },\n" + + " \"address\": [\n" + + " {\n" + + " \"use\": \"home\",\n" + + " \"city\": \"E. Kanateng\"\n" + + " }\n" + + " ],\n" + + " \"gender\": {\n" + + " \"coding\": [\n" + + " {\n" + + " \"system\": \"http://hl7.org/fhir/v3/AdministrativeGender\",\n" + + " \"code\": \"M\"\n" + + " }\n" + + " ]\n" + + " },\n" + + " \"birthDate\": \"2009-08-11T00:00:00\"\n" + + "}"; + + public static final String FAMILY_HISTORY_PAYLOAD = "{\n" + + " \"resourceType\": \"FamilyHistory\",\n" + + " \"id\": \"dda12af7-1691-11df-97a5-7038c432aabf\",\n" + + " \"patient\": {\n" + + " \"reference\": \"Patient/example\",\n" + + " \"display\": \"Peter Patient\"\n" + + " },\n" + + " \"relation\": [\n" + + " {\n" + + " \"relationship\": {\n" + + " \"coding\": [\n" + + " {\n" + + " \"system\": \"http://hl7.org/fhir/familial-relationship\",\n" + + " \"code\": \"father\"\n" + + " }\n" + + " ]\n" + + " },\n" + + " \"condition\": [\n" + + " {\n" + + " \"type\": {\n" + + " \"coding\": [\n" + + " {\n" + + " \"system\": \"http://snomed.info/sct\",\n" + + " \"code\": \"315619001\",\n" + + " \"display\": \"Myocardial Infarction\"\n" + + " }\n" + + " ],\n" + + " \"text\": \"Heart Attack\"\n" + + " },\n" + + " \"onsetAge\": {\n" + + " \"value\": 74,\n" + + " \"units\": \"a\",\n" + + " \"system\": \"http://unitsofmeasure.org\"\n" + + " },\n" + + " \"note\": \"Was fishing at the time. At least he went doing someting he loved.\"\n" + + " }\n" + + " ]\n" + + " }\n" + + " ]\n" + + "}"; + public static final String PERSON_PAYLOAD = "{\n" + + " \"resourceType\": \"Person\",\n" + + " \"id\": \"dda12af7-1691-11df-97a5-7038c432aabf\",\n" + + " \"name\": [\n" + + " {\n" + + " \"use\": \"official\",\n" + + " \"family\": [\n" + + " \"Chalmers\"\n" + + " ],\n" + + " \"given\": [\n" + + " \"Peter\",\n" + + " \"James\"\n" + + " ]\n" + + " },\n" + + " {\n" + + " \"use\": \"usual\",\n" + + " \"given\": [\n" + + " \"Jim\"\n" + + " ]\n" + + " }\n" + + " ],\n" + + " \"gender\": \"male\",\n" + + " \"birthDate\": \"1974-12-25\",\n" + + " \"address\": [\n" + + " {\n" + + " \"use\": \"home\",\n" + + " \"line\": [\n" + + " \"534 Erewhon St\"\n" + + " ],\n" + + " \"city\": \"PleasantVille\",\n" + + " \"state\": \"Vic\",\n" + + " \"postalCode\": \"3999\"\n" + + " }\n" + + " ],\n" + + " \"active\": true\n" + + "}"; + + public static final String ALLERGY_PAYLOAD = "{\n" + + " \"resourceType\": \"AllergyIntolerance\",\n" + + " \"id\": \"249d8c08-f453-4e7d-a46d-f68659e7d9e7\",\n" + + " \"recordedDate\": \"2015-03-31T00:00:00\",\n" + + " \"subject\": {\n" + + " \"reference\": \"Patient/dd9a7551-1691-11df-97a5-7038c432aabf\",\n" + + " \"display\": \"John Shavola(Identifier:7279MP-4)\"\n" + + " },\n" + + " \"substance\": {\n" + + " \"coding\": [\n" + + " {\n" + + " \"system\": \"http://openmrs.org\",\n" + + " \"code\": \"be4d5acd-1691-11df-97a5-7038c432aabf\",\n" + + " \"display\": \"AMYLASE\"\n" + + " }\n" + + " ]\n" + + " },\n" + + " \"criticality\": \"unassessible\"\n" + + "}"; +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerSpecificationController.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerSpecificationController.java new file mode 100644 index 00000000..3511d9dd --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerSpecificationController.java @@ -0,0 +1,67 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + *

+ * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + *

+ * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.api.context.Context; +import org.openmrs.module.fhir.api.util.FHIRConstants; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +public class SwaggerSpecificationController extends HttpServlet { + protected Log log = LogFactory.getLog(getClass()); + + protected void doGet(HttpServletRequest request, HttpServletResponse response) + throws ServletException { + + String swaggerSpecificationJSON; + try { + StringBuilder baseUrl = new StringBuilder(); + String scheme = request.getScheme(); + int port = request.getServerPort(); + + baseUrl.append(scheme); // http, https + baseUrl.append(SwaggerDocConstants.SLASHES); + baseUrl.append(request.getServerName()); + if ((SwaggerDocConstants.HTTP.equals(scheme) && port != 80) || (SwaggerDocConstants.HTTPS.equals(scheme) && port != 443)) { + baseUrl.append(SwaggerDocConstants.COLON); + baseUrl.append(request.getServerPort()); + } + + baseUrl.append(request.getContextPath()); + String resourcesUrl = Context.getAdministrationService().getGlobalProperty(FHIRConstants.URI_PREFIX_GLOBAL_PROPERTY_NAME, baseUrl.toString()); + String urlWithoutScheme = ""; + String basePath = SwaggerDocConstants.SHORT_FHIR_REST_PREFIX; + if (SwaggerDocConstants.HTTP.equals(scheme)) { + urlWithoutScheme = resourcesUrl.replace(SwaggerDocConstants.HTTP_WITH_SLASHES, SwaggerDocConstants.STR_EMPTY); + } else if (SwaggerDocConstants.HTTPS.equals(scheme)) { + urlWithoutScheme = resourcesUrl.replace(SwaggerDocConstants.HTTPS_WITH_SLASHES, SwaggerDocConstants.STR_EMPTY); + } + urlWithoutScheme = urlWithoutScheme.replace(SwaggerDocConstants.OPENMRS_PREFIX, SwaggerDocConstants.STR_EMPTY); + SwaggerSpecificationCreator creator = new SwaggerSpecificationCreator(urlWithoutScheme, basePath); + swaggerSpecificationJSON = creator.buildJSON(); + response.setContentType(SwaggerDocConstants.PRODUCES_JSON); + response.setCharacterEncoding(SwaggerDocConstants.UTF_8); + response.getWriter().write(swaggerSpecificationJSON); + } catch (Exception e) { + log.error("Error while processing request", e); + } + } + +} + diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerSpecificationCreator.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerSpecificationCreator.java new file mode 100644 index 00000000..1d50f700 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/SwaggerSpecificationCreator.java @@ -0,0 +1,647 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + *

+ * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + *

+ * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger; + +import ca.uhn.fhir.model.dstu2.resource.Conformance; +import ca.uhn.fhir.model.dstu2.resource.OperationDefinition; +import ca.uhn.fhir.model.primitive.CodeDt; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openmrs.module.fhir.server.ConformanceProvider; +import org.openmrs.module.fhir.swagger.docs.Contact; +import org.openmrs.module.fhir.swagger.docs.Definition; +import org.openmrs.module.fhir.swagger.docs.Definitions; +import org.openmrs.module.fhir.swagger.docs.ExternalDocs; +import org.openmrs.module.fhir.swagger.docs.Info; +import org.openmrs.module.fhir.swagger.docs.License; +import org.openmrs.module.fhir.swagger.docs.NullSerializer; +import org.openmrs.module.fhir.swagger.docs.Operation; +import org.openmrs.module.fhir.swagger.docs.Parameter; +import org.openmrs.module.fhir.swagger.docs.Path; +import org.openmrs.module.fhir.swagger.docs.Paths; +import org.openmrs.module.fhir.swagger.docs.Response; +import org.openmrs.module.fhir.swagger.docs.Schema; +import org.openmrs.module.fhir.swagger.docs.SwaggerSpecification; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SwaggerSpecificationCreator { + protected Log log = LogFactory.getLog(getClass()); + private SwaggerSpecification swaggerSpecification; + private Conformance conformance; + private String baseUrl; + private String basePath; + private Map definitionMap = new HashMap(); + + public SwaggerSpecificationCreator(String baseUrl, String basePath) { + this.swaggerSpecification = new SwaggerSpecification(); + this.conformance = ConformanceProvider.getConformance(); + this.baseUrl = baseUrl; + this.basePath = basePath; + } + + public String buildJSON() { + synchronized (this) { + createApiDefinition(); + addPaths(); + addParameters(); + createObjectDefinitions(); + } + return createSwaggerSpecification(); + } + + /* + * Creating the information section of the swagger including base path licence + */ + private void createApiDefinition() { + Info info = new Info(); + info.setVersion(SwaggerDocConstants.VERSION); + info.setTitle(SwaggerDocConstants.TITLE); + info.setDescription(SwaggerDocConstants.DESCRIPTION); + info.setTermsOfService(SwaggerDocConstants.TERMS_AND_CONDITIONS); + //Setting the contact + Contact contact = new Contact(); + contact.setName(SwaggerDocConstants.CONTACT_NAME); + contact.setUrl(SwaggerDocConstants.CONTACT_URL); + contact.setEmail(SwaggerDocConstants.CONTACT_EMAIL); + //Setting the licence + License license = new License(); + license.setName(SwaggerDocConstants.LICENSE_NAME); + license.setUrl(SwaggerDocConstants.LICENSE_URL); + info.setContact(contact); + info.setLicense(license); + swaggerSpecification.setInfo(info); + List produces = new ArrayList(); + //Set mime type supported + produces.add(SwaggerDocConstants.PRODUCES_JSON); + produces.add(SwaggerDocConstants.PRODUCES_XML); + List formats = conformance.getFormat(); + for(CodeDt format : formats) { + produces.add(format.getValue()); + } + List consumes = new ArrayList(); + consumes.add(SwaggerDocConstants.CONSUMES_XML); + consumes.add(SwaggerDocConstants.CONSUMES_JSON); + swaggerSpecification.setHost(getBaseUrl()); + swaggerSpecification.setProduces(produces); + swaggerSpecification.setConsumes(consumes); + swaggerSpecification.setBasePath(basePath); + List schemas = new ArrayList(); + schemas.add(SwaggerDocConstants.SCHEMA_HTTP); + schemas.add(SwaggerDocConstants.SCHEMA_HTTPS); + ExternalDocs externalDocs = new ExternalDocs(); + externalDocs.setDescription(SwaggerDocConstants.MORE_INFO); + externalDocs.setUrl(SwaggerDocConstants.DOCS_URL); + swaggerSpecification.setExternalDocs(externalDocs); + } + + /** + * Creating paths section swagger documentation + */ + private void addPaths() { + List resources = conformance.getRest(); + Paths fullPaths = new Paths();//Hold full path list + Map pathMap = new HashMap();//Map holding path to path object mappings + for (Conformance.Rest restResource : resources) { + for (Conformance.RestResource resource : restResource.getResource()) { + String resourceName = resource.getType(); + if(SwaggerDocConstants.STRUCTURE_DEFINITION.equalsIgnoreCase(resourceName)) { + continue; + } + List restResourceInteractions = resource.getInteraction(); + //Iterating over available opearations + for(Conformance.RestResourceInteraction restResourceInteraction : restResourceInteractions) { + //Add GET operation paths + if(SwaggerDocConstants.READ.equalsIgnoreCase(restResourceInteraction.getCode())) { + String pathId = "/" + resourceName + "/" + SwaggerDocConstants.READ_RESOURCE_PATH; + Path read; + Map readOperationsMap; + if(pathMap.containsKey(pathId)) { + read = pathMap.get(pathId); + readOperationsMap = read.getOperations(); + if(readOperationsMap == null) { + readOperationsMap = new HashMap(); + } + } else { + read = new Path(); + readOperationsMap = new HashMap(); + } + Operation readOperation = new Operation(); + readOperation.setSummary(SwaggerDocConstants.RETURNS + " " + resourceName + " " + SwaggerDocConstants.DETAILS_OF_GIVEN_ID); + List produces = new ArrayList(); + //Set mime type supported + produces.add(SwaggerDocConstants.PRODUCES_JSON); + produces.add(SwaggerDocConstants.PRODUCES_XML); + List formats = conformance.getFormat(); + for(CodeDt format : formats) { + produces.add(format.getValue()); + } + readOperation.setProduces(produces); + //Set parameters + List parameters = new ArrayList(); + Parameter parameter = new Parameter(); + parameter.setDescription(SwaggerDocConstants.ID_DESCRIPTION + " " + resourceName + " " + SwaggerDocConstants.RESOURCE); + parameter.setName(SwaggerDocConstants.ID); + parameter.setIn(SwaggerDocConstants.IN_PATH); + parameter.setRequired(true); + parameters.add(parameter); + readOperation.setParameters(parameters);; + + Map responseMap = new HashMap(); + //Set response schemas and example responses + Response responseSuccess = new Response(); + responseSuccess.setDescription(SwaggerDocConstants.RETURNS + " " + resourceName + " " + SwaggerDocConstants.DETAILS_OF_GIVEN_ID); + Schema schemaSuccess = new Schema(); + schemaSuccess.setRef(getSchemaRef(resourceName)); + schemaSuccess.setType(SwaggerDocConstants.OBJECT); + setExamples(resourceName, responseSuccess); + responseSuccess.setSchema(schemaSuccess); + responseMap.put(SwaggerDocConstants.SUCCESS_RESPONSE_CODE, responseSuccess); + + Response responseError = new Response(); + responseError.setDescription(SwaggerDocConstants.ERROR_OCCURRED); + Schema schemaError = new Schema(); + schemaError.setRef(getSchemaRef(SwaggerDocConstants.GENERAL_ERROR)); + schemaError.setType(SwaggerDocConstants.OBJECT); + responseError.setSchema(schemaError); + Map examplesError = new HashMap(); + examplesError.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.ERROR_PAYLOAD); + responseError.setExamples(examplesError); + responseMap.put(SwaggerDocConstants.ERROR_RESPONSE_CODE, responseError); + readOperation.setResponses(responseMap); + + readOperationsMap.put(SwaggerDocConstants.GET, readOperation); + read.setOperations(readOperationsMap); + pathMap.put(pathId, read); + } else if(SwaggerDocConstants.CREATE.equalsIgnoreCase(restResourceInteraction.getCode())) { + //Set POST operation path properties + String pathId = "/" + resourceName; + Path create; + Map createOperationsMap; + if(pathMap.containsKey(pathId)) { + create = pathMap.get(pathId); + createOperationsMap = create.getOperations(); + if(createOperationsMap == null) { + createOperationsMap = new HashMap(); + } + } else { + create = new Path(); + createOperationsMap = new HashMap(); + } + Operation createOperation = new Operation(); + createOperation.setSummary(SwaggerDocConstants.CREATE_RESOURCE + " " + resourceName + + " " + SwaggerDocConstants.RESOURCE + " " + SwaggerDocConstants.CONTENT_OF_THE_REQUEST); + List produces = new ArrayList(); + //Set mime type supported + produces.add(SwaggerDocConstants.PRODUCES_JSON); + produces.add(SwaggerDocConstants.PRODUCES_XML); + List formats = conformance.getFormat(); + for(CodeDt format : formats) { + produces.add(format.getValue()); + } + createOperation.setProduces(produces); + //Set parameters + List parameters = new ArrayList(); + Parameter parameter = new Parameter(); + parameter.setDescription(resourceName + " " + SwaggerDocConstants.RESOURCE + " " + SwaggerDocConstants.OBJECT); + parameter.setName(SwaggerDocConstants.BODY); + parameter.setIn(SwaggerDocConstants.IN_BODY); + parameter.setType(null); + parameter.setRequired(true); + Schema schema = new Schema(); + schema.setRef(getSchemaRef(resourceName)); + parameter.setSchema(schema); + parameters.add(parameter); + createOperation.setParameters(parameters); + + //Set response properties + Map responseMap = new HashMap(); + Response responseSuccess = new Response(); + responseSuccess.setDescription(SwaggerDocConstants.RETURNS_SUCCESS_OPERATION_OUTCOME); + Schema schemaSuccess = new Schema(); + schemaSuccess.setRef(getSchemaRef(SwaggerDocConstants.OPERATION_OUTCOME)); + schemaSuccess.setType(SwaggerDocConstants.OBJECT); + responseSuccess.setSchema(schemaSuccess); + Map examplesSuccess = new HashMap(); + examplesSuccess.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.SUCCESS_PAYLOAD); + responseSuccess.setExamples(examplesSuccess); + responseMap.put(SwaggerDocConstants.SUCCESS_RESPONSE_CODE, responseSuccess); + + Response responseError = new Response(); + responseError.setDescription(SwaggerDocConstants.ERROR_OCCURRED); + Schema schemaError = new Schema(); + schemaError.setRef(getSchemaRef(SwaggerDocConstants.GENERAL_ERROR)); + schemaError.setType(SwaggerDocConstants.OBJECT); + Map examplesError = new HashMap(); + examplesError.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.ERROR_PAYLOAD); + responseError.setExamples(examplesError); + responseError.setSchema(schemaError); + responseMap.put(SwaggerDocConstants.ERROR_RESPONSE_CODE, responseError); + createOperation.setResponses(responseMap); + + createOperationsMap.put(SwaggerDocConstants.POST, createOperation); + create.setOperations(createOperationsMap); + pathMap.put(pathId, create); + } else if(SwaggerDocConstants.UPDATE.equalsIgnoreCase(restResourceInteraction.getCode())) { + //Configure PUT operation path properties + String pathId = "/" + resourceName + "/" + SwaggerDocConstants.UPDATE_RESOURCE_PATH; + Path update; + Map updateOperationsMap; + if(pathMap.containsKey(pathId)) { + update = pathMap.get(pathId); + updateOperationsMap = update.getOperations(); + if(updateOperationsMap == null) { + updateOperationsMap = new HashMap(); + } + } else { + update = new Path(); + updateOperationsMap = new HashMap(); + } + Operation updateOperation = new Operation(); + updateOperation.setSummary(SwaggerDocConstants.UPDATR_RESOURCE + " " + resourceName + + " " + SwaggerDocConstants.RESOURCE + " " + SwaggerDocConstants.CONTENT_OF_THE_REQUEST); + List produces = new ArrayList(); + //Set mime type supported + produces.add(SwaggerDocConstants.PRODUCES_JSON); + produces.add(SwaggerDocConstants.PRODUCES_XML); + List formats = conformance.getFormat(); + for(CodeDt format : formats) { + produces.add(format.getValue()); + } + updateOperation.setProduces(produces); + //Set put operation parameters and responses + List parameters = new ArrayList(); + Parameter parameter = new Parameter(); + parameter.setDescription(resourceName + " " + SwaggerDocConstants.RESOURCE + " " + SwaggerDocConstants.OBJECT); + parameter.setName(SwaggerDocConstants.BODY); + parameter.setIn(SwaggerDocConstants.IN_BODY); + parameter.setRequired(true); + parameter.setType(null); + + Schema schema = new Schema(); + schema.setRef(getSchemaRef(resourceName)); + parameter.setSchema(schema); + + parameters.add(parameter); + + Parameter parameterId = new Parameter(); + parameterId.setDescription(SwaggerDocConstants.ID_DESCRIPTION + " " + resourceName + " " + SwaggerDocConstants.RESOURCE); + parameterId.setName(SwaggerDocConstants.ID); + parameterId.setIn(SwaggerDocConstants.IN_PATH); + parameterId.setRequired(true); + parameters.add(parameterId); + + updateOperation.setParameters(parameters); + + Map responseMap = new HashMap(); + Response responseSuccess = new Response(); + responseSuccess.setDescription(SwaggerDocConstants.RETURNS_SUCCESS_OPERATION_OUTCOME); + Schema schemaSuccess = new Schema(); + schemaSuccess.setRef(getSchemaRef(SwaggerDocConstants.OPERATION_OUTCOME)); + schemaSuccess.setType(SwaggerDocConstants.OBJECT); + responseSuccess.setSchema(schemaSuccess); + Map examplesSuccess = new HashMap(); + examplesSuccess.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.SUCCESS_PAYLOAD); + responseSuccess.setExamples(examplesSuccess); + responseMap.put(SwaggerDocConstants.SUCCESS_RESPONSE_CODE, responseSuccess); + + Response responseError = new Response(); + responseError.setDescription(SwaggerDocConstants.ERROR_OCCURRED); + Schema schemaError = new Schema(); + schemaError.setRef(getSchemaRef(SwaggerDocConstants.GENERAL_ERROR)); + schemaError.setType(SwaggerDocConstants.OBJECT); + responseError.setSchema(schemaError); + Map examplesError = new HashMap(); + examplesError.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.ERROR_PAYLOAD); + responseError.setExamples(examplesError); + responseMap.put(SwaggerDocConstants.ERROR_RESPONSE_CODE, responseError); + updateOperation.setResponses(responseMap); + + updateOperationsMap.put(SwaggerDocConstants.PUT, updateOperation); + update.setOperations(updateOperationsMap); + pathMap.put(pathId, update); + } else if(SwaggerDocConstants.DELETE.equalsIgnoreCase(restResourceInteraction.getCode())) { + //Set DELETE operation path properties + String pathId = "/" + resourceName + "/" + SwaggerDocConstants.DELETE_RESOURCE_PATH; + Path delete; + Map deleteOperationMap; + if(pathMap.containsKey(pathId)) { + delete = pathMap.get(pathId); + deleteOperationMap = delete.getOperations(); + if(deleteOperationMap == null) { + deleteOperationMap = new HashMap(); + } + } else { + delete = new Path(); + deleteOperationMap = new HashMap(); + } + Operation deleteOperation = new Operation(); + deleteOperation.setSummary(SwaggerDocConstants.RETURNS + " " + resourceName + " " + SwaggerDocConstants.DETAILS_OF_GIVEN_ID); + + List produces = new ArrayList(); + //Set mime type supported + produces.add(SwaggerDocConstants.PRODUCES_JSON); + produces.add(SwaggerDocConstants.PRODUCES_XML); + List formats = conformance.getFormat(); + for(CodeDt format : formats) { + produces.add(format.getValue()); + } + deleteOperation.setProduces(produces); + List parameters = new ArrayList(); + Parameter parameter = new Parameter(); + parameter.setDescription(SwaggerDocConstants.ID_DESCRIPTION + " " + resourceName + " " + SwaggerDocConstants.RESOURCE); + parameter.setName(SwaggerDocConstants.ID); + parameter.setIn(SwaggerDocConstants.IN_PATH); + parameter.setRequired(true); + parameters.add(parameter); + deleteOperation.setParameters(parameters);; + + Map responseMap = new HashMap(); + Response responseSuccess = new Response(); + responseSuccess.setDescription(SwaggerDocConstants.DELETE_DESCRIPTION + " " + resourceName + " " + SwaggerDocConstants.DETAILS_OF_GIVEN_ID); + Map examplesSuccess = new HashMap(); + examplesSuccess.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.SUCCESS_PAYLOAD); + responseSuccess.setExamples(examplesSuccess); + responseMap.put(SwaggerDocConstants.SUCCESS_RESPONSE_CODE, responseSuccess); + + Response responseError = new Response(); + responseError.setDescription(SwaggerDocConstants.ERROR_OCCURRED); + Schema schemaError = new Schema(); + schemaError.setRef(getSchemaRef(SwaggerDocConstants.GENERAL_ERROR)); + schemaError.setType(SwaggerDocConstants.OBJECT); + Map examplesError = new HashMap(); + examplesError.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.ERROR_PAYLOAD); + responseError.setExamples(examplesError); + responseError.setSchema(schemaError); + responseMap.put(SwaggerDocConstants.ERROR_RESPONSE_CODE, responseError); + deleteOperation.setResponses(responseMap); + + deleteOperationMap.put(SwaggerDocConstants.DELETE, deleteOperation); + delete.setOperations(deleteOperationMap); + pathMap.put(pathId, delete); + } else if(SwaggerDocConstants.SEARCH_TYPE.equalsIgnoreCase(restResourceInteraction.getCode())) { + //Set search operation GET method parameters + String pathId = "/" + resourceName; + Path search; + Map searchOperationMap; + if(pathMap.containsKey(pathId)) { + search = pathMap.get(pathId); + searchOperationMap = search.getOperations(); + if(searchOperationMap == null) { + searchOperationMap = new HashMap(); + } + } else { + search = new Path(); + searchOperationMap = new HashMap(); + } + Operation searchOperation = new Operation(); + searchOperation.setSummary(SwaggerDocConstants.RETURNS + " " + resourceName + " " + SwaggerDocConstants.RETURNS_MATCHING_RESTULS); + + List produces = new ArrayList(); + //Set mime type supported + produces.add(SwaggerDocConstants.PRODUCES_JSON); + produces.add(SwaggerDocConstants.PRODUCES_XML); + List formats = conformance.getFormat(); + for(CodeDt format : formats) { + produces.add(format.getValue()); + } + searchOperation.setProduces(produces); + Map parameters = new HashMap(); + List searchParams = resource.getSearchParam(); + for(Conformance.RestResourceSearchParam searchParam : searchParams) { + Parameter parameter = new Parameter(); + parameter.setDescription(searchParam.getDocumentation()); + parameter.setName(searchParam.getName()); + parameter.setIn(SwaggerDocConstants.IN_QUERY); + parameter.setRequired(false); + parameters.put(searchParam.getName(), parameter); + } + + Map responseMap = new HashMap(); + Response responseSuccess = new Response(); + responseSuccess.setDescription(SwaggerDocConstants.BUNDLE_DESCRIPTION + " " + resourceName + " " + SwaggerDocConstants.RESOURCES); + Schema schemaSuccess = new Schema(); + schemaSuccess.setRef(getSchemaRef(resourceName)); + schemaSuccess.setType(SwaggerDocConstants.ARRAY); + responseSuccess.setSchema(schemaSuccess); + setExamples(resourceName, responseSuccess); + responseMap.put(SwaggerDocConstants.SUCCESS_RESPONSE_CODE, responseSuccess); + + Response responseError = new Response(); + responseError.setDescription(SwaggerDocConstants.ERROR_OCCURRED); + Schema schemaError = new Schema(); + schemaError.setRef(getSchemaRef(SwaggerDocConstants.GENERAL_ERROR)); + schemaError.setType(SwaggerDocConstants.OBJECT); + responseError.setSchema(schemaError); + Map examplesError = new HashMap(); + examplesError.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.ERROR_PAYLOAD); + responseError.setExamples(examplesError); + responseMap.put(SwaggerDocConstants.ERROR_RESPONSE_CODE, responseError); + searchOperation.setResponses(responseMap); + List parametersAvailable = new ArrayList(); + for(Map.Entry parameter : parameters.entrySet()) { + parametersAvailable.add(parameter.getValue()); + } + searchOperation.setParameters(parametersAvailable); + searchOperationMap.put(SwaggerDocConstants.GET, searchOperation); + search.setOperations(searchOperationMap); + pathMap.put(pathId, search); + } + } + createDefinition(resourceName); + } + + //Set $everything operation properties + for(Conformance.RestOperation restOperation : restResource.getOperation()) { + if(SwaggerDocConstants.EVERYTHING.equalsIgnoreCase(restOperation.getName())) { + OperationDefinition resource = (OperationDefinition) restOperation.getDefinition().getResource(); + String resourceName = resource.getType().get(0).getValue(); + String pathId = "/" + resourceName + "/" + SwaggerDocConstants.POST_RESOURCE_PATH + "/" + SwaggerDocConstants.EVERYTHING; + Path everything; + Map everythingOperationsMap; + if(pathMap.containsKey(pathId)) { + everything = pathMap.get(pathId); + everythingOperationsMap = everything.getOperations(); + if(everythingOperationsMap == null) { + everythingOperationsMap = new HashMap(); + } + } else { + everything = new Path(); + everythingOperationsMap = new HashMap(); + } + + Operation everythingOp = new Operation(); + everythingOp.setSummary(SwaggerDocConstants.RETURNS + " " + resourceName + " " + SwaggerDocConstants.EVERYTHING_OF_GIVEN_ID); + List produces = new ArrayList(); + //Set mime type supported + produces.add(SwaggerDocConstants.PRODUCES_JSON); + produces.add(SwaggerDocConstants.PRODUCES_XML); + List formats = conformance.getFormat(); + for(CodeDt format : formats) { + produces.add(format.getValue()); + } + + everythingOp.setProduces(produces); + + List parameters = new ArrayList(); + Parameter parameter = new Parameter(); + parameter.setDescription(SwaggerDocConstants.ID_DESCRIPTION + " " + resourceName + " " + SwaggerDocConstants.RESOURCE); + parameter.setName(SwaggerDocConstants.ID); + parameter.setIn(SwaggerDocConstants.IN_PATH); + parameter.setRequired(true); + parameters.add(parameter); + + Parameter parameterBody = new Parameter(); + parameterBody.setDescription(resourceName + " " + SwaggerDocConstants.RESOURCE + " " + SwaggerDocConstants.BODY_SAMPLE_VALUE); + parameterBody.setName(SwaggerDocConstants.BODY); + parameterBody.setIn(SwaggerDocConstants.IN_BODY); + parameterBody.setType(null); + parameterBody.setRequired(true); + Schema schema = new Schema(); + schema.setRef(getSchemaRef(resourceName)); + parameterBody.setSchema(schema); + parameters.add(parameterBody); + + everythingOp.setParameters(parameters); + + Map responseMap = new HashMap(); + Response responseSuccess = new Response(); + responseSuccess.setDescription(SwaggerDocConstants.RETURNS + " " + resourceName + " " + SwaggerDocConstants.EVERYTHING_OF_GIVEN_ID); + Schema schemaSuccess = new Schema(); + schemaSuccess.setRef(getSchemaRef(resourceName)); + schemaSuccess.setType(SwaggerDocConstants.OBJECT); + responseSuccess.setSchema(schemaSuccess); + responseMap.put(SwaggerDocConstants.SUCCESS_RESPONSE_CODE, responseSuccess); + + Response responseError = new Response(); + responseError.setDescription(SwaggerDocConstants.ERROR_OCCURRED); + Schema schemaError = new Schema(); + schemaError.setRef(getSchemaRef(SwaggerDocConstants.GENERAL_ERROR)); + schemaError.setType(SwaggerDocConstants.OBJECT); + responseError.setSchema(schemaError); + Map examplesError = new HashMap(); + examplesError.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.ERROR_PAYLOAD); + responseError.setExamples(examplesError); + responseMap.put(SwaggerDocConstants.ERROR_RESPONSE_CODE, responseError); + everythingOp.setResponses(responseMap); + + everythingOperationsMap.put(SwaggerDocConstants.POST, everythingOp); + everything.setOperations(everythingOperationsMap); + pathMap.put(pathId, everything); + } + } + + createDefinition(SwaggerDocConstants.GENERAL_ERROR); + createDefinition(SwaggerDocConstants.OPERATION_OUTCOME); + createDefinition(SwaggerDocConstants.BUNDLE); + } + fullPaths.setPaths(pathMap); + swaggerSpecification.setPaths(fullPaths); + } + + private void createObjectDefinitions() { + Definitions definitions = new Definitions(); + definitions.setDefinitions(definitionMap); + swaggerSpecification.setDefinitions(definitions); + } + + private void createDefinition(String resourceName) { + String definitionName = resourceName; + Definition definition = new Definition(); + definition.setType(SwaggerDocConstants.OBJECT); + definitionMap.put(definitionName, definition); + } + + /** + * @return the swaggerSpecification + */ + public SwaggerSpecification getSwaggerSpecification() { + return swaggerSpecification; + } + + + private String createSwaggerSpecification() { + String json = ""; + try { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(SerializationFeature.INDENT_OUTPUT, true); + mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, true); + mapper.setSerializationInclusion(Include.NON_NULL); + mapper.getSerializerProvider().setNullKeySerializer(new NullSerializer()); + json = mapper.writeValueAsString(swaggerSpecification); + } catch (Exception exp) { + log.error("Error while creating object mapper", exp); + } + return json; + } + + /** + * @return the baseUrl + */ + public String getBaseUrl() { + return baseUrl; + } + + /** + * @param baseUrl the baseUrl to set + */ + public void setBaseUrl(String baseUrl) { + this.baseUrl = baseUrl; + } + + public void addParameters() { + Map parameters = new HashMap(); + Parameter parameter = new Parameter(); + parameter.setName(SwaggerDocConstants.FORMAT_PARAM); + parameter.setDescription(SwaggerDocConstants.FORMAT_PARAM_DESC); + parameter.setIn(SwaggerDocConstants.IN_QUERY); + parameter.setRequired(false); + parameters.put(SwaggerDocConstants.FORMAT_PARAM_NAME, parameter); + swaggerSpecification.setParameters(parameters); + } + + private String getSchemaRef(String resourceName) { + return "#/definitions/" + resourceName; + } + + private void setExamples(String resourceName, Response responseSuccess) { + Map examples = new HashMap(); + if(SwaggerDocConstants.PERSON_RESOURCE.equalsIgnoreCase(resourceName)) { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.PERSON_PAYLOAD); + } else if(SwaggerDocConstants.PATIENT_RESOURCE.equalsIgnoreCase(resourceName)) { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.PATIENT_PAYLOAD); + } else if(SwaggerDocConstants.PRACTITIONER_RESOURCE.equalsIgnoreCase(resourceName)) { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.PRACTITIONER_PAYLOAD); + } else if(SwaggerDocConstants.ENCOUNTER_RESOURCE.equalsIgnoreCase(resourceName)) { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.ENCOUNTER_PAYLOAD); + } else if(SwaggerDocConstants.FAMILY_HISTORY_RESOURCE.equalsIgnoreCase(resourceName)) { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.FAMILY_HISTORY_PAYLOAD); + } else if(SwaggerDocConstants.ALLERGY_RESOURCE.equalsIgnoreCase(resourceName)) { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.ALLERGY_PAYLOAD); + } else if(SwaggerDocConstants.OBSERVATION_RESOURCE.equalsIgnoreCase(resourceName)) { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.OBSERVATION_PAYLOAD); + } else if(SwaggerDocConstants.LOCATION_RESOURCE.equalsIgnoreCase(resourceName)) { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.LOCATION_PAYLOAD); + } else { + examples.put(SwaggerDocConstants.CONSUMES_JSON, SwaggerDocConstants.EMPTY); + } + responseSuccess.setExamples(examples); + } +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Contact.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Contact.java new file mode 100644 index 00000000..be253887 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Contact.java @@ -0,0 +1,64 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +//The contact information for the exposed API. +public class Contact { + + private String name; + + private String url; + + private String email; + + public Contact() { + + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the url + */ + public String getUrl() { + return url; + } + + /** + * @param url the url to set + */ + public void setUrl(String url) { + this.url = url; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Definition.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Definition.java new file mode 100644 index 00000000..fc49bfad --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Definition.java @@ -0,0 +1,80 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.util.List; + +/*An object that hold data types that can be consumed and produced by operations. These data types can be primitives, arrays or models.*/ +public class Definition { + + private String type; + + private List required; + + private Properties properties; + + private Xml xml; + + public Definition() { + + } + + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + + /** + * @return the required + */ + public List getRequired() { + return required; + } + + /** + * @param required the required to set + */ + public void setRequired(List required) { + this.required = required; + } + + /** + * @return the properties + */ + public Properties getProperties() { + return properties; + } + + /** + * @param properties the properties to set + */ + public void setProperties(Properties properties) { + this.properties = properties; + } + + public Xml getXml() { + return xml; + } + + public void setXml(Xml xml) { + this.xml = xml; + } +} + diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/DefinitionProperty.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/DefinitionProperty.java new file mode 100644 index 00000000..f318a99c --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/DefinitionProperty.java @@ -0,0 +1,39 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +/*Defines the type of the property */ +public class DefinitionProperty { + + private String type; + + public DefinitionProperty() { + + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + /** + * @param type the type to set + */ + public void setType(String type) { + this.type = type; + } + +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Definitions.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Definitions.java new file mode 100644 index 00000000..3953ec3b --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Definitions.java @@ -0,0 +1,44 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; + +//List of Definitions +public class Definitions { + + private Map definitions; + + public Definitions() { + + } + + /** + * @return the definitions + */ + @JsonAnyGetter + public Map getDefinitions() { + return definitions; + } + + /** + * @param definitions the definitions to set + */ + public void setDefinitions(Map definitions) { + this.definitions = definitions; + } + +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/ExternalDocs.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/ExternalDocs.java new file mode 100644 index 00000000..db5ae0a1 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/ExternalDocs.java @@ -0,0 +1,43 @@ +/* + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +public class ExternalDocs { + + private String description; + + private String url; + + /** + * @return the url + */ + public String getUrl() { + return url; + } + + /** + * @param url the url to set + */ + public void setUrl(String url) { + this.url = url; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Info.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Info.java new file mode 100644 index 00000000..22f59384 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Info.java @@ -0,0 +1,112 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +public class Info { + + private String version; + + private String title; + + private String description; + + private String termsOfService; + + private Contact contact; + + private License license; + + public Info() { + + } + + /** + * @return the version + */ + public String getVersion() { + return version; + } + + /** + * @param version the version to set + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * @return the title + */ + public String getTitle() { + return title; + } + + /** + * @param title the title to set + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * @return the contact + */ + public Contact getContact() { + return contact; + } + + /** + * @param contact the contact to set + */ + public void setContact(Contact contact) { + this.contact = contact; + } + + /** + * @return the license + */ + public License getLicense() { + return license; + } + + /** + * @param license the license to set + */ + public void setLicense(License license) { + this.license = license; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + public String getTermsOfService() { + return termsOfService; + } + + public void setTermsOfService(String termsOfService) { + this.termsOfService = termsOfService; + } +} + diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/License.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/License.java new file mode 100644 index 00000000..51570096 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/License.java @@ -0,0 +1,49 @@ +/* + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +public class License { + + private String name; + + private String url; + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the url + */ + public String getUrl() { + return url; + } + + /** + * @param url the url to set + */ + public void setUrl(String url) { + this.url = url; + } +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/NullSerializer.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/NullSerializer.java new file mode 100644 index 00000000..adb61568 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/NullSerializer.java @@ -0,0 +1,17 @@ +package org.openmrs.module.fhir.swagger.docs; + +import java.io.IOException; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonSerializer; +import com.fasterxml.jackson.databind.SerializerProvider; + +public class NullSerializer extends JsonSerializer { + + @Override + public void serialize(Object arg0, JsonGenerator arg1, SerializerProvider arg2) throws IOException, + JsonProcessingException { + arg1.writeFieldName(""); + } +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Operation.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Operation.java new file mode 100644 index 00000000..19847cdc --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Operation.java @@ -0,0 +1,147 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.util.List; +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +//Describes an operation available on a single path +public class Operation { + + @JsonIgnore + private String name; + + //A verbose explanation of the operation behavior + private String descritpion; + + //A short summary of what the operation does + private String summary; + + //A list of MIME types the operation can produce + private List produces; + + /*A list of tags for API documentation control. Tags can be used for logical grouping of operations by resources or any other qualifier.*/ + private List tags; + + //A list of parameters that are applicable for this operation + private List parameters; + + //The list of possible responses as they are returned from executing this operation. + private Map responses; + + public Operation() { + + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the descritpion + */ + public String getDescritpion() { + return descritpion; + } + + /** + * @param descritpion the descritpion to set + */ + public void setDescritpion(String descritpion) { + this.descritpion = descritpion; + } + + /** + * @return the produces + */ + public List getProduces() { + return produces; + } + + /** + * @param produces the produces to set + */ + public void setProduces(List produces) { + this.produces = produces; + } + + /** + * @return the parameters + */ + public List getParameters() { + return parameters; + } + + /** + * @param parameters the parameters to set + */ + public void setParameters(List parameters) { + this.parameters = parameters; + } + + /** + * @return the responses + */ + public Map getResponses() { + return responses; + } + + /** + * @param responses the responses to set + */ + public void setResponses(Map responses) { + this.responses = responses; + } + + /** + * @return the tags + */ + public List getTags() { + return tags; + } + + /** + * @param tags the tags to set + */ + public void setTags(List tags) { + this.tags = tags; + } + + /** + * @return the summary + */ + public String getSummary() { + return summary; + } + + /** + * @param summary the summary to set + */ + public void setSummary(String summary) { + this.summary = summary; + } + +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Parameter.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Parameter.java new file mode 100644 index 00000000..cfc584f6 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Parameter.java @@ -0,0 +1,114 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +public class Parameter{ + + /* The name of the parameter. Parameter names are case sensitive.*/ + private String name; + + /* he location of the parameter. Possible values are "query", "header", "path", "formData" or "body".*/ + private String in; + + /*A brief description of the parameter. This could contain examples of use.*/ + private String description; + + /*Determines whether this parameter is mandatory*/ + private Boolean required; + + public void setType(String type) { + this.type = type; + } + + /* we only need string */ + private String type = "string"; + + private Schema schema; + + public Parameter() { + + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the in + */ + public String getIn() { + return in; + } + + /** + * @param in the in to set + */ + public void setIn(String in) { + this.in = in; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the required + */ + public Boolean getRequired() { + return required; + } + + /** + * @param required the required to set + */ + public void setRequired(Boolean required) { + this.required = required; + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + public Schema getSchema() { + return schema; + } + + public void setSchema(Schema schema) { + this.schema = schema; + } +} + diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Path.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Path.java new file mode 100644 index 00000000..130b0e38 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Path.java @@ -0,0 +1,45 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; + +//Holds the relative path to the individual endpoints. The path is appended to the basePath in order to construct the full URL +public class Path { + + //Describes the operations available on a single path + private Map operations; + + public Path() { + + } + + /** + * @return the operation + */ + @JsonAnyGetter + public Map getOperations() { + return operations; + } + + /** + * @param operation the operation to set + */ + public void setOperations(Map operations) { + this.operations = operations; + } + +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Paths.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Paths.java new file mode 100644 index 00000000..25de1849 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Paths.java @@ -0,0 +1,44 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; + +//List of Available Paths. +public class Paths { + + private Map paths; + + public Paths() { + + } + + /** + * @return the paths + */ + @JsonAnyGetter + public Map getPaths() { + return paths; + } + + /** + * @param paths the paths to set + */ + public void setPaths(Map paths) { + this.paths = paths; + } + +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Properties.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Properties.java new file mode 100644 index 00000000..dc782880 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Properties.java @@ -0,0 +1,44 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.util.Map; + +import com.fasterxml.jackson.annotation.JsonAnyGetter; + +// Describes properties of an object +public class Properties { + + private Map properties; + + public Properties() { + + } + + /** + * @return the properties + */ + @JsonAnyGetter + public Map getProperties() { + return properties; + } + + /** + * @param properties the properties to set + */ + public void setProperties(Map properties) { + this.properties = properties; + } + +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Response.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Response.java new file mode 100644 index 00000000..e7d21d1a --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Response.java @@ -0,0 +1,65 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.util.Map; + +public class Response { + + private String description; + + private Schema schema; + + private Map examples; + + public Response() { + + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + + /** + * @return the schema + */ + public Schema getSchema() { + return schema; + } + + /** + * @param schema the schema to set + */ + public void setSchema(Schema schema) { + this.schema = schema; + } + + public Map getExamples() { + return examples; + } + + public void setExamples(Map examples) { + this.examples = examples; + } +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Schema.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Schema.java new file mode 100644 index 00000000..b81a3bf0 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Schema.java @@ -0,0 +1,50 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import com.fasterxml.jackson.annotation.JsonProperty; + +/*The Schema Object allows the definition of input and output data types. These types can be objects, but also primitives and arrays.*/ +public class Schema { + + private String ref; + private String type; + + public Schema() { + + } + + /** + * @return the ref + */ + @JsonProperty("$ref") + public String getRef() { + return ref; + } + + /** + * @param ref the ref to set + */ + public void setRef(String ref) { + this.ref = ref; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/SwaggerSpecification.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/SwaggerSpecification.java new file mode 100644 index 00000000..6aba5282 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/SwaggerSpecification.java @@ -0,0 +1,211 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.util.List; +import java.util.Map; + +/* The class describes the RESTful API in accordance with the Swagger specification and is represented as JSON objects and conform to the JSON standards */ +public class SwaggerSpecification { + + //Specifies the Swagger Specification version being used + private String swagger = "2.0"; + + // Provides metadata about the API + private Info info; + + //The host (name or ip) serving the API + private String host; + + //The base path on which the API is served + private String basePath; + + //Allows adding meta data to a single tag that is used by the Operation Object. + private List tags; + + //The transfer protocol of the API + private List schemes; + + //A list of MIME types the APIs can consume + private List consumes; + + //A list of MIME types the APIs can produce + private List produces; + + //The available paths and operations for the API. + private Paths paths; + + //An object to hold data types produced and consumed by operations. + private Definitions definitions; + + //An object to hold external documentation + private ExternalDocs externalDocs; + + //Object to hold common params + private Map parameters; + + public SwaggerSpecification() { + + } + + /** + * @return the info + */ + public Info getInfo() { + return info; + } + + /** + * @param info the info to set + */ + public void setInfo(Info info) { + this.info = info; + } + + /** + * @return the host + */ + public String getHost() { + return host; + } + + /** + * @param host the host to set + */ + public void setHost(String host) { + this.host = host; + } + + /** + * @return the basePath + */ + public String getBasePath() { + return basePath; + } + + /** + * @param basePath the basePath to set + */ + public void setBasePath(String basePath) { + this.basePath = basePath; + } + + /** + * @return the schemes + */ + public List getSchemes() { + return schemes; + } + + /** + * @param schemes the schemes to set + */ + public void setSchemes(List schemes) { + this.schemes = schemes; + } + + /** + * @return the consumes + */ + public List getConsumes() { + return consumes; + } + + /** + * @param consumes the consumes to set + */ + public void setConsumes(List consumes) { + this.consumes = consumes; + } + + /** + * @return the produces + */ + public List getProduces() { + return produces; + } + + /** + * @param produces the produces to set + */ + public void setProduces(List produces) { + this.produces = produces; + } + + /** + * @return the paths + */ + public Paths getPaths() { + return paths; + } + + /** + * @param paths the paths to set + */ + public void setPaths(Paths paths) { + this.paths = paths; + } + + /** + * @return the definitions + */ + public Definitions getDefinitions() { + return definitions; + } + + /** + * @param definitions the definitions to set + */ + public void setDefinitions(Definitions definitions) { + this.definitions = definitions; + } + + /** + * @return the swagger + */ + public String getSwagger() { + return swagger; + } + + /** + * @return the tags + */ + public List getTags() { + return tags; + } + + /** + * @param tags the tags to set + */ + public void setTags(List tags) { + this.tags = tags; + } + + public ExternalDocs getExternalDocs() { + return externalDocs; + } + + public void setExternalDocs(ExternalDocs externalDocs) { + this.externalDocs = externalDocs; + } + + public Map getParameters() { + return parameters; + } + + public void setParameters(Map parameters) { + this.parameters = parameters; + } +} + diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Tag.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Tag.java new file mode 100644 index 00000000..325b6e46 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Tag.java @@ -0,0 +1,57 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +import java.io.Serializable; + +// Unique tag used to group operations +public class Tag implements Serializable { + + private String name; + + private String description; + + public Tag() { + + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @param name the name to set + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + /** + * @param description the description to set + */ + public void setDescription(String description) { + this.description = description; + } + +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Test.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Test.java new file mode 100644 index 00000000..119f4d8f --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Test.java @@ -0,0 +1,271 @@ +/* + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +public class Test { + +public static String test = "{\n" + + " \"swagger\": \"2.0\",\n" + + " \"info\": {\n" + + " \"version\": \"1.0.0\",\n" + + " \"title\": \"FHIR OpenMRS APIs\",\n" + + " \"description\": \"Sample for demonstrate OpenMRS FHIR APIs\",\n" + + " \"termsOfService\": \"http://swagger.io/terms/\"\n" + + " },\n" + + " \"host\": \"localhost\",\n" + + " \"basePath\": \"/openmrs/ws/fhir/\",\n" + + " \"schemes\": [\n" + + " \"http\"\n" + + " ],\n" + + " \"consumes\": [\n" + + " \"application/json\"\n" + + " ],\n" + + " \"produces\": [\n" + + " \"application/json\"\n" + + " ],\n" + + " \"paths\": {\n" + + " \"/Patient\": {\n" + + " \"post\": {\n" + + " \"description\": \"Creates a new new patient\",\n" + + " \"operationId\": \"create new patient\",\n" + + " \"produces\": [\n" + + " \"application/json\",\n" + + " \"application/xml\"\n" + + " ],\n" + + " \"parameters\": [\n" + + " {\n" + + " \"name\": \"Patient\",\n" + + " \"in\": \"body\",\n" + + " \"description\": \"Add patient to the OpenMRS\",\n" + + " \"required\": true,\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/Patient\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"responses\": {\n" + + " \"200\": {\n" + + " \"description\": \"FHIR server response\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/Patient\"\n" + + " }\n" + + " },\n" + + " \"default\": {\n" + + " \"description\": \"unexpected error\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/ErrorModel\"\n" + + " }\n" + + " }\n" + + " }\n" + + " },\n" + + " \"get\": {\n" + + " \"description\": \"Returns a Patient based on a single ID\",\n" + + " \"operationId\": \"findPatientById\",\n" + + " \"produces\": [\n" + + " \"application/json\",\n" + + " \"application/xml\"\n" + + " ],\n" + + " \"parameters\": [\n" + + " {\n" + + " \"name\": \"id\",\n" + + " \"in\": \"path\",\n" + + " \"description\": \"ID of patient to fetch\",\n" + + " \"required\": true,\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int64\"\n" + + " },\n" + + " {\n" + + " \"name\": \"identifier\",\n" + + " \"in\": \"query\",\n" + + " \"description\": \"Identifire of patient to fetch\",\n" + + " \"required\": true,\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int64\"\n" + + " },\n" + + " {\n" + + " \"name\": \"_id\",\n" + + " \"in\": \"query\",\n" + + " \"description\": \"ID of patient to fetch\",\n" + + " \"required\": true,\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int64\"\n" + + " },\n" + + " {\n" + + " \"name\": \"name\",\n" + + " \"in\": \"query\",\n" + + " \"description\": \"Name of patient to fetch\",\n" + + " \"required\": true,\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int64\"\n" + + " },\n" + + " {\n" + + " \"name\": \"given\",\n" + + " \"in\": \"query\",\n" + + " \"description\": \"Given Name of patient to fetch\",\n" + + " \"required\": true,\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int64\"\n" + + " },\n" + + " {\n" + + " \"name\": \"active\",\n" + + " \"in\": \"query\",\n" + + " \"description\": \"Active Records\",\n" + + " \"required\": true,\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int64\"\n" + + " }\n" + + " ],\n" + + " \"responses\": {\n" + + " \"200\": {\n" + + " \"description\": \"FHIR response\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/Patient\"\n" + + " }\n" + + " },\n" + + " \"default\": {\n" + + " \"description\": \"unexpected error\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/ErrorModel\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " },\n" + + " \"/Patient/{id}\": {\n" + + " \"get\": {\n" + + " \"description\": \"Returns a Patient based on a single ID\",\n" + + " \"operationId\": \"findPatientById\",\n" + + " \"produces\": [\n" + + " \"application/json\",\n" + + " \"application/xml\"\n" + + " ],\n" + + " \"parameters\": [\n" + + " {\n" + + " \"name\": \"id\",\n" + + " \"in\": \"path\",\n" + + " \"description\": \"ID of patient to fetch\",\n" + + " \"required\": true,\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int64\"\n" + + " }\n" + + " ],\n" + + " \"responses\": {\n" + + " \"200\": {\n" + + " \"description\": \"FHIR response\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/Patient\"\n" + + " }\n" + + " },\n" + + " \"default\": {\n" + + " \"description\": \"unexpected error\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/ErrorModel\"\n" + + " }\n" + + " }\n" + + " }\n" + + " },\n" + + " \"put\": {\n" + + " \"description\": \"Updates patient\",\n" + + " \"operationId\": \"update patient\",\n" + + " \"produces\": [\n" + + " \"application/json\",\n" + + " \"application/xml\"\n" + + " ],\n" + + " \"parameters\": [\n" + + " {\n" + + " \"name\": \"Patient\",\n" + + " \"in\": \"body\",\n" + + " \"description\": \"Add patient to the OpenMRS\",\n" + + " \"required\": true,\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/Patient\"\n" + + " }\n" + + " }\n" + + " ],\n" + + " \"responses\": {\n" + + " \"200\": {\n" + + " \"description\": \"FHIR server response\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/Patient\"\n" + + " }\n" + + " },\n" + + " \"default\": {\n" + + " \"description\": \"unexpected error\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/ErrorModel\"\n" + + " }\n" + + " }\n" + + " }\n" + + " },\n" + + " \"delete\": {\n" + + " \"description\": \"deletes a single Patient based on the ID supplied\",\n" + + " \"operationId\": \"deletePatient\",\n" + + " \"parameters\": [\n" + + " {\n" + + " \"name\": \"id\",\n" + + " \"in\": \"path\",\n" + + " \"description\": \"ID of Patient to delete\",\n" + + " \"required\": true,\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int64\"\n" + + " }\n" + + " ],\n" + + " \"responses\": {\n" + + " \"204\": {\n" + + " \"description\": \"Patient deleted\"\n" + + " },\n" + + " \"default\": {\n" + + " \"description\": \"unexpected error\",\n" + + " \"schema\": {\n" + + " \"$ref\": \"#/definitions/ErrorModel\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + " },\n" + + " \"definitions\": {\n" + + " \"Patient\": {\n" + + " \"type\": \"object\",\n" + + " \"required\": [\n" + + " \"name\"\n" + + " ],\n" + + " \"properties\": {\n" + + " \"name\": {\n" + + " \"type\": \"string\"\n" + + " },\n" + + " \"identifier\": {\n" + + " \"type\": \"string\"\n" + + " }\n" + + " }\n" + + " },\n" + + " \"ErrorModel\": {\n" + + " \"type\": \"object\",\n" + + " \"required\": [\n" + + " \"code\",\n" + + " \"message\"\n" + + " ],\n" + + " \"properties\": {\n" + + " \"code\": {\n" + + " \"type\": \"integer\",\n" + + " \"format\": \"int32\"\n" + + " },\n" + + " \"message\": {\n" + + " \"type\": \"string\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; +} diff --git a/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Xml.java b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Xml.java new file mode 100644 index 00000000..bc815584 --- /dev/null +++ b/omod/src/main/java/org/openmrs/module/fhir/swagger/docs/Xml.java @@ -0,0 +1,32 @@ +/** + * The contents of this file are subject to the OpenMRS Public License + * Version 1.0 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://license.openmrs.org + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * Copyright (C) OpenMRS, LLC. All Rights Reserved. + */ +package org.openmrs.module.fhir.swagger.docs; + +public class Xml { + + private String name; + + public Xml() { + + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} + diff --git a/omod/src/main/java/org/openmrs/module/fhir/util/FHIROmodConstants.java b/omod/src/main/java/org/openmrs/module/fhir/util/FHIROmodConstants.java index 77b7376f..07628484 100644 --- a/omod/src/main/java/org/openmrs/module/fhir/util/FHIROmodConstants.java +++ b/omod/src/main/java/org/openmrs/module/fhir/util/FHIROmodConstants.java @@ -18,4 +18,7 @@ public class FHIROmodConstants { public static final String OPENMRS_FHIR_SERVER_NAME = "OpenMRS FHIR Server"; public static final String OPENMRS_FHIR_SERVER_VERSION = "0.9-SNAPSHOT"; public static final String OPENMRS_FHIR_SERVER_DES = "OpenMRS FHIR Resources"; + public static final String OPENMRS_FHIR_SWAGGER_SHORT_PATH = "/module/fhir/rest/swagger.json"; + public static final String OPENMRS_FHIR_SWAGGER_LONG_PATH = "/openmrs/module/fhir/rest/swagger.json"; + public static final String OPENMRS_FHIR_SWAGGER_ORG_PATH = "/ms/fhir/fhirDocServelet"; } diff --git a/omod/src/main/resources/config.xml b/omod/src/main/resources/config.xml index abb4f763..655f35bc 100644 --- a/omod/src/main/resources/config.xml +++ b/omod/src/main/resources/config.xml @@ -59,6 +59,11 @@ fhirServelet org.openmrs.module.fhir.server.FHIRRESTServer + + + fhirDocServelet + org.openmrs.module.fhir.swagger.SwaggerSpecificationController + @@ -96,10 +101,22 @@ forwardingFilterr org.openmrs.module.fhir.filter.ForwardingFilter + + swaggerForwardingFilterr + org.openmrs.module.fhir.filter.SwaggerForwardingFilter + forwardingFilterr /ws/fhir/* + + forwardingFilterr + /ms/fhir/fhirServelet/* + + + swaggerForwardingFilterr + /module/fhir/rest/swagger.json + ${project.parent.artifactId}.baseUrl @@ -224,6 +241,10 @@ Observations + + ${project.parent.artifactId}.uriPrefix + The URI prefix through which clients consuming web services will connect to the web application, should be of the form http://{ipAddress}:{port}/{contextPath} + View FHIR Client Gives access to FHIR rest client diff --git a/pom.xml b/pom.xml index 9c84b4c2..188c746d 100644 --- a/pom.xml +++ b/pom.xml @@ -211,6 +211,12 @@ + + + com.fasterxml.jackson.core + jackson-databind + 2.5.4 +