diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 1bec35e..cb22ebb 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -1,8 +1,120 @@ + + + + + + diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..44221aa --- /dev/null +++ b/.travis.yml @@ -0,0 +1,37 @@ +language: android +jdk: oraclejdk8 +dist: trusty + +env: + global: + - ANDROID_API_LEVEL=28 + - ANDROID_BUILD_TOOLS_VERSION=28.0.3 + +android: + licenses: + - 'android-sdk-preview-license-.+' + - 'android-sdk-license-.+' + - 'google-gdk-license-.+' + components: + - tools + - platform-tools + - build-tools-$ANDROID_BUILD_TOOLS_VERSION + - android-$ANDROID_API_LEVEL + + +before_install: + - yes | sdkmanager "platforms;android-$ANDROID_API_LEVEL" + +script: + - ./build.sh + +# Caching implemented as per Travis CI Docs +# https://docs.travis-ci.com/user/languages/android/#caching +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ + - $HOME/.android/build-cache \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..48c884a --- /dev/null +++ b/README.md @@ -0,0 +1,66 @@ + + +# Nigeria Telemedicine App + +[![Build Status](https://travis-ci.org/openmrs/openmrs-contrib-telemedicine-app.svg?branch=dev)](https://travis-ci.org/openmrs/openmrs-contrib-telemedicine-app) + + +The Nigeria Telemedicine App is light weight, easy to use telemedicine mobile app developed to make health services more +accessible to the Nigerian population. Users can register themselves on the app providing basic details like their +name ,phone-number and optionally a small description of their ailment. All this can be done within a minute as there is +no wasting time in login and verification etc. After succesful registration the user will receive a call from a doctor as +early as possible. This app is developed and maintained by OpenMRS together with a global community. +
+
+## Screenshots +

+ + + +

+ + + +## How to Contribute + +This is an OpenSource project and we would be happy to see new contributors. The issues should be raised via the GitHub issue tracker. + All fixes should be proposed via pull requests. + +### Branch Policy + +We have the following branches : + + * **dev** + All the contributions should be pushed to this branch. If you're making a contribution, + you are supposed to make a pull request to _dev_. + + It is advisable to clone only the development branch using the following command: + + `git clone -b ` + + With Git 1.7.10 and later, add --single-branch to prevent fetching of all branches. Example, with development branch: + + `git clone -b dev --single-branch https://github.com/username/openmrs-contrib-telemedicine-app.git` + + * **master** + The master branch contains all the stable and bug-free working code. The development branch once complete will be merged with this branch. + + +## Development Setup + +Before you begin, you should have already downloaded the Android Studio SDK and set it up correctly. You can find a guide on how to do this here: [Setting up Android Studio](http://developer.android.com/sdk/installing/index.html?pkg=studio). + +## Building the Code + +1. Clone the repository using HTTP: git clone https://github.com/openmrs/openmrs-contrib-telemedicine-app.git + +2. Open Android Studio. + +3. Click on 'Open an existing Android Studio project' + +4. Browse to the directory where you cloned the repo and click OK. + +5. Let Android Studio import the project. + +6. Sync and build the project in Android studio. + diff --git a/app/build.gradle b/app/build.gradle index f677bb9..c39e633 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,11 +4,18 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-kapt' + android { compileSdkVersion 28 + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } defaultConfig { applicationId "com.example.nigeriatelemedicineapp" minSdkVersion 14 + android.defaultConfig.vectorDrawables.useSupportLibrary = true targetSdkVersion 28 versionCode 1 versionName "1.0" @@ -20,11 +27,17 @@ android { proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' } } + + dataBinding { + enabled = true + } } dependencies { + def lifecycle_version = "2.0.0" + implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation 'androidx.appcompat:appcompat:1.0.2' implementation 'androidx.core:core-ktx:1.0.2' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' @@ -32,4 +45,17 @@ dependencies { testImplementation 'junit:junit:4.12' androidTestImplementation 'androidx.test:runner:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' + + implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion" + annotationProcessor "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion" + //retrofit & gson + implementation 'com.google.code.gson:gson:2.8.5' + implementation 'com.squareup.retrofit2:retrofit:2.5.0' + implementation 'com.squareup.retrofit2:converter-gson:2.5.0' + //okHttp3 + implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1' + implementation 'com.squareup.okhttp3:okhttp:3.4.1' + + //timber + implementation 'com.jakewharton.timber:timber:4.7.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index da76b43..96be009 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,26 +1,38 @@ + xmlns:dist="http://schemas.android.com/apk/distribution" + package="com.example.nigeriatelemedicineapp"> - + + + android:allowBackup="true" + android:name=".TelemedicineApp" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:roundIcon="@mipmap/ic_launcher_round" + android:supportsRtl="true" + android:theme="@style/AppTheme"> + android:name=".SplashScreen" + android:label="@string/app_name" + android:theme="@style/AppTheme.NoActionBar"> - - - + + + + + + diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/MainActivity.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/MainActivity.kt deleted file mode 100644 index 329c818..0000000 --- a/app/src/main/java/com/example/nigeriatelemedicineapp/MainActivity.kt +++ /dev/null @@ -1,39 +0,0 @@ -package com.example.nigeriatelemedicineapp - -import android.os.Bundle -import com.google.android.material.snackbar.Snackbar -import androidx.appcompat.app.AppCompatActivity; -import android.view.Menu -import android.view.MenuItem - -import kotlinx.android.synthetic.main.activity_main.* - -class MainActivity : AppCompatActivity() { - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_main) - setSupportActionBar(toolbar) - - fab.setOnClickListener { view -> - Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) - .setAction("Action", null).show() - } - } - - override fun onCreateOptionsMenu(menu: Menu): Boolean { - // Inflate the menu; this adds items to the action bar if it is present. - menuInflater.inflate(R.menu.menu_main, menu) - return true - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - // Handle action bar item clicks here. The action bar will - // automatically handle clicks on the Home/Up button, so long - // as you specify a parent activity in AndroidManifest.xml. - return when (item.itemId) { - R.id.action_settings -> true - else -> super.onOptionsItemSelected(item) - } - } -} diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/SplashScreen.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/SplashScreen.kt new file mode 100644 index 0000000..bb3e47e --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/SplashScreen.kt @@ -0,0 +1,19 @@ +package com.example.nigeriatelemedicineapp + +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import androidx.appcompat.app.AppCompatActivity; +import com.example.nigeriatelemedicineapp.dashboard.DashBoardActivity + +class SplashScreen : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.splash_screen) + Handler().postDelayed({ + startActivity(Intent(this, DashBoardActivity::class.java)) + finish() + },1000) + } +} diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/TelemedicineApp.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/TelemedicineApp.kt new file mode 100644 index 0000000..33208fa --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/TelemedicineApp.kt @@ -0,0 +1,20 @@ +package com.example.nigeriatelemedicineapp + +import android.app.Application +import com.example.nigeriatelemedicineapp.BuildConfig.DEBUG +import timber.log.Timber + +class TelemedicineApp : Application() { + + override fun onCreate() { + super.onCreate() + + if(DEBUG) { + Timber.plant(Timber.DebugTree()) + } + else{ + //custom logger to be planted if required for release + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/ApiEndpoints.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/ApiEndpoints.kt new file mode 100644 index 0000000..bd31ee8 --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/ApiEndpoints.kt @@ -0,0 +1,7 @@ +package com.example.nigeriatelemedicineapp.api + +object ApiEndpoints{ + + const val PATIENT = "patient" + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/ApiManager.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/ApiManager.kt new file mode 100644 index 0000000..b5167a1 --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/ApiManager.kt @@ -0,0 +1,58 @@ +package com.example.nigeriatelemedicineapp.api + +import com.example.nigeriatelemedicineapp.api.services.GetIdentifierService +import com.example.nigeriatelemedicineapp.api.services.RegisterPatientService +import okhttp3.OkHttpClient +import retrofit2.Retrofit +import retrofit2.converter.gson.GsonConverterFactory +import retrofit2.create + +class ApiManager { + + private val baseUrl = BaseUrl() + private val BASE_URL = baseUrl.getUrl() + private val username: String = "admin" + private val password: String = "Admin123" + private var retrofit: Retrofit? = null + private var patientApi: RegisterPatientService? = null + private var identifierApi: GetIdentifierService? = null + + + init { + createService() + } + + fun createService() { + val OkHttpClient = OkHttpInterceptor().getClient(username, password) + + retrofit = Retrofit.Builder() + .baseUrl(BASE_URL) + .addConverterFactory(GsonConverterFactory.create()) + .client(OkHttpClient) + .build() + + setUpServices() + + + } + + private fun setUpServices() { + patientApi = createApi(RegisterPatientService::class.java) + identifierApi = createApi(GetIdentifierService::class.java) + } + + private fun createApi(clazz: Class): T? { + return retrofit?.create(clazz) + } + + + fun getIdentifierApi(): GetIdentifierService? { + return identifierApi + } + + fun getRegisterPatientApi(): RegisterPatientService? { + return patientApi + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/BaseUrl.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/BaseUrl.kt new file mode 100644 index 0000000..cfbf27e --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/BaseUrl.kt @@ -0,0 +1,12 @@ +package com.example.nigeriatelemedicineapp.api + +class BaseUrl { + + val PROTOCOL_HTTPS = "https://" + val HOST = "openmrs-staging.callnigeriandoc.com" + val API_PATH = "/openmrs/ws/rest/v1/" + + fun getUrl(): String { + return PROTOCOL_HTTPS + HOST + API_PATH + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/OkHttpInterceptor.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/OkHttpInterceptor.kt new file mode 100644 index 0000000..eea47da --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/OkHttpInterceptor.kt @@ -0,0 +1,36 @@ +package com.example.nigeriatelemedicineapp.api + +import android.util.Base64 +import okhttp3.OkHttpClient +import okhttp3.logging.HttpLoggingInterceptor + +class OkHttpInterceptor { + + private val httpClient = OkHttpClient.Builder() + init { + + } + fun getClient(username: String?, password: String?) : OkHttpClient + { + if (username != null && password != null) { + val credentials = "$username:$password" + val basic = "Basic " + Base64.encodeToString(credentials.toByteArray(), Base64.NO_WRAP) + httpClient.addInterceptor { chain -> + val original = chain.request() + + val requestBuilder = original.newBuilder() + .header("Authorization", basic) + .header("Accept", "application/json") + .method(original.method(), original.body()) + + + val request = requestBuilder.build() + chain.proceed(request) + } + val loggingInterceptor = HttpLoggingInterceptor() + loggingInterceptor.level=HttpLoggingInterceptor.Level.BODY + httpClient.addInterceptor(loggingInterceptor) + } + return httpClient.build() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Identifier.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Identifier.kt new file mode 100644 index 0000000..4a7f70a --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Identifier.kt @@ -0,0 +1,21 @@ +package com.example.nigeriatelemedicineapp.api.models + +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class Identifier { + + @SerializedName("identifier") + @Expose + var identifier: String? = null + @SerializedName("identifierType") + @Expose + var identifierType: String? = "05a29f94-c0ed-11e2-94be-8c13b969e334" + @SerializedName("location") + @Expose + var location: String? = "aff27d58-a15c-49a6-9beb-d30dcfc0c66e" + @SerializedName("preferred") + @Expose + var preferred: Boolean? = true + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/IdentifierList.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/IdentifierList.kt new file mode 100644 index 0000000..56c27ea --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/IdentifierList.kt @@ -0,0 +1,17 @@ +package com.example.nigeriatelemedicineapp.api.models + +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class IdentifierList { + + @SerializedName("identifiers") + @Expose + var identifiers: List? = null + + fun getUuid() : String? + { + return identifiers?.get(0) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Link.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Link.kt new file mode 100644 index 0000000..b40d47c --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Link.kt @@ -0,0 +1,23 @@ +package com.example.nigeriatelemedicineapp.api.models + +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class Link { + + @SerializedName("rel") + @Expose + private var rel: String? = null + + + @SerializedName("uri") + @Expose + private var uri: String? = null + +} + + + + + + diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Name.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Name.kt new file mode 100644 index 0000000..3511133 --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Name.kt @@ -0,0 +1,15 @@ +package com.example.nigeriatelemedicineapp.api.models + +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class Name { + + @SerializedName("givenName") + @Expose + var givenName: String? = null + @SerializedName("familyName") + @Expose + var familyName: String? = null + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Patient.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Patient.kt new file mode 100644 index 0000000..0cc60ec --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Patient.kt @@ -0,0 +1,36 @@ +package com.example.nigeriatelemedicineapp.api.models + +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class Patient { + + @SerializedName("uuid") + @Expose + var uuid: String? = null + + @SerializedName("display") + @Expose + protected var display: String? = null + + @SerializedName("links") + @Expose + protected var links: List? = null + + @SerializedName("identifiers") + @Expose + var identifiers: List? = null + + @SerializedName("person") + @Expose + var person: Person? = null + + @SerializedName("voided") + @Expose + private var voided: Boolean? = null + + @SerializedName("resourceVersion") + @Expose + private var resourceVersion: String? = null + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Person.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Person.kt new file mode 100644 index 0000000..803412f --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/models/Person.kt @@ -0,0 +1,33 @@ +package com.example.nigeriatelemedicineapp.api.models + +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName + +class Person { + + @SerializedName("gender") + @Expose + var gender: String? = "M" + @SerializedName("age") + @Expose + var age: Int? = 49 + @SerializedName("birthdate") + @Expose + var birthdate: String? = null + @SerializedName("birthdateEstimated") + @Expose + var birthdateEstimated: Boolean? = false + @SerializedName("dead") + @Expose + var dead: Boolean? = false + @SerializedName("deathDate") + @Expose + var deathDate: Any? = null + @SerializedName("causeOfDeath") + @Expose + var causeOfDeath: Any? = null + @SerializedName("names") + @Expose + var names: List? = null + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/services/GetIdentifierService.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/services/GetIdentifierService.kt new file mode 100644 index 0000000..1425d79 --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/services/GetIdentifierService.kt @@ -0,0 +1,12 @@ +package com.example.nigeriatelemedicineapp.api.services + +import com.example.nigeriatelemedicineapp.api.models.IdentifierList +import retrofit2.Call +import retrofit2.http.GET +import retrofit2.http.Url + +interface GetIdentifierService { + + @GET + fun getIdentifier(@Url url: String ="https://openmrs-staging.callnigeriandoc.com/openmrs/module/idgen/generateIdentifier.form?source=1&username=admin&password=Admin123"): Call +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/api/services/RegisterPatientService.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/api/services/RegisterPatientService.kt new file mode 100644 index 0000000..c09526f --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/api/services/RegisterPatientService.kt @@ -0,0 +1,14 @@ +package com.example.nigeriatelemedicineapp.api.services + +import com.example.nigeriatelemedicineapp.api.ApiEndpoints +import com.example.nigeriatelemedicineapp.api.models.Patient +import retrofit2.Call +import retrofit2.http.Body +import retrofit2.http.Headers +import retrofit2.http.POST + +interface RegisterPatientService{ + + @POST(ApiEndpoints.PATIENT) + fun registerPatient(@Body patient: Patient): Call +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/dashboard/DashBoardActivity.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/dashboard/DashBoardActivity.kt new file mode 100644 index 0000000..2bfdafb --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/dashboard/DashBoardActivity.kt @@ -0,0 +1,41 @@ +package com.example.nigeriatelemedicineapp.dashboard + +import android.content.Intent +import android.os.Bundle +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.databinding.DataBindingUtil +import androidx.lifecycle.ViewModelProviders +import com.example.nigeriatelemedicineapp.registerpatient.RegisterPatientActivity +import com.example.nigeriatelemedicineapp.R +import com.example.nigeriatelemedicineapp.databinding.DashboardActivityBinding +import kotlinx.android.synthetic.main.dashboard_activity.* + +class DashBoardActivity : AppCompatActivity() { + + private lateinit var viewModel : DashBoardViewModel + private lateinit var binding: DashboardActivityBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = DataBindingUtil.setContentView(this, R.layout.dashboard_activity) + setSupportActionBar(toolbar) + val actionBar= supportActionBar + actionBar!!.title=getString(R.string.dashboard_actionbar) + viewModel= ViewModelProviders.of(this).get(DashBoardViewModel::class.java) + setupUI() + } + + private fun setupUI() + { + binding.registerPatient.setOnClickListener { startActivity(it) } + } + + private fun startActivity(it: View?) { + when(it){ + binding.registerPatient-> + startActivity(Intent(this, RegisterPatientActivity::class.java)) + } + + } +} diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/dashboard/DashBoardViewModel.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/dashboard/DashBoardViewModel.kt new file mode 100644 index 0000000..87fd778 --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/dashboard/DashBoardViewModel.kt @@ -0,0 +1,6 @@ +package com.example.nigeriatelemedicineapp.dashboard + +import androidx.lifecycle.ViewModel + +class DashBoardViewModel: ViewModel() { +} diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/registerpatient/RegisterPatientActivity.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/registerpatient/RegisterPatientActivity.kt new file mode 100644 index 0000000..e557920 --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/registerpatient/RegisterPatientActivity.kt @@ -0,0 +1,61 @@ +package com.example.nigeriatelemedicineapp.registerpatient + +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Toast +import androidx.databinding.DataBindingUtil +import androidx.lifecycle.Observer +import androidx.lifecycle.ViewModelProviders +import com.example.nigeriatelemedicineapp.R +import com.example.nigeriatelemedicineapp.databinding.ActivityAppointmentFormBinding + + +class RegisterPatientActivity : AppCompatActivity() { + + private lateinit var viewModel: RegisterPatientViewModel + private lateinit var binding: ActivityAppointmentFormBinding + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = + DataBindingUtil.setContentView(this, com.example.nigeriatelemedicineapp.R.layout.activity_appointment_form) + viewModel = ViewModelProviders.of(this).get(RegisterPatientViewModel::class.java) + setUpUI() + setUpObservers() + } + + private fun setUpObservers() { + val nameObserver = Observer { newName -> + Toast.makeText(this, " $newName ", Toast.LENGTH_LONG).show() + } + + viewModel.responseString.observe(this, nameObserver) + + val idfObv = Observer { idf -> + Toast.makeText(this, "Successfully Fetched identifier : $idf ", Toast.LENGTH_SHORT).show() + } + + viewModel.identifier.observe(this, idfObv) + + } + + fun setUpUI() { + setSupportActionBar(binding.toolbar) + val actionBar = supportActionBar + actionBar!!.title = getString(R.string.appointmentFormheading) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setDisplayShowHomeEnabled(true) + + binding.register.setOnClickListener { Register() } + + } + + private fun Register() { + viewModel.registerPatient( + binding.firstName.text.toString(), + binding.lastName.text.toString() + ) + } + +} diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/registerpatient/RegisterPatientViewModel.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/registerpatient/RegisterPatientViewModel.kt new file mode 100644 index 0000000..ee4ca39 --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/registerpatient/RegisterPatientViewModel.kt @@ -0,0 +1,95 @@ +package com.example.nigeriatelemedicineapp.registerpatient + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.example.nigeriatelemedicineapp.api.ApiManager +import com.example.nigeriatelemedicineapp.api.models.* +import com.example.nigeriatelemedicineapp.repository.Repository +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response +import timber.log.Timber + +class RegisterPatientViewModel : ViewModel() { + + var repository: Repository + + val identifier: MutableLiveData by lazy { + MutableLiveData() + } + + val responseString: MutableLiveData by lazy { + MutableLiveData() + } + + init { + repository= Repository(ApiManager()) + } + + fun registerPatient(firstname : String, lastname: String) + { + getIdentifier(firstname,lastname) + } + + private fun getIdentifier(firstname : String, lastname: String) { + repository.getIdentifier()?.enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + if (response.code() == 200) { + val Uuid=response.body()?.getUuid() + identifier.postValue(Uuid) + createPatient(Uuid,firstname,lastname) + } + } + override fun onFailure(call: Call, t: Throwable) { + identifier.postValue("Error fetching Identifier") + } + }) + } + + private fun createPatient(Uuid: String?, firstname: String, lastname: String) { + val name = Name() + name.givenName=firstname + name.familyName=lastname + + val person= Person() + person.names= listOf(name) + + val identifier= Identifier() + identifier.identifier=Uuid + + Timber.d("Creating patient with ${identifier.identifier} and name ${name.givenName} ${name.familyName}") + + val patient= Patient() + patient.identifiers= listOf(identifier) + patient.person=person + + syncPatient(patient) + + } + + private fun syncPatient(patient: Patient) { + repository.registerPatient(patient)?.enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + + responseString.postValue("Patient Was not Created") + Timber.d(" t.localised message-----${t.localizedMessage} ") + Timber.d(" t.message-----${t.message} ") + } + + override fun onResponse(call: Call, response: Response) { + if(response.code()==201) + { + responseString.postValue("Patient Was Created with Code ${response.code()}") + Timber.d("Patient registration successful") + } + else{ + responseString.postValue("Patient Was not Created with code ${response.code()} code ") + } + + } + + + }) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/nigeriatelemedicineapp/repository/Repository.kt b/app/src/main/java/com/example/nigeriatelemedicineapp/repository/Repository.kt new file mode 100644 index 0000000..0419475 --- /dev/null +++ b/app/src/main/java/com/example/nigeriatelemedicineapp/repository/Repository.kt @@ -0,0 +1,26 @@ +package com.example.nigeriatelemedicineapp.repository + +import com.example.nigeriatelemedicineapp.api.ApiManager +import com.example.nigeriatelemedicineapp.api.models.IdentifierList +import com.example.nigeriatelemedicineapp.api.models.Patient +import retrofit2.Call + +class Repository(apiManager: ApiManager ){ + + private var apiManagerInstance: ApiManager + init { + apiManagerInstance= apiManager + } + + fun getIdentifier() : Call? + { + return apiManagerInstance.getIdentifierApi()?.getIdentifier() + } + + fun registerPatient(patient: Patient) : Call? + { + return apiManagerInstance.getRegisterPatientApi()?.registerPatient(patient) + } + + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_account_circle_black_24dp.xml b/app/src/main/res/drawable/ic_account_circle_black_24dp.xml new file mode 100644 index 0000000..d8ea47b --- /dev/null +++ b/app/src/main/res/drawable/ic_account_circle_black_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/logo.png b/app/src/main/res/drawable/logo.png new file mode 100644 index 0000000..8c3967b Binary files /dev/null and b/app/src/main/res/drawable/logo.png differ diff --git a/app/src/main/res/drawable/telemedicine_icon.png b/app/src/main/res/drawable/telemedicine_icon.png new file mode 100644 index 0000000..556700c Binary files /dev/null and b/app/src/main/res/drawable/telemedicine_icon.png differ diff --git a/app/src/main/res/layout/activity_appointment_form.xml b/app/src/main/res/layout/activity_appointment_form.xml new file mode 100644 index 0000000..df7f2c6 --- /dev/null +++ b/app/src/main/res/layout/activity_appointment_form.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +