Skip to content

Commit

Permalink
chore: update generated Patient models, API files
Browse files Browse the repository at this point in the history
  • Loading branch information
Chinlinlee committed Jan 21, 2022
1 parent c58c8a4 commit 33cd4bf
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 25 deletions.
10 changes: 5 additions & 5 deletions api/FHIR/Patient/controller/getPatient.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const mongodb = require('models/mongodb');
const {
createBundle
} = require('models/FHIR/func');
const queryBuild = require('../../../../models/FHIR/queryBuild.js');
const queryBuild = require('models/FHIR/queryBuild.js');
const {
handleError
} = require('models/FHIR/httpMessage');
Expand All @@ -22,6 +22,7 @@ const paramsSearch = {
delete query["_id"];
}
}

paramsSearch["_lastUpdated"] = (query) => {
if (!_.isArray(query["_lastUpdated"])) {
query["_lastUpdated"] = [query["_lastUpdated"]]
Expand All @@ -35,7 +36,6 @@ paramsSearch["_lastUpdated"] = (query) => {
}
delete query["_lastUpdated"];
}

paramsSearchFields["address"] = ["address"];
paramsSearch["address"] = (query) => {
if (!_.isArray(query["address"])) {
Expand Down Expand Up @@ -164,7 +164,7 @@ paramsSearch["birthdate"] = (query) => {
}
delete query["birthdate"];
}
paramsSearchFields["email"] = ["telecom.where(system='email')"];
paramsSearchFields["email"] = ["telecom"];
paramsSearch["email"] = (query) => {
if (!_.isArray(query["email"])) {
query["email"] = [query["email"]]
Expand Down Expand Up @@ -240,7 +240,7 @@ paramsSearch["given"] = (query) => {
}
delete query['given'];
}
paramsSearchFields["phone"] = ["telecom.where(system='phone')"];
paramsSearchFields["phone"] = ["telecom"];
paramsSearch["phone"] = (query) => {
if (!_.isArray(query["phone"])) {
query["phone"] = [query["phone"]]
Expand Down Expand Up @@ -314,7 +314,7 @@ paramsSearch["active"] = (query) => {
}
delete query['active'];
}
paramsSearchFields["deceased"] = ["deceased.exists() and Patient.deceased != false"];
paramsSearchFields["deceased"] = "deceased";
paramsSearch["deceased"] = (query) => {
if (!_.isArray(query["deceased"])) {
query["deceased"] = [query["deceased"]]
Expand Down
6 changes: 4 additions & 2 deletions api/FHIR/Patient/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ router.use((req, res, next) => {
if (req.headers["content-type"]) {
if (req.headers["content-type"].includes("xml")) {
res.set('Content-Type', 'application/fhir+xml');
if (req.method == "POST") {
if (req.method == "POST" || req.method == "PUT") {
let Fhir = new FHIR();
req.body = Fhir.xmlToObj(req.body);
}
Expand All @@ -50,7 +50,9 @@ router.use((req, res, next) => {
}
});

router.use(user.tokenAuthentication);
if (process.env.ENABLE_TOKEN_AUTH == "true") {
router.use(user.tokenAuthentication);
}

if (_.get(config, "Patient.interaction.search", true)) {
router.get('/', FHIRValidateParams({
Expand Down
6 changes: 5 additions & 1 deletion models/mongodb/FHIRDataTypesSchema/Patient_Communication.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ module.exports = new mongoose.Schema({
},
preferred: boolean
}, {
_id: false
_id: false,
id: false,
toObject: {
getters: true
}
});
6 changes: 5 additions & 1 deletion models/mongodb/FHIRDataTypesSchema/Patient_Contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ module.exports = new mongoose.Schema({
default: void 0
}
}, {
_id: false
_id: false,
id: false,
toObject: {
getters: true
}
});
6 changes: 5 additions & 1 deletion models/mongodb/FHIRDataTypesSchema/Patient_Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,9 @@ module.exports = new mongoose.Schema({
default: void 0
}
}, {
_id: false
_id: false,
id: false,
toObject: {
getters: true
}
});
37 changes: 30 additions & 7 deletions models/mongodb/model/Patient.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const boolean = require('../FHIRDataTypesSchema/boolean');
const HumanName = require('../FHIRDataTypesSchema/HumanName');
const ContactPoint = require('../FHIRDataTypesSchema/ContactPoint');
const date = require('../FHIRDataTypesSchema/date');
const string = require('../FHIRDataTypesSchema/string');
const dateTime = require('../FHIRDataTypesSchema/dateTime');
const Address = require('../FHIRDataTypesSchema/Address');
const CodeableConcept = require('../FHIRDataTypesSchema/CodeableConcept');
const Attachment = require('../FHIRDataTypesSchema/Attachment');
Expand Down Expand Up @@ -61,7 +61,7 @@ module.exports = function() {
},
birthDate: date,
deceasedBoolean: boolean,
deceasedDateTime: string,
deceasedDateTime: dateTime,
address: {
type: [Address],
default: void 0
Expand Down Expand Up @@ -112,22 +112,36 @@ module.exports = function() {
...id,
index: true
}
Patient.contained = {
type: [Object],
default: void 0
}
module.exports.schema = Patient;
const PatientSchema = new mongoose.Schema(Patient, {
let schemaConfig = {
toObject: {
getters: true
},
toJSON: {
getters: true
},
versionKey: false
});
};
if (process.env.MONGODB_IS_SHARDING_MODE == "true") {
schemaConfig["shardKey"] = {
id: 1
};
}
const PatientSchema = new mongoose.Schema(Patient, schemaConfig);


PatientSchema.methods.getFHIRField = function() {
let result = this.toObject();
delete result._id;
delete result.__v;
if (_.get(result, "myCollection")) {
let tempCollectionField = _.cloneDeep(result["myCollection"]);
_.set(result, "collection", tempCollectionField);
}
return result;
}

Expand All @@ -136,7 +150,7 @@ module.exports = function() {
let storedID = await mongodb.FHIRStoredID.findOne({
id: this.id
});
if (storedID) {
if (storedID && process.env.ENABLE_CHECK_ALL_RESOURCE_ID == "true") {
if (storedID.resourceType == "Patient") {
const docInHistory = await mongodb.Patient_history.findOne({
id: this.id
Expand Down Expand Up @@ -164,8 +178,8 @@ module.exports = function() {
let item = result.toObject();
delete item._id;
let version = item.meta.versionId;
let port = (process.env.FHIRSERVER_PORT == "80" || process.env.FHIRSERVER_PORT == "443") ? "" : `:${process.env.FHIRSERVER_PORT}`;
if (version == "1") {
let port = (process.env.FHIRSERVER_PORT == "80" || process.env.FHIRSERVER_PORT == "443") ? "" : `:${process.env.FHIRSERVER_PORT}`;
_.set(item, "request", {
"method": "POST",
url: `http://${process.env.FHIRSERVER_HOST}${port}/${process.env.FHIRSERVER_APIPATH}/Patient/${item.id}/_history/${version}`
Expand All @@ -174,6 +188,15 @@ module.exports = function() {
status: "201"
});
let createdDocs = await mongodb['Patient_history'].create(item);
} else {
_.set(item, "request", {
"method": "PUT",
url: `http://${process.env.FHIRSERVER_HOST}${port}/${process.env.FHIRSERVER_APIPATH}/Patient/${item.id}/_history/${version}`
});
_.set(item, "response", {
status: "200"
});
let createdDocs = await mongodb['Patient_history'].create(item);
}
await mongodb.FHIRStoredID.findOneAndUpdate({
id: result.id
Expand All @@ -188,7 +211,7 @@ module.exports = function() {
PatientSchema.pre('findOneAndUpdate', async function(next) {
const docToUpdate = await this.model.findOne(this.getFilter());
let version = Number(docToUpdate.meta.versionId);
this._update.$set.meta = {};
this._update.$set.meta = docToUpdate.meta;
this._update.$set.meta.versionId = String(version + 1);
this._update.$set.meta.lastUpdated = new Date();
return next();
Expand Down
8 changes: 0 additions & 8 deletions models/mongodb/model/Patient_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ module.exports = function() {
PatientHistorySchema.methods.getFHIRField = function() {
let result = this.toObject();
delete result._id;
let version = result.__v;
if (version) {
_.set(result, 'meta.versionId', version.toString());
}
delete result.__v;
delete result['name._id'];
delete result['request'];
Expand All @@ -47,10 +43,6 @@ module.exports = function() {
PatientHistorySchema.methods.getFHIRBundleField = function() {
let result = this.toObject();
delete result._id;
let version = result.__v;
if (version) {
_.set(result, 'meta.versionId', version.toString());
}
delete result.__v;
delete result['name._id'];
return result;
Expand Down

0 comments on commit 33cd4bf

Please sign in to comment.