diff --git a/AstuteClient2/src/app/services/astute-client-service.ts b/AstuteClient2/src/app/services/astute-client-service.ts index aca3bdb..ba92b90 100644 --- a/AstuteClient2/src/app/services/astute-client-service.ts +++ b/AstuteClient2/src/app/services/astute-client-service.ts @@ -1,368 +1,423 @@ -import {HttpClient, HttpHeaders} from '@angular/common/http'; -import {Injectable} from '@angular/core'; - -@Injectable() -export class AstuteClientService { - headers = { - headers: new HttpHeaders().set('Content-Type', 'application/json'), - }; - private authUrl = 'http://localhost:8080/astutesystem/auth'; - private customerUrl = 'http://localhost:8080/astutesystem/customer'; - private POUrl = 'http://localhost:8080/astutesystem/po'; - private POServiceTypesUrl = 'http://localhost:8080/astutesystem/po/serviceTypes'; - private PODetailUrl = 'http://localhost:8080/astutesystem/po/detail'; - private invoiceUrl = 'http://localhost:8080/astutesystem/invoice'; - private invoiceDetailUrl = 'http://localhost:8080/astutesystem/invoice/detail'; - private invoiceGenUrl = 'http://localhost:8080/astutesystem/invoice/generatedInvoice'; - private sessionId; - - constructor(private http: HttpClient) { } - - // **************************************** AUTH Service methods - - public login(username: string, password: string): Promise { - const data = { - 'username': username, - 'password': password - }; - - return this.http - .post(this.authUrl, data, this.headers) - .toPromise() - .then(response => { - console.log(response['entity']); - const sessionId = response['entity']; - if (sessionId != null) { - localStorage.setItem('SESSION_ID', sessionId); - return sessionId; - } else { - return null; - } - }); - } - - private getSessionId(): string { - console.log(localStorage.getItem('SESSION_ID')); - return localStorage.getItem('SESSION_ID'); - } - - // **************************************** Customer Service methods - - public getCustomers(): Promise { - console.log("*** In getCustomers()"); - const url = `${this.customerUrl}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public updateCustomer(customerId: number, data: any): Promise { - console.log("*** In updateCustomer()"); - const url = `${this.customerUrl}/${customerId}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createCustomer(data: any): Promise { - console.log("*** In createCustomer()"); - const url = `${this.customerUrl}`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - // **************************************** PO Service methods - - - public getPOs(): Promise { - console.log("*** In getPOs()"); - const url = `${this.POUrl}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public getServiceTypes(): Promise { - console.log("*** In getPOServiceTypes()"); - const url = `${this.POServiceTypesUrl}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public getPODetail(ponum): Promise { - console.log("*** In getPODetails()"); - const url = `${this.PODetailUrl}?PONum=${ponum}`; - console.log(url); - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public updatePO(ponum: string, data: any): Promise { - console.log("*** In updatePO()"); - const url = `${this.POUrl}/${ponum}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createPO(data: any): Promise { - console.log("*** In createPO()"); - const url = `${this.POUrl}`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - // String serviceDesc; - // int feeTypeId; - // Double qty; - // int serviceTypeId; - // String schedule; - // Date deliverBy; - public updatePODetail(ponum, lineItemNo, data) { - console.log("*** In updatePODetail()"); - const url = `${this.POUrl}/detail/${ponum}/${lineItemNo}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createPODetail(data) { - console.log("*** In createPODetail()"); - const url = `${this.POUrl}/detail`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - // **************************************** Invoice Service methods - - // /{InvoiceNumber}/void - public submitInvoice (invoiceNumber) { - console.log("*** In submitInvoice(), invoiceNumber" + invoiceNumber); - const url = `${this.invoiceUrl}/${invoiceNumber}/submit`; - return this.http.put(url, {}) - .toPromise() - .then(response => { - console.log (response['entity']); - return response['entity']; - }); - } - - public voidInvoice (invoiceNumber) { - console.log("*** In voidInvoice(), invoiceNumber" + invoiceNumber); - const url = `${this.invoiceUrl}/${invoiceNumber}/void`; - return this.http.put(url, {}) - .toPromise() - .then(response => { - console.log (response['entity']); - return response['entity']; - }); - } - - public deleteInvoice (invoiceNumber) { - console.log("*** In deleteInvoice(), invoiceNumber" + invoiceNumber); - const url = `${this.invoiceUrl}/${invoiceNumber}/delete`; - return this.http.put(url, {}) - .toPromise() - .then(response => { - console.log (response['entity']); - return response['entity']; - }); - } - - public generateInvoiceNumber (ponum) { - console.log("*** In generateInvoiceNumber()"); - const url = `${this.invoiceUrl}/generateInvoiceNumber/${ponum}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log (response['entity']) - return response['entity']; - }); - } - - public getInvoices(): Promise { - console.log("*** In getInvoices()"); - const url = `${this.invoiceUrl}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public getInvoiceDetail(invoiceId: string): Promise { - console.log("*** In getInvoiceDetail()"); - const url = `${this.invoiceDetailUrl}?invoiceNumber=${invoiceId}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public getInvoiceGen (invoiceId: string): Promise { - console.log("*** In getInvoiceGen()"); - const url = `${this.invoiceGenUrl}/${invoiceId}`; - return this.http.get(url) - .toPromise() - .then(response => { - console.log(response['entity']); - return response['entity']; - }); - } - - public updateInvoice(invoiceNumber: string, data: any): Promise { - console.log("*** In updateInvoice()"); - const url = `${this.invoiceUrl}/${invoiceNumber}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createInvoice(data: any): Promise { - console.log("*** In createInvoice()"); - const url = `${this.invoiceUrl}`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - public updateInvoiceDetail(invNum, lineItemNo, data) { - console.log("*** In updateInvoiceDetail()"); - const url = `${this.invoiceUrl}/detail/${invNum}/${lineItemNo}`; //TODO send sessionId - return this.http.put(url, data) - .toPromise() - .then(response => response['entity']); - } - - public createInvoiceDetail(data) { - console.log("*** In createInvoiceDetail()"); - const url = `${this.invoiceUrl}/detail`; //TODO send sessionId - return this.http.post(url, data) - .toPromise() - .then(response => response['entity']); - } - - - // public getRecord(patientId: number): Promise { - // const url = `${this.recordsUrl}/${patientId}?sessionId=${this.getSessionId()}`; - // return this.http.get(url) - // .toPromise() - // .then(response => { - // console.log(response); - // }); - // } - // - // public getInfo(patientId: number): Promise { - // const url = `${this.recordsUrl}/${patientId}?sessionId=${this.getSessionId()}`; - // return this.http.get(url) - // .toPromise() - // .then(response => { - // return response['entity']; - // }); - // } - // - // public getVisits(patientId: number): Promise { - // const url = `${this.recordsUrl}/${patientId}/visits?sessionId=${this.getSessionId()}`; - // return this.http.get(url) - // .toPromise() - // .then(response => { - // return response['entity']; - // }); - // } - // - // public getAllVisits(): Promise { - // const url = `${this.recordsUrl}/visits?sessionId=${this.getSessionId()}`; - // return this.http.get(url) - // .toPromise() - // .then(response => { - // return response['entity']; - // }); - // } - // - // public getVitals(visitId: number): Promise { - // const url = `${this.visitsUrl}/${visitId}/vitals?sessionId=${this.getSessionId()}`; - // return this.http.get(url) - // .toPromise() - // .then(response => { - // return response['entity']; - // }); - // } - // - // public getLatestVitals(patientId: number): Promise { - // const url = `${this.recordsUrl}/${patientId}/vitals?sessionId=${this.getSessionId()}`; - // return this.http.get(url) - // .toPromise() - // .then(response => { - // return response['entity']; - // }); - // } - // - // public updateInfo(patientId: number, data: any): Promise { - // const url = `${this.recordsUrl}/${patientId}?sessionId=${this.getSessionId()}`; - // return this.http.put(url, data) - // .toPromise() - // .then(response => response['entity']); - // } - // public updateVisit(patientId: number, visit: any): Promise { - // console.log(visit); - // - // const url = `${this.recordsUrl}/${patientId}/visits/${visit.visitId}?sessionId=${this.getSessionId()}`; - // return this.http.put(url, visit) - // .toPromise() - // .then(response => { - // console.log(response['entity']); - // return response['entity']; - // }); - // } - // - // public getSessionPatientId(): Promise { - // const url = `${this.sessionsUrl}/${this.getSessionId()}`; - // console.log(url); - // return this.http.get(url) - // .toPromise() - // .then(response => { - // console.log(response); - // return response['entity'].patientId; - // }); - // } - // - // public startVisit(patientId: number): Promise { - // const url = `${this.recordsUrl}/${patientId}/visits?${this.getSessionId()}`; - // return this.http.post(url, null) - // .toPromise() - // .then(response => { - // console.log(response); - // return response['entity']; - // }); - // } - // - // getMedications() { - // const url = `${this.medsUrl}?${this.getSessionId()}`; - // return this.http.get(url) - // .toPromise() - // .then(response => { - // console.log(response); - // return response['entity']; - // }); - // } -} +import {HttpClient, HttpHeaders} from '@angular/common/http'; +import {Injectable} from '@angular/core'; + +@Injectable() +export class AstuteClientService { + headers = { + headers: new HttpHeaders().set('Content-Type', 'application/json'), + }; + private authUrl = 'http://localhost:8080/astutesystem/auth'; + private customerUrl = 'http://localhost:8080/astutesystem/customer'; + private POUrl = 'http://localhost:8080/astutesystem/po'; + private POServiceTypesUrl = 'http://localhost:8080/astutesystem/po/serviceTypes'; + private PODetailUrl = 'http://localhost:8080/astutesystem/po/detail'; + private invoiceUrl = 'http://localhost:8080/astutesystem/invoice'; + private invoiceDetailUrl = 'http://localhost:8080/astutesystem/invoice/detail'; + private invoiceGenUrl = 'http://localhost:8080/astutesystem/invoice/generatedInvoice'; + private invoicePaymentUrl = 'http://localhost:8080/astutesystem/invoicePayment'; + private sessionId; + + constructor(private http: HttpClient) { } + + // **************************************** AUTH Service methods + + public login(username: string, password: string): Promise { + const data = { + 'username': username, + 'password': password + }; + + return this.http + .post(this.authUrl, data, this.headers) + .toPromise() + .then(response => { + console.log(response['entity']); + const sessionId = response['entity']; + if (sessionId != null) { + localStorage.setItem('SESSION_ID', sessionId); + return sessionId; + } else { + return null; + } + }); + } + + private getSessionId(): string { + console.log(localStorage.getItem('SESSION_ID')); + return localStorage.getItem('SESSION_ID'); + } + + // **************************************** Customer Service methods + + public getCustomers(): Promise { + console.log("*** In getCustomers()"); + const url = `${this.customerUrl}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public updateCustomer(customerId: number, data: any): Promise { + console.log("*** In updateCustomer()"); + const url = `${this.customerUrl}/${customerId}`; //TODO send sessionId + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + + public createCustomer(data: any): Promise { + console.log("*** In createCustomer()"); + const url = `${this.customerUrl}`; //TODO send sessionId + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + + // **************************************** PO Service methods + + + public getPOs(): Promise { + console.log("*** In getPOs()"); + const url = `${this.POUrl}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public getServiceTypes(): Promise { + console.log("*** In getPOServiceTypes()"); + const url = `${this.POServiceTypesUrl}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public getPODetail(ponum): Promise { + console.log("*** In getPODetails()"); + const url = `${this.PODetailUrl}?PONum=${ponum}`; + console.log(url); + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public updatePO(ponum: string, data: any): Promise { + console.log("*** In updatePO()"); + const url = `${this.POUrl}/${ponum}`; //TODO send sessionId + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + + public createPO(data: any): Promise { + console.log("*** In createPO()"); + const url = `${this.POUrl}`; //TODO send sessionId + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + + // String serviceDesc; + // int feeTypeId; + // Double qty; + // int serviceTypeId; + // String schedule; + // Date deliverBy; + public updatePODetail(ponum, lineItemNo, data) { + console.log("*** In updatePODetail()"); + const url = `${this.POUrl}/detail/${ponum}/${lineItemNo}`; //TODO send sessionId + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + + public createPODetail(data) { + console.log("*** In createPODetail()"); + const url = `${this.POUrl}/detail`; //TODO send sessionId + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + + // **************************************** Invoice Service methods + + // /{InvoiceNumber}/void + public submitInvoice (invoiceNumber) { + console.log("*** In submitInvoice(), invoiceNumber" + invoiceNumber); + const url = `${this.invoiceUrl}/${invoiceNumber}/submit`; + return this.http.put(url, {}) + .toPromise() + .then(response => { + console.log (response['entity']); + return response['entity']; + }); + } + + public voidInvoice (invoiceNumber) { + console.log("*** In voidInvoice(), invoiceNumber" + invoiceNumber); + const url = `${this.invoiceUrl}/${invoiceNumber}/void`; + return this.http.put(url, {}) + .toPromise() + .then(response => { + console.log (response['entity']); + return response['entity']; + }); + } + + public deleteInvoice (invoiceNumber) { + console.log("*** In deleteInvoice(), invoiceNumber" + invoiceNumber); + const url = `${this.invoiceUrl}/${invoiceNumber}/delete`; + return this.http.put(url, {}) + .toPromise() + .then(response => { + console.log (response['entity']); + return response['entity']; + }); + } + + public generateInvoiceNumber (ponum) { + console.log("*** In generateInvoiceNumber()"); + const url = `${this.invoiceUrl}/generateInvoiceNumber/${ponum}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log (response['entity']) + return response['entity']; + }); + } + + public getInvoices(): Promise { + console.log("*** In getInvoices()"); + const url = `${this.invoiceUrl}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public getInvoiceDetail(invoiceId: string): Promise { + console.log("*** In getInvoiceDetail()"); + const url = `${this.invoiceDetailUrl}?invoiceNumber=${invoiceId}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public getInvoiceGen (invoiceId: string): Promise { + console.log("*** In getInvoiceGen()"); + const url = `${this.invoiceGenUrl}/${invoiceId}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public updateInvoice(invoiceNumber: string, data: any): Promise { + console.log("*** In updateInvoice()"); + const url = `${this.invoiceUrl}/${invoiceNumber}`; //TODO send sessionId + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + + public createInvoice(data: any): Promise { + console.log("*** In createInvoice()"); + const url = `${this.invoiceUrl}`; //TODO send sessionId + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + + public updateInvoiceDetail(invNum, lineItemNo, data) { + console.log("*** In updateInvoiceDetail()"); + const url = `${this.invoiceUrl}/detail/${invNum}/${lineItemNo}`; //TODO send sessionId + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + + public createInvoiceDetail(data) { + console.log("*** In createInvoiceDetail()"); + const url = `${this.invoiceUrl}/detail`; //TODO send sessionId + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + + + // **************************************** Invoice Payment Service methods + + public getSumittedInvoices(): Promise { + console.log("*** In getSumittedInvoices()"); + const url = `${this.invoiceUrl}/submitted`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public getInvoiceTypes(): Promise { + const url = `${this.invoicePaymentUrl}/paymentTypes`; + console.log("*** In getInvoiceTypes() ... calling " + url); + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public getInvoicePayments(): Promise { + console.log("*** In getInvoicePayments()"); + const url = `${this.invoicePaymentUrl}`; + return this.http.get(url) + .toPromise() + .then(response => { + console.log(response['entity']); + return response['entity']; + }); + } + + public updateInvoicePayment(invoiceNumber: string, invoicePaymentId: string, data: any): Promise { + console.log("*** In updateInvoicePayment()"); + const url = `${this.invoicePaymentUrl}/${invoiceNumber}/${invoicePaymentId}`; //TODO send sessionId + console.log("*** invoicePaymentUrl is " + url); + return this.http.put(url, data) + .toPromise() + .then(response => response['entity']); + } + + public addInvoicePayment(data: any): Promise { + console.log("*** In addInvoicePayment()"); + const url = `${this.invoicePaymentUrl}`; //TODO send sessionId + return this.http.post(url, data) + .toPromise() + .then(response => response['entity']); + } + + // public getRecord(patientId: number): Promise { + // const url = `${this.recordsUrl}/${patientId}?sessionId=${this.getSessionId()}`; + // return this.http.get(url) + // .toPromise() + // .then(response => { + // console.log(response); + // }); + // } + // + // public getInfo(patientId: number): Promise { + // const url = `${this.recordsUrl}/${patientId}?sessionId=${this.getSessionId()}`; + // return this.http.get(url) + // .toPromise() + // .then(response => { + // return response['entity']; + // }); + // } + // + // public getVisits(patientId: number): Promise { + // const url = `${this.recordsUrl}/${patientId}/visits?sessionId=${this.getSessionId()}`; + // return this.http.get(url) + // .toPromise() + // .then(response => { + // return response['entity']; + // }); + // } + // + // public getAllVisits(): Promise { + // const url = `${this.recordsUrl}/visits?sessionId=${this.getSessionId()}`; + // return this.http.get(url) + // .toPromise() + // .then(response => { + // return response['entity']; + // }); + // } + // + // public getVitals(visitId: number): Promise { + // const url = `${this.visitsUrl}/${visitId}/vitals?sessionId=${this.getSessionId()}`; + // return this.http.get(url) + // .toPromise() + // .then(response => { + // return response['entity']; + // }); + // } + // + // public getLatestVitals(patientId: number): Promise { + // const url = `${this.recordsUrl}/${patientId}/vitals?sessionId=${this.getSessionId()}`; + // return this.http.get(url) + // .toPromise() + // .then(response => { + // return response['entity']; + // }); + // } + // + // public updateInfo(patientId: number, data: any): Promise { + // const url = `${this.recordsUrl}/${patientId}?sessionId=${this.getSessionId()}`; + // return this.http.put(url, data) + // .toPromise() + // .then(response => response['entity']); + // } + // public updateVisit(patientId: number, visit: any): Promise { + // console.log(visit); + // + // const url = `${this.recordsUrl}/${patientId}/visits/${visit.visitId}?sessionId=${this.getSessionId()}`; + // return this.http.put(url, visit) + // .toPromise() + // .then(response => { + // console.log(response['entity']); + // return response['entity']; + // }); + // } + // + // public getSessionPatientId(): Promise { + // const url = `${this.sessionsUrl}/${this.getSessionId()}`; + // console.log(url); + // return this.http.get(url) + // .toPromise() + // .then(response => { + // console.log(response); + // return response['entity'].patientId; + // }); + // } + // + // public startVisit(patientId: number): Promise { + // const url = `${this.recordsUrl}/${patientId}/visits?${this.getSessionId()}`; + // return this.http.post(url, null) + // .toPromise() + // .then(response => { + // console.log(response); + // return response['entity']; + // }); + // } + // + // getMedications() { + // const url = `${this.medsUrl}?${this.getSessionId()}`; + // return this.http.get(url) + // .toPromise() + // .then(response => { + // console.log(response); + // return response['entity']; + // }); + // } + + +}