Skip to content

Commit

Permalink
feat: AuthorInstitution
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenzo-ingenito committed Sep 26, 2024
1 parent 315d03b commit 179833e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public class FhirSRV implements IFhirSRV {

@Override
public ResourceDTO createFhirResources(final String cda, String authorRole,final PublicationCreateReplaceMetadataDTO requestBody,
final Integer size, final String hash, String transformId, String engineId, String organizationId,final String authorInstitution,String sha1) {
final Integer size, final String hash, String transformId, String engineId, String organizationId,
final String authorInstitution,String sha1) {

final ResourceDTO output = new ResourceDTO();
final org.jsoup.nodes.Document docCDA = Jsoup.parse(cda);
Expand All @@ -70,16 +71,8 @@ public ResourceDTO createFhirResources(final String cda, String authorRole,final
final DocumentReferenceDTO documentReferenceDTO = buildDocumentReferenceDTO(encodedCDA, requestBody, size, hash);
FhirResourceDTO req = buildFhirResourceDTO(documentReferenceDTO, cda, transformId, engineId);

AuthorSlotDTO authorSlot = buildAuthorSlotDTO(authorRole,docCDA);
AuthorSlotDTO authorSlot = buildAuthorSlotDTO(authorInstitution,authorRole,docCDA);

// final TransformResDTO resDTO = client.callConvertCdaInBundle(req);

// if (!StringUtility.isNullOrEmpty(resDTO.getErrorMessage())) {
// output.setErrorMessage(resDTO.getErrorMessage());
// } else {
// output.setBundleJson(StringUtility.toJSON(resDTO.getJson()));

// AuthorSlotDTO authorSlot = buildAuthorSlotDTO(authorRole,docCDA);

try {
final SubmissionSetEntryDTO submissionSetEntryDTO = createSubmissionSetEntry(docCDA, requestBody.getTipoAttivitaClinica().getCode(),
Expand Down Expand Up @@ -266,21 +259,10 @@ private String buildPatient(final org.jsoup.nodes.Document docCDA) {
}


private static AuthorSlotDTO buildAuthorSlotDTO(final String authorRole,final org.jsoup.nodes.Document docCDA) {
private static AuthorSlotDTO buildAuthorSlotDTO(final String authorInstitution,final String authorRole,final org.jsoup.nodes.Document docCDA) {
AuthorSlotDTO author = new AuthorSlotDTO();
author.setAuthorRole(authorRole);
String representedOrganizationTag = "ClinicalDocument > author > assignedAuthor > representedOrganization";
final Element authorInstitutionElement = docCDA.select(representedOrganizationTag + " > id").first();
final Element authorInstitutionName = docCDA.select(representedOrganizationTag + " > name").first();
if (authorInstitutionElement != null && authorInstitutionName!=null) {
String extension = authorInstitutionElement.attr(EXTENSION_ATTRIBUTE);
String root = authorInstitutionElement.attr("root");
String name = authorInstitutionName.text();
author.setAuthorInstitution(name + "^^^^^&" + root + "&ISO^^^^" + extension);
} else {
author.setAuthorInstitution("AUTHOR_INSTITUTION_NOT_PRESENT");
}

author.setAuthorInstitution(authorInstitution);
final Element authorElement = docCDA.select("ClinicalDocument > author > assignedAuthor > id").first();
if (authorElement != null) {
String cfAuthor = authorElement.attr(EXTENSION_ATTRIBUTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import static org.apache.commons.lang3.StringUtils.isEmpty;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

import java.util.regex.Pattern;

import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -31,10 +33,6 @@
import it.finanze.sanita.fse2.ms.gtw.dispatcher.enums.SystemTypeEnum;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.exceptions.ValidationException;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.service.IJwtSRV;
import it.finanze.sanita.fse2.ms.gtw.dispatcher.utility.StringUtility;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Service
public class JwtSRV extends AbstractService implements IJwtSRV {
Expand Down Expand Up @@ -72,7 +70,7 @@ public void validatePayloadForCreate(JWTPayloadDTO payload) {
validateActionCoherence(payload, ActionEnum.CREATE);
performCommonValidation(payload);
validatePurposeOfUseCoherence(payload, PurposeOfUseEnum.TREATMENT);
isValidLocality(payload.getLocality(),true);
isValidLocality(payload.getLocality());
}

@Override
Expand All @@ -81,23 +79,21 @@ public void validatePayloadForReplace(JWTPayloadDTO payload) {
checkNull(payload.getResource_hl7_type(), "resource_hl7_type");
validateActionCoherence(payload, ActionEnum.UPDATE);
validatePurposeOfUseCoherence(payload, PurposeOfUseEnum.UPDATE);
isValidLocality(payload.getLocality(),true);
isValidLocality(payload.getLocality());
}

@Override
public void validatePayloadForUpdate(JWTPayloadDTO payload) {
performCommonValidation(payload);
validateActionCoherence(payload, ActionEnum.UPDATE);
validatePurposeOfUseCoherence(payload, PurposeOfUseEnum.UPDATE);
isValidLocality(payload.getLocality(),false);
}

@Override
public void validatePayloadForDelete(JWTPayloadDTO payload) {
performCommonValidation(payload);
validateActionCoherence(payload, ActionEnum.DELETE);
validatePurposeOfUseCoherence(payload, PurposeOfUseEnum.UPDATE);
isValidLocality(payload.getLocality(),false);
}

private void performCommonValidation(JWTPayloadDTO payload) {
Expand Down Expand Up @@ -233,7 +229,7 @@ public void checkFiscalCode(String givenValue, String fieldName) {
throw new ValidationException(error);
}
}


private boolean isValidOid(String oid) {
if (oid == null)
Expand Down Expand Up @@ -264,19 +260,12 @@ private ValidationException buildValidationException() {
}


public void isValidLocality(String input, boolean checkCreateAndReplace) {
String regex;
if (checkCreateAndReplace) {
// Nuova regex per il primo formato (senza "locality")
regex = "^[A-Z0-9_]+(\\^)+&\\d+(?:\\.\\d+)+&[A-Z0-9_]+(\\^)+[A-Z0-9_]+$";
} else {
// Regex per il secondo formato (con numeri e "&")
regex = "^\\d+(?:\\.\\d+)+&[A-Z0-9_]+(\\^\\^)+[A-Z0-9_]+$";
}
public void isValidLocality(String input) {
String regex = "^[a-zA-Z0-9]+[^\\^]*\\^\\^\\^\\^\\^\\&[^&]*\\&ISO\\^\\^\\^\\^[^\\^&]*$";
boolean isValid = Pattern.matches(regex, input);
if (!isValid) {
throw buildValidationException();
}
}

}

0 comments on commit 179833e

Please sign in to comment.