use of gov.ca.cwds.rest.api.domain.cms.PostedClient in project API by ca-cwds.
the class ScreeningToReferralService method processParticipants.
private void processParticipants(ScreeningToReferral screeningToReferral, Set<ErrorMessage> messages, String dateStarted, String referralId, Set<Participant> resultParticipants, HashMap<Long, String> victimClient, HashMap<Long, String> perpatratorClient) {
Set<Participant> participants = screeningToReferral.getParticipants();
for (Participant incomingParticipant : participants) {
try {
if (!ParticipantValidator.hasValidRoles(incomingParticipant)) {
String message = " Participant contains incompatiable roles ";
ServiceException exception = new ServiceException(message);
logError(message, exception, messages);
// next participant
continue;
}
} catch (Exception e1) {
String message = e1.getMessage();
logError(message, e1, messages);
// next participant
continue;
}
String genderCode = "";
if (!incomingParticipant.getGender().isEmpty()) {
genderCode = incomingParticipant.getGender().toUpperCase().substring(0, 1);
}
Set<String> roles = new HashSet<>(incomingParticipant.getRoles());
/**
* process the roles of this participant
*/
for (String role : roles) {
try {
if (ParticipantValidator.roleIsReporterType(role) && (!ParticipantValidator.roleIsAnonymousReporter(role) && !ParticipantValidator.selfReported(incomingParticipant))) {
/*
* CMS Reporter - if role is 'mandated reporter' or 'non-mandated reporter' and not
* anonymous reporter or self-reported
*/
try {
savedReporter = processReporter(incomingParticipant, role, referralId, messages);
incomingParticipant.setLegacyId(savedReporter.getReferralId());
incomingParticipant.setLegacySourceTable(REPORTER_TABLE_NAME);
} catch (ServiceException e) {
String message = e.getMessage();
logError(message, e, messages);
// next role
continue;
}
} else {
// reporter
if (!ParticipantValidator.roleIsAnonymousReporter(role)) {
String clientId;
if (incomingParticipant.getLegacyId() == null || incomingParticipant.getLegacyId().isEmpty()) {
// legacy Id not set - create a CLIENT row
PostedClient postedClient;
// not an anonymous reporter participant - create client
Client client = Client.createWithDefaults(incomingParticipant, dateStarted, genderCode);
buildErrors(messages, validator.validate(client));
postedClient = this.clientService.create(client);
clientId = postedClient.getId();
incomingParticipant.setLegacyId(clientId);
incomingParticipant.setLegacySourceTable(CLIENT_TABLE_NAME);
} else {
// legacy Id passed - check for existenct in CWS/CMS - no update yet
clientId = incomingParticipant.getLegacyId();
Client foundClient = this.clientService.find(clientId);
if (foundClient == null) {
String message = " Legacy Id of Participant does not correspond to an existing CWS/CMS Client ";
ServiceException se = new ServiceException(message);
logError(message, se, messages);
// next role
continue;
}
}
// CMS Referral Client
ReferralClient referralClient = ReferralClient.createWithDefault(ParticipantValidator.selfReported(incomingParticipant), referralId, clientId, DEFAULT_COUNTY_SPECIFIC_CODE, DEFAULT_APPROVAL_STATUS_CODE);
// validate referral client
buildErrors(messages, validator.validate(referralClient));
try {
gov.ca.cwds.rest.api.domain.cms.ReferralClient postedReferralClient = this.referralClientService.create(referralClient);
} catch (ServiceException se) {
logError(se.getMessage(), se, messages);
}
/*
* determine other participant/roles attributes relating to CWS/CMS allegation
*/
if (ParticipantValidator.roleIsVictim(role)) {
victimClient.put(incomingParticipant.getId(), clientId);
// since this is the victim - process the ChildClient
try {
this.processChildClient(incomingParticipant, clientId, messages);
} catch (ServiceException e) {
String message = e.getMessage();
logError(message, e, messages);
// next role
continue;
}
}
if (ParticipantValidator.roleIsPerpetrator(role)) {
perpatratorClient.put(incomingParticipant.getId(), clientId);
}
try {
// addresses associated with a client
Participant resultParticipant = processClientAddress(incomingParticipant, referralId, clientId, messages);
} catch (ServiceException e) {
String message = e.getMessage();
logError(message, e, messages);
// next role
continue;
}
}
}
} catch (Exception e) {
String message = e.getMessage();
logError(message, e, messages);
}
resultParticipants.add(incomingParticipant);
}
// next role
}
// next participant
}
use of gov.ca.cwds.rest.api.domain.cms.PostedClient in project API by ca-cwds.
the class ClientService method create.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
*/
@Override
public PostedClient create(Request request) {
assert request instanceof gov.ca.cwds.rest.api.domain.cms.Client;
gov.ca.cwds.rest.api.domain.cms.Client client = (gov.ca.cwds.rest.api.domain.cms.Client) request;
try {
String lastUpdatedId = staffPersonIdRetriever.getStaffPersonId();
Client managed = new Client(CmsKeyIdGenerator.cmsIdGenertor(lastUpdatedId), client, lastUpdatedId);
managed = clientDao.create(managed);
// checking the staffPerson county code
StaffPerson staffperson = staffpersonDao.find(managed.getLastUpdatedId());
if (staffperson != null && !(triggerTablesDao.getLaCountySpecificCode().equals(staffperson.getCountyCode()))) {
nonLaCountyTriggers.createClientCountyTrigger(managed);
}
return new PostedClient(managed, false);
} catch (EntityExistsException e) {
LOGGER.info("Client already exists : {}", client);
throw new ServiceException(e);
}
}
use of gov.ca.cwds.rest.api.domain.cms.PostedClient in project API by ca-cwds.
the class ClientServiceTest method createReturnsGeneratedId.
/*
* Test for checking the new Client Id generated and lenght is 10
*/
@SuppressWarnings("javadoc")
@Test
public void createReturnsGeneratedId() throws Exception {
Client clientDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Client/valid/serviceValid.json"), Client.class);
when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenAnswer(new Answer<gov.ca.cwds.data.persistence.cms.Client>() {
@Override
public gov.ca.cwds.data.persistence.cms.Client answer(InvocationOnMock invocation) throws Throwable {
gov.ca.cwds.data.persistence.cms.Client report = (gov.ca.cwds.data.persistence.cms.Client) invocation.getArguments()[0];
return report;
}
});
PostedClient returned = clientService.create(clientDomain);
assertEquals(returned.getId().length(), 10);
PostedClient newReturned = clientService.create(clientDomain);
Assert.assertNotEquals(returned.getId(), newReturned.getId());
}
use of gov.ca.cwds.rest.api.domain.cms.PostedClient in project API by ca-cwds.
the class ClientServiceTest method testCreateReturnsCorrectEntity.
@Override
@Test
public void testCreateReturnsCorrectEntity() throws Exception {
String id = "Aaeae9r0F4";
Client clientDomain = MAPPER.readValue(fixture("fixtures/domain/legacy/Client/valid/serviceValid.json"), Client.class);
gov.ca.cwds.data.persistence.cms.Client toCreate = new gov.ca.cwds.data.persistence.cms.Client(id, clientDomain, "q1p");
Client request = new Client(toCreate, false);
when(clientDao.create(any(gov.ca.cwds.data.persistence.cms.Client.class))).thenReturn(toCreate);
PostedClient expected = new PostedClient(toCreate, false);
PostedClient returned = clientService.create(request);
assertThat(returned, is(expected));
}
use of gov.ca.cwds.rest.api.domain.cms.PostedClient in project API by ca-cwds.
the class CmsReferralService method create.
/**
* {@inheritDoc}
*
* @see gov.ca.cwds.rest.services.CrudsService#create(gov.ca.cwds.rest.api.Request)
*/
@UnitOfWork(value = "cms")
@Override
public Response create(Request request) {
assert request instanceof CmsReferral;
CmsReferral cmsReferral = (CmsReferral) request;
PostedReferral referral = this.referralService.create(cmsReferral.getReferral());
String referralId = referral.getId();
List<String> clientIds = new ArrayList<>();
int clientInst = 0;
String sourceTableCode = "C";
Set<ClientUc> resultClientUc = new LinkedHashSet<>();
Set<PostedClient> postedClients = new LinkedHashSet<>();
if (cmsReferral.getClient() != null && !cmsReferral.getClient().isEmpty()) {
for (Client incomingClient : cmsReferral.getClient()) {
PostedClient savedClient = null;
if (incomingClient.getExistingClientId() != null) {
savedClient = clientService.findInboundId(incomingClient.getExistingClientId());
}
if (savedClient == null) {
Client client = new Client(incomingClient.getExistingClientId(), incomingClient.getAdjudicatedDelinquentIndicator(), incomingClient.getAdoptionStatusCode(), incomingClient.getAlienRegistrationNumber(), incomingClient.getBirthCity(), incomingClient.getBirthCountryCodeType(), incomingClient.getBirthDate(), incomingClient.getBirthFacilityName(), incomingClient.getBirthStateCodeType(), incomingClient.getBirthplaceVerifiedIndicator(), incomingClient.getChildClientIndicatorVar(), incomingClient.getClientIndexNumber(), incomingClient.getCommentDescription(), incomingClient.getCommonFirstName(), incomingClient.getCommonLastName(), incomingClient.getCommonMiddleName(), incomingClient.getConfidentialityActionDate(), incomingClient.getConfidentialityInEffectIndicator(), incomingClient.getCreationDate(), incomingClient.getCurrCaChildrenServIndicator(), incomingClient.getCurrentlyOtherDescription(), incomingClient.getCurrentlyRegionalCenterIndicator(), incomingClient.getDeathDate(), incomingClient.getDeathDateVerifiedIndicator(), incomingClient.getDeathPlace(), incomingClient.getDeathReasonText(), incomingClient.getDriverLicenseNumber(), incomingClient.getDriverLicenseStateCodeType(), incomingClient.getEmailAddress(), incomingClient.getEstimatedDobCode(), incomingClient.getEthUnableToDetReasonCode(), incomingClient.getFatherParentalRightTermDate(), incomingClient.getGenderCode(), incomingClient.getHealthSummaryText(), incomingClient.getHispUnableToDetReasonCode(), incomingClient.getHispanicOriginCode(), incomingClient.getImmigrationCountryCodeType(), incomingClient.getImmigrationStatusType(), incomingClient.getIncapacitatedParentCode(), incomingClient.getIndividualHealthCarePlanIndicator(), incomingClient.getLimitationOnScpHealthIndicator(), incomingClient.getLiterateCode(), incomingClient.getMaritalCohabitatnHstryIndicatorVar(), incomingClient.getMaritalStatusType(), incomingClient.getMilitaryStatusCode(), incomingClient.getMotherParentalRightTermDate(), incomingClient.getNamePrefixDescription(), incomingClient.getNameType(), incomingClient.getOutstandingWarrantIndicator(), incomingClient.getPrevCaChildrenServIndicator(), incomingClient.getPrevOtherDescription(), incomingClient.getPrevRegionalCenterIndicator(), incomingClient.getPrimaryEthnicityType(), incomingClient.getPrimaryLanguageType(), incomingClient.getReligionType(), incomingClient.getSecondaryLanguageType(), incomingClient.getSensitiveHlthInfoOnFileIndicator(), incomingClient.getSensitivityIndicator(), incomingClient.getSoc158PlacementCode(), incomingClient.getSoc158SealedClientIndicator(), incomingClient.getSocialSecurityNumChangedCode(), incomingClient.getSocialSecurityNumber(), incomingClient.getSuffixTitleDescription(), incomingClient.getTribalAncestryClientIndicatorVar(), incomingClient.getTribalMembrshpVerifctnIndicatorVar(), incomingClient.getUnemployedParentCode(), incomingClient.getZippyCreatedIndicator(), null);
PostedClient postedclient = this.clientService.create(client);
postedClients.add(postedclient);
clientIds.add(postedclient.getId());
if (postedclient.getCommonFirstName() != null) {
ClientUc clientUc = new ClientUc(postedclient.getId(), sourceTableCode, postedclient.getCommonFirstName().toUpperCase(), postedclient.getCommonLastName().toUpperCase(), postedclient.getCommonMiddleName().toUpperCase());
clientUc = this.clientUcService.create(clientUc);
resultClientUc.add(clientUc);
}
} else {
clientIds.add(savedClient.getId());
postedClients.add(savedClient);
}
}
}
Set<PostedAllegation> resultAllegation = new LinkedHashSet<>();
if (cmsReferral.getAllegation() != null && !cmsReferral.getAllegation().isEmpty()) {
for (Allegation incomingAllegation : cmsReferral.getAllegation()) {
Allegation allegation = new Allegation(incomingAllegation.getAbuseEndDate(), incomingAllegation.getAbuseFrequency(), incomingAllegation.getAbuseFrequencyPeriodCode(), incomingAllegation.getAbuseLocationDescription(), incomingAllegation.getAbuseStartDate(), incomingAllegation.getAllegationDispositionType(), incomingAllegation.getAllegationType(), incomingAllegation.getDispositionDescription(), incomingAllegation.getDispositionDate(), incomingAllegation.getInjuryHarmDetailIndicator(), incomingAllegation.getNonProtectingParentCode(), incomingAllegation.getStaffPersonAddedIndicator(), incomingAllegation.getVictimClientId(), incomingAllegation.getPerpetratorClientId(), referralId, incomingAllegation.getCountySpecificCode(), incomingAllegation.getZippyCreatedIndicator(), incomingAllegation.getPlacementFacilityType());
PostedAllegation postedallegation = this.allegationService.create(allegation);
resultAllegation.add(postedallegation);
}
}
Set<CrossReport> resultCrossReport = new LinkedHashSet<>();
if (cmsReferral.getCrossReport() != null && !cmsReferral.getCrossReport().isEmpty()) {
for (CrossReport incomingCrossReport : cmsReferral.getCrossReport()) {
CrossReport crossReport = new CrossReport(incomingCrossReport.getThirdId(), incomingCrossReport.getCrossReportMethodType(), incomingCrossReport.getFiledOutOfStateIndicator(), incomingCrossReport.getGovernmentOrgCrossRptIndicatorVar(), incomingCrossReport.getInformTime(), incomingCrossReport.getRecipientBadgeNumber(), incomingCrossReport.getRecipientPhoneExtensionNumber(), incomingCrossReport.getRecipientPhoneNumber(), incomingCrossReport.getInformDate(), incomingCrossReport.getRecipientPositionTitleDesc(), incomingCrossReport.getReferenceNumber(), referralId, incomingCrossReport.getLawEnforcementId(), incomingCrossReport.getStaffPersonId(), incomingCrossReport.getDescription(), incomingCrossReport.getRecipientName(), incomingCrossReport.getOutStateLawEnforcementAddr(), incomingCrossReport.getCountySpecificCode(), incomingCrossReport.getLawEnforcementIndicator(), incomingCrossReport.getOutStateLawEnforcementIndicator(), incomingCrossReport.getSatisfyCrossReportIndicator());
crossReport = this.crossReportService.create(crossReport);
resultCrossReport.add(crossReport);
}
}
Set<ReferralClient> resultReferralClient = new LinkedHashSet<>();
if (cmsReferral.getReferralClient() != null && !cmsReferral.getReferralClient().isEmpty()) {
for (ReferralClient incomingReferralClient : cmsReferral.getReferralClient()) {
ReferralClient referralClient = new ReferralClient(incomingReferralClient.getApprovalNumber(), incomingReferralClient.getApprovalStatusType(), incomingReferralClient.getDispositionClosureReasonType(), incomingReferralClient.getDispositionCode(), incomingReferralClient.getDispositionDate(), incomingReferralClient.getSelfReportedIndicator(), incomingReferralClient.getStaffPersonAddedIndicator(), referralId, (String) clientIds.toArray()[clientInst], incomingReferralClient.getDispositionClosureDescription(), incomingReferralClient.getAgeNumber(), incomingReferralClient.getAgePeriodCode(), incomingReferralClient.getCountySpecificCode(), incomingReferralClient.getMentalHealthIssuesIndicator(), incomingReferralClient.getAlcoholIndicator(), incomingReferralClient.getDrugIndicator());
referralClient = this.referralClientService.create(referralClient);
resultReferralClient.add(referralClient);
clientInst++;
}
}
PostedReporter savedreporter = new PostedReporter();
if (cmsReferral.getReporter() != null) {
Reporter incomingReporter = cmsReferral.getReporter();
Reporter reporter = new Reporter(incomingReporter.getBadgeNumber(), incomingReporter.getCityName(), incomingReporter.getColltrClientRptrReltnshpType(), incomingReporter.getCommunicationMethodType(), incomingReporter.getConfidentialWaiverIndicator(), incomingReporter.getDrmsMandatedRprtrFeedback(), incomingReporter.getEmployerName(), incomingReporter.getFeedbackDate(), incomingReporter.getFeedbackRequiredIndicator(), incomingReporter.getFirstName(), incomingReporter.getLastName(), incomingReporter.getMandatedReporterIndicator(), incomingReporter.getMessagePhoneExtensionNumber(), incomingReporter.getMessagePhoneNumber(), incomingReporter.getMiddleInitialName(), incomingReporter.getNamePrefixDescription(), incomingReporter.getPrimaryPhoneNumber(), incomingReporter.getPrimaryPhoneExtensionNumber(), incomingReporter.getStateCodeType(), incomingReporter.getStreetName(), incomingReporter.getStreetNumber(), incomingReporter.getSuffixTitleDescription(), incomingReporter.getZipcode(), referralId, incomingReporter.getLawEnforcementId(), incomingReporter.getZipSuffixNumber(), incomingReporter.getCountySpecificCode());
PostedReporter postedreporter = this.reporterService.create(reporter);
savedreporter = postedreporter;
}
return new PostedCmsReferral(referral, postedClients, resultAllegation, resultCrossReport, resultReferralClient, savedreporter);
}
Aggregations