/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2021
 */

import { UIDatabase } from '../database/index';

const PATIENT_SURVEY_TYPE = 'PatientSurvey';
const VACCINE_SUPPLEMENTAL_DATA = 'VaccineSupplementalData';

export const selectSurveySchemas = () => selectFormSchema(`type=='${PATIENT_SURVEY_TYPE}'`);

export const selectSupplementalDataSchemas = () =>
  selectFormSchema(`type=='${VACCINE_SUPPLEMENTAL_DATA}'`);

const selectFormSchema = filter =>
  UIDatabase.objects('FormSchema').filtered(filter).sorted('version', true);

/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2021
 */

import { UIDatabase } from '../database/index';

const PATIENT_SURVEY_TYPE = 'PatientSurvey';
const VACCINE_SUPPLEMENTAL_DATA = 'VaccineSupplementalData';

export const selectSurveySchemas = () =>
  UIDatabase.objects('FormSchema').filtered(`type=='${PATIENT_SURVEY_TYPE}'`);

export const selectSupplementalDataSchemas = () =>
  UIDatabase.objects('FormSchema').filtered(`type=='${VACCINE_SUPPLEMENTAL_DATA}'`);

--- 
+++ 
@@ -8,8 +8,10 @@
 const PATIENT_SURVEY_TYPE = 'PatientSurvey';
 const VACCINE_SUPPLEMENTAL_DATA = 'VaccineSupplementalData';
 
-export const selectSurveySchemas = () =>
-  UIDatabase.objects('FormSchema').filtered(`type=='${PATIENT_SURVEY_TYPE}'`);
+export const selectSurveySchemas = () => selectFormSchema(`type=='${PATIENT_SURVEY_TYPE}'`);
 
 export const selectSupplementalDataSchemas = () =>
-  UIDatabase.objects('FormSchema').filtered(`type=='${VACCINE_SUPPLEMENTAL_DATA}'`);
+  selectFormSchema(`type=='${VACCINE_SUPPLEMENTAL_DATA}'`);
+
+const selectFormSchema = filter =>
+  UIDatabase.objects('FormSchema').filtered(filter).sorted('version', true);
Sort form schemas by version and return highest version
