Without using commercial tools, is there an easy way to generate sample FHIR resources?
I'm working an a project to store FHIR messages to Elasticsearch, and I need a tool to generate FHIR sample messages in real-time to ship over TCP/IP.
Did some digging and here is what I've found.
If you do not need a lot of samples, the easiest way is to grab a zip file with resource examples from hl7 website
http://hl7.org/fhir/downloads.html
IMHO the easiest way I've found to get more than a few samples is by using Synthea project. You can generate millions of records of synthetic realistic data
https://github.com/synthetichealth/synthea
They even run a public server. Here is an example to get a bundle with 100 patients - very neat!
https://syntheticmass.mitre.org/fhir/Patient?_offset=0&_count=100
You can also find examples of bulk FHIR API implementations - some of them have demo web sites you can use to download examples:
https://github.com/smart-on-fhir/fhir-bulk-data-docs/blob/master/implementations.md
Another generator in Python from SMART on FHIR project (looks outdated):
https://github.com/smart-on-fhir/sample-patients.
The only way I know to do this is to use a service provided by test.fhir.org. You call
http://test.fhir.org/r3/StructureDefinition/[resource]/$generate-template
e.g.
http://test.fhir.org/r3/StructureDefinition/Patient/$generate-template
An easy way to generate example resources (in 2022) is to use FHIR Shorthand (FSH). Here's a copy of the example on FSH School from which you easily create the JSON.
Link: https://fshschool.org/FSHOnline/#/share/3LH920m
Instance: PatientExample
InstanceOf: Patient
Description: "Example of Patient"
* name.family = "Anyperson"
* name.given[0] = "John"
* name.given[1] = "B."
// The first element [0] can also be represented as [+] if it is not preceded by any hard index
* contact.telecom[+].system = #phone
* contact.telecom[=].value = "555-555-5555"
* contact.telecom[=].use = #home
* gender = #male
* birthDate = "1951-01-20"
* address.line = "123 Main St"
* address.city = "Anytown"
* address.postalCode = "12345"
* address.country = "US"
Have a try at https://fshschool.org/
A bonus is that you can reverse JSON into FSH as well. And, templating is easy enough use in FSH (though it's not built-in.). For a worked example see https://github.com/intrahealth/bulk-fsh
Related
I need some help getting the value and unit of a result from the FHIR Observation DSTU2 resource. I want to map these values to strings but it looks like Observation.value[x] can have different type of data. Any thoughts on how to do this in C#? I tried a few ways but no luck so far because the sandbox I'm using contains results as strings, Quantity and CodeableConcept.
http://hl7.org/fhir/observation-definitions.html#Observation.value_x_
For the Observation.value field you indeed have a choice of type, so the data in the FHIR resource can hold any of the choices listed for that field.
If you use the Hl7.Fhir.Dstu2 library - the official C# reference implementation available through NuGet, you can use it to easily retrieve the resources from your sandbox and get them into a POCO. Here's an example:
using Hl7.Fhir.Model;
using Hl7.Fhir.Rest;
var client = new FhirClient("<your sandbox url>");
var obs = client.Read<Observation>("Observation/<technical id>");
// now you can access obs.Value regardless of the type in it
if you need to serialize the data to xml or json, you use the serializer:
using Hl7.Fhir.Serialization;
var serializer = new FhirJsonSerializer();
Console.WriteLine(serializer.SerializeToString(obs));
I have been reading through the API docs for YouTube, but I am having a hard time figuring out how I can calculate the number of views per week of a given video in Python. Is this possible? Thanks!
The YouTube Analytics and Reporting APIs does not provide a metric of the kind you need -- views per week (as far as I know).
The YouTube Data API doesn't provide the info you need -- views per week -- either, but you may well compute that yourself base on this property:
statistics.viewCount (unsigned long)
The number of times the video has been viewed.
Thus, you should call the Videos.list API endpoint, passing on to it the parameters id=VIDEO_ID and part=statistics, where VIDEO_ID is the ID of the video you're interested in.
Arrange your program to read the viewCount property weekly, for computing the views per week as needed.
In the context of Python, if you're using the Google APIs Client Library for Python, then your call to the Videos.list endpoint would look like:
from googleapiclient.discovery import build
youtube = build('youtube', 'v3', developerKey = APP_KEY)
response = youtube.videos().list(
id = VIDEO_ID,
part = 'statistics',
fields = 'items(statistics(viewCount))',
maxResults = 1
).execute()
view_count = response['items'][0]['statistics']['viewCount']
Note that the code above is simplified quite much since there's no error handling.
Also note that the code above is using the parameter fields to obtain from the endpoint only the viewCount property. (It's always good to ask from the API only the info that is really needed.)
Yet another caveat using this endpoint is the following:
Even if the official doc says that the endpoint's response contains a viewCount property of type unsigned long, the actual JSON response has the value of that property being of type string:
{
"items": [
{
"statistics": {
"viewCount": "54508"
}
}
]
}
Thus, the variable view_count above will be of type str; using it as an integer would, of course, require a conversion of form int(view_count).
Google Analytics Management API goals endpoint. this is the link showing the goal endpoint I will be using to get a value. Is it possible for me to get the goal value broken up by date? I want to know the goal value for each day so I can create a line graph with accurate data. This endpoint is apart of the management API, but I know the core reporting API is more flexible with sorting by date. I would like to know if it is possible. If it is, please enlighten me!
Any reason you can't use the reporting API? You can use dimension=ga:date and metrics=ga:goalXXCompletions (ga:goal1Completions).
See the link to the query explorer report below:
https://ga-dev-tools.appspot.com/query-explorer/?start-date=2016-01-01&end-date=2016-03-27&metrics=ga%3Agoal1Completions&dimensions=ga%3Adate&samplingLevel=HIGHER_PRECISION&max-results=10000
You can query them together.
# get report data
query.list <- Init(start.date = "XXXXXX",
end.date = "XXXXXX",
dimensions = "ga:date",
metrics = "ga:goalXXValue",
table.id = "ga:XXXXX")
http://kb.mailchimp.com/api/resources/lists/members/lists-members-collection
Using this resource we can obtain only first 10 members. How to get all?
The answer is quite simple - use offset and count parameters in URL query:
https://us10.api.mailchimp.com/3.0/lists/b5b5fdc2fa/members?offset=150&count=10
Finally I found PHP API client for MailChimp API v3:
https://github.com/pacely/mailchimp-api-v3
And official docs about pagination.. I missed it before :(
http://kb.mailchimp.com/api/article/api-3-overview
I stumbled on this one while researching a way to get all list members in MC API 3.0 as well. I noticed that there were some comments on the API timing out when trying to get all list members on one page. I also encountered this at first but was able to overcome it by limiting the fields in the result by using the 'fields' param. My code is for a mass deleter so all I really needed was the ID of each member to put together a batch delete request. Here's how my fetch request looks (psuedo-code):
$total_members = $result['total_items'];//get number of members in list via previous request
https://usXX.api.mailchimp.com/3.0/lists/foobarx/members?fields=members.id&count=total_members
This way I'm able to fetch over 15,000 subscribers on one page without error.
offset and count is the official way on the docs, but the problem is that has linear slowdown. It appears to be an n^2 solution, so if you have 20,000 items, you're in trouble. Their docs http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#read-get_lists_list_id_members warn you against using offset.
If you're scenario permits you to use other filters (like since_last_changed), then you can do it quickly. See What is the right syntax for "timeframe" in MailChimp API 3.0 for format for datetime.
Using offset and count parameters are correct as mentioned in some of the other answers, but becomes tedious for large lists.
A more efficient way, is to use a client for the MailChimp API. I used mailchimp3 for python. Using this, it's pretty easy to get all members on your list because it handles the pagination. Here's how you would do it.
from mailchimp3 import MailChimp
client = MailChimp('YOUR_USERNAME', 'YOUR_SECRET_KEY')
client.lists.members.all('YOUR_LIST_ID', get_all=True, fields="members.email_address")
You can do it just with count, making an API call to the list root so in the next API call you include the count parameter and you have all your list members.
I ran into issues with this because I had a moderate list with 2600 members and MailChimp was throwing an error, but it worked with 1500 people.
So for a list bigger than 1500 members I use MailChimp export API bare in mind that this is going to get discontinued but I could not find any other acceptable solutions.
Alternatively for bigger lists (>1500) you could get the total of members and then make multiple api calls to the Member endpoint but I really dislike that :(
If anyone has a better alternative I would be really glad to hear it.
With MailChimp.Net.
Use the offset value.
List<Member> listMembers = new List<Member>();
IMailChimpManager manager = new MailChimpManager(MailChimpApiKey);
bool moreAvailable = true;
int offset = 0;
while (moreAvailable)
{
var listMembers = manager.Members.GetAllAsync(yourListId, new MemberRequest
{
Status = Status.Subscribed,
Limit = 250,
Offset = offset
}).ConfigureAwait(false);
var Allmembers = listMembers.GetAwaiter().GetResult();
foreach(Member member in Allmembers)
{
listMembers.Add(member);
}
if (Allmembers.Count() == 250)
//if the count is < of 250 then it means that there aren't more results
offset += 250;
else
moreAvailable = false;
}
Reading the API Blueprint specification, it seems set up to allow one to specify 'Data Structures' like:
Address
street: 100 Main Str. (string) - street address
zip: 77777-7777 (string) - zip / postal code
...
Customer:
handle: mrchirpy (string)
address: (address)
And then in the model, make a reference to the data structure:
Model
[Customer][]
It seems all set up that by referencing the data structure it should generate documentation and examples in-line with the end points.
However, I can't seem to get it to work, nor can I find examples using "fully normalized data abstraction". I want to define my data structures once, and then reference everywhere. It seems like it might be a problem with the tooling, specifically I'm using aglio as the rendering agent.
It seems like all this would be top of the fold type stuff so I'm confused and wondering if I'm missing something or making the wrong assumptions about what's possible here.
#zanerock, I'm the author of Aglio. The data structure support that you mention is a part of MSON, which was recently added as a feature to API Blueprint to describe data structures / schemas. Aglio has not yet been updated to support this, but I do plan on adding the feature.