Skip to content

Commit

Permalink
phac_dexa export issue WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
ddooley committed Oct 24, 2024
1 parent e9e46f7 commit 4f0b5cf
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 6 deletions.
9 changes: 9 additions & 0 deletions web/templates/phac_dexa/exampleInput/small_samples_valid.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
SPECIMEN_ID ISOLATE_ID SAMPLE_ID SENTINEL_SITE LFZ_ADDITIONAL_SAMPLE_ID LFZ_ORIGIN_COUNTRY SUBJECT_CODE SUBJECT_DESCRIPTIONS SUBMITTINGORG_1 SUBMITTINGLAB_1 PROJECT_1 COUNTRY_1 PROVINCE_1 CENSUSDIVISION_1 REGION YEAR MONTH QTR DATECOLLECTED_1 DATERECEIVED_1 DATESHIPPED_1 ESTABLISHMENT_1 SPECIES STTYPE STYPE COMMODITY SPECIMENSOURCE_1 SPECIMENSUBSOURCE_1 SUBJECT_SUBTYPE FIELDSTAFF_1 IN_STORE_PROCESSING MAYCONTAINFROZENMEAT_1 NOOFCASHREGISTERS_1 PRICEPERKG_1 STORETYPE_SAMPLINGSITE_1 TEMPERATUREMAX_1 TEMPERATUREMIN_1 TEMPERATUREARRIVAL_1 VETID ROOMID PENID SAMPLING_TYPE BARN_ID DATE_PACKED FINAL_ID_GENUS FINAL_ID_SPECIES FINAL_ID_SUBSPECIES FINAL_ID_SEROTYPE FINAL_ID_ANTIGEN FINAL_ID_PHAGETYPE SA_Serotype_Method SEROTYPE_GR MIC_AMC MIC_AMK MIC_AMP MIC_AZM MIC_CEP MIC_CHL MIC_CIP MIC_CRO MIC_FOX MIC_GEN MIC_KAN MIC_MEM MIC_NAL MIC_SSS MIC_STR MIC_SXT MIC_TET MIC_TIO N_OF_RESISTANCE NBTESTED R_PATTERN AMR_PA2C RLEAST1 RLEAST2 RLEAST3 RLEAST4 RLEAST5 SIR_AMC SIR_AMK SIR_AMP SIR_AZM SIR_CEP SIR_CHL SIR_CIP SIR_CRO SIR_FOX SIR_GEN SIR_KAN SIR_MEM SIR_NAL SIR_SSS SIR_STR SIR_SXT SIR_TET SIR_TIO RAMC RAMK RAMP RAZM RCEP RCHL RCIP RCRO RFOX RGEN RKAN RMEM RNAL RSSS RSTR RSXT RTET RTIO A2C CAMC CAMK CAMP CAZM CCEP CCHL CCIP CCRO CFOX CGEN CKAN CMEM CNAL CSSS CSTR CSXT CTET CTIO STHY_TESTSRC_ID WINN_TESTSRC_ID GUEL_TESTSRC_ID RCIP_DANMAP EPIDATESTAMP_1 ACSSUT AKSSUT ACKSSUT MDR_A_SSUT EXCLUSION RAMINOGLY RBETALACTAM RQUINOLONES RFOLINHIBITOR MDR specimen_number EXTERNAL_AGENT FARM_FLAG AMIKACINGELET
29992 SA20132545 SA20132545 SA20132545 UofG - Food Microbiology 13-024322-1 Industrial Monitoring Canada ONTARIO ONTARIO 2013 5 2 09-May-13 09-May-13 Chicken ANIMAL Avian Domestic/Farmed Carcass Swab <n/a> 0 0 Salmonella enterica enterica (I) Schwarzengrund 4:d:1,7 PT Other serovars 0 SA20132545 23-May-13 Salmonella |
29993 SA20132546 SA20132546 SA20132546 UofG - Food Microbiology 13-025636-1 Industrial Monitoring Canada ONTARIO ONTARIO 2013 5 2 09-May-13 09-May-13 Chicken ANIMAL Avian Domestic/Farmed Carcass Swab <n/a> 0 0 Salmonella enterica enterica (I) Bredeney 4:l,v:1,7 PT Other serovars 0 SA20132546 23-May-13 Salmonella |
29994 SA20132547 SA20132547 SA20132547 UofG - Food Microbiology 13-027114-1 Industrial Monitoring Canada ONTARIO ONTARIO 2013 5 2 09-May-13 09-May-13 Chicken ANIMAL Avian Domestic/Farmed Carcass Swab <n/a> 0 0 Salmonella enterica enterica (I) Rubislaw 11:r:e,n,x PT Other serovars 0 SA20132547 23-May-13 Salmonella |
36372 SA20133878 SA20133878 SA20133878 UofG - Food Microbiology 13-045380-1 Industrial Monitoring Canada ONTARIO ONTARIO 2013 6 2 04-Jun-13 11-Jul-13 Chicken ANIMAL Avian Domestic/Farmed Carcass Swab <n/a> 0 0 Salmonella enterica enterica (I) Schwarzengrund 4:d:1,7 PT Other serovars 0 SA20133878 06-Aug-13 Salmonella |
36373 SA20133879 SA20133879 SA20133879 UofG - Food Microbiology 13-045380-3 Industrial Monitoring Canada ONTARIO ONTARIO 2013 6 2 06-Jun-13 11-Jul-13 Chicken ANIMAL Avian Domestic/Farmed Carcass Swab <n/a> 0 0 Salmonella enterica enterica (I) Schwarzengrund 4:d:1,7 PT Other serovars 0 SA20133879 06-Aug-13 Salmonella |
36374 SA20133880 SA20133880 SA20133880 UofG - Food Microbiology 13-048524-1 Industrial Monitoring Canada ONTARIO ONTARIO 2013 6 2 10-Jun-13 11-Jul-13 Chicken ANIMAL Avian Domestic/Farmed Carcass Swab <n/a> 0 0 Salmonella enterica enterica (I) Muenchen 6,8:d:1,2 PT Other serovars 0 SA20133880 06-Aug-13 Salmonella |
36375 SA20133881 SA20133881 SA20133881 UofG - Food Microbiology 13-048524-3 Industrial Monitoring Canada ONTARIO ONTARIO 2013 6 2 12-Jun-13 11-Jul-13 Chicken ANIMAL Avian Domestic/Farmed Carcass Swab <n/a> 0 0 Salmonella enterica enterica (I) Muenchen 6,8:d:1,2 PT Other serovars 0 SA20133881 06-Aug-13 Salmonella |
36376 SA20133882 SA20133882 SA20133882 UofG - Food Microbiology 13-048520-1 Industrial Monitoring Canada ONTARIO ONTARIO 2013 7 3 11-Jul-13 11-Jul-13 Chicken ANIMAL Avian Domestic/Farmed Carcass Swab <n/a> 0 0 Salmonella enterica enterica (I) Muenchen 6,8:d:1,2 PT Other serovars 0 SA20133882 06-Aug-13 Salmonella |
68 changes: 62 additions & 6 deletions web/templates/phac_dexa/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default {
];

const sourceFields = dh.getFields(dh.table);
const sourceFieldNameMap = dh.getFieldNameMap(sourceFields);
const sourceFieldNameMap = dh.getFieldTitleMap(sourceFields);

// Fills in the above mapping of export field to source fields (or just set
// source fields manually above)
Expand All @@ -117,7 +117,7 @@ export default {
// Copy headers to 1st row of new export table
const outputMatrix = [[...ExportHeaders.keys()]];

let normalize = self.initLookup(self);
let normalize = self.initLookup();

const inputMatrix = dh.getTrimmedData(dh.hot);
for (const inputRow of inputMatrix) {
Expand Down Expand Up @@ -192,6 +192,55 @@ export default {
return value.join(';');
},


/**
* Get a dictionary of empty arrays for each ExportHeader field
* FUTURE: enable it to work with hierarchic vocabulary lists
*
* @param {Array<String>} sourceRow array of values to be exported.
* @param {Array<String>} sourceFields list of source fields to examine for mappings.
* @param {Array<Array>} RuleDB list of export fields modified by rules.
* @param {Array<Array>} fields list of export fields modified by rules.
* @param {Array<Integer>} titleMap map of field names to column index.
* @param {String} prefix of export format to examine.
* @return {Array<Object>} fields Dictionary of all fields.
*/

getRowMap: function (sourceRow, ruleSourceFieldNames, RuleDB, fields, titleMap, prefix) {
for (const title of ruleSourceFieldNames) {
const sourceIndex = titleMap[title];
let value = sourceRow[sourceIndex]; // All text values.
// Sets source field to data value so that rules can reference it easily.
RuleDB[title] = value;
// Check to see if value is in vocabulary of given select field, and if it
// has a mapping for export to a GRDI target field above, then set target
// to value.
if (value && value.length > 0) {
console.log("FIELDS", fields[sourceIndex], value);
const vocab_list = fields[sourceIndex]['flatVocabulary'];
if (vocab_list && vocab_list.includes(value)) {
const term = vocab_list[value];
console.log("TERM", term);
// Looking for term.exportField['GRDI'] for example:
if ('exportField' in term && prefix in term.exportField) {
for (let mapping of term.exportField[prefix]) {
// Here mapping involves a value substitution
if ('value' in mapping) {
value = mapping.value;
// Changed on a copy of data, not handsongrid table
sourceRow[sourceIndex] = value;
}
if ('field' in mapping && mapping['field'] in RuleDB) {
RuleDB[mapping['field']] = value;
}
}
}
}
}
}
},


/** Rule-based target field value calculation based on given data row
* @param {Object} dataRow.
* @param {Object} sourceFields.
Expand Down Expand Up @@ -238,7 +287,7 @@ export default {
// This will set content of a target field based on data.js vocabulary
// exportField {'field':[target column],'value':[replacement value]]}
// mapping if any.
dh.getRowMap(
this.getRowMap(
dataRow,
ruleSourceFieldNames,
RuleDB,
Expand All @@ -247,13 +296,18 @@ export default {
'GRDI'
);

console.log("getRowMap");
console.log(dataRow, ruleSourceFieldNames, RuleDB, sourceFields,sourceFieldNameMap);

// So all rule field values can be referenced in lower case.
for (let sourceField of Object.keys(RuleDB)) {
if (RuleDB[sourceField])
RuleDB[sourceField] = RuleDB[sourceField].toLowerCase();
}

// STTYPE: ANIMAL ENVIRONMENT FOOD HUMAN PRODUCT QA UNKNOWN
switch (RuleDB.STTYPE) {

case 'animal': {
// species-> host (common name);
RuleDB['host (common name)'] = RuleDB.SPECIES;
Expand All @@ -265,6 +319,7 @@ export default {
) {
RuleDB.animal_or_plant_population = RuleDB.SPECIES;
}
console.log("TESTING:RuleDB.STTYPE", RuleDB.STTYPE, RuleDB.SPECIES,RuleDB.collection_device,RuleDB.environmental_site, RuleDB.animal_or_plant_population);
break; // prevents advancing to FOOD
}

Expand Down Expand Up @@ -345,9 +400,10 @@ export default {
*
* @return {Object} term normalize lookup table.
*/
initLookup: function (self) {
initLookup: function () {
let normalize = {};
for (const line of self.LOOKUP.split('\n')) {
for (const line of this.LOOKUP.split('\n')) {

let [ontology_id, parent, label, normalization] = line
.split('\t')
.map(function (e) {
Expand Down Expand Up @@ -810,5 +866,5 @@ FOODON_00002361 food_product white pepper
FOODON_03411345 food_product yeast
UBERON_0001040 anatomical_part yolk sac
ENVO_00010625 environmental_site zoo pet/zoo; calgary zoo`,
},
}
};

0 comments on commit 4f0b5cf

Please sign in to comment.