Skip to content

Commit

Permalink
feat: generate search parameter of date choiceType
Browse files Browse the repository at this point in the history
- If field is not in StructureDefinition,
that might is choice type,
1. map every name of date type
2. check if field is in StructureDefinition
3. If true, refresh the search fields
  • Loading branch information
Chinlinlee committed Nov 11, 2022
1 parent 2029166 commit abdfb53
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
1 change: 0 additions & 1 deletion FHIR-mongoose-Models-Generator/resourceGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ function generateResourceSchema (type) {
process.exit(1);
}
let result = getSchema(FHIRJson[type]);
console.log("The resource schema" , type , result);
for (let i in result) {
if (_.get(result[i] , "type")) {
// let cleanType = result[i].type.replace(/[\[\]]/gm , '');
Expand Down
5 changes: 3 additions & 2 deletions api_generator/API_Generator_V2.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ function generateAPI(option) {
resourceParameterHandler += (searchFuncTxt);
} catch (e) {
if (e.message.includes("not a function")) {
console.log(type);
console.error(`The parameter type "${type}" is not support`);
} else {
console.error(e);
}
}
Expand Down Expand Up @@ -317,7 +318,7 @@ function generateMetaData() {
}
]
};
console.log(dirInFHIRAPI);

for (let resource of dirInFHIRAPI) {
metaData.rest[0].resource.push({
"type": resource,
Expand Down
40 changes: 39 additions & 1 deletion api_generator/parameterHandler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const _ = require('lodash');
const { capitalizeFirstLetter } = require('normalize-text');
const jp = require("jsonpath");

/**
* get clean fields of search parameter
Expand Down Expand Up @@ -407,21 +408,58 @@ class DateParameter {
`;
}

refreshChoiceTypeSearchFields(searchFields) {
let choiceFields = [];
const dateTypeList = [
"Date",
"DateTime",
"Instant",
"Period",
"Timing"
];

for(let field of searchFields) {
let count = jp.query(this.ResourceDef, `$..${field}`).length;
if (count === 0 ) {
for (let dateType of dateTypeList) {
let choiceField = `${field}${dateType}`;
let choiceCount = jp.query(this.ResourceDef, `$..${choiceField}`);
if (choiceCount.length > 0) {
choiceFields.push(choiceField);
}
}
}
}

if (choiceFields.length > 0) {
return choiceFields;
}

return searchFields;
}

/**
* TODO: handle the choice type
*/
getCodeString() {
let searchFields = getSearchFields(this.Field);
searchFields = this.refreshChoiceTypeSearchFields(searchFields);

let paramsSearchFieldTxt = `//#region ${this.Param}\r\nparamsSearchFields["${this.Param}"]= ${JSON.stringify(searchFields)};\r\n`;
let codeStr = paramsSearchFieldTxt;
codeStr += `const ${this.NormalizeParamName}SearchFunc = {};`;
for (let i = 0 ; i < searchFields.length; i++) {
let field = searchFields[i];
let typeOfField = _.get(this.ResourceDef, `${field}.type`);

if (!typeOfField && field.includes("timing")) {
typeOfField = "timing";
}

try {
codeStr += this[`handle${capitalizeFirstLetter(typeOfField)}`](field);
} catch(e) {
console.error(`field: ${this.Field}, type of field: ${typeOfField}, search fields ${searchFields}`, e , this.ResourceDef);
console.error(`field: ${this.Field}, clean field: ${field}, type of field: ${typeOfField}, search fields ${searchFields}`, e , this.ResourceDef);
}
}
codeStr += `
Expand Down

0 comments on commit abdfb53

Please sign in to comment.