4.3.0 • Published 6 months ago

@afyadigital/rx-engine v4.3.0

Weekly downloads
-
License
-
Repository
-
Last release
6 months ago

Afya Digital: Prescription Engine

Library for consuming Afya Digital Prescription Engine - Frontend integration

Previous version status: | Version | Status | | ------- | ---------- | | 1.x | deprecated | | 2.x | deprecated | | 3.x | deprecated |

Installation

# npm
npm install @afyadigital/rx-engine --save

# yarn
yarn add @afyadigital/rx-engine

API

render

Renders the RX Engine App, given a configuration object

EngineConfiguration Object

PropertyTypeDefaultDescription
targetstring-Selector of target element to render the app
authObject { token }-Authentication info object
auth.tokenstring-Physician token(*)
initialValueObject { appointment, patient }-Info used on app initialization
initialValue.appointmentObject { id }-Appointment info object
initialValue.appointment.idstring-Appointment id on host application
initialValue.patientObject { id, name, address }-Patient info object
initialValue.patient.idstring-Patient id on host application
initialValue.patient.namestring-Patient name on host application
initialValue.patient.civilNamestring-Patient civil name on host application
initialValue.patient.addressstring-Patient address on host application (optional)
initialValue.patient.phonestring-Patient phone on host application (optional), eleven digits of length
initialValue.patient.emailstring-Patient email on host application (optional)
initialValue.patient.cpfstring-Patient cpf on host application (optional)
initialValue.patient.heightstring-Patient height on host application (optional), in centimeters (cm)
initialValue.patient.weightstring-Patient weight on host application (optional), in kilos (kg)
initialValue.patient.motherNamestring-Patient mother name on host application (optional)

* Get the physician authentication token through our api

Example:

/** Create a configuration to render the Prescription Engine */

const config: EngineConfig = {
  // target element selector. example: <div id="rx-engine"></div>
  target: `#rx-engine`,
  // physician authentication token
  auth: { token: 'jwt-token' },
  initialValue: {
    appointment: {
      id: '123'
    }
    // patient identification and name to create a prescription with
    patient: {
      id: '123',
      name: 'Jhon Doe',
      civilName: 'Jhonnie',
      address: 'Foo Bar',
      phone: '45999999999',
      email: 'patient@email.com',
      cpf: '682.733.635-20',
      height: "179",
      weight: "90",
      motherName: 'Jhoana Doe'
    },
  },
}

/** Render it on your target element */

render(config)

unmount

Clean previous mounted app and listeners

unmount()

events

API so you can register to events from prescription app. Make sure to render the app before subscribing to events. | name | description | payload | | -------------------------- | ------------------------------------------- | --------------------------------- | | 'app:init' | on app initialization | null | | 'app:revokedToken' | when physician token is expired/invalid | null | | 'prescription:saved' | when user saves the prescription | SavedPrescriptionEventPayload | | 'prescription:itemAdded' | when user adds another item to prescription | PrescriptionItemEventPayload |

type FreeTextItem = {
  title: string
  patientInstruction: string
  quantity: number
  unit: string
}

type MedicationItem = FreeTextItem & {
  id: string
}

type PrescriptionItemEventPayload = {
  type: 'product' | 'substance' | 'freeText'
  origin: 'user' | 'integration'
  data: FreeTextItem | MedicationItem
}

Example:

import { events } from '@afyadigital/rx-engine'

const doSomething = (prescriptionItem) => { ... }

// register a callback function to an event
events.listen('prescription:itemAdded', doSomething)

// remove an event listener
events.remove('prescription:itemAdded', doSomething)

// remove all listeners
events.cleanup()
type Patient = {
  name: string
  externalId: string
  address?: string
  phone?: string
  email?: string
  cpf?: string
  height?: string
  weight?: string
  motherName?: string
}

type UserInput = {
  patientInstruction: string
  quantity?: number
  unit?: string
  printType: PrintTypeEnum // simple | special | antimicrobial
}

type FreeText = {
  type: 'freeText'
  title: string
} & UserInput

type Product = {
  type: 'product'
  id: string
  title: string
  subtitle: string
  description: string
  laboratoryName: string
  category: string
  maxPrice: string
  available: boolean
} & UserInput

type Substance = {
  type: 'substance'
  id: string
  title: string
} & UserInput

type PrescriptionItem = FreeText | Product | Substance

export type Exam = {
  id: string
  code: string
  term: string
}

export type PrescritableExam = {
  quantity: number
  exam: Exam
}

export type ExamPage = {
  items: PrescritableExam[]
  clinicalIndication?: string
}

export type VaccineBase = {
  title: string
  patientInstruction: string
  quantity: number
}

export type VaccineProduct = {
  id: string
  type: 'product'
} & VaccineBase

export type VaccineFreeText = {
  type: 'freeText'
} & VaccineBase

export type Vaccine = VaccineProduct | VaccineFreeText

export type VaccinePage = {
  items: Vaccine[]
}

export type Lme = {
  patient: {
    fullName: string
    height: string
    isCapable: boolean
    mothersName: string
    weight: string
    responsibleName?: string
    filledBy: {
      responsible: 'patient' | 'patientMother' | 'responsible' | 'physician' | 'other',
      name?: string,
      cpf?: string,
    },
    skinColor: 'branca' | 'preta' | 'parda' | 'amarela' | 'indigena',
    ethnicity?: string,
    document: {
      type: 'cpf' | 'cns',
      value: string,
    },
    email: string,
    phone: string,
  }
  org: {
    cnes: string
    name: string
  }
  physician: {
    name: string
    cns: string
  }
  treatments: LmeTreatment[]
}

export type LmeTreatment = {
  id: string
  cid10: string
  diagnostic: string
  solicitationDate: string
  anamnese: string
  exams: {
    id: string
    term: string
    code: string
    type: string
    quantity: number
  }[]
  medications: {
    months: string[]
    name: string
    id: string
    type: string
  }[]

  onTreatment: boolean
  treatmentReport?: string

  pdfUrl: string // LME prescription pdf
  examUrl?: string // prescription pdf for all exams
  protocols?: string[] // terms prescriptions
  prescriptions?: {
    // LME medications prescriptions
    simple: LmeMedicationPrescription
    special: LmeMedicationPrescription[]
    antimicrobial: LmeMedicationPrescription[]
  }
}

export type LmeMedicationPrescription = {
  id: string
  pdfUrl: string
  prescriptionDate: string
  quantity: number
  medications: string[]
}

export type SavedPrescriptionEventPayload = {
  id: string
  patient: Patient
  issuedAt?: string
  items: PrescriptionItem[]
  exams: ExamPage[]
  vaccines: VaccinePage[]
  pdfUrl?: string
  lme?: Lme
}

commands

After engine app was initialized (check 'app:init' event above), you can dispatch events on the engine.

addPrescriptionItem(item: PrescriptionItem) : adds item into prescription.

type ItemFreeText = {
  title: string
  type: 'freeText'
  patientInstruction: string
  quantity: number
  unit: string
}

type ItemMedication = {
  id: string
  type: 'product' | 'substance'
  patientInstruction: string
  quantity: number
  unit: string
}

export type PrescriptionItem = ItemFreeText | ItemMedication

Usage example:

import { commands, events } from '@afyadigital/rx-engine'

const onInit = async () => {
  await commands.addPrescriptionItem({
    title: 'Paracetamol',
    type: 'freeText',
    patientInstruction: 'tomar 2x ao dia com intervalo de 4 horas',
    quantity: 2,
    unit: 'comprimidos',
  })
}

events.listen('app:init', onInit)

updateToken(token: string) : Updates the physician token

Usage example:

import { commands, events } from '@afyadigital/rx-engine'

events.listen('revokedToken', async () => {
  const token = await getPhysicianToken() // check physician login below*

  await commands.updateToken(token)
})

*physician login

trackUserActivity(click: TrackUserActivityEvent): Trigger event from user source

enum TrackActivityClickEnum {
  MenuPep = 'menuPep',
}

type TrackUserActivityEvent = {
  click: TrackActivityClickEnum
}

Usage example:

import { commands } from '@afyadigital/rx-engine'

const handleClick = () => {
  commands.trackUserActivity({ click: TrackActivityClickEnum.MenuPep })
}

return (
  <MenuItem>
    <Button onClick={handleClick}>Prescrição</Button>
  </MenuItem>
)

React dummy example

import { useEffect } from 'react'
import { render, unmount } from '@afyadigital/rx-engine'
import type { EngineConfig } from '@afyadigital/rx-engine'

const TARGET_ID = 'rx-engine-container'

function AfyaPrescription() {
  useEffect(() => {
    const config: EngineConfig = {
      target: `#${TARGET_ID}`,
      auth: { token: 'physician-auth-token' },
      initialValue: {
        patient: {
          id: '123',
          name: 'Jhon Doe',
          civilName: 'Jonnie',
          address: 'Foo Bar',
          phone: '45999999999',
          email: 'patient@email.com',
          cpf: '682.733.635-20',
          height: '179',
          weight: '90',
          motherName: 'Jhoana Doe',
        },
      },
    }

    render(config)

    return () => unmount()
  }, [])

  return <div id={TARGET_ID} />
}
4.3.0

6 months ago

4.2.0

6 months ago

4.1.0

6 months ago

4.1.0-beta

9 months ago

4.0.1

9 months ago

4.0.0

10 months ago

3.2.2

1 year ago

3.2.1

1 year ago

3.2.0

1 year ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.1

2 years ago

3.0.0-beta

2 years ago

3.0.0-rc-1

2 years ago

3.0.0-rc-2

2 years ago

2.5.1

2 years ago

3.0.0

2 years ago

2.5.0

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.4.0

2 years ago

2.1.0

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

1.0.0

3 years ago

0.9.0

3 years ago

0.8.0

3 years ago

0.7.0

3 years ago

0.6.2

3 years ago

0.6.1

3 years ago

0.5.0

3 years ago

0.6.0

3 years ago

0.4.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.0.1

3 years ago