func (t *TabFile) CheckSensibility() ([]string, error) {
	batchnames := []string{"Inclusion", "Exclusion"}
	batches := [][]TabEntry{t.AllIncluded(), t.AllExcluded()}

	missingFields := make(map[int]struct{})
	errs := make([]string, 0)

	// Iterate over all the fields you're including and excluding separately.
	// Rationale: if you successfully listed all the primary and secondary ICD10
	// fields for inclusion, but only listed one of them for exclusion and
	// forgot to list the other, that's probably unintentional and should be
	// flagged.
	for batchID, batch := range batches {
		icd9 := make(map[int]struct{})
		icd10 := make(map[int]struct{})
		opcs := make(map[int]struct{})

		for _, v := range batch {
			// Capitalized ICD9 (etc) here refer to the manual global maps that
			// we create in special_fields.go which list all possible FieldIDs
			// for ICD9 codes. Lower case icd9 represents the local map that
			// will track which of those FieldIDs actually appeared in the
			// tabfile. Basically, this is a lookup to see whether the field we
			// are currently looking at is an ICD9 field, etc.
			if _, exists := ICD9[v.FieldID]; exists {
				icd9[v.FieldID] = struct{}{}
			}
			if _, exists := ICD10[v.FieldID]; exists {
				icd10[v.FieldID] = struct{}{}
			}
			if _, exists := OPCS[v.FieldID]; exists {
				opcs[v.FieldID] = struct{}{}
			}
		}

		// So, you included at least one ICD9 field, but you failed to include
		// all of them. Probably an error.
		if len(icd9) > 0 && len(icd9) < len(ICD9) {
			for known := range ICD9 {
				if _, exists := icd9[known]; !exists {
					missingFields[known] = struct{}{}
				}
			}
			errs = append(errs, fmt.Sprintf("In the %s subset, you included ICD9 fields %v. Consider including all IC9 fields: %v", batchnames[batchID], icd9, ICD9))
		}

		if len(icd10) > 0 && len(icd10) < len(ICD10) {
			for known := range ICD10 {
				if _, exists := icd10[known]; !exists {
					missingFields[known] = struct{}{}
				}
			}
			errs = append(errs, fmt.Sprintf("In the %s subset, you included ICD10 fields %v. Consider including all IC10 fields: %v", batchnames[batchID], icd10, ICD10))
		}

		if len(opcs) > 0 && len(opcs) < len(OPCS) {
			for known := range OPCS {
				if _, exists := opcs[known]; !exists {
					missingFields[known] = struct{}{}
				}
			}
			errs = append(errs, fmt.Sprintf("In the %s subset, you included OPCS fields %v. Consider including all OPCS fields: %v", batchnames[batchID], opcs, OPCS))
		}
	}

	// If we think you forgot one or more FieldIDs, we'll let you know about all
	// of them.
	if len(errs) > 0 {
		missingSlice := make([]string, 0, len(missingFields))
		for missing := range missingFields {
			missingSlice = append(missingSlice, strconv.Itoa(missing))
		}

		return missingSlice, errors.New(strings.Join(errs, " | "))
	}

	return nil, nil
}
// ICD9, ICD10, and OPCS codes in the UK Biobank are distributed across many
// FieldIDs. For example, there is a FieldID for "primary ICD10 code" as well as
// a separate FieldID for "secondary ICD10 code". For our purposes, we almost
// always want to consider them equally. Therefore, if a tabfile includes one of
// those fields but not the other, that's usually in error. (It's not *always*
// in error or else we could just override it: there may be special
// circumstances where an analyist only wants to review primary diagnoses.) So,
// this method looks over all of the fields in a tabfile and lets you know
// whether it thinks there are additional FieldIDs you should be adding.
ICD9, ICD10, and OPCS codes in the UK Biobank are distributed across many
FieldIDs. For example, there is a FieldID for "primary ICD10 code" as well as
a separate FieldID for "secondary ICD10 code". For our purposes, we almost
always want to consider them equally. Therefore, if a tabfile includes one of
those fields but not the other, that's usually in error. (It's not *always
in error or else we could just override it: there may be special
circumstances where an analyist only wants to review primary diagnoses.) So,
this method looks over all of the fields in a tabfile and lets you know
whether it thinks there are additional FieldIDs you should be adding.
// ICD9 ICD10 and OPCS codes in the UK Biobank are distributed across many // FieldIDs . For example there is a FieldID for " primary ICD10 code " as well as // a separate FieldID for " secondary ICD10 code " . For our purposes we almost // always want to consider them equally . Therefore if a tabfile includes one of // those fields but not the other that ' s usually in error . ( It ' s not * always * // in error or else we could just override it : there may be special // circumstances where an analyist only wants to review primary diagnoses . ) So // this method looks over all of the fields in a tabfile and lets you know // whether it thinks there are additional FieldIDs you should be adding .
func (t *TabFile) CheckSensibility() ([]string, error) {
	batchnames := []string{"Inclusion", "Exclusion"}
	batches := [][]TabEntry{t.AllIncluded(), t.AllExcluded()}
	missingFields := make(map[int]struct{})
	errs := make([]string, 0)
	for batchID, batch := range batches {
		icd9 := make(map[int]struct{})
		icd10 := make(map[int]struct{})
		opcs := make(map[int]struct{})
		for _, v := range batch {
			if _, exists := ICD9[v.FieldID]; exists {
				icd9[v.FieldID] = struct{}{}
			}
			if _, exists := ICD10[v.FieldID]; exists {
				icd10[v.FieldID] = struct{}{}
			}
			if _, exists := OPCS[v.FieldID]; exists {
				opcs[v.FieldID] = struct{}{}
			}
		}
		if len(icd9) > 0 && len(icd9) < len(ICD9) {
			for known := range ICD9 {
				if _, exists := icd9[known]; !exists {
					missingFields[known] = struct{}{}
				}
			}
			errs = append(errs, fmt.Sprintf("In the %s subset, you included ICD9 fields %v. Consider including all IC9 fields: %v", batchnames[batchID], icd9, ICD9))
		}
		if len(icd10) > 0 && len(icd10) < len(ICD10) {
			for known := range ICD10 {
				if _, exists := icd10[known]; !exists {
					missingFields[known] = struct{}{}
				}
			}
			errs = append(errs, fmt.Sprintf("In the %s subset, you included ICD10 fields %v. Consider including all IC10 fields: %v", batchnames[batchID], icd10, ICD10))
		}
		if len(opcs) > 0 && len(opcs) < len(OPCS) {
			for known := range OPCS {
				if _, exists := opcs[known]; !exists {
					missingFields[known] = struct{}{}
				}
			}
			errs = append(errs, fmt.Sprintf("In the %s subset, you included OPCS fields %v. Consider including all OPCS fields: %v", batchnames[batchID], opcs, OPCS))
		}
	}
	if len(errs) > 0 {
		missingSlice := make([]string, 0, len(missingFields))
		for missing := range missingFields {
			missingSlice = append(missingSlice, strconv.Itoa(missing))
		}
		return missingSlice, errors.New(strings.Join(errs, " | "))
	}
	return nil, nil
}
func ( t * TabFile ) CheckSensibility ( ) ( [ ] string , error ) { batchnames := [ ] string { " " , " " } batches := [ ] [ ] TabEntry { t . AllIncluded ( ) , t . AllExcluded ( ) } missingFields := make ( map [ int ] struct { } ) errs := make ( [ ] string , 0 ) for batchID , batch := range batches { icd9 := make ( map [ int ] struct { } ) icd10 := make ( map [ int ] struct { } ) opcs := make ( map [ int ] struct { } ) for _ , v := range batch { if _ , exists := ICD9 [ v . FieldID ] ; exists { icd9 [ v . FieldID ] = struct { } { } } if _ , exists := ICD10 [ v . FieldID ] ; exists { icd10 [ v . FieldID ] = struct { } { } } if _ , exists := OPCS [ v . FieldID ] ; exists { opcs [ v . FieldID ] = struct { } { } } } if len ( icd9 ) > 0 && len ( icd9 ) < len ( ICD9 ) { for known := range ICD9 { if _ , exists := icd9 [ known ] ; ! exists { missingFields [ known ] = struct { } { } } } errs = append ( errs , fmt . Sprintf ( " " , batchnames [ batchID ] , icd9 , ICD9 ) ) } if len ( icd10 ) > 0 && len ( icd10 ) < len ( ICD10 ) { for known := range ICD10 { if _ , exists := icd10 [ known ] ; ! exists { missingFields [ known ] = struct { } { } } } errs = append ( errs , fmt . Sprintf ( " " , batchnames [ batchID ] , icd10 , ICD10 ) ) } if len ( opcs ) > 0 && len ( opcs ) < len ( OPCS ) { for known := range OPCS { if _ , exists := opcs [ known ] ; ! exists { missingFields [ known ] = struct { } { } } } errs = append ( errs , fmt . Sprintf ( " " , batchnames [ batchID ] , opcs , OPCS ) ) } } if len ( errs ) > 0 { missingSlice := make ( [ ] string , 0 , len ( missingFields ) ) for missing := range missingFields { missingSlice = append ( missingSlice , strconv . Itoa ( missing ) ) } return missingSlice , errors . New ( strings . Join ( errs , " " ) ) } return nil , nil }
ICD9, ICD10, and OPCS codes in the UK Biobank are distributed across many
FieldIDs.
ICD9 ICD10 and OPCS codes in the UK Biobank are distributed across many FieldIDs .
// Iterate over all the fields you're including and excluding separately. // Rationale: if you successfully listed all the primary and secondary ICD10 // fields for inclusion, but only listed one of them for exclusion and // forgot to list the other, that's probably unintentional and should be // flagged. // Capitalized ICD9 (etc) here refer to the manual global maps that // we create in special_fields.go which list all possible FieldIDs // for ICD9 codes. Lower case icd9 represents the local map that // will track which of those FieldIDs actually appeared in the // tabfile. Basically, this is a lookup to see whether the field we // are currently looking at is an ICD9 field, etc. // So, you included at least one ICD9 field, but you failed to include // all of them. Probably an error. // If we think you forgot one or more FieldIDs, we'll let you know about all // of them.