I am looking for curl request example to write Vitals on Smart on FHIR (hir-open-api-dstu2.smarthealthit.org) database.
Here is what I have found on http://docs.smarthealthit.org/tutorials/server-quick-start/
Example of Read Patient Demographics:
curl 'https://fhir-open-api-dstu2.smarthealthit.org/Patient/1482713' -H 'Accept: application/json'
Example to retrieve Vitals:
curl 'https://fhir-open-api-dstu2.smarthealthit.org/Observation?subject%3APatient=1482713&code=3141-9%2C8302-2%2C8287-5%2C39156-5&_count=50' -H 'Accept: application/json'
PatientID=1482713 and LOINC Codes: 3141-9, 8302-2, 8287-5, 39156-5 (Vitals)
How to write - it is certainly possible as outlined here:
https://fhirblog.com/2015/03/06/smart-writing/
https://fhirblog.com/2016/03/23/smart-scopes-and-profiles/
A curl request to write vitals would look like this (an example which does not work):
curl 'https://fhir-open-api-dstu2.smarthealthit.org/Observation.write?subject%3APatient=1482713&code=3141-9=10&_count=50' -H 'Accept: application/json'
Thanks for your help!
To write, you'll want to use:
curl \
-X POST \
https://fhir-open-api-dstu2.smarthealthit.org/Observation \
-H 'Content-type: application/json+fhir' \
-H 'Accept: application/json+fhir' \
--data '{"resourceType": "Observation"}'
And of course, you should provide more details about your observation in the data payload :-)
This is based on Josh M's reply:
curl -X POST \
https://fhir-open-api-dstu2.smarthealthit.org/Observation \
-H 'Content-type: application/json+fhir' \
-H 'Accept: application/json+fhir' \
--data #payload.json
A more defined payload file with effective date, blood pressure and its two components:
--payload.json file ---
{
"resourceType": "Observation",
"status": "final",
"subject": {
"reference": "Patient/1951076"
},
"category": {
"coding": [
{
"system": "http://hl7.org/fhir/observation-category",
"code": "vital-signs",
"display": "Vital Signs"
}
],
"text": "Vital Signs"
},
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "55284-4",
"display": "SBlood pressure systolic and diastolic"
}
],
"text": "Blood pressure systolic and diastolic"
},
"encounter": {
"reference": "Encounter/787"
},
"effectiveDateTime": "2016-08-17",
"component": [
{
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "8480-6",
"display": "Systolic blood pressure"
}
],
"text": "Systolic blood pressure"
},
"valueQuantity": {
"value": 125,
"unit": "mmHg",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
},
{
"code": {
"coding": [
{
"system": "http://loinc.org",
"code": "8462-4",
"display": "Diastolic blood pressure"
}
],
"text": "Diastolic blood pressure"
},
"valueQuantity": {
"value": 75,
"unit": "mmHg",
"system": "http://unitsofmeasure.org",
"code": "mm[Hg]"
}
}
]
}
Related
Could you please help me with that? I did try my best to get this function up and running?
Here are the articles that I viewed-
https://www.zoho.com/creator/help/script/invoking-a-function.html
curl --location --request POST 'https://gw.cmtelecom.com/v1.0/message' \
--header 'Content-Type: application/json' \
--data-raw '{
"messages": {
"authentication": {
"producttoken": "test"
},
"msg": [
{
"from": "00919538893819",
"to": [
{
"number": "00918892449978"
}
],
"body": {
"type": "auto",
"content": "This is a WhatsApp message"
},
"allowedChannels": [
"WhatsApp"
],
"richContent": {
"conversation": [
{
"template": {
"whatsapp": {
"namespace": "5c198301_106c_4fc2_a2f6_7556d8847746",
"element_name": "otp",
"language": {
"policy": "deterministic",
"code": "en"
},
"components": [
{
"type": "body",
"parameters": [
{
"type": "text",
"text": "Dhanush"
},
{
"type": "text",
"text": "627728289"
}
]
}
]
}
}
}
]
}
}
]
}
}'
Is there a different way we could execute this?
You should define a variable with the JSON data first, and then pass the data as a string to invokeUrl.
See the following example:
void APICall()
{
data = {"messages":{"authentication":{"producttoken":"******"},"msg":{{"from":"00919538893819","to":{{"number":"00918892449978"}},"body":{"type":"auto","content":"This is a WhatsApp message"},"allowedChannels":{"WhatsApp"},"richContent":{"conversation":{{"template":{"whatsapp":{"namespace":"5c198301_106c_4fc2_a2f6_7556d8847746","element_name":"otp","language":{"policy":"deterministic","code":"en"},"components":{{"type":"body","parameters":{{"type":"text","text":"Dhanush"},{"type":"text","text":"627728289"}}}}}}}}}}}}};
response = invokeUrl
[
url: "https://gw.cmtelecom.com/v1.0/message"
type: POST
parameters: data.toString()
headers: {"Content-Type": "application/json"}
];
info response;
}
Please, do not post API Authentication Tokens in your quetions!
I am trying to perform an elastic-search query that will return documents where "every" element of the nested collection has a match, not just one.
For example, I have a Driver object, with the List of cars, and each car has the color attribute.
Driver index:
curl --location --request PUT 'localhost:9200/driver' \
--header 'Content-Type: application/json' \
--data-raw '{
"mappings": {
"properties": {
"driver": {
"type": "nested",
"properties": {
"name": {
"type": "text"
},
"car": {
"type": "nested",
"properties": {
"color": {
"type": "text"
}
}
}
}
}
}
}
}'
And the following data: Driver John with green and red car, and Driver Bob with two green cars.
curl --location --request PUT 'localhost:9200/driver/_doc/1' \
--header 'Content-Type: application/json' \
--data-raw '{
"driver": {
"name": "John",
"car": [
{
"color": "red"
},
{
"color": "green"
}
]
}
}'
curl --location --request PUT 'localhost:9200/driver/_doc/2' \
--header 'Content-Type: text/plain' \
--data-raw '{
"driver": {
"name": "Bob",
"car": [
{
"color": "green"
},
{
"color": "green"
}
]
}
}'
I want to find the driver that has ONLY green cars (i.e. Bob).
I tried the following query, but it returns a driver that has at least one car that matches color:
curl --location --request GET 'localhost:9200/driver/_search' \
--header 'Content-Type: application/json' \
--data-raw '{
"query": {
"nested": {
"path": "driver",
"query": {
"nested": {
"path": "driver.car",
"query": {
"bool": {
"must": [
{
"match": {
"driver.car.color": "green"
}
}
]
}
}
}
}
}
}
}'
This query returns every driver that has at least one green car. What is the fix? Thank you.
You can add a must_not query explicitly ruling out red:
{
"query": {
"bool": {
"must": [
{
"nested": {
"path": "driver.car",
"query": {
"match": {
"driver.car.color": "green"
}
}
}
}
],
"must_not": [
{
"nested": {
"path": "driver.car",
"query": {
"range": {
"driver.car.color": {
"gt": "green"
}
}
}
}
}
]
}
}
}
BTW you don't need the double nesting -- drive.car will work exactly the same as driver -> driver.car.
Following is the mapping for the index index_new
{
"mappings": {
"_doc": {
"properties": {
"title": {
"type": "text"
},
"name": {
"type": "text"
},
"age": {
"type": "integer"
},
"price_amount": {
"properties": {
"val": {
"type": "scaled_float",
"scaling_factor": 100
}
}
}
}
}
}
}
While adding the data to this index
curl -X POST \
http://localhost:9200/new_index1/1 \
-H 'Content-Type: application/json' \
-d '{
"title": "new data for index",
"name": "balakarthik",
"age": 24,
"price_amount": {
"val": 1005,
"scaling_factor": 100
}
}'
this returns an error
{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Field [val] misses required parameter [scaling_factor]"
}
},
"status": 400
}
As the scaling factor is already provided in the mapping do we need to send the scaling factor in each requests, if so then how we need to send the scaling factor in each requests.
Definition for scaled_float is available here
I encountered this error but got past it by changing the URL.
Your PUT should go to: http://localhost:9200/new_index1/_doc/1
Also, you should change your input data to only specify the value. Something like this:
{
"title": "new data for index",
"name": "balakarthik",
"age": 24,
"price_amount": 10.05
}
I'm new to Elasticsearch. I've created the INDEX & inserted some documents by following CURL commands.
curl -XPUT 'localhost:9200/museums?pretty' -H 'Content-Type: application/json' -d'
{
"mappings": {
"doc": {
"properties": {
"location": {
"type": "geo_point"
}
}
}
}
}
'
curl -XPOST 'localhost:9200/museums/doc/_bulk?refresh&pretty' -H 'Content-Type: application/json' -d'
{"index":{"_id":1}}
{"location": "52.374081,4.912350", "name": "NEMO Science Museum"}
{"index":{"_id":2}}
{"location": "52.369219,4.901618", "name": "Museum Het Rembrandthuis"}
{"index":{"_id":3}}
{"location": "52.371667,4.914722", "name": "Nederlands Scheepvaartmuseum"}
{"index":{"_id":4}}
{"location": "51.222900,4.405200", "name": "Letterenhuis"}
{"index":{"_id":5}}
{"location": "48.861111,2.336389", "name": "Musée du Louvre"}
{"index":{"_id":6}}
{"location": "48.860000,2.327000", "name": "Musée d\u0027Orsay"}
{"index":{"_id":7}}
{"location": "52.374081,4.912350", "name": "NEMO7 Science Museum"}
{"index":{"_id":8}}
{"location": "52.369219,4.901618", "name": "Museum8 Het Rembrandthuis"}
{"index":{"_id":9}}
{"location": "52.371667,4.914722", "name": "Nederlands9 Scheepvaartmuseum"}
{"index":{"_id":10}}
{"location": "51.222900,4.405200", "name": "Letterenhuis10"}
{"index":{"_id":11}}
{"location": "48.861111,2.336389", "name": "Musée11 du Louvre"}
{"index":{"_id":12}}
{"location": "48.860000,2.327000", "name": "Musée12 d\u0027Orsay"}
'
If you'll see the curl commands I've made some duplicate documents & inserted those also. Now, I want to fetch all documents having UNIQUE GEO CODES & apply SORT(ASC) on that.
I got one sample CURL command like following.
curl -XPOST 'localhost:9200/museums/_search?size=0&pretty' -H 'Content-Type: application/json' -d'
{
"aggs" : {
"rings_around_amsterdam" : {
"geo_distance" : {
"field" : "location",
"origin" : "52.3760, 4.894",
"ranges" : [
{ "to" : 100000 },
{ "from" : 100000, "to" : 300000 },
{ "from" : 300000 }
]
}
}
}
}
'
But, it uses RANGE on that. I just want to fetch only UNIQUE GEO CODES & SORT those in ascending order. I googled also but, whatever I'm getting to fetch UNIQUE documents are works on only TEXT/NUMERIC type documents. Not on GEO CODES type document.
Need some help.
Try :
curl -XPOST 'localhost:9200/museums/_search?size=0&pretty' -H 'Content-Type: application/json' -d'
{
"size" : 0,
"aggs": {
"distinct_geo_distance" : {
"cardinality" : {
"field" : "location"
}
}
}
}
Suppose there is a simple blog index which contains two types: blog and comment. One blog can have multiple comments. The index is created like this
curl -X PUT \
'http://localhost:9200/%3Cblog-%7Bnow%2Fd%7D-000001%3E?pretty=' \
-H 'content-type: application/json' \
-d '{
"mappings": {
"comment": {
"_parent": { "type": "blog" },
"properties": {
"name": { "type": "keyword" },
"comment": { "type": "text" }
}
},
"blog": {
"properties": {
"author": { "type": "keyword" },
"subject": { "type": "text" },
"content": { "type": "text" }
}
}
}
}'
The index %3Cblog-%7Bnow%2Fd%7D-000001%3E is equal to <blog-{now/d}-000001> (see here for more about date math).
We're going to add 'blog-active' alias to this index. This alias is going to be used for storing data.
curl -X POST 'http://localhost:9200/_aliases?pretty=' \
-H 'content-type: application/json' \
-d '{ "actions" : [ { "add" : { "index" : "blog-*", "alias" : "blog-active" } } ] }'
Now if we do the following actions:
1.Add a blog using blog-active alias
curl -X POST http://localhost:9200/blog-active/blog/1 \
-H 'content-type: application/json' \
-d '{
"author": "author1",
"subject": "subject1",
"content": "content1"
}'
2.Add a comment to the blog
curl -X POST \
'http://localhost:9200/blog-active/comment/1?parent=1' \
-H 'content-type: application/json' \
-d '{
"name": "commenter1",
"comment": "new comment1"
}'
3.Do a rollover with max_docs = 2
curl -X POST \
http://localhost:9200/blog-active/_rollover \
-H 'content-type: application/json' \
-d '{
"conditions": {
"max_docs": 2
},
"mappings": {
"comment": {
"_parent": { "type": "blog" },
"properties": {
"name": { "type": "keyword" },
"comment": { "type": "text" }
}
},
"blog": {
"properties": {
"author": { "type": "keyword" },
"subject": { "type": "text" },
"content": { "type": "text" }
}
}
}
}'
4.And add another comment to the blog
curl -X POST \
'http://localhost:9200/blog-active/comment/1?parent=1' \
-H 'content-type: application/json' \
-d '{
"name": "commenter2",
"comment": "new comment2"
}'
Now if we search all blog indices for all comments on 'author1' blogs with (blog-%2A is blog-*)
curl -X POST \
http://localhost:9200/blog-%2A/comment/_search \
-H 'content-type: application/json' \
-d '{
"query": {
"has_parent" : {
"query" : {
"match" : { "author" : { "query" : "author1" } }
},
"parent_type" : "blog"
}
}
}'
the result only contains first comment.
This is due to the fact that second comment is in the second index which does not have parent blog document in itself. So it doesn't know about the author of the blog.
So, my question is how do I approach parent-child relations when rollover is used?
Is the relationship even possible in that case?
Similar question: ElasticSearch parent/child on different indexes
All documents that form part of a parent-child relationship need to live in the same index, more preciously same shard. Therefore it's not possible to have parent-child relationship if rollover is used, since it creates new indices.
One solution for the problem above could be to denormalize data by adding filed blog_author and blog_id in comment type. The mapping in that case will look like this (notice that parent-child relationship has been removed):
"mappings": {
"comment": {
"properties": {
"blog_id": { "type": "keyword" },
"blog_author": { "type": "keyword" },
"name": { "type": "keyword" },
"comment": { "type": "text" }
}
},
"blog": {
"properties": {
"author": { "type": "keyword" },
"subject": { "type": "text" },
"content": { "type": "text" }
}
}
}
and the query to fetch comments by blog author is:
curl -X POST \
http://localhost:9200/blog-%2A/comment/_search \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"query": {
"match": {
"blog_author": "user1"
}
}
}'