@causalfoundry/react-native-cf-chw-mgmt
Version:
causalfoundry.ai SDK for tracking logs for Community Healthcare Worker's usage of the app.
286 lines (269 loc) • 13.6 kB
text/typescript
import {NativeModules, Platform} from 'react-native';
import {
ChwCatalogModel,
ChwModelObject,
ChwSiteCatalogModel,
CounselingEventObject,
InvestigationEventObject,
PatientCatalogModel,
PrescriptionEventObject,
SubmitAssessmentEventObject,
SubmitEnrolmentEventObject,
SubmitMedicalReviewObject,
SubmitScreeningEventObject,
TreatmentPlanEventObject
} from "./typings";
const {CfLogChwMgmt} = NativeModules;
/**
* logChwModuleEvent is to log the selection of the module selected by the user in the app.
*
* @param chwModuleType the name of the module user is selecting.
* @param meta is to send any other data you want to send with ingest, can also be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logChwModuleEvent = (properties: ChwModelObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logChwModuleEvent(properties.type, null, false)
}
}
/**
* logSubmitScreeningEvent is to log the submission of screening event for the patients.
*
* @param patientId patient id in the system.
* @param siteId site id in the system.
* @param siteCategory category for the site of screening in the system.
* @param screeningType type for the screening.
* @param diagnosisVitalsList list of the diagnosis value provided by the user for recording patient vitals.
* @param diagnosisSymptomsList list of the diagnosis Symptoms value provided by the user.
* @param diagnosisQuestionnaireList list of the diagnosis Questionnaire value provided by the user.
* @param diagnosisValueList list of the diagnosis value provided by the user.
* @param diagnosisResultList list of the diagnosis result provided by the user.
* @param pregnancyDetailObject object for pregnancy diagnosis result provided by the user.
* @param isReferredForAssessment is the user referred for further assessment.
* @param meta is to send any other data you want to send with ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logSubmitScreeningEvent = (properties: SubmitScreeningEventObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logSubmitScreeningEvent(properties.patient_id, properties.site_id,
properties.category, properties.type,
JSON.stringify(properties.vitals_list),
JSON.stringify(properties.diagnosis_symptoms_list),
JSON.stringify(properties.diagnosis_questionnaire_list),
JSON.stringify(properties.diagnosis_values_list),
JSON.stringify(properties.diagnosis_results_list),
JSON.stringify(properties.pregnancy_details),
properties.referred_for_assessment, null, false)
}
}
/**
* logSubmitAssessmentEvent is to submit the assessment report for the patient. It requires
* some values as required by the logs to segregate the patient category.
*
* @param patientId patient id in the system.
* @param siteId site id in the system.
* @param medicalAdherence the string about patient's adherence to medical treatment.
* @param diagnosisVitalsList list of the diagnosis value provided by the user for recording patient vitals.
* @param diagnosisQuestionnaireList list of the diagnosis Questionnaire value provided by the user.
* @param diagnosisValueList list of the diagnosis values provided by the user.
* @param diagnosisResultList list of the diagnosis results provided by the user.
* @param diagnosisSymptomList list of the diagnosis symptoms provided by the user.
* @param isReferredForAssessment is the user referred for further assessment.
* @param pregnancyDetailObject object for pregnancy diagnosis result provided by the user.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logSubmitAssessmentEvent = (properties: SubmitAssessmentEventObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logSubmitAssessmentEvent(properties.patient_id,
properties.site_id, properties.category, properties.type,
JSON.stringify(properties.medication_adherence),
JSON.stringify(properties.vitals_list),
JSON.stringify(properties.diagnosis_questionnaire_list),
JSON.stringify(properties.diagnosis_values_list),
JSON.stringify(properties.diagnosis_results_list),
JSON.stringify(properties.diagnosis_symptoms_list),
JSON.stringify(properties.pregnancy_details),
properties.referred_for_assessment, null, false)
}
}
/**
* logSubmitEnrolmentEvent is to submit the enrollment values for the patient to enroll in the system.
*
* @param patientId patient id in the system.
* @param siteId site id in the system.
* @param enrollmentAction enrollment Action for the submission, add or edit.
* @param diagnosisVitalsList list of the diagnosis value provided by the user for recording patient vitals.
* @param diagnosisValueList list of the diagnosis values provided by the user.
* @param diagnosisResultList list of the diagnosis results provided by the user.
* @param patientStatusList list of the patient stats provided by the user.
* @param treatmentPlanList list of the treatment plan provided by the user.
* @param diagnosisQuestionnaireList list of the diagnosis Questionnaire value provided by the user.
* @param pregnancyDetailObject object for pregnancy diagnosis result provided by the user.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logSubmitEnrolmentEvent = (properties: SubmitEnrolmentEventObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logSubmitEnrolmentEvent(properties.patient_id, properties.site_id, properties.action,
JSON.stringify(properties.vitals_list),
JSON.stringify(properties.diagnosis_values_list),
JSON.stringify(properties.diagnosis_results_list),
JSON.stringify(properties.patient_status_list),
JSON.stringify(properties.treatment_plan_list),
JSON.stringify(properties.diagnosis_questionnaire_list),
JSON.stringify(properties.pregnancy_details),
null, false)
}
}
/**
* logCounselingEvent is to add and update lifestyle related events for patients.
*
* @param patientId patient id in the system.
* @param siteId site id in the system.
* @param counselingId counseling id in the system.
* @param counselingType counseling type, if it is lifestyle or psychological.
* @param counselingPlanList list of the counseling plan provided by the user.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logCounselingEvent = (properties: CounselingEventObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logCounselingEvent(properties.patient_id, properties.site_id,
properties.id, properties.counseling_type,
JSON.stringify(properties.counseling_plan_list), null, false)
}
}
/**
* logInvestigationEvent to log the investigation related events of the patient treatment.
*
* @param patientId patient id in the system.
* @param siteId site id in the system.
* @param investigationId investigation id in the system.
* @param investigationList list of the investigation items provided by the user.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logInvestigationEvent = (properties: InvestigationEventObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logInvestigationEvent(properties.patient_id, properties.site_id,
properties.id,
JSON.stringify(properties.prescribed_tests_list), null, false)
}
}
/**
* logTreatmentPlanEvent to log the investigation related events of the patient treatment.
*
* @param patientId patient id in the system.
* @param siteId site id in the system.
* @param treatmentPlanId treatment plan id in the system.
* @param treatmentPlanList list of the treatment plan items provided by the user.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logTreatmentPlanEvent = (properties: TreatmentPlanEventObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logTreatmentPlanEvent(properties.patient_id, properties.site_id,
properties.id,
JSON.stringify(properties.treatment_plan_list), null, false)
}
}
/**
* logPrescriptionEvent is to log additions, updates or deletions in prescription
* related events for the patient.
*
* @param patientId patient id in the system.
* @param siteId site id in the system.
* @param prescriptionId prescription id in the system.
* @param prescriptionList list of the prescriptions items provided by the user.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logPrescriptionEvent = (properties: PrescriptionEventObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logPrescriptionEvent(properties.patient_id, properties.site_id, properties.id,
JSON.stringify(properties.prescription_list), null, false)
}
}
/**
* logSubmitMedicalReviewEvent is to submit the medical review details about the patient.
*
* @param patientId patient id in the system.
* @param siteId site id in the system.
* @param medicalReviewObject is the details about the medical review.
* @param meta is to send any other data you want to send with the ingest, can be null.
* @param updateImmediately is default set to true, you can use that to log events when the app
* goes in the background or closed.
*/
const logSubmitMedicalReviewEvent = (properties: SubmitMedicalReviewObject) => {
if (Platform.OS === 'android') {
console.log(properties)
CfLogChwMgmt.logSubmitMedicalReviewEvent(properties.patient_id, properties.site_id, JSON.stringify(properties.medical_review), null, false)
}
}
/**
* Chw catalog values
*
* @param chwId chw id in the system
* @param chwCatalogModel props for the chw
*/
const updateChwCatalog = (chwId: string, chwCatalogModel: ChwCatalogModel) => {
if (Platform.OS === 'android') {
console.log(chwCatalogModel)
CfLogChwMgmt.updateChwCatalog(chwId, JSON.stringify(chwCatalogModel))
}
}
/**
* Site catalog values
*
* @param siteId site id in the system
* @param chwSiteCatalogModel props for the site
*/
const updateChwSiteCatalog = (siteId: string, chwSiteCatalogModel: ChwSiteCatalogModel) => {
if (Platform.OS === 'android') {
console.log(chwSiteCatalogModel)
CfLogChwMgmt.updateChwSiteCatalog(siteId, JSON.stringify(chwSiteCatalogModel))
}
}
/**
* Patient catalog values
*
* @param patientId patient id in the system
* @param sitePatientModel props for the patient
*/
const updatePatientCatalog = (patientId: string, sitePatientModel: PatientCatalogModel) => {
if (Platform.OS === 'android') {
console.log(sitePatientModel)
CfLogChwMgmt.updatePatientCatalog(patientId, JSON.stringify(sitePatientModel))
}
}
export default {
logChwModuleEvent,
logSubmitScreeningEvent,
logSubmitAssessmentEvent,
logSubmitEnrolmentEvent,
logCounselingEvent,
logInvestigationEvent,
logTreatmentPlanEvent,
logPrescriptionEvent,
logSubmitMedicalReviewEvent,
updateChwCatalog,
updateChwSiteCatalog,
updatePatientCatalog
}