Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Oct 10, 2023
2 parents 3fa702a + 49855f8 commit 0f1e8ad
Show file tree
Hide file tree
Showing 623 changed files with 19,907 additions and 21,476 deletions.
6 changes: 2 additions & 4 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ FHIRSERVER_PORT=8080
FHIRSERVER_APIPATH="fhir"

ENABLE_CHECK_ALL_RESOURCE_ID=false
ENABLE_CHECK_REFERENCE=false
ENABLE_CHECK_REF_DELETION=false

ENABLE_CSHARP_VALIDATOR=false
VALIDATION_FILES_ROOT_PATH="/validationResources"
VALIDATION_API_URL="http://burni-fhir-validator-api:7414"
ENABLE_VALIDATOR=false
10 changes: 5 additions & 5 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"parserOptions": {
"ecmaVersion": 2018
"ecmaVersion": 2022
},
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": ["eslint:recommended"],
"extends": ["eslint:recommended", "prettier"],
"rules": {
"semi": ["error", "always"],
"comma-dangle": ["error", "never"],
"comma-dangle": ["error", "never"],
"no-unused-vars": "off",
"no-console": 0 ,
"no-console": 0,
"no-useless-escape": "off",
"no-useless-catch": "off"
},
"ignorePatterns": ["public/**", "temp/**", "models/FHIR/fhir/**", "docs/**"]
}
}
11 changes: 11 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ignore everything recursively
*

# But not the .ts files
!*.js

# Check subdirectories too
!*/

docs/**
public/**
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"trailingComma": "none",
"tabWidth": 4,
"semi": true,
"singleQuote": false,
"quoteProps": "consistent"
}
131 changes: 67 additions & 64 deletions FHIR-mongoose-Models-Generator/ComplexGenerator.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,41 @@
const fs =require('fs');
const _ = require('lodash');
const beautify = require('js-beautify').js;
const primitiveType = ["Boolean" , "String" , "Date" , "Number" , "Buffer"];
let skipFieldTypes = ["Number" , "String" , "Date" , "this", "Object"];
const path = require('path');
const mkdirp = require('mkdirp');
let schemaJson = JSON.parse(fs.readFileSync(path.join(__dirname ,'./fhir.schema.json') , {encoding: 'utf-8'}));
const fs = require("fs");
const _ = require("lodash");
const beautify = require("js-beautify").js;
const primitiveType = ["Boolean", "String", "Date", "Number", "Buffer"];
let skipFieldTypes = ["Number", "String", "Date", "this", "Object"];
const path = require("path");
const mkdirp = require("mkdirp");
let schemaJson = JSON.parse(
fs.readFileSync(path.join(__dirname, "./fhir.schema.json"), {
encoding: "utf-8"
})
);

let resourceList = schemaJson.definitions.ResourceList.oneOf.map(v=> {
let resourceList = schemaJson.definitions.ResourceList.oneOf.map((v) => {
let itemSplit = v["$ref"].split("/");
return itemSplit[itemSplit.length - 1];
});

let FHIRJson = schemaJson.definitions;
let genedType = [];

const DataTypesSummary = require("./DataTypesSummary");

const DataTypesSummary = require('./DataTypesSummary');


function checkIsFHIRResource (resourceName) {
return resourceList.find(v=> {
return v.includes(resourceName) &&
v.length === resourceName.length;
function checkIsFHIRResource(resourceName) {
return resourceList.find((v) => {
return v.includes(resourceName) && v.length === resourceName.length;
});
}

function cleanChildSchema (item) {
function cleanChildSchema(item) {
for (let i in item) {
if (_.get(item[i] , "type")){
if (_.get(item[i], "type")) {
let isArray = /[\[\]]/gm.test(item[i].type);
let type = item[i].type.replace(/[\[\]]/gm,'');
let type = item[i].type.replace(/[\[\]]/gm, "");
if (type == "number") {
item[i].type = isArray ? "[Number]" : "Number";
} else if (type == "ResourceList") { //todo, the resourceList need all resource, maybe just generate minium resourceList dynamic?
} else if (type == "ResourceList") {
//todo, the resourceList need all resource, maybe just generate minium resourceList dynamic?
item[i].type = "Object";
}
}
Expand All @@ -43,83 +45,81 @@ function cleanChildSchema (item) {
function isPrimitiveType(typeName) {
return /^[a-z]/.test(typeName) && typeName != "number";
}
function getSchema (resource , name) {
function getSchema(resource, name) {
//let skipCol = ["resourceType" , "id" , "meta" ,"implicitRules" ,"language" , "text" ,"contained" , "extension" , "modifierExtension"];
let skipCol = ["id"];
let result = {};

for (let i in resource.properties) {
//skip the unusual type
if (skipCol.indexOf(i) >= 0 ) continue;
else if (i.indexOf("_") == 0 ) continue;
let type = _.get(resource.properties[i] , "type");
let refSchema = _.get(resource.properties[i] , "$ref");
let isCode = _.get(resource.properties[i] , "enum");
if (type == 'array') {
if (skipCol.indexOf(i) >= 0) continue;
else if (i.indexOf("_") == 0) continue;
let type = _.get(resource.properties[i], "type");
let refSchema = _.get(resource.properties[i], "$ref");
let isCode = _.get(resource.properties[i], "enum");
if (type == "array") {
let arrayRef = resource.properties[i].items.$ref;
if (resource.properties[i].items.enum) {
result[i] = {
type : `[String]`
type: `[String]`
};
continue;
}
let arrayRefClean = arrayRef.split('/');
let typeOfField = arrayRefClean[arrayRefClean.length-1];
let arrayRefClean = arrayRef.split("/");
let typeOfField = arrayRefClean[arrayRefClean.length - 1];
if (typeOfField == name) typeOfField = "this";
if (/^#/.test(arrayRef)) {
result[i] = {
type : `[${typeOfField}]`
type: `[${typeOfField}]`
};
} else {
result[i] = {
type : `[${typeOfField}]`
type: `[${typeOfField}]`
};
}
}
else if (refSchema) {
} else if (refSchema) {
if (/^#/.test(refSchema)) {
let refClean = refSchema.split('/');
let typeOfField = refClean[refClean.length-1];
let refClean = refSchema.split("/");
let typeOfField = refClean[refClean.length - 1];
if (isPrimitiveType(typeOfField)) {
result[i] = typeOfField;
} else {
result[i] = {
type : typeOfField
type: typeOfField
};
}

} else if (!/^#/.test(refSchema)) {
let refClean = refSchema.split('/');
let typeOfField = refClean[refClean.length-1];
let refClean = refSchema.split("/");
let typeOfField = refClean[refClean.length - 1];
if (isPrimitiveType(typeOfField)) {
result[i] = typeOfField;
} else {
result[i] = {
type : typeOfField
type: typeOfField
};
}
}
} else if (isCode) {
let typeOfField = "String";
//console.log(type);
result[i] = {
type : typeOfField ,
enum : JSON.stringify(isCode)
type: typeOfField,
enum: JSON.stringify(isCode)
};
} else {
if (isPrimitiveType(type)) {
result[i] = type;
} else {
result[i] = {
type : type
type: type
};
}
}
let isRequired = _.get(resource , "required");
let isRequired = _.get(resource, "required");
if (isRequired) {
for (let item of isRequired) {
if (item == i) {
Object.assign(result[i] , {required : true});
Object.assign(result[i], { required: true });
}
}
}
Expand All @@ -133,50 +133,53 @@ function getImportLibs(schema) {
let cleanType = "";
for (let i in schema) {
let item = schema[i];
if (_.get(item , "type")) {
if (_.get(item, "type")) {
item.default = "void 0";
cleanType = item.type.replace(/[\[\]]/gm , '');
cleanType = item.type.replace(/[\[\]]/gm, "");
} else {
cleanType = item.replace(/[\[\]]/gm , '');
cleanType = item.replace(/[\[\]]/gm, "");
}
if (skipFieldTypes.indexOf(cleanType) < 0 && !importedTypeLib.includes(cleanType)) {
if (
skipFieldTypes.indexOf(cleanType) < 0 &&
!importedTypeLib.includes(cleanType)
) {
if (isPrimitiveType(cleanType)) {
importLib =`${importLib}const ${cleanType} = require('../FHIRDataTypesSchema/${cleanType}');\r\n`;
importLib = `${importLib}const ${cleanType} = require('../FHIRDataTypesSchema/${cleanType}');\r\n`;
} else {
importLib =`${importLib}const {${cleanType}} = require('../FHIRDataTypesSchemaExport/allTypeSchemaTopDef');\r\n`;
importLib = `${importLib}const {${cleanType}} = require('../FHIRDataTypesSchemaExport/allTypeSchemaTopDef');\r\n`;
}
importedTypeLib.push(cleanType);
}
}
return importLib;
}
async function generateSchema (type) {
let schema = getSchema(FHIRJson[type] , type);
async function generateSchema(type) {
let schema = getSchema(FHIRJson[type], type);
cleanChildSchema(schema);
let importLibs = getImportLibs(schema);
let schemaStr = JSON.stringify(schema , null , 4).replace(/\"/gm , '');
let schemaStr = JSON.stringify(schema, null, 4).replace(/\"/gm, "");
let code = `
const { ${type} } = require("../FHIRDataTypesSchemaExport/allTypeSchemaTopDef");
${type}.add(${schemaStr.replace(/\\/gm, '"')});
module.exports.${type} = ${ type };`;
module.exports.${type} = ${type};`;
code = `${importLibs}${code}`;

await mkdirp(`./models/mongodb/FHIRDataTypesSchema-New`);
fs.writeFileSync(`./models/mongodb/FHIRDataTypesSchema-New/${type}.js` , beautify(code , {indent_size : 4 ,pace_in_empty_paren: true }));
fs.writeFileSync(
`./models/mongodb/FHIRDataTypesSchema-New/${type}.js`,
beautify(code, { indent_size: 4, pace_in_empty_paren: true })
);
}


function main() {

for (let FHIRType in FHIRJson) {
for (let FHIRType in FHIRJson) {
let [maybeResourceName] = FHIRType.split("_");
if (!checkIsFHIRResource(FHIRType) && FHIRType != "ResourceList") {
if (/^[A-Z]/.test(FHIRType)) {
generateSchema(FHIRType);
}
}
}

}

main();
main();
62 changes: 31 additions & 31 deletions FHIR-mongoose-Models-Generator/DataTypesSummary.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
module.exports = {
PrimitiveTypes : [
"instant" ,
"time" ,
"date" ,
"dateTime" ,
"base64Binary" ,
"decimal" ,
"boolean" ,
"url" ,
"code" ,
"string" ,
"integer" ,
"uri" ,
"canonical" ,
"markdown" ,
"id" ,
"oid" ,
"uuid" ,
"unsignedInt" ,
PrimitiveTypes: [
"instant",
"time",
"date",
"dateTime",
"base64Binary",
"decimal",
"boolean",
"url",
"code",
"string",
"integer",
"uri",
"canonical",
"markdown",
"id",
"oid",
"uuid",
"unsignedInt",
"positiveInt"
] ,
GeneralPurposeDataTypes : [
],
GeneralPurposeDataTypes: [
"Ratio",
"Period",
"Range",
Expand All @@ -44,7 +44,7 @@ module.exports = {
"Count",
"MoneyQuantity",
"SimpleQuantity"
] ,
],
MetadataTypes: [
"ContactDetail",
"Contributor",
Expand All @@ -54,15 +54,15 @@ module.exports = {
"ParameterDefinition",
"Expression",
"TriggerDefinition"
] ,
],
SpecialPurposeDataTypes: [
"Reference" ,
"Meta" ,
"Dosage" ,
"xhtml" ,
"BackboneElement" ,
"Narrative" ,
"Extension" ,
"Reference",
"Meta",
"Dosage",
"xhtml",
"BackboneElement",
"Narrative",
"Extension",
"ElementDefinition"
]
};
};
Loading

0 comments on commit 0f1e8ad

Please sign in to comment.