Skip to content

Commit

Permalink
Merge branch 'main' into create-side-profile-view
Browse files Browse the repository at this point in the history
  • Loading branch information
sharon2719 committed May 22, 2024
2 parents f1771fc + 417b099 commit fcf688f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export const productCharacteristics = [
coding: [
{
code: '33467722',
display: 'Quantity ',
display: 'Quantity',
system: 'http://smartregister.org/codes',
},
],
Expand Down Expand Up @@ -1309,7 +1309,7 @@ export const createdInventoryGroup1 = {
{
code: {
coding: [
{ system: 'http://smartregister.org/codes', code: '33467722', display: 'Quantity ' },
{ system: 'http://smartregister.org/codes', code: '33467722', display: 'Quantity' },
],
},
valueQuantity: { value: '20' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,30 @@ describe('fhir-group-management/src/components/LocationInventory/utils', () => {
const noAttractiveCharacteristic = commodity1.characteristic?.filter(
(char) => char.code.coding?.[0].code !== attractiveCharacteristicCode
);
const newCommodity = {
const nonAttractiveItem = {
...commodity1,
characteristic: noAttractiveCharacteristic,
};
const attractiveItem = {
...commodity1,
characteristic: [
{
code: {
coding: [
{
system: 'http://smartregister.org/codes',
code: '23435363',
display: 'Attractive Item code',
},
],
},
valueBoolean: true,
},
],
};
expect(isAttractiveProduct()).toEqual(false);
expect(isAttractiveProduct(commodity1)).toEqual(true);
expect(isAttractiveProduct(newCommodity)).toEqual(false);
expect(isAttractiveProduct(attractiveItem)).toEqual(true);
expect(isAttractiveProduct(nonAttractiveItem)).toEqual(false);
});

it('get item accounterbility months works as expected', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import dayjs, { Dayjs } from 'dayjs';
import { TFunction } from '@opensrp/i18n';
import { Rule } from 'rc-field-form/lib/interface';
import {
attractiveCharacteristicCode,
accountabilityCharacteristicCode,
attractiveCharacteristicCoding,
} from '../../helpers/utils';
import { GroupCharacteristic } from '@smile-cdr/fhirts/dist/FHIR-R4/classes/groupCharacteristic';
import { Identifier } from '@smile-cdr/fhirts/dist/FHIR-R4/classes/identifier';
Expand All @@ -35,21 +35,17 @@ import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation';
import { getValueSetOptionsValue } from '@opensrp/react-utils';
import { IBundle } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/IBundle';
import {
donorCharacteristicCoding,
getCharacteristicWithCoding,
inventoryGroupCoding,
poNumberIdentifierCoding,
quantityCharacteristicCoding,
sectionCharacteristicCoding,
serialNumberIdentifierCoding,
servicePointProfileInventoryListCoding,
smartregisterSystemUri,
} from '@opensrp/fhir-helpers';

const codeSystem = 'http://smartregister.org/codes';
const unicefCharacteristicCode = '98734231';
const donorCharacteristicCode = '45981276';
const quantityCharacteristicCode = '33467722';
const supplyInventoryCode = '78991122';
const poNumberDisplay = 'PO Number';
const poNumberCode = 'PONUM';
const serialNumberDisplay = 'Serial Number';
const serialNumberCode = 'SERNUM';
const listSupplyInventoryCode = '22138876';

/**
* Check if date in past
*
Expand All @@ -75,18 +71,19 @@ export const handleDisabledFutureDates = (current?: Dayjs) => {
};

/**
* check if product is an atrractive item
* check if product is an attractive item
*
* @param product - product data
*/
export const isAttractiveProduct = (product?: IGroup) => {
if (!product) {
return false;
}
const isAttractive = product.characteristic?.some(
(char) => char.code.coding?.[0]?.code === attractiveCharacteristicCode
const attractiveCharacteristic = getCharacteristicWithCoding(
product.characteristic ?? [],
attractiveCharacteristicCoding
);
return isAttractive as boolean;
return !!attractiveCharacteristic?.valueBoolean;
};

/**
Expand Down Expand Up @@ -168,9 +165,9 @@ export const generateCharacteristics = (
listResourceObj?: IGroup
): GroupCharacteristic[] => {
const knownCodes = [
unicefCharacteristicCode,
donorCharacteristicCode,
quantityCharacteristicCode,
sectionCharacteristicCoding.code,
donorCharacteristicCoding.code,
quantityCharacteristicCoding.code,
];
const unknownCharacteristics =
listResourceObj?.characteristic?.filter((char) => {
Expand All @@ -181,13 +178,7 @@ export const generateCharacteristics = (
...unknownCharacteristics,
{
code: {
coding: [
{
system: codeSystem,
code: unicefCharacteristicCode,
display: 'Unicef Section',
},
],
coding: [sectionCharacteristicCoding],
},
valueCodeableConcept: {
coding: [unicefSection],
Expand All @@ -198,13 +189,7 @@ export const generateCharacteristics = (
if (donor) {
characteristics.push({
code: {
coding: [
{
system: codeSystem,
code: donorCharacteristicCode,
display: 'Donor',
},
],
coding: [donorCharacteristicCoding],
},
valueCodeableConcept: {
coding: [donor],
Expand All @@ -215,13 +200,7 @@ export const generateCharacteristics = (
if (quantity) {
characteristics.push({
code: {
coding: [
{
system: codeSystem,
code: quantityCharacteristicCode,
display: 'Quantity ',
},
],
coding: [quantityCharacteristicCoding],
},
valueQuantity: { value: quantity },
});
Expand All @@ -242,7 +221,7 @@ export const generateIdentifier = (
serialId?: string,
listResourceObj?: IGroup
): Identifier[] => {
const knownCodes = [poNumberCode, serialNumberCode];
const knownCodes = [poNumberIdentifierCoding.code, serialNumberIdentifierCoding.code];
const unknownIdentifiers =
listResourceObj?.identifier?.filter((identifier) => {
const code = identifier.type?.coding?.[0].code;
Expand All @@ -252,14 +231,8 @@ export const generateIdentifier = (
{
use: IdentifierUseCodes.SECONDARY,
type: {
coding: [
{
system: codeSystem,
code: poNumberCode,
display: poNumberDisplay,
},
],
text: poNumberDisplay,
coding: [poNumberIdentifierCoding],
text: poNumberIdentifierCoding.display,
},
value: poId,
},
Expand All @@ -269,14 +242,8 @@ export const generateIdentifier = (
identifiers.push({
use: IdentifierUseCodes.OFFICIAL,
type: {
coding: [
{
system: codeSystem,
code: serialNumberCode,
display: serialNumberDisplay,
},
],
text: serialNumberDisplay,
coding: [serialNumberIdentifierCoding],
text: serialNumberIdentifierCoding.display,
},
value: serialId,
});
Expand Down Expand Up @@ -309,13 +276,7 @@ export const getLocationInventoryPayload = (
member: getMember(values.product, values.deliveryDate, values.accountabilityEndDate),
characteristic: generateCharacteristics(unicefSection, donor, values.quantity, listResourceObj),
code: {
coding: [
{
system: codeSystem,
code: supplyInventoryCode,
display: 'Supply Inventory',
},
],
coding: [inventoryGroupCoding],
},
};
if (editMode) {
Expand Down Expand Up @@ -476,14 +437,8 @@ function createCommonListResource(id: string): IList {
],
status: 'current',
code: {
coding: [
{
system: codeSystem,
code: listSupplyInventoryCode,
display: 'Supply Inventory List',
},
],
text: 'Supply Inventory List',
coding: [servicePointProfileInventoryListCoding],
text: servicePointProfileInventoryListCoding.display,
},
};
}
Expand Down Expand Up @@ -528,14 +483,8 @@ export function createUpdateLocationInventoryList(
const stringDate = now.toISOString();
const newEntry: ListEntry = {
flag: {
coding: [
{
system: codeSystem,
code: listSupplyInventoryCode,
display: 'Supply Inventory List',
},
],
text: 'Supply Inventory List',
coding: [servicePointProfileInventoryListCoding],
text: servicePointProfileInventoryListCoding.display,
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
date: stringDate as any,
Expand Down Expand Up @@ -567,28 +516,28 @@ export const getInventoryInitialValues = (inventory: IGroup): GroupFormFields =>
} as GroupFormFields;
inventory.identifier?.forEach((identifier) => {
const code = identifier.type?.coding?.[0].code;
if (code === poNumberCode) {
if (code === poNumberIdentifierCoding.code) {
initialValues.poNumber = identifier.value as string;
}
if (code === serialNumberCode) {
if (code === serialNumberIdentifierCoding.code) {
initialValues.serialNumber = identifier.value as string;
}
});
inventory.characteristic?.forEach((characteristic) => {
const code = characteristic.code.coding?.[0].code;
if (code === unicefCharacteristicCode) {
if (code === sectionCharacteristicCoding.code) {
const coding = characteristic.valueCodeableConcept?.coding?.[0];
if (coding) {
initialValues.unicefSection = getValueSetOptionsValue(coding) as string;
}
}
if (code === donorCharacteristicCode) {
if (code === donorCharacteristicCoding.code) {
const coding = characteristic.valueCodeableConcept?.coding?.[0];
if (coding) {
initialValues.donor = getValueSetOptionsValue(coding);
}
}
if (code === quantityCharacteristicCode) {
if (code === quantityCharacteristicCoding.code) {
initialValues.quantity = characteristic.valueQuantity?.value;
}
});
Expand Down

0 comments on commit fcf688f

Please sign in to comment.