Skip to content

Commit

Permalink
Updated helper scripts to read from excel and to create examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeaduncan committed Feb 5, 2024
1 parent 2999bbd commit fb6a862
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
31 changes: 15 additions & 16 deletions tools/node/makeExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@ for(let doc of docs) {

options.birth = shiftDate(options.birth)
const topDir = directory + "/" + options.id
fs.mkdirSync(topDir)
//fs.mkdirSync(topDir, true)

fs.mkdirSync(topDir+"/Patient")
fs.mkdirSync(topDir+"/Patient", {recursive: true})
let patient = makePatient( options.id, options.patient, options.birth )
fs.writeFileSync( topDir + "/Patient/" + options.id +".json", Buffer.from( JSON.stringify(patient,null,2) ))
if ( options.immunization ) {
fs.mkdirSync(topDir+"/Immunization")
fs.mkdirSync(topDir+"/Immunization", {recursive: true})
for( let immz in options.immunization ) {
let immzr = makeImmunization( immz, options.id, options.immunization[immz] )
let immzr = makeImmunization( immz, options.id, options.immunization[immz], options.birth )
fs.writeFileSync( topDir+"/Immunization/"+immzr.id+".json", Buffer.from( JSON.stringify(immzr,null,2)))
}
}
if ( options.condition ) {
fs.mkdirSync(topDir+"/Condition")
fs.mkdirSync(topDir+"/Condition", {recursive: true})
for( let cond in options.condition ) {
let condr = makeCondition( cond, options.id, options.condition[cond] )
let condr = makeCondition( cond, options.id, options.condition[cond], options.birth )
fs.writeFileSync( topDir+"/Condition/"+condr.id+".json", Buffer.from( JSON.stringify(condr,null,2)))
}
}
Expand All @@ -41,8 +41,7 @@ function shiftDate( shift, birth ) {

let shifted
let start = new Date()
let match = shift.match( /([bn]?)+?(-?\d+)([wdmy])/)
//console.log(match)
let match = shift.match( /([bn]?)\+?(-?\d+)([wdmy])/)
if ( match[1] == 'b' ) start = new Date(birth)
switch( match[3] ) {
case 'd':
Expand All @@ -57,16 +56,16 @@ function shiftDate( shift, birth ) {
case 'y':
shifted = Dates.year.shift(start, parseInt(match[2]))
break
}
}
return shifted.toISOString().replace(/T.+/, '')
}

function copyFHIR( resource, options ) {
function copyFHIR( resource, options, birth ) {
if ( options.fhir ) {
let elements = options.fhir
for( let element in elements ) {
if ( element.endsWith('Date') || element.endsWith('DateTime') ) {
elements[element] = shiftDate( elements[element], options.birth )
elements[element] = shiftDate( elements[element], birth )
}
resource[element] = elements[element]
}
Expand Down Expand Up @@ -94,12 +93,12 @@ function makePatient ( id, options, birth ) {
if ( birth ) {
patient.birthDate = birth
}
copyFHIR( patient, options )
copyFHIR( patient, options, birth )

return patient
}

function makeImmunization( immz, patient, options ) {
function makeImmunization( immz, patient, options, birth ) {
let immunization = {
"resourceType": "Immunization",
"id": "",
Expand All @@ -121,12 +120,12 @@ function makeImmunization( immz, patient, options ) {
immunization.id = immz+"-"+patient
immunization.patient.reference = "Patient/"+patient
immunization.vaccineCode.coding[0] = options.vaccine
copyFHIR( immunization, options )
copyFHIR( immunization, options, birth )

return immunization
}

function makeCondition( cond, patient, options ) {
function makeCondition( cond, patient, options, birth ) {
let condition = {
"resourceType": "Condition",
"id": "",
Expand All @@ -149,7 +148,7 @@ function makeCondition( cond, patient, options ) {
condition.id = cond+"-"+patient
condition.subject.reference = "Patient/"+patient
condition.code.coding[0] = options.code
copyFHIR( condition, options )
copyFHIR( condition, options, birth )

return condition
}
2 changes: 2 additions & 0 deletions tools/node/processDTInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ for( let c = cs; c <= ce; c++ ) {
for ( let r = rs; r <= re; r++ ) {
if ( sheet[0].data[r] && sheet[0].data[r][c] && sheet[0].data[r][c] != '-' ) {
[ title, pseudo ] = sheet[0].data[r][c].split( "\n", 2 )
title = trim(title)
pseudo = trim(pseudo)
console.log( "/*\n@input: " + title + "\n@pseudocode: " + pseudo + "\n*/\ndefine \""+title+"\":\n\n")
}
}
Expand Down
6 changes: 4 additions & 2 deletions tools/node/processDTOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ for ( let r = rs[0]; r <= rs[1]; r++ ) {
let content = []
if ( sheet[r] && sheet[r][c] && sheet[r][c] != '-' ) {
content = sheet[r][c].split( "\n", 2 )
prevtitles[c] = content[0]
prevtitles[c] = trim(content[0])
}
if ( !content[0] && sheet[r][c] != '-' ) content[0] = prevtitles[c]
if ( content[0] ) {
expression.push( 'input."' + content[0] + '"' )
expression.push( 'input."' + trim(content[0]) + '"' )
}
}

let content = sheet[r][1+parseInt(cs[1])].split( "\n", 2 );
content[0] = trim(content[0])
content[1] = trim(content[1])
if ( !outputs[ content[0] ] ) outputs[ content[0] ] = []
outputs[ content[0] ].push( { content, expression: expression.join("\n and "), guidance: sheet[r][parseInt(cs[1])+2] } )

Expand Down

0 comments on commit fb6a862

Please sign in to comment.