Summary Table
Categories |
Total Count |
PII |
0 |
URL |
0 |
DNS |
0 |
EKL |
0 |
IP |
0 |
PORT |
0 |
VsID |
0 |
CF |
0 |
AI |
0 |
VPD |
0 |
PL |
0 |
Other |
0 |
File Content
package gov.va.med.pbm.ampl.asset.mock;
import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.Collection;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import gov.va.med.pbm.ampl.constant.MockDataConstants;
import gov.va.med.pbm.ampl.controller.EnvironmentInternalController;
import gov.va.med.pbm.ampl.model.Allergy;
import gov.va.med.pbm.ampl.model.AllergyReaction;
import gov.va.med.pbm.ampl.model.AllergySeverity;
import gov.va.med.pbm.ampl.model.Comment;
import gov.va.med.pbm.ampl.utility.CollectionUtility;
import gov.va.med.pbm.ampl.utility.DateUtility;
import gov.va.med.pbm.ampl.utility.NumberUtility;
import gov.va.med.pbm.ampl.utility.operations.SortOperation;
/**
* This class generates mock data for the {@link EnvironmentInternalController} end points .
*
* @author Ian Meinert
* @author Pavani Mukthipudi
*
* @since 1.0
*/
public class AllergyData {
private String patientId;
/**
* The application logger.
*/
static final Logger LOGGER = LoggerFactory.getLogger(AllergyData.class);
/**
* Single parameter constructor.
*
* @param patientId {@link Long}
*/
public AllergyData(String patientId) {
this.patientId = patientId;
}
/**
* Generates an {@link Allergy} {@link Collection} used in mock cases.
*
* @param c the count of {@link Allergy} to create
* @return a {@link Collection} of {@link Allergy} with mock data
*/
public Collection<Allergy> testAllergiesForPatient(int c) {
Collection<Allergy> ac = new ArrayList<Allergy>();
SignatureData sig = new SignatureData();
FacilityData f = new FacilityData();
// for some fields generate mock data that is tspecific to a single allergy entry
// also generate mock data that is common across multiple allergies that can be used for sorting data
for (int i = 1; i <= c; i++) {
String s = Allergy.class.getSimpleName().toUpperCase() + i;
int k = NumberUtility.randomBetween(MockDataConstants.ZERO, MockDataConstants.SEVEN);
OffsetDateTime dt = DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN);
Allergy a = new Allergy();
if (!NumberUtility.isPrime(i) || i <= MockDataConstants.THREE) {
a.setGmrAllergy(s + ": gmrAllergy");
} else {
a.setAllergyAssessment(
(String) CollectionUtility.getRandom(new String[] { "NKA", "NKDA", "NDKA", new String() }));
}
a.setCategory(testCategory(NumberUtility.randomBetween(0, 2)));
a.setCausativeAgent(s + ": causativeAgent");
a.setComments(
this.testCommentCollection(s + ": comment_", NumberUtility.randomBetween(0, MockDataConstants.SEVEN)));
a.setDrugClass(
testDrugClassCollection(s + ": drugClass_", NumberUtility.randomBetween(0, MockDataConstants.SEVEN)));
a.setFacility(f.testFacilityForPatient(k));
a.setGmrAllergySource(this.generateRandomFileEntry());
a.setIngredients(
testIngredientsCollection(s + ": ingredient_", NumberUtility.randomBetween(0, MockDataConstants.SEVEN)));
if (k < MockDataConstants.THREE) {
// generate a random number of reactions with random severity for the observed allergy
a.setObservedHistorical("OBSERVED");
a.setReactions(testReactionsCollection(s, false, NumberUtility.randomBetween(0, MockDataConstants.FOUR)));
a.setVerified("Y");
a.setVerifierSig(sig.generateSignature(k,
dt.plusHours(NumberUtility.randomBetween(MockDataConstants.FIFTEEN, MockDataConstants.ONE_TWENTY))));
} else {
// generate a random number of reactions with no severity for the historical allergy
a.setObservedHistorical("HISTORICAL");
a.setReactions(testReactionsCollection(s, true, NumberUtility.randomBetween(0, MockDataConstants.FOUR)));
a.setVerified("N");
}
a.setPatientId(patientId);
if (NumberUtility.isPrime(i)) {
a.setOriginatorSig(sig.generateSignature(k, dt));
}
// XXX Adding Status to Patient For Testing purposes Note Entered In Error Will Not Appear
// String[] statuses = new String[] { "active", "entered-in-error", "refuted", "resolved", "inactive", "confirmed",
// "unconfirmed", new String() };
// a.setStatus((String) CollectionUtility.getRandom(statuses));
a.setStatus(testAllergyStatus(NumberUtility.randomBetween(0, 1)));
if ("entered-in-error".equalsIgnoreCase(a.getStatus())) {
a.setEnteredInError(this.testCommentCollection(s, c)[0]);
}
ac.add(a);
}
return ac;
}
/**
* This method implements a business rule which moves the missing assessments and NKDAs to the top of the stack.
*
* @param allergies list of {@link Allergy}
* @return collection of {@link Allergy}
*/
public Collection<Allergy> sortAllergyAssessments(Collection<Allergy> allergies) {
SortOperation<Allergy> sortOperation = new SortOperation<Allergy>();
sortOperation.setSortParams("allergyAssessment[DESC]");
Collection<Allergy> temp = sortOperation.sortFieldWithNull(allergies);
return temp;
}
/**
* This method generates a mock {@link Allergy} status value.
*
* @param c an int representing mock incrementing
* @return String value based on the given int
*/
private String testAllergyStatus(int c) {
switch (c) {
case MockDataConstants.ZERO:
return "active";
case MockDataConstants.ONE:
return "entered-in-error";
case MockDataConstants.TWO:
return "refuted";
case MockDataConstants.THREE:
return "resolved";
case MockDataConstants.FOUR:
return "inactive";
case MockDataConstants.FIVE:
return "confirmed";
case MockDataConstants.SIX:
return "unconfirmed";
default:
return new String();
}
}
/**
* Method to generate a {@link Collection} of mock {@link AllergyReaction} (signs and symptoms) for an {@link Allergy}.
*
* @param s string used to append to mock values
* @param isHistorical boolean indicating historical or observed {@link Allergy}
* @param c integer indicating the number of {@link AllergyReaction} to generate
* @return {@link Collection} of {@link AllergyReaction}
*/
private Collection<AllergyReaction> testReactionsCollection(String s, boolean isHistorical, int c) {
Collection<AllergyReaction> rc = new ArrayList<AllergyReaction>();
for (int i = 1; i <= c; i++) {
AllergyReaction r = new AllergyReaction();
String[] m = new String[i];
for (int j = 0; j < i; j++) {
m[j] = "Reaction" + i + "_manifestation_" + j;
}
r.setCertainty(s + " certainty_" + i);
r.setDescription("description for AllergyReaction" + i + " for " + s);
r.setManifestation(m);
r.setMechanism(this.testMechanism(NumberUtility.randomBetween(0, 2)));
r.setNote("note for AllergyReaction" + i + " for " + s);
r.setOnset(DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN));
// if the allergy is historical set severity to no severity found
if (isHistorical) {
r.setSeverity(this.testAllergySeverity(0));
} else {
r.setSeverity(this.testAllergySeverity(NumberUtility.randomBetween(0, MockDataConstants.THREE)));
}
r.setSubstance(s + " substance_" + i);
r.setVerifiedTime(DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN));
rc.add(r);
}
return rc;
}
/**
* This method generates a mock {@link Allergy} category value.
*
* @param c an int representing mock incrementing
* @return String value based on the given int
*/
private String testCategory(int c) {
switch (c) {
case 0:
return "DRUG";
case 1:
return "FOOD";
case 2:
return "OTHER";
default:
return new String();
}
}
/**
* This method generates a mock {@link AllergyReaction} mechanism.
*
* @param c an int representing mock incrementing
* @return String value based on the given int
*/
private String testMechanism(int c) {
switch (c) {
case 0:
return "ALLERGY";
case 1:
return "PHARMACOLOGIC";
case 2:
return "UNKNOWN";
default:
return new String();
}
}
/**
* This method generates a mock {@link AllergySeverity}.
*
* @param c an int representing mock incrementing
* @return String value based on the given int
*/
private AllergySeverity testAllergySeverity(int c) {
switch (c) {
case 1:
return AllergySeverity.MILD;
case 2:
return AllergySeverity.MODERATE;
case MockDataConstants.THREE:
return AllergySeverity.SEVERE;
default:
return AllergySeverity.NO_SEVERITY_FOUND;
}
}
/**
* This method generates an String Array of ingredients for mock data.
*
* @param s String representing mock data
* @param c an int representing mock incrementing
* @return a String Array
*/
private String[] testIngredientsCollection(String s, int c) {
Collection<String> a = new ArrayList<String>();
for (int i = 1; i <= c; i++) {
a.add(s + i);
}
return a.toArray(new String[a.size()]);
}
/**
* This method generates a String Array drug classes for mock data.
*
* @param s String representing mock data
* @param c an int representing mock incrementing
* @return a String Array
*/
private String[] testDrugClassCollection(String s, int c) {
Collection<String> a = new ArrayList<String>();
for (int i = 1; i <= c; i++) {
a.add(s + i);
}
return a.toArray(new String[a.size()]);
}
/**
* This method generates an array of comments for mock data.
*
* @param s String representing mock data for comment text and signature
* @param c an int representing mock incrementing
* @return a Comment Array
*/
private Comment[] testCommentCollection(String s, int c) {
Collection<Comment> a = new ArrayList<Comment>();
SignatureData sig = new SignatureData();
int k;
OffsetDateTime dt;
for (int i = 1; i <= c; i++) {
Comment comment = new Comment();
k = NumberUtility.randomBetween(MockDataConstants.ZERO, MockDataConstants.SEVEN);
dt = DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN);
comment.setClassification("Classification_" + i);
comment.setSignature(sig.generateSignature(k,
dt.plusMinutes(NumberUtility.randomBetween(MockDataConstants.FIFTEEN, MockDataConstants.ONE_TWENTY))));
comment.setText(s + i);
a.add(comment);
}
return a.toArray(new Comment[a.size()]);
}
/**
* Generates a random file entry used by gmrAllergySource.
*
* @return string
*/
private String generateRandomFileEntry() {
String[] entries = { "120.82", "50.6", "50.416", "50.605" };
int index = NumberUtility.randomBetween(0, entries.length);
return "00;ZZZZ(" + entries[index] + ",";
}
}