Skip to content

Commit

Permalink
OZ-708: Add symbol, unit-label, and sub-unit-label currency money ext…
Browse files Browse the repository at this point in the history
…ensions
  • Loading branch information
corneliouzbett committed Oct 1, 2024
1 parent 605cf2c commit 9f8d7b1
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ public class OdooConstants {

public static final String FHIR_OPENMRS_SYSTEM_PREFIX = "https://fhir.openmrs.org/";

public static final String FHIR_OPENMRS_EXT_PREFIX = FHIR_OPENMRS_SYSTEM_PREFIX + "ext/";

public static final String FHIR_OPENMRS_EXT_CURRENCY = FHIR_OPENMRS_EXT_PREFIX + "currency/";

public static final String FHIR_OPENMRS_EXT_CURRENCY_SYMBOL = FHIR_OPENMRS_EXT_CURRENCY + "symbol";

public static final String FHIR_OPENMRS_EXT_CURRENCY_UNIT_LABEL = FHIR_OPENMRS_EXT_CURRENCY + "unit-label";

public static final String FHIR_OPENMRS_EXT_CURRENCY_SUBUNIT_LABEL = FHIR_OPENMRS_EXT_CURRENCY + "subunit-label";

public static final String FHIR_OPENMRS_CONCEPT_SYSTEM_PREFIX = FHIR_OPENMRS_SYSTEM_PREFIX + "concept-system/";

public static final String FHIR_OPENMRS_INVENTORY_ITEM = FHIR_OPENMRS_CONCEPT_SYSTEM_PREFIX + "inventory-item";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,24 @@ private static ChargeItemDefinition.ChargeItemDefinitionPropertyGroupPriceCompon
Money money = new Money();
money.setValue(product.getStandardPrice());
if (currency != null) {
money.setCurrency(currency.getSymbol());

money.setCurrency(currency.getName());
addCurrencyExtension(money, currency);
}
priceComponent.setAmount(money);
// Base price
priceComponent.setType(ChargeItemDefinition.ChargeItemDefinitionPriceComponentType.BASE);
return priceComponent;
}

private static void addCurrencyExtension(Money money, Currency currency) {
money.addExtension()
.setUrl(OdooConstants.FHIR_OPENMRS_EXT_CURRENCY_SYMBOL)
.setValue(new org.hl7.fhir.r4.model.StringType(currency.getSymbol()));
money.addExtension()
.setUrl(OdooConstants.FHIR_OPENMRS_EXT_CURRENCY_UNIT_LABEL)
.setValue(new org.hl7.fhir.r4.model.StringType(currency.getCurrencyUnitLabel()));
money.addExtension()
.setUrl(OdooConstants.FHIR_OPENMRS_EXT_CURRENCY_SUBUNIT_LABEL)
.setValue(new org.hl7.fhir.r4.model.StringType(currency.getCurrencySubunitLabel()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ void shouldMapFieldsCorrectly() {
when(product.isActive()).thenReturn(true);
when(product.getStandardPrice()).thenReturn(100.0);
when(extId.getName()).thenReturn("TestID");
when(currency.getName()).thenReturn("USD");
when(currency.getSymbol()).thenReturn("$");
when(currency.getCurrencyUnitLabel()).thenReturn("Dollar");
when(currency.getCurrencySubunitLabel()).thenReturn("Cent");

resourceMap.put(OdooConstants.MODEL_PRODUCT, product);
resourceMap.put(OdooConstants.MODEL_EXTERNAL_IDENTIFIER, extId);
Expand All @@ -94,7 +97,7 @@ void shouldMapFieldsCorrectly() {
.getValue()
.doubleValue());
assertEquals(
"$",
"USD",
result.getPropertyGroup()
.get(0)
.getPriceComponent()
Expand Down Expand Up @@ -129,4 +132,45 @@ void shouldSetStatusToRetiredWhenProductIsInactive() {
assertNotNull(result);
assertEquals(Enumerations.PublicationStatus.RETIRED, result.getStatus());
}

@Test
@DisplayName("Should add currency symbol, unit label and subunit label to the money as extensions")
void shouldAddCurrencySymbolUnitLabelAndSubunitLabelToTheMoneyAsExtensions() {
var resourceMap = new HashMap<>();
Product product = mock(Product.class);
ExtId extId = mock(ExtId.class);
Currency currency = mock(Currency.class);

when(product.isActive()).thenReturn(true);
when(product.getName()).thenReturn("Test Product");
when(product.getDescription()).thenReturn("Test Description");
when(product.getLastModifiedOn()).thenReturn(new java.util.Date());
when(product.getStandardPrice()).thenReturn(100.0);
when(extId.getName()).thenReturn("TestID");
when(currency.getName()).thenReturn("USD");
when(currency.getSymbol()).thenReturn("$");
when(currency.getCurrencyUnitLabel()).thenReturn("Dollar");
when(currency.getCurrencySubunitLabel()).thenReturn("Cent");

resourceMap.put(OdooConstants.MODEL_PRODUCT, product);
resourceMap.put(OdooConstants.MODEL_EXTERNAL_IDENTIFIER, extId);
resourceMap.put(OdooConstants.MODEL_CURRENCY, currency);

ChargeItemDefinition result = mapper.toFhir(resourceMap);

assertNotNull(result);
assertEquals(1, result.getPropertyGroup().size());
assertEquals(1, result.getPropertyGroup().get(0).getPriceComponent().size());

var priceComponent =
result.getPropertyGroup().get(0).getPriceComponent().get(0);
assertEquals(100.0, priceComponent.getAmount().getValue().doubleValue());
assertEquals("USD", priceComponent.getAmount().getCurrency());

// Check the extensions
var extensions = priceComponent.getAmount().getExtension();
assertEquals("$", extensions.get(0).getValue().toString());
assertEquals("Dollar", extensions.get(1).getValue().toString());
assertEquals("Cent", extensions.get(2).getValue().toString());
}
}

0 comments on commit 9f8d7b1

Please sign in to comment.