Skip to content

Commit

Permalink
Add JSON replace and write
Browse files Browse the repository at this point in the history
  • Loading branch information
florianschoffke committed Jul 26, 2024
1 parent 1f697db commit e332b4b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/utils/Processing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,21 @@ export function writeFHIRResources(
)
) {
checkNullValuesOnArray(resource);
fs.outputJSONSync(path.join(exportDir, resource.getFileName()), resource.toJSON(snapshot), {
spaces: 2
});
const replacer = (key: any, value: string) => {
if (typeof value === "string" && !isNaN(Number(value))) {

Check failure on line 568 in src/utils/Processing.ts

View workflow job for this annotation

GitHub Actions / Check tsc, lint, and prettier

Strings must use singlequote
// Format the number while keeping the exact number of zeros after the decimal point
const numValue = Number(value);
return value.includes('.') ? numValue.toFixed(value.split('.')[1].length) : numValue;
}
return value;
};
const jsonString = JSON.stringify(resource.toJSON(snapshot), replacer, 2);

// Manually format the JSON string to maintain number type with precision
const formattedJsonString = jsonString.replace(/"(\d+\.\d+)"|"\d+"/g, (match) => match.replace(/"/g, ''));

// Write the modified JSON string directly to a file
fs.outputFileSync(path.join(exportDir, resource.getFileName()), formattedJsonString);
count++;
} else {
logger.error(
Expand Down

0 comments on commit e332b4b

Please sign in to comment.