Skip to content

Commit

Permalink
operationOutcomeException handling
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinMayfield committed Jul 13, 2018
1 parent fe50cff commit 411d2fc
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam CarePl
method.setOperationOutcome(opOutcome);

try {
CarePlan newCarePlan = carePlanDao.create(ctx,carePlan, theId, theConditional);
method.setId(newCarePlan.getIdElement());
method.setResource(newCarePlan);
CarePlan newCarePlan = carePlanDao.create(ctx,carePlan, theId, theConditional);
method.setId(newCarePlan.getIdElement());
method.setResource(newCarePlan);
} catch (Exception ex) {

if (ex instanceof OperationOutcomeException) {
Expand Down Expand Up @@ -87,11 +87,21 @@ public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam CarePl

method.setOperationOutcome(opOutcome);


CarePlan newCarePlan = carePlanDao.create(ctx,carePlan, null,null);
method.setId(newCarePlan.getIdElement());
method.setResource(newCarePlan);

try {
CarePlan newCarePlan = carePlanDao.create(ctx,carePlan, null,null);
method.setId(newCarePlan.getIdElement());
method.setResource(newCarePlan);
} catch (Exception ex) {
if (ex instanceof OperationOutcomeException) {
OperationOutcomeException outcomeException = (OperationOutcomeException) ex;
method.setOperationOutcome(outcomeException.getOutcome());
method.setCreated(false);
} else {
log.error(ex.getMessage());
method.setCreated(false);
method.setOperationOutcome(OperationOutcomeFactory.createOperationOutcome(ex.getMessage()));
}
}


return method;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public MethodOutcome update(HttpServletRequest theRequest, @ResourceParam Compos
OperationOutcome opOutcome = new OperationOutcome();
method.setOperationOutcome(opOutcome);
try {
Composition newComposition = compositionDao.create(ctx,composition, theId, theConditional);
method.setId(newComposition.getIdElement());
method.setResource(newComposition);
Composition newComposition = compositionDao.create(ctx,composition, theId, theConditional);
method.setId(newComposition.getIdElement());
method.setResource(newComposition);
} catch (Exception ex) {

if (ex instanceof OperationOutcomeException) {
Expand All @@ -84,10 +84,22 @@ public MethodOutcome create(HttpServletRequest theRequest, @ResourceParam Compos
method.setCreated(true);
OperationOutcome opOutcome = new OperationOutcome();
method.setOperationOutcome(opOutcome);
try {
Composition newComposition = compositionDao.create(ctx,composition, null,null);
method.setId(newComposition.getIdElement());
method.setResource(newComposition);
} catch (Exception ex) {

Composition newComposition = compositionDao.create(ctx,composition, null,null);
method.setId(newComposition.getIdElement());
method.setResource(newComposition);
if (ex instanceof OperationOutcomeException) {
OperationOutcomeException outcomeException = (OperationOutcomeException) ex;
method.setOperationOutcome(outcomeException.getOutcome());
method.setCreated(false);
} else {
log.error(ex.getMessage());
method.setCreated(false);
method.setOperationOutcome(OperationOutcomeFactory.createOperationOutcome(ex.getMessage()));
}
}

return method;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
import org.hl7.fhir.dstu3.model.IdType;
import org.hl7.fhir.dstu3.model.OperationOutcome;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import uk.nhs.careconnect.fhir.OperationOutcomeException;
import uk.nhs.careconnect.ri.daointerface.EpisodeOfCareRepository;
import uk.nhs.careconnect.ri.lib.OperationOutcomeFactory;

Expand All @@ -36,6 +39,7 @@ public Class<? extends IBaseResource> getResourceType() {
return EpisodeOfCare.class;
}

private static final Logger log = LoggerFactory.getLogger(EpisodeOfCareProvider.class);

@Override
public Long count() {
Expand All @@ -52,10 +56,23 @@ public MethodOutcome updateEpisodeOfCare(HttpServletRequest theRequest, @Resourc

method.setOperationOutcome(opOutcome);

try {
EpisodeOfCare newEpisodeOfCare = episodeDao.create(ctx, episode, theId, theConditional);
method.setId(newEpisodeOfCare.getIdElement());
method.setResource(newEpisodeOfCare);
} catch (Exception ex) {

if (ex instanceof OperationOutcomeException) {
OperationOutcomeException outcomeException = (OperationOutcomeException) ex;
method.setOperationOutcome(outcomeException.getOutcome());
method.setCreated(false);
} else {
log.error(ex.getMessage());
method.setCreated(false);
method.setOperationOutcome(OperationOutcomeFactory.createOperationOutcome(ex.getMessage()));
}
}

EpisodeOfCare newEpisodeOfCare = episodeDao.create(ctx,episode, theId, theConditional);
method.setId(newEpisodeOfCare.getIdElement());
method.setResource(newEpisodeOfCare);



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public MethodOutcome updateHealthcareService(HttpServletRequest theRequest, @Res
method.setOperationOutcome(opOutcome);

try {
HealthcareService newHealthcareService = serviceDao.create(ctx, service, theId, theConditional);
method.setId(newHealthcareService.getIdElement());
method.setResource(newHealthcareService);
HealthcareService newHealthcareService = serviceDao.create(ctx, service, theId, theConditional);
method.setId(newHealthcareService.getIdElement());
method.setResource(newHealthcareService);
} catch (Exception ex) {

if (ex instanceof OperationOutcomeException) {
Expand All @@ -75,8 +75,6 @@ public MethodOutcome updateHealthcareService(HttpServletRequest theRequest, @Res
}




return method;
}

Expand All @@ -90,9 +88,23 @@ public MethodOutcome createHealthcareService(HttpServletRequest theRequest, @Res

method.setOperationOutcome(opOutcome);

HealthcareService newHealthcareService = serviceDao.create(ctx, service,null,null);
method.setId(newHealthcareService.getIdElement());
method.setResource(newHealthcareService);
try {
HealthcareService newHealthcareService = serviceDao.create(ctx, service,null,null);
method.setId(newHealthcareService.getIdElement());
method.setResource(newHealthcareService);
} catch (Exception ex) {

if (ex instanceof OperationOutcomeException) {
OperationOutcomeException outcomeException = (OperationOutcomeException) ex;
method.setOperationOutcome(outcomeException.getOutcome());
method.setCreated(false);
} else {
log.error(ex.getMessage());
method.setCreated(false);
method.setOperationOutcome(OperationOutcomeFactory.createOperationOutcome(ex.getMessage()));
}
}


return method;
}
Expand Down

0 comments on commit 411d2fc

Please sign in to comment.