-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/74-bottom-sheets-and-record-operations
- Loading branch information
Showing
25 changed files
with
800 additions
and
43 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
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
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
51 changes: 51 additions & 0 deletions
51
app/src/main/kotlin/edu/stanford/bdh/engagehf/questionnaire/QuestionnaireRepository.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,51 @@ | ||
package edu.stanford.bdh.engagehf.questionnaire | ||
|
||
import com.google.firebase.firestore.FirebaseFirestore | ||
import edu.stanford.bdh.engagehf.observations.ObservationCollection | ||
import edu.stanford.bdh.engagehf.observations.ObservationCollectionProvider | ||
import edu.stanford.healthconnectonfhir.QuestionnaireDocumentMapper | ||
import edu.stanford.spezi.core.coroutines.di.Dispatching | ||
import edu.stanford.spezi.core.logging.speziLogger | ||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.tasks.await | ||
import kotlinx.coroutines.withContext | ||
import org.hl7.fhir.r4.model.Questionnaire | ||
import org.hl7.fhir.r4.model.QuestionnaireResponse | ||
import javax.inject.Inject | ||
|
||
class QuestionnaireRepository @Inject constructor( | ||
@Dispatching.IO private val ioDispatcher: CoroutineDispatcher, | ||
private val questionnaireDocumentMapper: QuestionnaireDocumentMapper, | ||
private val observationCollectionProvider: ObservationCollectionProvider, | ||
private val firestore: FirebaseFirestore, | ||
) { | ||
private val logger by speziLogger() | ||
|
||
suspend fun getQuestionnaire(id: String): Result<Questionnaire> { | ||
return withContext(ioDispatcher) { | ||
runCatching { | ||
val document = firestore.collection(QUESTIONNAIRE_COLLECTION) | ||
.document(id) | ||
.get() | ||
.await() | ||
questionnaireDocumentMapper.map(document) | ||
}.onFailure { exception -> | ||
logger.e(exception) { "Error fetching questionnaire" } | ||
} | ||
} | ||
} | ||
|
||
suspend fun save(questionnaireResponse: QuestionnaireResponse): Result<Unit> { | ||
return withContext(ioDispatcher) { | ||
runCatching { | ||
val document = questionnaireDocumentMapper.map(questionnaireResponse) | ||
observationCollectionProvider.getCollection(ObservationCollection.QUESTIONNAIRE) | ||
.add(document).await().let { } | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
private const val QUESTIONNAIRE_COLLECTION = "questionnaires" | ||
} | ||
} |
Oops, something went wrong.