Search in sources :

Example 1 with Code

use of com.b2international.snowowl.fhir.core.model.dt.Code in project snow-owl by b2ihealthcare.

the class ConceptTest method build.

@Test
public void build() throws Exception {
    assertEquals(new Code("conceptCode"), concept.getCode());
    ConceptProperty conceptProperty = concept.getProperties().iterator().next();
    assertTrue(conceptProperty instanceof CodeConceptProperty);
}
Also used : CodeConceptProperty(com.b2international.snowowl.fhir.core.model.property.CodeConceptProperty) ConceptProperty(com.b2international.snowowl.fhir.core.model.property.ConceptProperty) Code(com.b2international.snowowl.fhir.core.model.dt.Code) CodeConceptProperty(com.b2international.snowowl.fhir.core.model.property.CodeConceptProperty) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Example 2 with Code

use of com.b2international.snowowl.fhir.core.model.dt.Code in project snow-owl by b2ihealthcare.

the class FhirMetadataController method collectResources.

private Collection<Resource> collectResources(final OpenAPI openAPI) {
    final Paths paths = openAPI.getPaths();
    final List<io.swagger.v3.oas.models.tags.Tag> tags = openAPI.getTags();
    return tags.stream().filter(t -> t.getExtensions() != null && t.getExtensions().containsKey(B2I_OPENAPI_X_NAME)).map(t -> {
        final Map<?, ?> nameExtensionMap = (Map<?, ?>) t.getExtensions().get(B2I_OPENAPI_X_NAME);
        final String profile = (String) nameExtensionMap.get(B2I_OPENAPI_PROFILE);
        final Resource.Builder resourceBuilder = Resource.builder().type(t.getName()).profile(profile);
        // Collect the operations that belong to the same tagged class resource
        paths.values().stream().flatMap(pi -> pi.readOperations().stream()).filter(o -> o.getTags().contains(t.getName()) && o.getExtensions() != null && o.getExtensions().containsKey(B2I_OPENAPI_X_INTERACTION)).forEachOrdered(op -> {
            final Map<String, Object> operationExtensionMap = op.getExtensions();
            final Map<?, ?> interactionMap = (Map<?, ?>) operationExtensionMap.get(B2I_OPENAPI_X_INTERACTION);
            interactionMap.entrySet().forEach(e -> {
                final Interaction.Builder interactionBuilder = Interaction.builder().code((String) e.getKey());
                final String value = (String) e.getValue();
                if (!StringUtils.isEmpty(value)) {
                    interactionBuilder.documentation((String) value);
                }
                resourceBuilder.addInteraction(interactionBuilder.build());
            });
        });
        return resourceBuilder.build();
    }).sorted(Comparator.comparing(r -> r.getType().getCodeValue())).collect(Collectors.toList());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) Iterables(com.google.common.collect.Iterables) OpenApiWebMvcResource(org.springdoc.webmvc.api.OpenApiWebMvcResource) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) Uri(com.b2international.snowowl.fhir.core.model.dt.Uri) SnowOwlOpenApiWebMvcResource(com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource) OperationDefinition(com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition) Supplier(java.util.function.Supplier) FhirApiConfig(com.b2international.snowowl.core.rest.FhirApiConfig) Code(com.b2international.snowowl.fhir.core.model.dt.Code) Extension(io.swagger.v3.oas.annotations.extensions.Extension) Operation(io.swagger.v3.oas.annotations.Operation) StringUtils(com.b2international.commons.StringUtils) MvcUriComponentsBuilder(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder) B2I_OPENAPI_PROFILE(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_PROFILE) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) GetMapping(org.springframework.web.bind.annotation.GetMapping) Suppliers(com.google.common.base.Suppliers) OperationKind(com.b2international.snowowl.fhir.core.codesystems.OperationKind) Schema(io.swagger.v3.oas.models.media.Schema) SnowOwlConfiguration(com.b2international.snowowl.core.config.SnowOwlConfiguration) NotFoundException(com.b2international.commons.exceptions.NotFoundException) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Collection(java.util.Collection) RestfulCapabilityMode(com.b2international.snowowl.fhir.core.codesystems.RestfulCapabilityMode) PathItem(io.swagger.v3.oas.models.PathItem) ExtensionProperty(io.swagger.v3.oas.annotations.extensions.ExtensionProperty) Paths(io.swagger.v3.oas.models.Paths) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) List(java.util.List) Tag(io.swagger.v3.oas.annotations.tags.Tag) CoreActivator(com.b2international.snowowl.core.CoreActivator) CapabilityStatementKind(com.b2international.snowowl.fhir.core.codesystems.CapabilityStatementKind) Platform(org.eclipse.core.runtime.Platform) Parameter(com.b2international.snowowl.fhir.core.model.operationdefinition.Parameter) B2I_OPENAPI_INTERACTION_READ(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_INTERACTION_READ) B2I_OPENAPI_X_NAME(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_NAME) PublicationStatus(com.b2international.snowowl.fhir.core.codesystems.PublicationStatus) Comparator(java.util.Comparator) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) com.b2international.snowowl.fhir.core.model.capabilitystatement(com.b2international.snowowl.fhir.core.model.capabilitystatement) B2I_OPENAPI_X_INTERACTION(com.b2international.snowowl.core.rest.OpenAPIExtensions.B2I_OPENAPI_X_INTERACTION) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) OpenApiWebMvcResource(org.springdoc.webmvc.api.OpenApiWebMvcResource) SnowOwlOpenApiWebMvcResource(com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource) Paths(io.swagger.v3.oas.models.Paths) Tag(io.swagger.v3.oas.annotations.tags.Tag) Map(java.util.Map) Maps.newHashMap(com.google.common.collect.Maps.newHashMap)

Example 3 with Code

use of com.b2international.snowowl.fhir.core.model.dt.Code in project snow-owl by b2ihealthcare.

the class FhirRequestEntryProcessor method doProcess.

@Override
public void doProcess(ArrayNode arrayNode, HttpServletRequest request) throws Exception {
    BatchRequest batchRequest = requestEntry.getRequest();
    Code requestMethod = batchRequest.getMethod();
    if (!requestMethod.equals(HttpVerb.GET.getCode())) {
        createInvalidMethodResponse(arrayNode, requestMethod);
        return;
    }
    HttpHeaders headers = getHeaders(request);
    RestTemplate restTemplate = getRestTemplate();
    StringBuilder uriBuilder = new StringBuilder(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getLocalPort()).append(request.getRequestURI()).append(batchRequest.getUrl().getUriValue());
    HttpEntity<String> httpEntity = new HttpEntity<>(headers);
    ResponseEntity<String> response = restTemplate.exchange(uriBuilder.toString(), HttpMethod.GET, httpEntity, String.class);
    String json = response.getBody();
    ObjectNode resourceNode = (ObjectNode) objectMapper.readTree(json);
    addResponse(arrayNode, resourceNode, String.valueOf(response.getStatusCode().value()));
}
Also used : BatchRequest(com.b2international.snowowl.fhir.core.model.BatchRequest) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RestTemplate(org.springframework.web.client.RestTemplate) Code(com.b2international.snowowl.fhir.core.model.dt.Code)

Example 4 with Code

use of com.b2international.snowowl.fhir.core.model.dt.Code in project snow-owl by b2ihealthcare.

the class FhirResourceRequestEntryProcessor method doProcess.

@Override
public void doProcess(ArrayNode arrayNode, HttpServletRequest request) throws JsonMappingException, JsonProcessingException {
    BatchRequest batchRequest = requestEntry.getRequest();
    Code requestMethod = batchRequest.getMethod();
    if (!requestMethod.equals(HttpVerb.POST.getCode())) {
        createInvalidMethodResponse(arrayNode, requestMethod);
        return;
    }
    HttpHeaders headers = getHeaders(request);
    RestTemplate restTemplate = getRestTemplate();
    StringBuilder uriBuilder = new StringBuilder(request.getScheme()).append("://").append(request.getServerName()).append(":").append(request.getLocalPort()).append(request.getRequestURI()).append(batchRequest.getUrl().getUriValue());
    HttpEntity<?> httpEntity = new HttpEntity<>(requestEntry.getRequestResource(), headers);
    ResponseEntity<String> response = restTemplate.exchange(uriBuilder.toString(), HttpMethod.POST, httpEntity, String.class);
    String json = response.getBody();
    ObjectNode resourceNode = (ObjectNode) objectMapper.readTree(json);
    addResponse(arrayNode, resourceNode, String.valueOf(response.getStatusCode().value()));
}
Also used : BatchRequest(com.b2international.snowowl.fhir.core.model.BatchRequest) HttpHeaders(org.springframework.http.HttpHeaders) HttpEntity(org.springframework.http.HttpEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RestTemplate(org.springframework.web.client.RestTemplate) Code(com.b2international.snowowl.fhir.core.model.dt.Code)

Example 5 with Code

use of com.b2international.snowowl.fhir.core.model.dt.Code in project snow-owl by b2ihealthcare.

the class QuantityTest method deserialize.

@Test
public void deserialize() throws Exception {
    Quantity readQuantity = objectMapper.readValue(objectMapper.writeValueAsString(quantity), Quantity.class);
    assertEquals(Double.valueOf(12.3), readQuantity.getValue());
    assertEquals("mg", readQuantity.getUnit());
    assertEquals(new Uri("uri:LOINC"), readQuantity.getSystem());
    assertEquals(new Code("code"), readQuantity.getCode());
    assertEquals(QuantityComparator.GREATER_OR_EQUAL_TO.getCode(), readQuantity.getComparator());
}
Also used : Quantity(com.b2international.snowowl.fhir.core.model.dt.Quantity) Uri(com.b2international.snowowl.fhir.core.model.dt.Uri) Code(com.b2international.snowowl.fhir.core.model.dt.Code) FhirTest(com.b2international.snowowl.fhir.tests.FhirTest) Test(org.junit.Test)

Aggregations

Code (com.b2international.snowowl.fhir.core.model.dt.Code)22 FhirTest (com.b2international.snowowl.fhir.tests.FhirTest)13 Test (org.junit.Test)13 Uri (com.b2international.snowowl.fhir.core.model.dt.Uri)11 OperationOutcomeCode (com.b2international.snowowl.fhir.core.codesystems.OperationOutcomeCode)4 BatchRequest (com.b2international.snowowl.fhir.core.model.BatchRequest)3 SimpleQuantity (com.b2international.snowowl.fhir.core.model.dt.SimpleQuantity)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 HttpEntity (org.springframework.http.HttpEntity)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RestTemplate (org.springframework.web.client.RestTemplate)3 SnowOwlConfiguration (com.b2international.snowowl.core.config.SnowOwlConfiguration)2 SnowOwlOpenApiWebMvcResource (com.b2international.snowowl.core.rest.SnowOwlOpenApiWebMvcResource)2 Designation (com.b2international.snowowl.fhir.core.model.Designation)2 OperationDefinition (com.b2international.snowowl.fhir.core.model.operationdefinition.OperationDefinition)2 StringUtils (com.b2international.commons.StringUtils)1 NotFoundException (com.b2international.commons.exceptions.NotFoundException)1 ApplicationContext (com.b2international.snowowl.core.ApplicationContext)1 CoreActivator (com.b2international.snowowl.core.CoreActivator)1 FhirApiConfig (com.b2international.snowowl.core.rest.FhirApiConfig)1