Skip to content

Commit

Permalink
Pilot patch (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmanko committed Nov 15, 2023
1 parent b6f89bf commit 296974c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/lib/locationMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ async function getFacilityMappings() {
const rowStartIndex = 2
const rowEndIndex = 90

if (!worksheet) throw new Error('Could not find worksheet')

const rows = worksheet?.getRows(rowStartIndex, rowEndIndex) ?? []

const mappings = rows.map((row: Excel.Row): FacilityMapping => {
Expand Down
24 changes: 20 additions & 4 deletions src/workflows/botswana/locationWorkflows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,29 @@ export async function addBwLocations(bundle: R4.IBundle): Promise<R4.IBundle> {
)
}

const orderingLocation = <R4.ILocation>getBundleEntry(bundle.entry, 'Location', locationId)
const orderingOrganization = <R4.IOrganization>(
let orderingLocation = <R4.ILocation>getBundleEntry(bundle.entry, 'Location', locationId)
let orderingOrganization = <R4.IOrganization>(
getBundleEntry(bundle.entry, 'Organization', uniqueOrgIds[0])
)

if (orderingLocation && orderingOrganization) {
if (
if (!orderingLocation) {
logger.error('Could not find ordering Location! Using Omrs Location instead.')
orderingLocation = <R4.ILocation>getBundleEntry(bundle.entry, 'Location')
}

if (orderingLocation) {
if (!orderingOrganization) {
logger.error('No ordering Organization found - copying location info!')
orderingOrganization = {
resourceType: 'Organization',
id: crypto
.createHash('md5')
.update('Organization/' + orderingLocation.name)
.digest('hex'),
identifier: orderingLocation.identifier,
name: orderingLocation.name,
}
} else if (
!orderingLocation.managingOrganization ||
orderingLocation.managingOrganization.reference?.split('/')[1] != orderingOrganization.id
) {
Expand Down

0 comments on commit 296974c

Please sign in to comment.