Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzalsif committed Jan 15, 2025
2 parents 8996246 + 1e9377a commit 854162d
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions scripts/create-queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ async function processMappings(datastoreKeyData) {
return mappingItem.code;
});
}

query += ` FROM encounter_flat en \n`;

// Be careful when choosing right vs left join
Expand Down Expand Up @@ -193,20 +192,26 @@ async function processMappings(datastoreKeyData) {
}
}
});
}

query += `LEFT JOIN patient_flat pt ON pt.id = en.patient_id \n `;
if (loincObsCodes.length > 0) {
query += ` RIGHT JOIN observation_flat obs ON obs.encounter_id = en.encounter_id \n`;
query += `AND obs.val_concept_code IN ('${loincObsCodes.join(
"','"
)}') \n`;
}

query +=
loincOrderCodes.length > 0
? `AND drep.effective_datetime >='${startDate}' AND drep.effective_datetime <='${endDate}' \n`
: `AND en.period_start >= '${startDate}' AND en.period_start <= '${endDate}' \n`;
query += `LEFT JOIN patient_flat pt ON pt.id = en.patient_id \n `;

query += ` GROUP BY `;
query += icdCodes && icdCodes.length > 0 ? `cond.code,` : "";
query += hasGender ? `pt.gender,` : "";
query += ` en.organization_id;`;
console.log(query);
query +=
loincOrderCodes.length > 0
? `AND drep.effective_datetime >='${startDate}' AND drep.effective_datetime <='${endDate}' \n`
: `AND en.period_start >= '${startDate}' AND en.period_start <= '${endDate}' \n`;

query += ` GROUP BY `;
query += icdCodes && icdCodes.length > 0 ? `cond.code,` : "";
query += hasGender ? `pt.gender,` : "";
query += ` en.organization_id;`;
console.log(query);
}
}
});
}

0 comments on commit 854162d

Please sign in to comment.