Skip to content

Commit

Permalink
Correction to the event datastructure
Browse files Browse the repository at this point in the history
Signed-off-by: Loganathan Sekar <[email protected]>
  • Loading branch information
Loganathan Sekar authored and Loganathan Sekar committed Feb 26, 2024
1 parent 9e54bb6 commit 9f3ad0d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ public class DecryptedEventDto {
public static class Event {
public static class Context {
public static class Entry {
public static class Coding {
public String system;
public String code;
}
public static class Resource {
public static class Focus {
public String reference;
}
public static class Identifier{
public String type;
public static class Type{
public List<Coding> coding;
}
public Type type;
public String system;
public String value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
package io.mosip.opencrvs.service;

import io.mosip.kernel.core.exception.BaseCheckedException;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.kernel.core.util.DateUtils;
import io.mosip.kernel.core.util.HMACUtils2;
import io.mosip.opencrvs.constant.ApiName;
import io.mosip.opencrvs.constant.Constants;
import io.mosip.opencrvs.constant.LoggingConstants;
import io.mosip.opencrvs.dto.BaseEventRequest;
import io.mosip.opencrvs.dto.DecryptedEventDto;
import io.mosip.opencrvs.error.ErrorCode;
import io.mosip.opencrvs.util.LogUtil;
import io.mosip.opencrvs.util.OpencrvsCryptoUtil;
import io.mosip.opencrvs.util.OpencrvsDataUtil;
import io.mosip.opencrvs.util.RestTokenUtil;
import java.util.Collections;
import java.util.List;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.core.env.Environment;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import io.mosip.kernel.core.exception.BaseCheckedException;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.kernel.core.util.DateUtils;
import io.mosip.opencrvs.constant.ApiName;
import io.mosip.opencrvs.constant.Constants;
import io.mosip.opencrvs.constant.LoggingConstants;
import io.mosip.opencrvs.dto.BaseEventRequest;
import io.mosip.opencrvs.dto.DecryptedEventDto;
import io.mosip.opencrvs.error.ErrorCode;
import io.mosip.opencrvs.util.LogUtil;
import io.mosip.opencrvs.util.OpencrvsDataUtil;
import io.mosip.opencrvs.util.RestTokenUtil;

@Service
public class DeathEventHandlerService {
Expand Down Expand Up @@ -124,7 +118,7 @@ public String getUINFromDecryptedEvent(DecryptedEventDto decryptedEventDto) thro
throw ErrorCode.MISSING_UIN_IN_DEATH_EVENT.throwChecked();
}
for(DecryptedEventDto.Event.Context.Entry.Resource.Identifier identifier: patient.identifier){
if("NATIONAL_ID".equals(identifier.type)){
if("NATIONAL_ID".equals(OpencrvsDataUtil.getTypeCode(identifier))){
return identifier.value;
}
}
Expand Down
39 changes: 23 additions & 16 deletions mediator/src/main/java/io/mosip/opencrvs/util/OpencrvsDataUtil.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
package io.mosip.opencrvs.util;

import io.mosip.kernel.core.exception.BaseCheckedException;
import io.mosip.kernel.core.exception.BaseUncheckedException;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.kernel.core.util.StringUtils;
import io.mosip.opencrvs.constant.LoggingConstants;
import io.mosip.opencrvs.dto.DecryptedEventDto;
import io.mosip.opencrvs.dto.ReceiveDto;
import io.mosip.opencrvs.error.ErrorCode;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import io.mosip.kernel.core.logger.spi.Logger;
import io.mosip.kernel.core.util.StringUtils;
import io.mosip.opencrvs.constant.LoggingConstants;
import io.mosip.opencrvs.dto.DecryptedEventDto;
import io.mosip.opencrvs.dto.DecryptedEventDto.Event.Context.Entry.Resource.Identifier;
import io.mosip.opencrvs.dto.ReceiveDto;
import io.mosip.opencrvs.error.ErrorCode;

@Component
public class OpencrvsDataUtil {
Expand Down Expand Up @@ -127,13 +124,23 @@ public ReceiveDto buildIdJson(DecryptedEventDto opencrvsRequestBody){

public String getOpencrvsBRNFromPatientBody(DecryptedEventDto.Event.Context.Entry.Resource patient){
for(DecryptedEventDto.Event.Context.Entry.Resource.Identifier identifier : patient.identifier){
if("BIRTH_REGISTRATION_NUMBER".equals(identifier.type)){
if("BIRTH_REGISTRATION_NUMBER".equals(getTypeCode(identifier))){
return identifier.value;
}
}
return null;
}

public static String getTypeCode(DecryptedEventDto.Event.Context.Entry.Resource.Identifier identifier) {
return Optional.ofNullable(identifier)
.map(id -> id.type)
.map(typ -> typ.coding)
.filter(codings -> !codings.isEmpty())
.map(codings -> codings.get(0))
.map(coding -> coding.code)
.orElse("");
}

public String getFullNameFromPatientBody(DecryptedEventDto.Event.Context.Entry.Resource patient){
try{
String ret = "";
Expand Down Expand Up @@ -220,7 +227,7 @@ public String getRidFromBody(DecryptedEventDto decryptedEvent){
for(DecryptedEventDto.Event.Context.Entry entry: contextEntries) {
if ("Patient".equals(entry.resource.resourceType)) {
for(DecryptedEventDto.Event.Context.Entry.Resource.Identifier identifier : entry.resource.identifier){
if("MOSIP_AID".equals(identifier.type)){
if("MOSIP_AID".equals(getTypeCode(identifier))){
return identifier.value;
}
}
Expand Down

0 comments on commit 9f3ad0d

Please sign in to comment.