@@ -13,7 +13,7 @@ import org.simple.clinic.facility.Facility
1313import org.simple.clinic.medicalhistory.Answer
1414import org.simple.clinic.overdue.Appointment.AppointmentType.Manual
1515import org.simple.clinic.overdue.Appointment.Status.Scheduled
16- import org.simple.clinic.patient.Answer.*
16+ import org.simple.clinic.patient.Answer.Unanswered
1717import org.simple.clinic.patient.PatientSearchCriteria.Name
1818import org.simple.clinic.patient.PatientSearchCriteria.NumericCriteria
1919import org.simple.clinic.patient.SyncStatus.DONE
@@ -741,6 +741,31 @@ class PatientRepository @Inject constructor(
741741 }
742742 }
743743
744+ fun fetchCompleteMedicalRecord (): List <CompleteMedicalRecord > {
745+ val patientProfiles = database.patientDao().allPatientProfiles()
746+ return patientProfiles.map { patientProfile ->
747+ val patientUuid = patientProfile.patientUuid
748+ val medicalHistory = database.medicalHistoryDao().historyForPatientImmediate(patientUuid)
749+ val appointments = database.appointmentDao().getAllAppointmentsForPatient(patientUuid)
750+ val bloodPressures = database.bloodPressureDao().allBloodPressuresRecordedSinceImmediate(
751+ patientUuid,
752+ Instant .EPOCH
753+ )
754+ val bloodSugars = database.bloodSugarDao().allBloodSugarsImmediate(patientUuid)
755+
756+ val prescribedDrugs = database.prescriptionDao().forPatientImmediate(patientUuid)
757+
758+ CompleteMedicalRecord (
759+ patient = patientProfile,
760+ medicalHistory = medicalHistory,
761+ appointments = appointments,
762+ bloodPressures = bloodPressures,
763+ bloodSugars = bloodSugars,
764+ prescribedDrugs = prescribedDrugs
765+ )
766+ }
767+ }
768+
744769 fun addIdentifiersToPatient (
745770 patientUuid : UUID ,
746771 businessIds : List <BusinessId >
0 commit comments