Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

POC-131 # add update endpoint for the client re-verification #43

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/patient-registry/app/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ export const apiRoutes: ServerRoute[] = [
const service = new PatientService();
const identifiers = await service.searchPatientByID(request.query);

const response = h.response(identifiers);
return response;
},
},
{
method: "PUT",
path: "/api/uno",
handler: async function (request, h: ResponseToolkit) {
const service = new PatientService();
const identifiers = await service.updatePatient(request.query);
const response = h.response(identifiers);
return response;
},
Expand Down
23 changes: 22 additions & 1 deletion packages/patient-registry/app/helpers/auth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import qs from "qs";
import * as fs from "fs";
import config from "@amrs-integrations/core";
import HttpClient from "@amrs-integrations/core/dist/app/http-client";
export default async function getAccessToken() {
// Validate token in file
var data = qs.stringify({
Expand Down Expand Up @@ -32,7 +33,27 @@ export default async function getAccessToken() {
);
return response;
}

export async function client(implementation: string) {
let httpClient: any;
if (implementation === "dhp") {
let access_token = await validateToken();
new config.HTTPInterceptor(
config.dhp.url || "",
"",
"",
"dhp",
access_token
);
}else{
httpClient=new config.HTTPInterceptor(
config.amrsUrl || "",
config.amrsUsername || "",
config.amrsPassword || "",
"amrs"
);
}
return httpClient;
}
export async function validateToken() {
let isValid = false;
try {
Expand Down
23 changes: 4 additions & 19 deletions packages/patient-registry/app/helpers/patient.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import config from "@amrs-integrations/core";
import { client } from "./auth";

export async function getPatientIdentifiers(patientUUID: string) {
let httpClient = new config.HTTPInterceptor(
config.amrsUrl || "",
config.amrsUsername || "",
config.amrsPassword || "",
"amrs"
);
let httpClient =await client("amrs")
let identifiers = await httpClient.axios(
"/ws/rest/v1/patient/" + patientUUID + "/identifier",
{
Expand All @@ -22,12 +17,7 @@ export async function saveCountryAttribute(patientUuid:string, countryCode:strin
value: countryCode,
};

let httpClient = new config.HTTPInterceptor(
config.amrsUrl || "",
config.amrsUsername || "",
config.amrsPassword || "",
"amrs"
);
let httpClient = await client("amrs")
return await httpClient.axios.post(
"/ws/rest/v1/patient/" + patientUuid + "/attribute",
payload
Expand All @@ -45,12 +35,7 @@ export async function saveUpiIdentifier(
preferred: false,
};

let httpClient = new config.HTTPInterceptor(
config.amrsUrl || "",
config.amrsUsername || "",
config.amrsPassword || "",
"amrs"
);
let httpClient = await client("amrs")
return await httpClient.axios.post(
"/ws/rest/v1/patient/" + patientUuid + "/identifier",
payload
Expand Down
69 changes: 61 additions & 8 deletions packages/patient-registry/app/services/patient.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import config from "@amrs-integrations/core";
import { validateToken } from "../helpers/auth";
import { client, validateToken } from "../helpers/auth";
import { saveUpiIdentifier, getPatientIdentifiers, saveCountryAttribute } from "../helpers/patient";
import { getPatient, getFacilityMfl } from "../models/queries";
import Gender from "../ClientRegistryLookupDictionaries/gender";
Expand Down Expand Up @@ -65,13 +65,7 @@ export default class PatientService {
public async searchPatient(params: any) {
// await scheduleBatchUpdate(); //TODO -> Trigger using cron job
let accessToken = await validateToken();
let httpClient = new config.HTTPInterceptor(
config.dhp.url || "",
"",
"",
"dhp",
accessToken
);
let httpClient = await client("dhp");
let identifiers = await getPatientIdentifiers(params.patientUuid);
let universalId = identifiers.results.filter(
(id: any) =>
Expand Down Expand Up @@ -189,7 +183,66 @@ export default class PatientService {

return payload;
}
public async updatePatient(
params: any
) {
let identifiers = await getPatientIdentifiers(params.patientUuid);
let location="";
let nupi="";
identifiers.results.forEach((id: any) => {
if( id.identifierType.uuid == "ced014a1-068a-4a13-b6b3-17412f754af2"){
location=id.location;
nupi=id.identifier;
}
});
let httpClient = await client("dhp");
let payload = await this.constructPayload(
params.patientUuid,
location,
params.countryCode
);
payload.clientNumber=nupi;
console.log("Current patient payload ", payload);
/** Patient not found: Construct payload and save to Registry*/
const slackService = new SlackService();

httpClient.axios
.post("", payload)
.then(async (dhpResponse: any) => {
// let savedUpi: any = await this.saveUpiNumber(
// dhpResponse.clientNumber,
// params.patientUuid,
// location,
// params.countryCode
// );
console.log("Created successfully, assigned UPI", dhpResponse);
})
.catch((err: any) => {
const slackPayload = {
patientIdentifier: params.amrsNumber
? params.amrsNumber
: params.patientUuid,
errors: "",
};

if (err.response.data.errors !== undefined) {
/**Send bad request error to slack, error 400 */
slackPayload.errors = JSON.stringify(err.response.data.errors);
} else {
/**Queue patient in Redis, error 500 */
slackPayload.errors = "Verification retried";
const redisBody = {
payload: payload,
params: params,
location: location,
};
//this.queueClientsToRetry(redisBody);
}
slackService.postErrorMessage(slackPayload);
});

return payload;
}
private async constructPayload(
patientUuid: string,
locationUuid: string,
Expand Down