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 java.util.List;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
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.AuditHistory;
import gov.va.med.pbm.ampl.model.Comment;
import gov.va.med.pbm.ampl.model.Problem;
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;
import gov.va.med.pbm.ampl.utility.operations.SearchOperation;
import gov.va.med.pbm.ampl.utility.operations.criteria.SearchCriteria;
/**
* This class generates mock data for the {@link EnvironmentInternalController} end points.
*
* @author Ian Meinert
* @author Pavani Mukthipudi
* @author David Overstreet
*
*/
public class ProblemData {
private String patientId;
/**
* The application logger.
*/
static final Logger LOGGER = LoggerFactory.getLogger(ProblemData.class);
/**
* Single parameter constructor.
*
* @param patientId {@link Long}
*/
public ProblemData(String patientId) {
this.patientId = patientId;
}
/**
* Generates a {@link Problem} {@link Collection} used in mock cases.
*
* @param c the count of {@link Problem} objects to create
* @return a {@link Collection} of {@link Problem} with mock data
*/
public Collection<Problem> testProblemListForPatient(int c) {
Collection<Problem> problemList = new ArrayList<Problem>();
FacilityData facilityData = new FacilityData();
for (int i = 1; i <= c; i++) {
String s = Problem.class.getSimpleName().toUpperCase() + i;
OffsetDateTime dt = DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN);
Problem problem = new Problem();
problem.setPatientId(this.patientId);
problem.setDiagnosis("Diagnosis_" + i);
problem.setDiagnosisCode("DiagnosisCode_" + i);
problem.setCodingSystem("CodingSystem_" + i);
problem.setCategory("Category_" + i);
problem.setOnsetDate(dt);
problem.setStatus((String) CollectionUtility.getRandom(new String[] { "Active", "Inactive", "Removed" }));
problem.setVerified(
(String) CollectionUtility.getRandom(new String[] { "Verified", "Unverified", "Removed", "Unknown" }));
problem.setImmediacy((String) CollectionUtility.getRandom(new String[] { "Acute", "Chronic", "Unknown" }));
problem.setDescription("Description_" + i);
problem.setCondition("Condition_" + i);
problem.setServiceConnected((boolean) CollectionUtility.getRandom(new Boolean[] { true, false }));
problem.setExposures(this.testExposures(NumberUtility.randomBetween(0, MockDataConstants.SIX)));
problem.setService("Service_" + i);
problem.setClinic("Clinic_" + i);
problem.setProvider("Provider_" + i);
problem.setEnteredBy("EnteredBy_" + i);
problem.setEntryDate(DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN));
problem.setRecordedBy("RecordedBy_" + i);
problem
.setRecordedDate(DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN));
problem.setLastUpdatedDate(
DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN));
problem.setComments(
this.testCommentCollection("Comment_" + s, NumberUtility.randomBetween(0, MockDataConstants.FOUR)));
problem.setFacility(facilityData.testFacilityForPatient(i));
problem.setAuditHistory(this.testAuditHistoryCollection(NumberUtility.randomBetween(0, MockDataConstants.FOUR)));
problemList.add(problem);
}
return problemList;
}
/**
* Creates a list of exposure strings for a {@link Problem}.
*
* @param c integer indicating the number of exposure strings to set
* @return an array of exposure strings for a {@link Problem}
*/
private String[] testExposures(int c) {
Collection<String> expList = new ArrayList<String>();
String[] listOfExposures = new String[] { "Agent Orange Exposure", "Ionizing Radiation Exposure",
"Persian Gulf Exposure", "Head and/or Neck Cancer", "Military Sexual Trauma", "Combat Veteran",
"Shipboard Hazard & Defense" };
for (int i = 0; i <= c; i++) {
expList.add(listOfExposures[i]);
}
return expList.toArray(new String[expList.size()]);
}
/**
* Creates a collection of {@link AuditHistory} objects for a {@link Problem} with mock data.
*
* @param c integer indicating the number of {@link AuditHistory} objects to generate
* @return {@link Collection} of {@link AuditHistory} objects for a {@link Problem}
*/
private Collection<AuditHistory> testAuditHistoryCollection(int c) {
Collection<AuditHistory> auditHistoryList = new ArrayList<AuditHistory>();
for (int i = 1; i <= c; i++) {
AuditHistory auditHistory = new AuditHistory();
auditHistory.setFieldChanged("Field_" + i);
auditHistory.setOldValue("OldValue_" + i);
auditHistory.setNewValue("NewValue_" + i);
auditHistory.setModifiedBy("ModifiedBy_" + i);
auditHistory
.setModifiedDate(DateUtility.randomOffsetDateTime(MockDataConstants.TWO_K, MockDataConstants.TWO_K_EIGHTTEEN));
auditHistoryList.add(auditHistory);
}
return auditHistoryList;
}
/**
* Creates a collection of {@link Comment} objects for a {@link Problem} with mock data.
*
* @param s string representing mock data for comment text and signature
* @param c integer indicating the number of {@link Comment} objects to generate
* @return {@link Collection} of {@link Comment} objects for a {@link Problem}
*/
private Collection<Comment> testCommentCollection(String s, int c) {
SignatureData sig = new SignatureData();
Collection<Comment> commentsList = new ArrayList<Comment>();
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));
comment.setText(s + "_" + i);
commentsList.add(comment);
}
return commentsList;
}
/**
* Applies given search criteria to generated test data.
*
* @param search String value of the {@link SearchCriteria}
* @return collection of {@link Problem}
*/
public Collection<Problem> searchProblems(Optional<String> search) {
String searchParams = search.isPresent() ? search.get() : new String();
// set up the Problem search operation
SearchOperation<Problem> opProblem = new SearchOperation<Problem>();
Collection<Problem> problems = this
.testProblemListForPatient(NumberUtility.randomBetween(0, MockDataConstants.ONE_HUNDRED));
opProblem.setSearchParams(searchParams);
// now that the search params are set, lets see if there is one for the comments
Iterator<Entry<String, List<SearchCriteria>>> it = opProblem.getSearchParams().entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, List<SearchCriteria>> pair = (Map.Entry<String, List<SearchCriteria>>) it.next();
List<SearchCriteria> criterias = pair.getValue();
for (int i = 0; i < pair.getValue().size(); i++) {
SearchCriteria criteria = pair.getValue().get(i);
String[] keys = criteria.getKey().split("\\.");
if (criteria.getKey().contains(".") && keys[0].equalsIgnoreCase("comments")) {
// Instantiate the operation and set the found search parameter
SearchOperation<Comment> opComment = new SearchOperation<Comment>();
criteria.setKey(keys[1]);
opComment.setSearchParams(criteria.toString());
Iterator<Problem> probIt = problems.iterator();
// Apply the filter to each of the Problems comments.
while (probIt.hasNext()) {
Collection<Comment> c = new ArrayList<Comment>();
Problem p = probIt.next();
c.addAll(p.getComments());
if (opComment.search(c).isEmpty()) {
probIt.remove();
}
}
// the criteria was already applied, remove it
criterias.remove(criteria);
}
}
// update the search params
opProblem.getSearchParams().put(pair.getKey(), criterias);
}
problems = opProblem.search(problems);
return problems;
}
/**
* This method implements a business rule which sorts the problem list comments by date desc by default.
*
* @param problem collection of {@link Problem}
* @return collection of {@link Problem}
*/
public Collection<Problem> sortCommentsByDateDesc(Collection<Problem> problem) {
List<Problem> problemCollection = new ArrayList<>(problem);
SortOperation<Comment> sortOperation = new SortOperation<Comment>();
sortOperation.setSortParams("signature.signDate[DESC]");
for (Problem item : problemCollection) {
if (!item.getComments().isEmpty()) {
Collection<Comment> temp = sortOperation.sort(item.getComments());
item.setComments(temp);
}
}
return problemCollection;
}
}