Commit 612a6e35 authored by sunchu chowdary's avatar sunchu chowdary

Capture dose/unit from the data file (product.txt) and persist in the

database. Display strength information in JSON response. For
multi-component drugs, dose/unit is assigned based on the order the
components appear in the product.txt file.
parent 32ecfc12
......@@ -55,4 +55,7 @@ UnitOfMeasure of the UNDEFINED type (see: Dose.UNDEFINED).
This is done because active ingredient quantities are not represented (or
represented incompletely) within the underlying dataset. Without using a
third party data set, there is no better way to model this information.
\ No newline at end of file
third party data set, there is no better way to model this information.
Update: For multi-component drugs, dose/unit is assigned based on the
order in which the components appear in the data file (product.txt).
\ No newline at end of file
......@@ -400,6 +400,12 @@ implements DictionaryService
final String dosageForm =
r.get(field(name("dosage_form"), String.class));
final String activeNumeratorStrength =
r.get(field(name("active_numerator_strength"), String.class));
final String activeIngredUnit =
r.get(field(name("active_ingred_unit"), String.class));
final String name =
r.get(field(name("proprietary_name"), String.class));
......@@ -417,17 +423,48 @@ implements DictionaryService
d = Collections.singletonList(new Drug(fallback));
}
final Dose dose = d.size() == 1
? Dose.create("unit", new UnitOfMeasure(dosageForm, false), 1, false)
: Dose.UNDEFINED;
final Dose dose = d.size() >= 1
? Dose.create(activeNumeratorStrength, new UnitOfMeasure(activeIngredUnit, false), 1, false)
: Dose.UNDEFINED;
final Set<ProductComponent> components =
final List<ProductComponent> componentList =
d.stream()
.map(drug -> new ProductComponent(drug, dose))
.collect(Collectors.toSet());
.collect(Collectors.toList());
/*
* Handle multi-component drugs with separate dose/unit for each component.
* Dose/unit for each component is assigned in the order they appear in the data file.
*/
return new NDCProduct(name, ndc, npns, components,
dosageForm);
Set<ProductComponent> componentSet = new HashSet<>();
if (componentList.size() > 1)
{
String [] doses = activeNumeratorStrength.split(";");
String [] units = activeIngredUnit.split(";");
int i=0;
for (ProductComponent p : componentList) {
if ((i < doses.length) && (i < units.length))
{
componentSet.add(new ProductComponent(p.drug(), Dose.create(doses[i].trim(), new UnitOfMeasure(units[i].trim(), false), 1, false)));
i++;
}
else
{
componentSet.add(new ProductComponent(p.drug(), Dose.UNDEFINED));
i++;
}
}
}
else
{
componentSet.addAll(componentList);
}
return new NDCProduct(name, ndc, npns, componentSet,
dosageForm, activeNumeratorStrength, activeIngredUnit);
});
}
......
......@@ -57,15 +57,19 @@ implements Product
{
private final Set<ProductComponent> components;
private final String dosageForm;
private final String activeNumeratorStrength;
private final String activeIngredUnit;
private final String name;
private final NDC ndc;
private final Set<String> npns;
public NDCProduct(String name, NDC ndc, Set<String> npns,
Set<ProductComponent> components, String dosageForm)
Set<ProductComponent> components, String dosageForm, String activeNumeratorStrength, String activeIngredUnit)
{
this.components = new HashSet<>(components);
this.dosageForm = dosageForm;
this.activeNumeratorStrength = activeNumeratorStrength;
this.activeIngredUnit = activeIngredUnit;
this.name = name;
this.ndc = ndc;
this.npns = new HashSet<>(npns);
......@@ -112,6 +116,20 @@ implements Product
{
return this.dosageForm;
}
@JsonGetter("active_numerator_strength")
public String
activeNumeratorStrength()
{
return this.activeNumeratorStrength;
}
@JsonGetter("active_ingred_unit")
public String
activeIngredUnit()
{
return this.activeIngredUnit;
}
@Override
public String
......@@ -119,9 +137,21 @@ implements Product
{
return this.name()
+ " (NDC: " + this.ndc().toString()
+ ", dosage form: " + this.dosageForm() + ")";
+ componentStrength()
+ ", [dosage form: " + this.dosageForm() + "])";
}
public String componentStrength()
{
StringBuffer dispName = new StringBuffer();
dispName.append(", [Components: ");
for (ProductComponent p : this.components) {
dispName.append(p.drug().canonicalName() + " " + p.dose().name() + " " + p.dose().unit().name() + ", ");
}
dispName.setLength(dispName.length() - 2);
dispName.append("]");
return dispName.toString();
}
}
......@@ -90,7 +90,7 @@ implements DBDictionaryProvider, ConfigurableProvider
@Override
public String persistenceID()
{
return null;
return "DB-" + this.getClass().getCanonicalName();
}
@Override
......@@ -143,6 +143,10 @@ implements DBDictionaryProvider, ConfigurableProvider
e.getProductNDC())
.set(field(name("dosage_form"), String.class),
e.getDosageFormName())
.set(field(name("active_numerator_strength"), String.class),
e.getActiveNumeratorStrength())
.set(field(name("active_ingred_unit"), String.class),
e.getActiveIngredUnit())
.set(field(name("proprietary_name"), String.class),
e.getProprietaryName())
.set(field(name("phonetic_hash"), String.class),
......
......@@ -116,6 +116,8 @@ implements Iterable<Entry>, Closeable
r.get("PRODUCTTYPENAME"),
r.get("PROPRIETARYNAME"),
r.get("DOSAGEFORMNAME"),
r.get("ACTIVE_NUMERATOR_STRENGTH"),
r.get("ACTIVE_INGRED_UNIT"),
parseMVColumn(r.get("NONPROPRIETARYNAME")),
parseMVColumn(r.get("SUBSTANCENAME")));
......@@ -280,6 +282,8 @@ implements Iterable<Entry>, Closeable
private final String productTypeName;
private final String proprietaryName;
private final String dosageFormName;
private final String activeNumeratorStrength;
private final String activeIngredUnit;
private final List<String> nonProprietaryNames;
private final List<String> substanceNames;
......@@ -288,6 +292,7 @@ implements Iterable<Entry>, Closeable
private Entry(String productID, String productNDC,
String productTypeName, String proprietaryName,
String dosageFormName,
String activeNumeratorStrength, String activeIngredUnit,
List<String> nonProprietaryNames, List<String> substanceNames)
{
this.productID = productID;
......@@ -295,6 +300,8 @@ implements Iterable<Entry>, Closeable
this.productTypeName = productTypeName;
this.proprietaryName = proprietaryName;
this.dosageFormName = dosageFormName;
this.activeNumeratorStrength = activeNumeratorStrength;
this.activeIngredUnit = activeIngredUnit;
this.nonProprietaryNames = nonProprietaryNames;
this.substanceNames = substanceNames;
}
......@@ -327,6 +334,16 @@ implements Iterable<Entry>, Closeable
{
return this.dosageFormName;
}
public final String getActiveNumeratorStrength()
{
return this.activeNumeratorStrength;
}
public final String getActiveIngredUnit()
{
return this.activeIngredUnit;
}
public final List<String>
getNonProprietaryNames()
......
......@@ -3,12 +3,14 @@ DROP TABLE IF EXISTS "substances";
DROP TABLE IF EXISTS "entries";
CREATE TABLE "entries" (
"id" UUID PRIMARY KEY NOT NULL,
"product_id" VARCHAR(256) NOT NULL,
"ndc" VARCHAR(14) NOT NULL,
"dosage_form" VARCHAR(256) NOT NULL,
"proprietary_name" VARCHAR(512) NOT NULL,
"phonetic_hash" VARCHAR(32) NOT NULL
"id" UUID PRIMARY KEY NOT NULL,
"product_id" VARCHAR(256) NOT NULL,
"ndc" VARCHAR(14) NOT NULL,
"dosage_form" VARCHAR(256) NOT NULL,
"active_numerator_strength" VARCHAR(256),
"active_ingred_unit" VARCHAR(256),
"proprietary_name" VARCHAR(512) NOT NULL,
"phonetic_hash" VARCHAR(32) NOT NULL
);
CREATE INDEX IF NOT EXISTS "entries_n_idx" ON "entries" ("ndc");
CREATE INDEX IF NOT EXISTS "entries_d_idx" ON "entries" ("dosage_form");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment