-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(PNC Child Birth) add Child Birth Form
- Loading branch information
1 parent
46324b8
commit 8cfb09c
Showing
18 changed files
with
583 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
app/src/main/java/com/kabarak/kabarakmhis/pnc/ChildAdd.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
package com.kabarak.kabarakmhis.pnc | ||
|
||
import android.os.Bundle | ||
import android.util.Log | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.os.bundleOf | ||
import androidx.core.view.ViewCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
import androidx.fragment.app.commit | ||
import ca.uhn.fhir.context.FhirContext | ||
import ca.uhn.fhir.context.FhirVersionEnum | ||
import com.google.android.fhir.datacapture.QuestionnaireFragment | ||
import com.kabarak.kabarakmhis.R | ||
import com.kabarak.kabarakmhis.helperclass.QuestionnaireUtil | ||
|
||
class ChildAdd : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_child_add) | ||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> | ||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) | ||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) | ||
insets | ||
} | ||
|
||
// Configure a QuestionnaireFragment | ||
val questionnaireJsonString = getStringFromAssets("new-patient-registration.json") | ||
|
||
if (savedInstanceState == null && questionnaireJsonString != null) { | ||
supportFragmentManager.commit { | ||
setReorderingAllowed(true) | ||
val fragment = QuestionnaireFragment() | ||
fragment.arguments = bundleOf(QuestionnaireUtil.getExtraQuestionnaireJsonString() to questionnaireJsonString) | ||
add(R.id.fragment_container_view, fragment) | ||
} | ||
} else { | ||
Log.e("ChildAdd", "Failed to load questionnaire JSON") | ||
} | ||
|
||
// Get a questionnaire response | ||
val fragment = supportFragmentManager.findFragmentById(R.id.fragment_container_view) | ||
if (fragment is QuestionnaireFragment) { | ||
val questionnaireResponse = fragment.getQuestionnaireResponse() | ||
|
||
// Print the response to the log | ||
val jsonParser = FhirContext.forCached(FhirVersionEnum.R4).newJsonParser() | ||
val questionnaireResponseString = jsonParser.encodeResourceToString(questionnaireResponse) | ||
Log.d("response", questionnaireResponseString) | ||
} else { | ||
Log.e("ChildAdd", "QuestionnaireFragment not found") | ||
} | ||
// Submit button callback | ||
supportFragmentManager.setFragmentResultListener( | ||
QuestionnaireFragment.SUBMIT_REQUEST_KEY, | ||
this, | ||
) { _, _ -> | ||
Log.d("ChildAdd", "Submit request received") | ||
submitQuestionnaire() | ||
} | ||
} | ||
|
||
private fun getStringFromAssets(fileName: String): String? { | ||
return try { | ||
val inputStream = assets.open(fileName) | ||
val size = inputStream.available() | ||
val buffer = ByteArray(size) | ||
inputStream.read(buffer) | ||
inputStream.close() | ||
String(buffer, Charsets.UTF_8) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
null | ||
} | ||
} | ||
|
||
private fun submitQuestionnaire() { | ||
// Retrieve the QuestionnaireFragment | ||
val fragment = supportFragmentManager.findFragmentById(R.id.fragment_container_view) | ||
if (fragment is QuestionnaireFragment) { | ||
// Get the QuestionnaireResponse from the fragment | ||
val questionnaireResponse = fragment.getQuestionnaireResponse() | ||
|
||
// Use FHIR's JSON parser to convert QuestionnaireResponse into a JSON string | ||
val fhirContext = FhirContext.forR4() | ||
val jsonParser = fhirContext.newJsonParser() | ||
|
||
// Serialize the response to a JSON string | ||
val questionnaireResponseString = jsonParser.encodeResourceToString(questionnaireResponse) | ||
|
||
// Log the response (you can replace this with saving to a database or sending to a server) | ||
Log.d("submitQuestionnaire", questionnaireResponseString) | ||
|
||
// Optionally, save the response or send it to a server | ||
saveQuestionnaireResponse(questionnaireResponseString) | ||
} else { | ||
Log.e("submitQuestionnaire", "QuestionnaireFragment not found or is null") | ||
} | ||
} | ||
|
||
private fun saveQuestionnaireResponse(response: String) { | ||
try { | ||
val outputStream = openFileOutput("questionnaire_response.json", MODE_PRIVATE) | ||
outputStream.write(response.toByteArray(Charsets.UTF_8)) | ||
outputStream.close() | ||
Log.d("saveQuestionnaireResponse", "Questionnaire response saved successfully") | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
Log.e("saveQuestionnaireResponse", "Failed to save questionnaire response") | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/kabarak/kabarakmhis/pnc/ChildBirthView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.kabarak.kabarakmhis.pnc | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.view.ViewCompat | ||
import androidx.core.view.WindowInsetsCompat | ||
import com.kabarak.kabarakmhis.R | ||
import kotlinx.android.synthetic.main.activity_child_birth_view.btnAdd | ||
|
||
class ChildBirthView : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_child_birth_view) | ||
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets -> | ||
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()) | ||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom) | ||
insets | ||
} | ||
|
||
btnAdd.setOnClickListener { | ||
val intent = Intent(this, ChildAdd::class.java) | ||
startActivity(intent) | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<androidx.constraintlayout.widget.ConstraintLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/main" | ||
tools:context=".MainActivity" | ||
> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
android:id="@+id/fragment_container_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
app:layout_constraintTop_toTopOf="parent" /> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
Oops, something went wrong.