{"version":3,"sources":["webpack:///src/app/modules/external-document/base-external-document.component.ts"],"names":["BaseExternalDocumentComponent","router","route","fb","coreService","documentService","healthProfessionalService","patientService","petService","clientAppService","adding","typesOfDocuments","documentTypes","prescription","exam","attestation","orientation","other","infusion","messages","initialLoading","loading","_request","_colorSetting","primary","secondary","footer","this","documentForm","group","patientForm","_id","cpf","name","required","usePdfV1Endpoint","requestStr","atob","payload","logVersions","console","log","request","JSON","parse","e","error","length","Object","entries","obj","value","local","valid","keys","constructor","signed","snapshot","params","token","queryParams","document","status","ui","showLocal","showPatientName","sendDocumentRequired","url","includes","prescriber","professionalType","VETERINARIAN","features","find","f","colorSetting","type","documentType","convertToTypeOfDocument","toLowerCase","apiKey","envCmSereneApiKey","patient","patchValue","address","victaFeature","code","patientId","petId","response","callbackUrl","Error","splitedToken","split","isInvalidPayloadRequest","token1","documentCode","payloadChecksum","showSendDocumentModal","isPet","validateToken","toString","then","err","push","isNewRoute","isValidNewRequest","getPrescriberData","isVeterinarian","getPetData","id","getPatientData","toggleAdding","isValidEditRequest","getDocumentData","resend","title","pet","version","supportedVersion","localId","getHealthProfessional","toPromise","cpfValue","transform","getHealthProfessionalByCpf","commercialData","c","getPatient","getPatientByCpf","getPetById","isValid","p","firstLetter","getDocument","fillForm","healthProfessional","isEditRoute","getBackendVersion","frontendVersion","a"],"mappings":"qNAiBO,MAAeA,EA+BpB,YACYC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,EACAC,GARA,KAAAR,SACA,KAAAC,QACA,KAAAC,KACA,KAAAC,cACA,KAAAC,kBACA,KAAAC,4BACA,KAAAC,iBACA,KAAAC,aACA,KAAAC,mBAhCZ,KAAAC,QAAS,EACT,KAAAC,iBAAmB,CAAC,mBAAc,QAAS,WAAY,SAAU,cACjE,KAAAC,cAAgB,CACdC,aAAc,mBACdC,KAAM,QACNC,YAAa,WACbC,YAAa,SACbC,MAAO,SACPC,SAAU,cAGZ,KAAAC,SAAqB,GAErB,KAAAC,gB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,SAAWA,EAEXlC,KAAK8G,qBACD5E,EAASyB,YACTzB,EAASC,QAGlBnC,KAAKqF,eAGC,wBAAwBpC,GAC9B,OAAOjD,KAAKf,cAAcgE,GAGpB,oBACN,MAAM0C,QAAgB3F,KAAKvB,YAAYsI,oBAAoBhB,YAC3DlF,QAAQC,IAAI,KAAMd,KAAKvB,YAAYuI,gBAAiB,KAAMrB,IA9P5D,SAAAsB,EAAA,EADC,I,2IA+FD,SAAAA,EAAA,EADC,I,8JAmCD,SAAAA,EAAA,EADC,I,2JAuBD,aADC,I,uJAqED,aADC,I,4JAmCD,aADC,I","file":"x","sourcesContent":["import { FormBuilder, FormGroup, Validators } from '@angular/forms';\nimport { ActivatedRoute, Router } from '@angular/router';\nimport { CoreService } from '@app/core/services/core.service';\nimport { Comercial, HealthProfessional } from '@app/shared/models';\nimport { ColorSetting } from '@app/shared/models/color-setting';\nimport { ProfessionalType } from '@app/shared/models/professional-type.enum';\nimport { OnlyNumbersPipe } from '@app/shared/pipes';\nimport { md5 } from '@app/utils/md5';\nimport { DocumentService } from '../document/services/document.service';\nimport { HealthProfessionalService } from '../health-professional/services/health-professional.service';\nimport { PatientsService } from '../patients/services/patients.service';\nimport { PetPatientService } from '../patients/services/pet-patient.service';\nimport { IRequest } from './models/IRequest';\nimport { ClientAppService } from './services/client-app.service';\nimport { nativeAsync } from '@app/shared/decorators/nativeAsync';\nimport { environment } from '@env/environment';\n\nexport abstract class BaseExternalDocumentComponent {\n prescriber: HealthProfessional;\n local: Comercial;\n\n documentForm: FormGroup;\n patientForm: FormGroup;\n document: any;\n\n adding = false;\n typesOfDocuments = ['Prescrição', 'Exame', 'Atestado', 'Outros', 'Infusão'];\n documentTypes = {\n prescription: 'Prescrição',\n exam: 'Exame',\n attestation: 'Atestado',\n orientation: 'Outros',\n other: 'Outros',\n infusion: 'Infusão'\n };\n\n messages: string[] = [];\n features: string[];\n initialLoading = true;\n loading = false;\n\n private _request = null;\n private _colorSetting: ColorSetting = {\n primary: '#1b403a',\n secondary: '#00d3b2',\n footer: '#1b403a'\n };\n\n constructor(\n protected router: Router,\n protected route: ActivatedRoute,\n protected fb: FormBuilder,\n protected coreService: CoreService,\n protected documentService: DocumentService,\n protected healthProfessionalService: HealthProfessionalService,\n protected patientService: PatientsService,\n protected petService: PetPatientService,\n protected clientAppService: ClientAppService\n ) {\n this.documentForm = this.fb.group({});\n this.patientForm = this.fb.group({\n _id: [null],\n cpf: [null],\n name: ['', [Validators.required]]\n });\n\n this.documentService.usePdfV1Endpoint();\n }\n\n get request(): IRequest {\n if (!this._request) {\n const requestStr = atob(this.payload);\n\n this.logVersions();\n console.log('payload', requestStr);\n try {\n const request = JSON.parse(requestStr);\n this._request = request;\n } catch (e) {\n console.error(e);\n this._request = {} as IRequest;\n }\n }\n\n return this._request;\n }\n\n get validRequest(): boolean {\n return !this.messages.length;\n }\n\n get isInvalidPayloadRequest(): boolean {\n return !Object.entries(this.request).length;\n }\n\n get invalidForm(): boolean {\n const obj = this.documentForm.value;\n return (\n this.messages.length > 0 ||\n !this.patientForm.value._id ||\n !this.patientForm.value.name ||\n !this.local ||\n !this.documentForm.valid ||\n (Object.keys(obj).length === 0 && obj.constructor === Object) ||\n this.signed\n );\n }\n\n get token(): string {\n return this.route.snapshot.params.token;\n }\n\n get payload(): string {\n return this.route.snapshot.queryParams.payload;\n }\n\n get signed(): boolean {\n return this.document && this.document.status === 'Assinada';\n }\n\n get showLocal(): boolean {\n return this.request.ui && this.request.ui.showLocal === true;\n }\n\n get showPatientName(): boolean {\n return this.request.ui && this.request.ui.showPatientName === true;\n }\n\n get isSendDocumentRequired(): boolean {\n return this.request.ui && this.request.ui.sendDocumentRequired === true;\n }\n\n get isNewRoute() {\n return this.router.url.includes('/new');\n }\n\n get isEditRoute() {\n return this.router.url.includes('/edit');\n }\n\n get isVeterinarian(): boolean {\n return this.prescriber && this.prescriber.professionalType === ProfessionalType.VETERINARIAN;\n }\n\n get victaFeature(): boolean {\n return this.features && !!this.features.find(f => f === 'Victa');\n }\n\n get colorSetting(): ColorSetting {\n if (this.request.colorSetting) {\n return {\n ...this._colorSetting,\n ...this.request.colorSetting\n };\n }\n return this._colorSetting;\n }\n\n get documentType(): string {\n if (this.document && this.document.type) {\n return this.document.type;\n }\n if (this.request.documentType) {\n return this.convertToTypeOfDocument(this.request.documentType.toLowerCase());\n }\n return this.typesOfDocuments[0];\n }\n\n get patient() {\n return this.patientForm.value;\n }\n\n get isClientCmSerene() {\n console.log(this.clientAppService.apiKey);\n console.log(environment.envCmSereneApiKey);\n return this.clientAppService.apiKey === environment.envCmSereneApiKey;\n }\n\n set patient(patient: any) {\n this.patientForm.patchValue(patient);\n }\n\n changeLocal(address: Comercial) {\n this.local = address;\n }\n\n toggleAdding() {\n if (!this.victaFeature) {\n this.adding = !this.adding;\n }\n }\n\n @nativeAsync\n async init(): Promise<void> {\n try {\n const { code, patientId, petId, payload, response, callbackUrl } = this.route.snapshot.queryParams;\n\n if (!this.token) {\n throw Error('Token não encontrado');\n }\n\n // expected token format: 708I9DG2AD3I4DH5DH31258635IH7DA9-5f4bab65dac35d12cc6b404cc6be9a7c\n const splitedToken = this.token.split('-');\n if (splitedToken.length !== 2) {\n throw Error('Token inválido');\n }\n\n if (this.isInvalidPayloadRequest) {\n throw Error('Formato payload JSON inválido');\n }\n\n const [apiKey, token1] = splitedToken;\n this.clientAppService.apiKey = apiKey;\n\n const { documentCode, prescriber, patient } = this.request;\n const payloadChecksum = md5(this.payload);\n\n if (code && (patientId || petId) && response) {\n this.showSendDocumentModal(code, patientId || petId, {\n callbackUrl,\n payload,\n response,\n isPet: !!petId,\n colorSetting: this.colorSetting\n });\n this.clientAppService\n .validateToken(token1, payloadChecksum.toString())\n .then(({ features }) => (this.features = features));\n } else {\n try {\n const { features } = await this.clientAppService.validateToken(\n token1,\n payloadChecksum.toString()\n );\n this.features = features;\n } catch (err) {\n this.messages.push(\n 'Verifique se as chaves de API foram corretamente informadas e tente novamente.'\n );\n throw err;\n }\n }\n\n if (this.isNewRoute) {\n // documentCode defined means that the document was signed and callbackUrl is not defined\n // so we do not need to verify the request\n if (!documentCode && this.isValidNewRequest(this.request)) {\n await this.getPrescriberData(prescriber);\n\n if (this.isVeterinarian) {\n await this.getPetData(patient.id);\n } else {\n await this.getPatientData(patient);\n }\n\n if (this.isVeterinarian && this.documentType !== this.typesOfDocuments[0]) {\n this.messages.push(\n `Documento do tipo ${this.documentType} não é permitido para veterinários`\n );\n } else {\n this.toggleAdding();\n }\n }\n } else if (this.isValidEditRequest(documentCode)) {\n const exists = await this.getDocumentData(documentCode);\n if (exists) {\n if (this.signed) {\n // show send document modal for signed documents\n this.showSendDocumentModal(this.document.code, this.document.patient._id, {\n resend: true,\n title: 'Reenvio de documento',\n isPet: this.document.pet && this.document.pet._id,\n colorSetting: this.colorSetting\n });\n } else if (this.document.version !== this.supportedVersion) {\n this.messages.push(`Documento incompatÃvel (${this.document.version}).`);\n }\n }\n }\n } catch (err) {\n console.error(err);\n this.messages.push('Requisição inválida');\n } finally {\n this.initialLoading = false;\n }\n }\n @nativeAsync\n async getPrescriberData({ id, cpf, type, localId }: any) {\n try {\n this.loading = true;\n if (id) {\n this.prescriber = await this.healthProfessionalService.getHealthProfessional(id).toPromise();\n } else {\n const cpfValue = new OnlyNumbersPipe().transform(cpf);\n this.prescriber = await this.healthProfessionalService\n .getHealthProfessionalByCpf(cpfValue, type)\n .toPromise();\n }\n\n if (this.prescriber.commercialData && this.prescriber.commercialData.length > 0) {\n const commercialData = this.prescriber.commercialData.find(c => c._id === localId);\n if (commercialData) {\n this.local = commercialData;\n } else {\n this.local = this.prescriber.commercialData[0];\n }\n }\n if (!this.local) {\n this.messages.push('O prescritor não possui clÃnica cadastrada');\n }\n } catch (error) {\n console.error(error);\n if (error.status === 404) {\n this.messages.push('Prescritor não localizado em nossa base de dados');\n } else {\n this.messages.push('Erro ao carregar dados do prescritor');\n }\n }\n this.loading = false;\n }\n @nativeAsync\n async getPatientData({ id, cpf }: any) {\n try {\n this.loading = true;\n let patient: any;\n if (id) {\n patient = await this.patientService.getPatient(id).toPromise();\n } else {\n const cpfValue = new OnlyNumbersPipe().transform(cpf);\n patient = await this.patientService.getPatientByCpf(cpfValue).toPromise();\n }\n this.patient = patient;\n } catch (error) {\n if (error.status === 404) {\n this.messages.push('Paciente não localizado em nossa base de dados');\n } else {\n console.error(error);\n this.messages.push('Erro ao carregar dados do paciente');\n }\n }\n this.loading = false;\n }\n @nativeAsync\n private async getPetData(petId: string) {\n try {\n this.loading = true;\n const pet = await this.petService.getPetById(petId).toPromise();\n this.patient = pet;\n } catch (error) {\n if (error.status === 404) {\n this.messages.push('Pet não localizado em nossa base de dados');\n } else {\n console.error(error);\n this.messages.push('Erro ao carregar dados do pet');\n }\n }\n this.loading = false;\n }\n\n private isValidNewRequest({ patient, prescriber, documentType: type }: IRequest): boolean {\n const isValid = p => p && (p.id || p.cpf);\n\n if (!isValid(patient)) {\n this.messages.push('O ID ou CPF do paciente deve ser informado');\n }\n\n if (!isValid(prescriber)) {\n this.messages.push('O ID ou CPF do prescritor deve ser informado');\n }\n\n if (type) {\n type = type.toLowerCase();\n if (\n type !== 'prescription' &&\n type !== 'attestation' &&\n type !== 'exam' &&\n type !== 'orientation' &&\n type !== 'other' &&\n type !== 'infusion'\n ) {\n this.messages.push('O tipo de documento informado é inválido');\n }\n }\n\n if (!this.victaFeature && type === 'infusion') {\n this.messages.push('O tipo de documento informado é inválido');\n }\n\n return this.messages.length === 0;\n }\n\n private isValidEditRequest(documentCode: string) {\n if (!documentCode) {\n this.messages.push('O código do documento deve ser informado');\n } else {\n const firstLetter = documentCode[0];\n if (\n firstLetter !== 'P' &&\n firstLetter !== 'A' &&\n firstLetter !== 'E' &&\n firstLetter !== 'O' &&\n firstLetter !== 'I' &&\n firstLetter !== 'V'\n ) {\n this.messages.push('Código do documento inválido');\n }\n }\n\n return this.messages.length === 0;\n }\n @nativeAsync\n private async getDocumentData(documentCode: string): Promise<boolean> {\n try {\n const document = await this.documentService.getDocument(documentCode);\n this.fillForm(document);\n return true;\n } catch (err) {\n console.error(err);\n this.messages.push('Erro ao consultar documento');\n return false;\n }\n }\n\n private fillForm(document: any) {\n // this.documentType = document.type;\n this.local = document.local;\n\n this.patient = document.patient || document.pet;\n this.patientForm.patchValue(this.patient);\n this.prescriber = document.healthProfessional;\n\n this.document = document;\n\n if (!this.isEditRoute) {\n delete document.code;\n delete document.status;\n }\n\n this.toggleAdding();\n }\n\n private convertToTypeOfDocument(type: string): string {\n return this.documentTypes[type];\n }\n @nativeAsync\n private async logVersions(): Promise<void> {\n const version = await this.coreService.getBackendVersion().toPromise();\n console.log('F:', this.coreService.frontendVersion, 'B:', version);\n }\n\n // ----- Abstract methods -----\n\n abstract showSendDocumentModal(\n code: string,\n patientId: string,\n { callbackUrl, payload, response, resend, title, isPet, colorSetting }?: any\n ): void;\n\n abstract get supportedVersion(): string;\n}\n"]}