How to include the full object instead of "contained" in HAPI FHIR - java

I am very new to hapi FHIR, I am trying to encode the request in following format.
CoverageEligibilityRequest coverageEligibilityRequest = new CoverageEligibilityRequest();
Patient patient = new Patient().addIdentifier(new Identifier().setType(getPatientIdentifierCodeableConcept()).setSystem("http://www.abc.xyz").setValue("123"));
coverageEligibilityRequest.setPatient(new Reference(patient));
Above code is java snippet for populating the patient in CoverageEligibilityRequest.
{
"resourceType": "Bundle",
"type": "batch",
"entry": [ {
"resource": {
"resourceType": "CoverageEligibilityRequest",
"id": "7890",
"contained": [ {
"resourceType": "Patient",
"id": "1",
"identifier": [ {
"type": {
"coding": [ {
...
...
}
But I want the request should be of following format
{
"resourceType": "Bundle",
"type": "batch",
"entry": [ {
"resource": {
"resourceType": "CoverageEligibilityRequest",
"id": "7890",
"patient": {
"type": "Patient",
"identifier": {
"type": {
"coding": [ {
...
...
} ]
},
where I want to omit contained with actual string?

FHIR doesn't generally let you express an entire graph of objects as a single resource, so if you're trying to send a Patient resource as part of a CoverageEligibilityRequest resource, the only way you can do that is by setting the patient in the contained field. The CoverageEligibilityResource.patient field is defined as a Reference type and so can only contain the data allowed by a Reference data type and not arbitrary data.
It seems like what you actually want to do is to add a Patient to the HAPI FHIR server and a CoverageEligibilityRequest resource that references the patient. The right way to do this in FHIR is to construct a single batch or transaction bundle containing both of the resources. Basically, you want to construct a Bundle that looks something like this:
{
"resourceType": "Bundle",
"type": "batch",
"entry": [ {
"resource": {
"resourceType": "Patient",
"id": "1",
"identifier": [ {
"type": {
"coding": [ {
...
}
}, {
"resource": {
"resourceType": "CoverageEligibilityRequest",
"id": "7890",
"patient": "Patient/1",
...
The easiest way to construct something similar in HAPI FHIR would be to use a transaction bundle like this:
IGenericClient client = ...
CoverageEligibilityRequest coverageEligibilityRequest = new CoverageEligibilityRequest();
Patient patient = new Patient().addIdentifier(new Identifier().setType(getPatientIdentifierCodeableConcept()).setSystem("http://www.abc.xyz").setValue("123"));
coverageEligibilityRequest.setPatient(new Reference(patient));
client.transaction().withResources(patient, coverageEligibilityRequest);

Related

Camunda send list as process variable when start process

I have some process in my Springboot application and wanna start it via rest.
http://localhost:8080/rest/process-definition/Kvorum:2:c10196c1-1935-11eb-b60d-7a7bf841afbd/start
with body:
{
"variables": {
"list": {
"value": "[\"1\",\"2\"]",
"type": "String"
}
},
"businessKey": "myBusinessKey",
"withVariablesInReturn": true
}
What do I need to write here:
"list": {
"value": "[\"1\",\"2\"]",
"type": "Object"
}
to receive List instead of String and use it in JavaDelegate with code like:
List<String> list = (List) execution.getVariable("list");
"list": {
"value": "[\"1\",\"2\"]",
"type": "Object",
"valueInfo" : {"objectTypeName": "java.util.ArrayList", "serializationDataFormat":"application/json"}
}

How to implement Post API JSON with Spring?

I'm having difficulty implementing a JSON to send as a POST call in Spring.
Which is the fastest and most effective way to turn this json into a java object or a map and make the call?
below is an example of a json to send:
{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": {
"name": "edge-ws"
},
"spec": {
"selector": {
"matchLabels": {
"run": "edge-ws"
}
},
"replicas": 1,
"template": {
"metadata": {
"labels": {
"run": "edge-ws"
}
},
"spec": {
"containers": [
{
"name": "edge-ws",
"image": "server-tim:latest",
"imagePullPolicy": "Never",
"ports": [
{
"containerPort": 80
}
]
}
]
}
}
}
}
this and the second body that has a value (nodeport) that must be taken from a field entered by the user front end side.(page created in html)
{
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "edge-ws",
"labels": {
"run": "edge-ws"
}
},
"spec": {
"type": "NodePort",
"ports": [
{
"port": 8080,
"targetPort": 80,
"nodePort": 30200,
"protocol": "TCP",
"name": "http"
}
],
"selector": {
"run": "edge-ws"
}
}
}
Both files must be sent with a single click on a button on the front end side.the first call with the first body starts and if everything is ok the second body starts
What should the class that maps objects look like? What should the controller look like instead?
They also gave me an address to call that can only be used on the machine, how can I test this call locally?
Thanks in advance!
You can use google's Gson library to convert the JsonString to Object and then use below code:
Gson gson = new Gson();
Object requestObject = gson.fromJson(jsonString, Object.class);
ResponseObject responseObject = restTemplate.postForObject(url, requestObject, ResponseObject.class);

open api generator oneof

using 4.3.1 of open api generator and trying to get the java code out of the json.
In the json file I have the following (changed for example):
"xComponents": {
"type": "array",
"title": "This is a title",
"items": {
"oneOf": [
{
"$ref": "xComponent.AAA.schema.json"
},
{
"$ref": "xComponent.BBB.schema.json"
},
{
"$ref": "xComponent.CCC.schema.json"
},
{
"$ref": "xComponent.DDD.schema.json"
}
],
"type": "object"
},
"minItems": 1
}
It generates this list wierd class name that cannot get build:
private List<**OneOfxComponentAAASchemaJsonxComponentBBBSchemaJsonxComponentCCCSchemaJsonxComponentDDDSchemaJson**> xComponents =
new ArrayList<**OneOfxComponentAAASchemaJsonxComponentBBBSchemaJsonxComponentCCCSchemaJsonxComponentDDDSchemaJson**>();
Whats the correct way to deal with oneOf? what im I doing wrong (either with the json file or with the open api generator)?

Validate json schema of a particular JSON object from a response

I have a json response like this(Response is getting in the com.jayway.restassured.response.Response format).
[{
gameIdGlobal: 1947634,
season: 2017,
views: [{
name: "Recap",
displayOrder: 1,
groups: [{
type: "static",
displayOrder: 1
}
],
localizedName: {
ENG: "Recap",
ESP: "Resumen"
}
}
]
}
]
From this I need to validate the json schema of views object only.No need to validate the entire json . for that
I have created a json schema for views object only schema1.
schema1.json
{
"type": "array",
"items": {
"id": "view.json",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"displayOrder": {
"type": "integer",
"minimum": 1
},
"groups": {
"type": "array"
},
"localizedName": {
"type": "object",
"properties": {
"ENG": {
"type": "string",
"description": "the name of the view in english"
},
"ESP": {
"type": "string",
"description": "the name of the view in spanish"
}
}
}
}
}
}
How can i perform the schema validation of particular json object(views object from josn response)
code
Response response = RestAssured.given().when().get(getURL);
ValidatableResponse valResponse = response.then().contentType(ContentType.JSON);
valResponse.body(schema1.json("schema1.json")).assertThat();
You can specify that Additional Properties are allowed on the object that holds the array as its property. Here is the schema for the entire response json object:
{
"$schema": "http://json-schema.org/draft-06/schema#",
"type": "array",
"items": {
"type": "object",
"required": ["views"],
"additionalProperties": true,
"properties": {
"views": {
"type": "array",
"items": {
"id": "view.json",
...
}
}
}

How to apply a sub schema in the JSON Schema validator?

Hi I'm using the JSON Schema evaluator in version 2.2.6 to validate my server responses. These responses can contain single objects of type A, B or C, but also composite objects, e.g., D containing an array of A objects. To reuse the schema definitions of each object, I started to describe all entities in the same file as described here. Now my problem is, that I have to reference one of those single objects when validating the response.
Here is my (not) SWE.
JSON schema file:
{
"id":"#root",
"properties": {
"objecta": {
"type": "object",
"id":"#objecta",
"properties": {
"attribute1": {"type": "integer"},
"attribute2": {"type": "null"},
},
"required": ["attribute1", "attribute2"]
},
"objectb": {
"type": "object",
"id":"#objectb",
"properties": {
"attribute1": {"type": "integer"},
"attribute2": {
"type": "array",
"items": {
"$ref": "#/objecta"
}
}
}
},
"required": ["attribute1", "attribute2"]
},
}
}
Now I want to validate a server response containing object B. For this, I tried the following:
public class SchemeValidator {
public static void main(String[] args) {
String jsonData = pseudoCodeFileLoad("exampleresponse/objectb.txt");
final File jsonSchemaFile = new File("resources/jsonschemes/completescheme.json");
final URI uri = jsonSchemaFile.toURI();
ProcessingReport report = null;
try {
JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final JsonSchema schema = factory.getJsonSchema(uri.toString() + "#objectb");
JsonNode data = JsonLoader.fromString(jsonData);
report = schema.validate(data);
} catch (JsonParseException jpex) {
// ... handle parsing errors etc.
}
}
}
The problem is that the scheme is not loaded correctly. I either get no error (even for invalid responses) or I get fatal: illegalJsonRef as the scheme seems to be empty. How can I use the schema of object b in my Java code? Thank you!!
It looks like your $ref is incorrect. It needs to be a relative reference from the base of the JSON Schema file (see here).
So your JSON schema would become:
{
"id":"#root",
"properties": {
"objecta": {
"type": "object",
"id":"#objecta",
"properties": {
"attribute1": {"type": "integer"},
"attribute2": {"type": "null"},
},
"required": ["attribute1", "attribute2"]
},
"objectb": {
"type": "object",
"id":"#objectb",
"properties": {
"attribute1": {"type": "integer"},
"attribute2": {
"type": "array",
"items": {
"$ref": "#/properties/objecta"
}
}
}
},
"required": ["attribute1", "attribute2"]
},
}
}
I've added '/properties' to your $ref. It's operating like XPath to the definition of the object in the schema file.

Categories

Resources