Accessing a resource within a Bundle HL7-FHIR - hl7

I was just wondering if there is a way to access a resource within a bundle.
I.E
FhirContext ctx = FhirContext.forDstu3();
String baseSite= "http://fhirtest.uhn.ca/baseDstu3/";
IGenericClient client = ctx.newRestfulGenericClient("http://fhirtest.uhn.ca/baseDstu3");
System.out.println("Connected to server");
Bundle bundle = client.search().forResource(DiagnosticReport.class).where(DiagnosticReport.IDENTIFIER.exactly().identifier(id)).returnBundle(Bundle.class).execute();
DiagnosticReport diag =client.read().resource(DiagnosticReport.class).withId(bundle.getEntry().get(0).getResource());
String finalBundle=ctx.newXmlParser().setPrettyPrint(true).encodeResourceToString(diag);
System.out.println(finalBundle);
Observation obv = client.read().resource(Observation.class).withUrl(baseSite+diag.getResult().get(0).getReference()).execute();
Sequence seq = client.read().resource(Sequence.class).withUrl(baseSite+obv.getRelated().get(0).getTarget()).execute();
diag is currently what is causing issues. Since I have a client access their report via ID that is generated (thus the bundle search command) but to access all the other resources that are referenced by diagnosticReport I can't find a way to either separate the resource from the bundle or directly grab from the bundle.
Thank you

If you just want to grab the DiagnosticReport resource from the bundle you should be able to do something like:
DiagnosticReport dr = (DiagnosticReport) bundle.getEntry().get(0).getResource();
If you wanted, you could also use includes to return the other linked resources in a single call to the server:
Bundle bundle = client.search().forResource(DiagnosticReport.class)
.where(new StringClientParam("_id").matches().value("117376"))
.include(new Include("DiagnosticReport:patient"))
.include(new Include("DiagnosticReport:result"))
.returnBundle(Bundle.class)
.execute();

Related

How to run iOS unit tests with cocoapods + static library

We are having many development pods that are currently linked as dynamic frameworks.
I'm trying to migrate the dynamic framework to static libraries
For static-libs, I'm setting resource bundle like below (pod_spec)
s.resource_bundles = { 'BundleName' => [ 'BundleName/**/*.{xcassets,lproj,storyboard,xib,xcassets,imageset,png,mp3,mp4,wma}' ] }
and accessing in code like below
Bundle.main.url(forResource: "BundleName", withExtension: "bundle")
when I run the app, I'm getting the resource bundle path, from that I can able to get images/localized text
The same is not working when I run Unit tests. resource bundle path is nil and all my test related to localized text are failing
how can I fix this?
thanks in advance
The issue is that your tests are a separate bundle from your application, so when running Bundle.main.url(...) it will try to give a resource from your test bundle, not your app bundle.
I guess the easiest way of doing things is to add the resources to your test bundle. Depending on what you want to achieve. Some more background information might be helpful.
Answering my own question after struggled for a whole day
When the unit test runs your code, your unit test bundle is NOT the main bundle.
Even though you are running tests, not your application, your application bundle is still the main bundle. so, when you run unit tests with static libraries mode, you won't find resource_bundles if you search the main bundle.
you have to check in the list of Bundle and find the one with ".xctest" extension and append the module name
enter code here
class func bundle(for name: String) -> Bundle {
var url = Bundle.main.bundleURL
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
url = bundle.bundleURL.deletingLastPathComponent()
}
url = url.appendingPathComponent( name + "/" + name + ".bundle")
guard let bundle = Bundle(url: url) else {
return Bundle.main
}
return bundle
}

How to access a list of all files in resource folder of my project?

I have some .TXT files saved in Resource folder of my project. I want to display a list to user in which all files from resource folder are shown and user can select the file he desires.
Later on i will read the user selected file and show it on screen.
Take a look at the NSBundle function pathsForResourcesOfType:inDirectory: That will give you a list of the paths to all the files in a sub-bundle of a bundle. if you call that method on the main bundle you'll get a list of all the files of a certain type in a sub-directory of the main bundle.
(I have no idea how to make use of these functions from xamarin.)
This gets FileInfo's on all txt files in the resources:
var fileInfos = NSBundle.GetPathsForResources(".txt", path)
.Select(a => new FileInfo(a));
Now you have the short name, full name etc to play with:
foreach (var fileInfo in fileInfos)
{
System.Diagnostics.Debug.WriteLine(fileInfo.Name);
using (var streamReader = new StreamReader(new FileStream(fileInfo.FullName, FileMode.Open)))
{
System.Diagnostics.Debug.WriteLine(streamReader.ReadToEnd());
}
}

How do I derive physical path of a relative directory inside Config.groovy?

I am trying to set up Weceem using the source from GitHub. It requires a physical path definition for the uploads directory, and for a directory for appears to be used for writing searchable indexes. The default setting for uploads is:
weceem.upload.dir = 'file:/var/www/weceem.org/uploads/'
I would like to define those using relative paths like WEB-INF/resources/uploads. I tried a methodology I have used previously for accessing directories with relative path like this:
File uploadDirectory = ApplicationHolder.application.parentContext.getResource("WEB-INF/resources/uploads").file
def absoluteUploadDirectory = uploadDirectory.absolutePath
weceem.upload.dir = 'file:'+absoluteUploadDirectory
However, 'parentContext' under ApplicationHolder.application is NULL. Can anyone offer a solution to this that would allow me to use relative paths?
look at your Config.groovy you should have (maybe it is commented)
// locations to search for config files that get merged into the main config
// config files can either be Java properties files or ConfigSlurper scripts
// "classpath:${appName}-config.properties", "classpath:${appName}-config.groovy",
grails.config.locations = [
"file:${userHome}/.grails/${appName}-config.properties",
"file:${userHome}/.grails/${appName}-config.groovy"
]
Create Conig file in deployment server
"${userHome}/.grails/${appName}-config.properties"
And define your prop (even not relative path) in that config file.
To add to Aram Arabyan's response, which is correct, but lacks an explanation:
Grails apps don't have a "local" directory, like a PHP app would have. They should be (for production) deployed in a servlet container. The location of that content is should not be considered writable, as it can get wiped out on the next deployment.
In short: think of your deployed application as a compiled binary.
Instead, choose a specific location somewhere on your server for the uploads to live, preferably outside the web server's path, so they can't be accessed directly. That's why Weceem defaults to a custom folder under /var/www/weceem.org/.
If you configure a path using the externalized configuration technique, you can then have a path specific to the server, and include a different path on your development machine.
In both cases, however, you should use absolute paths, or at least paths relative to known directories.
i.e.
String base = System.properties['base.dir']
println "config: ${base}/web-app/config/HookConfig.grooy"
String str = new File("${base}/web-app/config/HookConfig.groovy").text
return new ConfigSlurper().parse(str)
or
def grailsApplication
private getConfig() {
String str = grailsApplication.parentContext.getResource("config/HookConfig.groovy").file.text
return new ConfigSlurper().parse(str)
}

SF2 : Allow user to configure bundle without checking some part of the bundle configuration

I'm actually developping a symfony 2 bundle. I would like to allow user to configure my bundle with the DIC without checking some part of the bundle configuration.
For example, the user sets this configuration :
root_node:
node:
key1: value1
key2: value2
key3: value3
And my configuration bundle is set like that :
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('root_node');
$rootNode
->children()
->arrayNode('node')->children()->end()
->end();
I would like the children nodes of "node" can be configure by the user without been checking by the bundle configuration. I don't know how modify the configuration for this issue.
After some reseach on the symfony2 github repository, I found the solution. For the others who want to do the same thing, the solution is :
$rootNode
->children()
->arrayNode('node')
->useAttributeAsKey('node')->prototype('scalar')->end()
->end()
->end();

system.io.directorynotfound -> But it works in Console

My files are referenced like so (it's all relative):
// WHERE YOU KEEP THE PAGE TITLE XML
public static string myPageTitleXML = "xml/pagetitles.xml";
and
using (StreamReader r = new StreamReader(myPageTitleXML))
{ //etc.. . .etc....etc..
}
I get system.io.directorynotfound, and "this problem needs to be shut down", when I double click the executable. But running it from the console works like a charm. What's wrong here?
I played around with attempting to set Environment.CurrentDirectory but couldn't get anything to work. Why should I have to do that anyway? It defeats the purpose of a relative path no?
responding.. .
"application" does not exist in the current context, i'll keep trying what people have mentioned, this is not a windows.form
testing
Path.GetDirectoryName(Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), myPageTitleXML); gives error URI formats are not supported, as does Path.GetFullPath(). Server.MapPath results in an error as well, this is currently offline
Well assuming this directory is somewhere under the directory in which your code is executing, it sounds like you can use ..
Application.ExecutablePath()
or
Application.StartUpPath()
.. to get an idea as to what your application is seeing when it goes in search of an 'xml' directory with the 'pagetitles.xml' file in it.
If the directory returned by one of these methods does not point where you thought it did, you'll need to move the location of your application or the location of this folder so that it is within the same directory as the app.
Hope this gets you on the right path.
So, when you run it from double clicking the executable, is there a file named pagetitles.xml in a folder named xml, where xml is a folder in the same location as the executable?
It's certainly possible to use relative paths like this, but I wouldn't really recommend it. Instead, maybe use something like:
string fileToOpen = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase), myPageTitleXML);
using (StreamReader r = new StreamReader(fileToOpen))
{
//etc.. . .etc....etc..
}
Is this ASP.NET code? If so then you probably need to do MapPath("xml/pagetitles.xml")

Resources