Skip to content

Commit

Permalink
Merge branch 'dev' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Jan 23, 2022
2 parents eb4979b + d32cb2d commit 72c6785
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions FHIR-mongoose-Models-Generator/resourceGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,24 @@ function cleanChildSchema (item) {
}
}

function isChoiceType (fieldName) {
function fixChoiceTypeOfDate (fieldName, type) {
if (fieldName == "modifierExtension") return {
yes: false,
type: ""
};
const allDataTypes = [...DataTypesSummary.PrimitiveTypes, ...DataTypesSummary.GeneralPurposeDataTypes, ...DataTypesSummary.MetadataTypes, ...DataTypesSummary.SpecialPurposeDataTypes];
for (let i = 0 ; i< allDataTypes.length ; i++) {
let dataType = allDataTypes[i];
dataType = dataType.charAt(0).toUpperCase() + dataType.slice(1);
let typeOfField = fieldName.match(/([A-Z])\w+/g);
if (typeOfField == dataType && fieldName.length > dataType.length) {
let lowerFirstDataType = dataType.charAt(0).toLowerCase() + dataType.slice(1);
if (isPrimitiveType(lowerFirstDataType)) return {
const dateTypes = ["Date", "DateTime", "Instant", "Time"];
let typeOfField = fieldName.match(/([A-Z])\w+/g);

for (let i = 0 ; i < dateTypes.length ; i++) {
let dateType = dateTypes[i];

if (typeOfField == dateType && type == "string") {
console.info(`fieldName ${fieldName} typeOfField ${typeOfField} , dateType ${dateType} , type ${type}`);
let lowerFirstDateTypes = dateType.charAt(0).toLowerCase() + dateType.slice(1);
return {
yes: true,
type: lowerFirstDataType
type: lowerFirstDateTypes
}
return {
yes : true,
type: dataType
};
}
}
return {
Expand All @@ -75,7 +73,7 @@ function getSchema (resource , name) {
if (skipCol.indexOf(i) >= 0 ) continue;
else if (i.indexOf("_") == 0 ) continue;
let type = _.get(resource.properties[i] , "type");
//let choiceType = isChoiceType(i);
let choiceTypeDate = fixChoiceTypeOfDate(i, type);
let refSchema = _.get(resource.properties[i] , "$ref");
let isCode = _.get(resource.properties[i] , "enum");
if (type == 'array') {
Expand All @@ -89,15 +87,15 @@ function getSchema (resource , name) {
let arrayRefClean = arrayRef.split('/');
let typeOfField = arrayRefClean[arrayRefClean.length-1];
if (typeOfField == name) typeOfField = "this"; //The type of field reference self
//if (choiceType.yes) typeOfField = choiceType.type;
if (choiceTypeDate.yes) typeOfField = choiceTypeDate.type;
result[i] = {
type : `[${typeOfField}]`
}
} else if (refSchema) {
if (/^#/.test(refSchema)) {
let refClean = refSchema.split('/');
let typeOfField = refClean[refClean.length-1];
//if (choiceType.yes) typeOfField = choiceType.type;
if (choiceTypeDate.yes) typeOfField = choiceTypeDate.type;
if (isPrimitiveType(typeOfField)) {
result[i] = typeOfField;
} else {
Expand All @@ -109,7 +107,7 @@ function getSchema (resource , name) {
} else if (!/^#/.test(refSchema)) {
let refClean = refSchema.split('/');
let typeOfField = refClean[refClean.length-1];
//if (choiceType.yes) typeOfField = choiceType.type;
if (choiceTypeDate.yes) typeOfField = choiceTypeDate.type;
if (isPrimitiveType(typeOfField)) {
result[i] = typeOfField;
} else {
Expand All @@ -126,8 +124,9 @@ function getSchema (resource , name) {
enum : JSON.stringify(isCode)
}
} else {
//if (choiceType.yes) type = choiceType.type;
if (choiceTypeDate.yes) type = choiceTypeDate.type;
if (isPrimitiveType(type)) {
console.log(i, type);
result[i] = type;
} else {
result[i] = {
Expand Down

0 comments on commit 72c6785

Please sign in to comment.